Commit a6c27e2f by David

Blank step hash become empty strings

Blank step hash become empty strings
parent 5c51567e
...@@ -112,7 +112,7 @@ def print_step_ran(step): ...@@ -112,7 +112,7 @@ def print_step_ran(step):
else: else:
lines_up = int(lines_up) + 1 lines_up = int(lines_up) + 1
prefix = prefix * lines_up #prefix = prefix * lines_up
if step.failed: if step.failed:
color = "\033[0;31m" color = "\033[0;31m"
......
...@@ -39,6 +39,10 @@ def get_stripped_lines(string, ignore_lines_starting_with=''): ...@@ -39,6 +39,10 @@ def get_stripped_lines(string, ignore_lines_starting_with=''):
def split_wisely(string, sep, strip=False): def split_wisely(string, sep, strip=False):
string = unicode(string) string = unicode(string)
if strip:
string=string.strip()
else:
string=string.strip("\n")
sep = unicode(sep) sep = unicode(sep)
regex = re.compile(escape_if_necessary(sep), re.UNICODE | re.M | re.I) regex = re.compile(escape_if_necessary(sep), re.UNICODE | re.M | re.I)
...@@ -49,7 +53,7 @@ def split_wisely(string, sep, strip=False): ...@@ -49,7 +53,7 @@ def split_wisely(string, sep, strip=False):
else: else:
items = [i.strip("\n") for i in items] items = [i.strip("\n") for i in items]
return [unicode(i) for i in items if i] return [unicode(i) for i in items]
def wise_startswith(string, seed): def wise_startswith(string, seed):
string = unicode(string) string = unicode(string)
......
...@@ -42,7 +42,7 @@ def assert_lines(original, expected): ...@@ -42,7 +42,7 @@ def assert_lines(original, expected):
def assert_lines_unicode(original, expected): def assert_lines_unicode(original, expected):
if original != expected: if original != expected:
diff = ''.join(list(Differ().compare(expected.splitlines(1), original.splitlines(1)))) diff = ''.join(list(Differ().compare(expected.splitlines(1), original.splitlines(1))))
raise AssertionError, 'Output differed as follows:\n' + diff + "\nOutput was:\n" + original raise AssertionError, 'Output differed as follows:\n' + diff + "\nOutput was:\n" + original +"\nExpected was:\n"+expected
assert_equals(len(expected), len(original), 'Output appears equal, but of different lengths.') assert_equals(len(expected), len(original), 'Output appears equal, but of different lengths.')
......
Feature: Allow blanks in steps
Scenario: blank values default to blank strings
Given I ignore step
When I ignore step
Then the string length calc should be correct:
| string | string2 | length |
| car | bike | 7 |
| | bike | 4 |
| car | | 3 |
And I ignore step
...@@ -1043,3 +1043,32 @@ def test_commented_scenario(): ...@@ -1043,3 +1043,32 @@ def test_commented_scenario():
"1 step (1 passed)\n" "1 step (1 passed)\n"
) )
#with_setup(prepare_stderr)
@with_setup(prepare_stdout)
def test_blank_step_hash_value():
"syntax checking: Blank in step hash column = empty string"
from lettuce import step
@step('ignore step')
def append_2_more(step):
pass
@step('string length calc')
def append_2_more(step):
for hash in step.hashes:
if len(hash["string"])+len(hash["string2"]) != int(hash["length"]):
raise AssertionError("fail")
filename = syntax_feature_name('blank_values_in_hash')
runner = Runner(filename, verbosity=1)
runner.run()
assert_stdout_lines(
"...."
"\n"
"1 feature (1 passed)\n"
"1 scenario (1 passed)\n"
"4 steps (4 passed)\n"
)
...@@ -253,3 +253,36 @@ def test_parse_hashes_escapes_pipes(): ...@@ -253,3 +253,36 @@ def test_parse_hashes_escapes_pipes():
assert_equals(keys, got_keys) assert_equals(keys, got_keys)
assert_equals(dicts, got_dicts) assert_equals(dicts, got_dicts)
def test_parse_hashes_allow_empty():
"strings.parse_hashes allow empty"
keys = [u'name', u'age']
dicts = [
{
u'name': u'Gabriel',
u'age': u'22'
},
{
u'name': u'',
u'age': u'33'
},
{
u'name': u'Dave',
u'age': u''
}
]
table = [
u"| name | age |\n",
u"| Gabriel | 22 |\n",
u"| | 33 |\n",
u"| Dave | |\n",
]
got_keys, got_dicts = strings.parse_hashes(table)
assert_equals(keys, got_keys)
assert_equals(dicts, got_dicts)
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