allow empty example values

This commit is contained in:
Anatoly Bubenkov 2014-03-27 11:52:39 +01:00
parent 689a34b579
commit dbe3f9da31
6 changed files with 69 additions and 6 deletions

View File

@ -5,6 +5,7 @@ Changelog
-----
- Allow more than one parameter per step (bubenkoff)
- Allow empty example values (bubenkoff)
2.0.0

View File

@ -79,8 +79,8 @@ def get_step_params(name):
return tuple(frozenset(STEP_PARAM_RE.findall(name)))
def strip(line):
"""Remove leading and trailing whitespaces and comments.
def strip_comments(line):
"""Remove comments.
:param line: Line of the Feature file.
:return: Stripped line.
@ -147,7 +147,8 @@ class Feature(object):
with _open_file(filename, encoding) as f:
content = force_unicode(f.read(), encoding)
for line_number, line in enumerate(content.splitlines()):
line = strip(line)
raw_line = line.strip()
line = strip_comments(line)
if not line:
continue
mode = get_step_type(line) or mode
@ -182,12 +183,12 @@ class Feature(object):
elif mode == types.EXAMPLES_VERTICAL:
mode = types.EXAMPLE_LINE_VERTICAL
elif mode == types.EXAMPLES_HEADERS:
scenario.set_param_names([l.strip() for l in line.split('|') if l.strip()])
scenario.set_param_names([l.strip() for l in line.split('|')[1:-1] if l.strip()])
mode = types.EXAMPLE_LINE
elif mode == types.EXAMPLE_LINE:
scenario.add_example([l.strip() for l in line.split('|') if l.strip()])
scenario.add_example([l.strip() for l in raw_line.split('|')[1:-1]])
elif mode == types.EXAMPLE_LINE_VERTICAL:
line = [l.strip() for l in line.split('|') if l.strip()]
line = [l.strip() for l in raw_line.split('|')[1:-1]]
scenario.add_example_row(line[0], line[1:])
elif mode and mode != types.FEATURE:
scenario.add_step(step_name=line, step_type=mode)

View File

@ -0,0 +1,3 @@
Scenario: Comments
# Comment
Given I have a bar

View File

@ -39,3 +39,24 @@ Scenario Outline: Outlined with vertical example table
| start | 12 | 2 |
| eat | 5 | 1 |
| left | 7 | 1 |
Scenario Outline: Outlined with empty example values vertical
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples: Vertical
| start | # |
| eat | |
| left | |
Scenario Outline: Outlined with empty example values
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| # | | |

View File

@ -79,3 +79,27 @@ def test_vertical_example():
"""Test outlined scenario with vertical examples table."""
assert test_vertical_example.parametrize.args == (
[u'start', u'eat', u'left'], [[12, 5.0, '7'], [2, 1.0, '1']])
def test_empty_example_values():
"""Test outlined scenario with empty example values."""
@scenario(
'outline.feature',
'Outlined with empty example values',
)
def test_scenario():
pass
assert test_scenario.parametrize.args == (
[u'start', u'eat', u'left'], [['#', '', '']])
@scenario(
'outline.feature',
'Outlined with empty example values vertical',
)
def test_scenario():
pass
assert test_scenario.parametrize.args == (
[u'start', u'eat', u'left'], [['#', '', '']])

View File

@ -13,3 +13,16 @@ def test_scenario_not_found(request):
'not_found.feature',
'NOT FOUND'
)
def test_scenario_comments(request):
"""Test comments inside scenario."""
@scenario(
'comments.feature',
'Comments'
)
def test():
pass
test(request)