Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #47 from sh1r0/bug722330
Browse files Browse the repository at this point in the history
support unmatched syntax for bulk cases form
  • Loading branch information
camd committed Dec 19, 2013
2 parents 18c7874 + bb7d58f commit 502303f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
4 changes: 3 additions & 1 deletion moztrap/model/library/bulk.py
Expand Up @@ -91,13 +91,15 @@ def description(self, lc, orig, data):

def instruction(self, lc, orig, data):
"""Expecting to encounter a step instruction."""
if lc.startswith("when ") or lc.startswith("and when ") or lc.startswith("test that "):
return self.expectedresult(lc, orig, data)
if lc.startswith("then "):
data[-1]["steps"][-1]["expected"] = [orig]
return self.expectedresult
data[-1]["steps"][-1]["instruction"].append(orig)
return self.instruction
instruction.keys = ["then "]
instruction.expect_end = False
instruction.expect_end = True


def expectedresult(self, lc, orig, data):
Expand Down
89 changes: 72 additions & 17 deletions tests/model/library/test_bulk.py
Expand Up @@ -220,14 +220,16 @@ def test_early_end_description(self):
)


def test_early_end_instruction(self):
"""Unexpected end of input in the midst of a step causes error."""
def test_early_end_after_and(self):
"""Unexpected end of input after 'and' is ok."""
self.assertEqual(
self.parser().parse(
textwrap.dedent("""
Test That a perfectly good name
And a good description
When insufficiently assisted
Then may not
And
""")
),
[
Expand All @@ -237,41 +239,94 @@ def test_early_end_instruction(self):
"steps": [
{
"instruction": "When insufficiently assisted",
"expected": "Then may not",
},
],
"error": (
"Unexpected end of input, looking for 'Then '"
"Unexpected end of input, looking for 'When '"
),
},
]
)


def test_early_end_after_and(self):
"""Unexpected end of input after 'and' is ok."""
def test_unmatched_when_then(self):
"""Unexpected end of input in the midst of a step causes error."""
self.assertEqual(
self.parser().parse(
textwrap.dedent("""
Test That a perfectly good name
And a good description
When insufficiently assisted
Then may not
And
Test that this case is good
when ever you are
tesT that this case is better
when it's there
Test that bulk parsing works
When I type a sonnet in the textarea
And I sing my sonnet aloud
And when I click the submit button
When I am done
Then I feel satisfied
wHen nothing happens
tEst that another testcase works
With any old description
whEn I do this thing
""")
),
[
{
"name": "Test That a perfectly good name",
"description": "And a good description",
"name": "Test that this case is good",
"description": "",
"steps": [
{
"instruction": "When insufficiently assisted",
"expected": "Then may not",
"instruction": (
"when ever you are"
),
},
]
},
{
"name": "tesT that this case is better",
"description": "",
"steps": [
{
"instruction": (
"when it's there"
),
},
]
},
{
"name": "Test that bulk parsing works",
"description": "",
"steps": [
{
"instruction": (
"When I type a sonnet in the textarea\n"
"And I sing my sonnet aloud"
),
},
{
"instruction": "And when I click the submit button",
},
{
"instruction": "When I am done",
"expected": "Then I feel satisfied",
},
{
"instruction": "wHen nothing happens",
},
]
},
{
"name": "tEst that another testcase works",
"description": "With any old description",
"steps": [
{
"instruction": (
"whEn I do this thing"
),
},
],
"error": (
"Unexpected end of input, looking for 'When '"
),
},
]
)

0 comments on commit 502303f

Please sign in to comment.