Commit af0d68f6 by Gabriel Falcão

renamed Step's member "data_list" to "hashes" to look more likely cucumber :)

parent 336b9c38
......@@ -24,18 +24,18 @@ from lettuce.registry import CALLBACK_REGISTRY
from lettuce.exceptions import ReasonToFail
from lettuce.exceptions import NoDefinitionFound
def parse_data_list(lines):
def parse_hashes(lines):
keys = []
data_list = []
hashes = []
if lines:
first_line = lines.pop(0)
keys = strings.split_wisely(first_line, "|", True)
for line in lines:
values = strings.split_wisely(line, "|", True)
data_list.append(dict(zip(keys, values)))
hashes.append(dict(zip(keys, values)))
return keys, data_list
return keys, hashes
class StepDefinition(object):
"""A step definition is a wrapper for user-defined callbacks. It
......@@ -122,10 +122,10 @@ class Step(object):
self.sentence = sentence
self.original_sentence = sentence
self._remaining_lines = remaining_lines
keys, data_list = self._parse_remaining_lines(remaining_lines)
keys, hashes = self._parse_remaining_lines(remaining_lines)
self.keys = tuple(keys)
self.data_list = list(data_list)
self.hashes = list(hashes)
self.described_at = StepDescription(line, filename)
def solve_and_clone(self, data):
......@@ -159,7 +159,7 @@ class Step(object):
max_length_original = len(self.original_sentence) + self.indentation
max_length = max([max_length_original, max_length_sentence])
for data in self.data_list:
for data in self.hashes:
key_size = self._calc_key_length(data)
if key_size > max_length:
max_length = key_size
......@@ -177,15 +177,15 @@ class Step(object):
where = self.defined_at
return strings.rfill(head, self.scenario.feature.max_length + 1, append='# %s:%d\n' % (where.file, where.line))
def represent_data_list(self):
lines = strings.dicts_to_string(self.data_list, self.keys).splitlines()
def represent_hashes(self):
lines = strings.dicts_to_string(self.hashes, self.keys).splitlines()
return "\n".join([(" " * self.table_indentation) + line for line in lines]) + "\n"
def __repr__(self):
return u'<Step: "%s">' % self.sentence
def _parse_remaining_lines(self, lines):
return parse_data_list(lines)
return parse_hashes(lines)
def _get_match(self, ignore_case):
matched, func = None, lambda: None
......@@ -444,7 +444,7 @@ class Scenario(object):
outlines = []
if len(splitted) is 2:
part = splitted[1]
keys, outlines = parse_data_list(strings.get_stripped_lines(part))
keys, outlines = parse_hashes(strings.get_stripped_lines(part))
lines = strings.get_stripped_lines(string)
scenario_line = lines.pop(0)
......
......@@ -58,8 +58,8 @@ def print_step_running(step):
string = step.represent_string(step.original_sentence)
string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')
write_out("%s%s" % (color, string))
if step.data_list:
for line in step.represent_data_list().splitlines():
if step.hashes:
for line in step.represent_hashes().splitlines():
write_out("\033[1;30m%s\033[0m\n" % line)
@after.each_step
......@@ -67,8 +67,8 @@ def print_step_ran(step):
if step.scenario.outlines:
return
if step.data_list:
write_out("\033[A" * (len(step.data_list) + 1))
if step.hashes:
write_out("\033[A" * (len(step.hashes) + 1))
string = step.represent_string(step.original_sentence)
......@@ -94,8 +94,8 @@ def print_step_ran(step):
write_out("%s%s%s" % (prefix, color, string))
if step.data_list:
for line in step.represent_data_list().splitlines():
if step.hashes:
for line in step.represent_hashes().splitlines():
write_out("%s%s\033[0m\n" % (color, line))
if step.failed:
......
......@@ -27,16 +27,16 @@ def wrt(what):
@before.each_step
def print_step_running(step):
wrt(step.represent_string(step.original_sentence))
if step.data_list:
wrt(step.represent_data_list())
if step.hashes:
wrt(step.represent_hashes())
@after.each_step
def print_step_ran(step):
if step.scenario.outlines:
return
if step.data_list:
wrt("\033[A" * (len(step.data_list) + 1))
if step.hashes:
wrt("\033[A" * (len(step.hashes) + 1))
if step.defined_at:
wrt("\033[A" + step.represent_string(step.original_sentence))
......@@ -44,8 +44,8 @@ def print_step_ran(step):
else:
wrt(step.represent_string(step.original_sentence).rstrip() + " (undefined)\n")
if step.data_list:
wrt(step.represent_data_list())
if step.hashes:
wrt(step.represent_hashes())
if step.failed:
print_spaced = lambda x: wrt("%s%s\n" % (" " * step.indentation, x))
......
......@@ -31,7 +31,7 @@ def compare_bucks(step, cash):
@step('I have these items')
def havetheseitems(step):
cars = {}
for data in step.data_list:
for data in step.hashes:
key = data['name']
value = int(data['price'])
cars[key] = value
......@@ -46,7 +46,7 @@ def sell_item(step, name):
@step('my garage contains:')
def alsothese(step):
cars = {}
for data in step.data_list:
for data in step.hashes:
key = data['name']
value = int(data['price'])
cars[key] = value
......
......@@ -131,12 +131,12 @@ def test_step_represent_string_when_defined():
)
def test_step_represent_table():
"Step.represent_data_list"
"Step.represent_hashes"
step = core.Step.from_string(STEP_WITH_TABLE)
assert_equals(
step.represent_data_list(),
step.represent_hashes(),
' | name | description |\n'
' | Glass | a nice glass to drink grape juice |\n'
' | Pasta | a pasta to cook and eat with grape juice in the glass |\n'
......@@ -153,7 +153,7 @@ Examples:
'''
def test_scenario_outline_represent_examples():
"Step.represent_data_list"
"Step.represent_hashes"
step = core.Scenario.from_string(SCENARIO_OUTLINE)
......
......@@ -168,7 +168,7 @@ def test_feature_has_scenarios():
assert_equals(feature.scenarios[1].steps[0].keys, ('Name', 'Rating', 'New', 'Available'))
assert_equals(
feature.scenarios[1].steps[0].data_list,
feature.scenarios[1].steps[0].hashes,
[
{'Name': 'A night at the museum 2', 'Rating': '3 stars', 'New': 'yes', 'Available': '9'},
{'Name': 'Matrix Revolutions', 'Rating': '4 stars', 'New': 'no', 'Available': '6'},
......
......@@ -137,7 +137,7 @@ def test_scenario_has_steps():
assert_equals(scenario.steps[0].keys, ('Name', 'Duration'))
assert_equals(
scenario.steps[0].data_list,
scenario.steps[0].hashes,
[
{'Name': 'Computer Science', 'Duration': '5 years'},
{'Name': 'Nutrition', 'Duration': '4 years'},
......
......@@ -56,10 +56,10 @@ def test_can_parse_tables():
step = Step.from_string(STEP1)
assert isinstance(step.data_list, list)
assert_equals(len(step.data_list), 2)
assert isinstance(step.hashes, list)
assert_equals(len(step.hashes), 2)
assert_equals(
step.data_list[0],
step.hashes[0],
{
'Name': 'Skol',
'Type': 'Beer',
......@@ -67,7 +67,7 @@ def test_can_parse_tables():
}
)
assert_equals(
step.data_list[1],
step.hashes[1],
{
'Name': 'Nestea',
'Type': 'Ice-tea',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment