def get_rules_from(features_list): """Execute gherkins and return rules.""" base_context = {'final_rules': []} runner = Runner(Configuration()) with empty_argv(): for data in features_list: with local_context(base_context, runner) as context: parse_feature(data.strip(), None, None).run(runner) yield from context.final_rules
def test_parses_feature_with_a_step_with_a_string_with_blank_lines(self): doc = u''' Feature: Stuff Scenario: Doing stuff Given there is stuff: """ So Much Stuff """ Then stuff happens '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert len(feature.scenarios) == 1 eq_(feature.scenarios[0].name, "Doing stuff") self.compare_steps( feature.scenarios[0].steps, [ ("given", "Given", "there is stuff", "So\n\nMuch\n\n\nStuff", None), ("then", "Then", "stuff happens", None, None), ], )
def test_parses_feature_with_a_scenario_with_and_and_but(self): doc = u""" Feature: Stuff Scenario: Doing stuff Given there is stuff And some other stuff When I do stuff Then stuff happens But not the bad stuff """.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert len(feature.scenarios) == 1 eq_(feature.scenarios[0].name, "Doing stuff") self.compare_steps( feature.scenarios[0].steps, [ ("given", "Given", "there is stuff", None, None), ("given", "And", "some other stuff", None, None), ("when", "When", "I do stuff", None, None), ("then", "Then", "stuff happens", None, None), ("then", "But", "not the bad stuff", None, None), ], )
def test_parses_feature_with_a_step_with_a_table_argument(self): doc = u""" Feature: Stuff Scenario: Doing stuff Given we classify stuff: | type of stuff | awesomeness | ridiculousness | | fluffy | large | frequent | | lint | low | high | | green | variable | awkward | Then stuff is in buckets """.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert len(feature.scenarios) == 1 eq_(feature.scenarios[0].name, "Doing stuff") table = model.Table( [u"type of stuff", u"awesomeness", u"ridiculousness"], 0, [[u"fluffy", u"large", u"frequent"], [u"lint", u"low", u"high"], [u"green", u"variable", u"awkward"]], ) self.compare_steps( feature.scenarios[0].steps, [("given", "Given", "we classify stuff", None, table), ("then", "Then", "stuff is in buckets", None, None)], )
def test_properly_handles_whitespace_on_keywords_that_do_not_want_it(self): doc = u""" # language: zh-TW \u529f\u80fd: I have no idea what I'm saying \u5834\u666f: No clue whatsoever \u5047\u8a2dI've got no idea \u7576I say things \u800c\u4e14People don't understand \u90a3\u9ebcPeople should laugh \u4f46\u662fI should take it well """ feature = parser.parse_feature(doc) eq_(feature.name, "I have no idea what I'm saying") eq_(len(feature.scenarios), 1) eq_(feature.scenarios[0].name, 'No clue whatsoever') self.compare_steps(feature.scenarios[0].steps, [ ('given', u'\u5047\u8a2d', "I've got no idea", None, None), ('when', u'\u7576', 'I say things', None, None), ('when', u'\u800c\u4e14', "People don't understand", None, None), ('then', u'\u90a3\u9ebc', "People should laugh", None, None), ('then', u'\u4f46\u662f', "I should take it well", None, None), ])
def test_parses_rule_with_scenario(self): text = u''' Feature: With Rule Rule: R4 Scenario: R4.Scenario_1 Given scenario step 1 When scenario step 2 '''.lstrip() feature = parse_feature(text) rule1 = feature.rules[0] rule1_scenario1 = rule1.scenarios[0] assert feature.name == "With Rule" assert feature.background is None assert len(feature.rules) == 1 assert len(feature.scenarios) == 0 assert rule1.name == "R4" assert rule1.description == [] assert rule1.tags == [] assert rule1.background is None assert len(rule1.scenarios) == 1 assert rule1_scenario1.name == "R4.Scenario_1" assert_compare_steps(rule1_scenario1.steps, [ ("given", "Given", "scenario step 1", None, None), ("when", "When", "scenario step 2", None, None), ])
def test_parses_rule_without_background_should_inherit_feature_background(self): """If a Rule has no Background, it inherits the Feature's Background (if one exists). """ text = u''' Feature: With Rule Background: Feature.Background Given feature background step 1 When feature background step 2 Rule: R3A Scenario: R3A.Scenario_1 Given scenario step 1 When scenario step 2 '''.lstrip() feature = parse_feature(text) rule1 = feature.rules[0] assert feature.name == "With Rule" assert feature.background is not None assert len(feature.rules) == 1 assert len(feature.scenarios) == 0 assert rule1.name == "R3A" assert rule1.description == [] assert rule1.tags == [] assert len(rule1.scenarios) == 1 assert rule1.background is feature.background assert_compare_steps(rule1.scenarios[0].all_steps, [ ("given", "Given", "feature background step 1", None, None), ("when", "When", "feature background step 2", None, None), ("given", "Given", "scenario step 1", None, None), ("when", "When", "scenario step 2", None, None), ])
def test_parses_rule_with_background(self): text = u''' Feature: With Rule Rule: R3 Background: R3.Background Given background step 1 When background step 2 '''.lstrip() feature = parse_feature(text) rule1 = feature.rules[0] assert feature.name == "With Rule" assert feature.background is None assert len(feature.rules) == 1 assert len(feature.scenarios) == 0 assert rule1.name == "R3" assert rule1.description == [] assert rule1.tags == [] assert len(rule1.scenarios) == 0 assert rule1.background is not None assert_compare_steps(rule1.background.steps, [ ("given", "Given", "background step 1", None, None), ("when", "When", "background step 2", None, None), ])
def test_parses_rule_with_description(self): text = u''' Feature: With Rule Rule: R3 Rule description line 1. Rule description line 2. Rule description line 3. '''.lstrip() feature = parse_feature(text) rule1 = feature.rules[0] assert feature.name == "With Rule" assert feature.background is None assert len(feature.rules) == 1 assert len(feature.scenarios) == 0 assert rule1.name == "R3" assert rule1.description == [ "Rule description line 1.", "Rule description line 2.", "Rule description line 3.", # -- HINT: EMPTY-LINES are ignored. ] assert rule1.tags == [] assert rule1.background is None assert len(rule1.scenarios) == 0
def test_use_example_alias(self): """HINT: Some Scenarios may exist before the first Rule.""" text = u''' Feature: With Example as Alias for Scenario Example: Scenario_1 Given scenario_1 step_1 When scenario_1 step_2 '''.lstrip() feature = parse_feature(text) assert feature.name == "With Example as Alias for Scenario" assert len(feature.scenarios) == 1 assert len(feature.run_items) == 1 scenario1 = feature.scenarios[0] assert feature.run_items == [scenario1] assert scenario1.name == "Scenario_1" assert scenario1.keyword == "Example" assert scenario1.background is None assert scenario1.parent is feature assert scenario1.feature is feature assert scenario1.tags == [] assert scenario1.description == [] assert_compare_steps(scenario1.all_steps, [ ("given", "Given", 'scenario_1 step_1', None, None), ("when", "When", 'scenario_1 step_2', None, None), ])
def test_parse_scenario_with_description_but_without_steps(self): doc = u''' Feature: Scenario Description Scenario: With description but without steps First line of scenario description. Second line of scenario description. Scenario: Another one Given we have stuff When we do stuff Then we have things '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Scenario Description") assert (len(feature.scenarios) == 2) eq_(feature.scenarios[0].name, "With description but without steps") eq_(feature.scenarios[0].tags, []) eq_(feature.scenarios[0].description, [ "First line of scenario description.", "Second line of scenario description.", ]) eq_(feature.scenarios[0].steps, []) eq_(feature.scenarios[1].name, "Another one") eq_(feature.scenarios[1].tags, []) eq_(feature.scenarios[1].description, []) self.compare_steps(feature.scenarios[1].steps, [ ('given', 'Given', 'we have stuff', None, None), ('when', 'When', 'we do stuff', None, None), ('then', 'Then', 'we have things', None, None), ])
def test_parses_feature_with_description_and_background_and_scenario(self): doc = u""" Feature: Stuff Oh my god, it's full of stuff... Background: Given I found some stuff Scenario: Doing stuff Given there is stuff When I do stuff Then stuff happens """.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert feature.background self.compare_steps(feature.background.steps, [("given", "Given", "I found some stuff", None, None)]) assert len(feature.scenarios) == 1 eq_(feature.scenarios[0].name, "Doing stuff") self.compare_steps( feature.scenarios[0].steps, [ ("given", "Given", "there is stuff", None, None), ("when", "When", "I do stuff", None, None), ("then", "Then", "stuff happens", None, None), ], )
def test_parses_feature_with_table_and_escaped_pipe_in_cell_values(self): doc = u''' Feature: Scenario: Given we have special cell values: | name | value | | alice | one\|two | | bob |\|one | | charly | one\|| | doro | one\|two\|three\|four | '''.lstrip() feature = parser.parse_feature(doc) assert(len(feature.scenarios) == 1) table = model.Table( [u"name", u"value"], 0, [ [u"alice", u"one|two"], [u"bob", u"|one"], [u"charly", u"one|"], [u"doro", u"one|two|three|four"], ] ) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we have special cell values', None, table), ])
def test_parses_feature_with_a_step_with_a_string_with_blank_lines(self): doc = u''' Feature: Stuff Scenario: Doing stuff Given there is stuff: """ So Much Stuff """ Then stuff happens '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert(len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'there is stuff', "So\n\nMuch\n\n\nStuff", None), ('then', 'Then', 'stuff happens', None, None), ])
def test_parses_french(self): doc = u""" Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... Contexte: Soit I found some stuff Sc\xe9nario: test stuff Soit I am testing stuff Alors it should work Sc\xe9nario: test more stuff Soit I am testing stuff Alors it will work """.lstrip() feature = parser.parse_feature(doc, 'fr') eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert(feature.background) self.compare_steps(feature.background.steps, [ ('given', 'Soit', 'I found some stuff', None, None), ]) assert(len(feature.scenarios) == 2) eq_(feature.scenarios[0].name, 'test stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Soit', 'I am testing stuff', None, None), ('then', 'Alors', 'it should work', None, None), ])
def test_parse_scenario_description(self): doc = u''' Feature: Scenario Description Scenario: With scenario description First line of scenario description. Second line of scenario description. Third line of scenario description (after an empty line). Given we have stuff When we do stuff Then we have things '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Scenario Description") assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, "With scenario description") eq_(feature.scenarios[0].tags, []) eq_(feature.scenarios[0].description, [ "First line of scenario description.", "Second line of scenario description.", "Third line of scenario description (after an empty line).", ]) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we have stuff', None, None), ('when', 'When', 'we do stuff', None, None), ('then', 'Then', 'we have things', None, None), ])
def test_parse_scenario_with_description_but_without_steps_followed_by_scenario_with_tags(self): doc = u''' Feature: Scenario Description Scenario: With description but without steps First line of scenario description. Second line of scenario description. @foo @bar Scenario: Another one Given we have stuff When we do stuff Then we have things '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Scenario Description") assert(len(feature.scenarios) == 2) eq_(feature.scenarios[0].name, "With description but without steps") eq_(feature.scenarios[0].tags, []) eq_(feature.scenarios[0].description, [ "First line of scenario description.", "Second line of scenario description.", ]) eq_(feature.scenarios[0].steps, []) eq_(feature.scenarios[1].name, "Another one") eq_(feature.scenarios[1].tags, ["foo", "bar"]) eq_(feature.scenarios[1].description, []) self.compare_steps(feature.scenarios[1].steps, [ ('given', 'Given', 'we have stuff', None, None), ('when', 'When', 'we do stuff', None, None), ('then', 'Then', 'we have things', None, None), ])
def test_parses_french(self): doc = u""" Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... Contexte: Soit I found some stuff Sc\xe9nario: test stuff Soit I am testing stuff Alors it should work Sc\xe9nario: test more stuff Soit I am testing stuff Alors it will work """.lstrip() feature = parser.parse_feature(doc, "fr") eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert feature.background self.compare_steps(feature.background.steps, [("given", "Soit", "I found some stuff", None, None)]) assert len(feature.scenarios) == 2 eq_(feature.scenarios[0].name, "test stuff") self.compare_steps( feature.scenarios[0].steps, [("given", "Soit", "I am testing stuff", None, None), ("then", "Alors", "it should work", None, None)], )
def test_parses_feature_with_a_step_with_a_string_with_blank_lines(self): doc = u''' Feature: Stuff Scenario: Doing stuff Given there is stuff: """ So Much Stuff """ Then stuff happens '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'there is stuff', "So\n\nMuch\n\n\nStuff", None), ('then', 'Then', 'stuff happens', None, None), ])
def test_parse__rule_scenarios_without_feature_and_rule_background(self): text = u''' Feature: Without Feature.Background and Rule.Background Rule: R1 Scenario: R1.Scenario_1 Given rule R1 scenario_1 step_1 '''.lstrip() feature = parse_feature(text) assert feature.name == "Without Feature.Background and Rule.Background" assert feature.background is None assert len(feature.scenarios) == 0 assert len(feature.rules) == 1 assert len(feature.run_items) == 1 rule1 = feature.rules[0] rule1_scenario1 = rule1.scenarios[0] assert feature.run_items == [rule1] assert rule1.background is None assert rule1_scenario1.name == "R1.Scenario_1" assert rule1_scenario1.background is None assert rule1_scenario1.background is rule1.background assert rule1_scenario1.background_steps == [] assert_compare_steps(rule1_scenario1.all_steps, [ (u"given", u"Given", u'rule R1 scenario_1 step_1', None, None), ])
def test_parse__norule_scenarios_use_feature_background(self): """AFFECTED: Scenarios outside of rules (before first rule).""" text = u''' Feature: With Scenarios and Rules Background: Feature.Background Given feature background step_1 Scenario: Scenario_1 Given scenario_1 step_1 Rule: R1 Scenario: R1.Scenario_1 Given rule R1 scenario_1 step_1 '''.lstrip() feature = parse_feature(text) assert feature.name == "With Scenarios and Rules" assert feature.background is not None assert len(feature.scenarios) == 1 assert len(feature.rules) == 1 assert len(feature.run_items) == 2 scenario1 = feature.scenarios[0] rule1 = feature.rules[0] assert feature.run_items == [scenario1, rule1] assert scenario1.name == "Scenario_1" assert scenario1.background is feature.background assert scenario1.background_steps == feature.background.steps assert_compare_steps(scenario1.all_steps, [ (u"given", u"Given", u'feature background step_1', None, None), (u"given", u"Given", u'scenario_1 step_1', None, None), ])
def test_parse_scenario_description(self): doc = u''' Feature: Scenario Description Scenario: With scenario description First line of scenario description. Second line of scenario description. Third line of scenario description (after an empty line). Given we have stuff When we do stuff Then we have things '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Scenario Description") assert(len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, "With scenario description") eq_(feature.scenarios[0].tags, []) eq_(feature.scenarios[0].description, [ "First line of scenario description.", "Second line of scenario description.", "Third line of scenario description (after an empty line).", ]) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we have stuff', None, None), ('when', 'When', 'we do stuff', None, None), ('then', 'Then', 'we have things', None, None), ])
def test_parses_feature_with_a_step_with_a_table_argument(self): doc = u''' Feature: Stuff Scenario: Doing stuff Given we classify stuff: | type of stuff | awesomeness | ridiculousness | | fluffy | large | frequent | | lint | low | high | | green | variable | awkward | Then stuff is in buckets '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert(len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') table = model.Table( [u'type of stuff', u'awesomeness', u'ridiculousness'], 0, [ [u'fluffy', u'large', u'frequent'], [u'lint', u'low', u'high'], [u'green', u'variable', u'awkward'], ] ) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we classify stuff', None, table), ('then', 'Then', 'stuff is in buckets', None, None), ])
def test_parses_feature_with_description_and_background_and_scenario(self): doc = u""" Feature: Stuff Oh my god, it's full of stuff... Background: Given I found some stuff Scenario: Doing stuff Given there is stuff When I do stuff Then stuff happens """.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert (feature.background) self.compare_steps(feature.background.steps, [ ('given', 'Given', 'I found some stuff', None, None), ]) assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'there is stuff', None, None), ('when', 'When', 'I do stuff', None, None), ('then', 'Then', 'stuff happens', None, None), ])
def test_parses_feature_with_a_scenario_outline(self): doc = u''' Feature: Stuff Scenario Outline: Doing all sorts of stuff Given we have <Stuff> When we do stuff Then we have <Things> Examples: Some stuff | Stuff | Things | | wool | felt | | cotton | thread | | wood | paper | | explosives | hilarity | '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing all sorts of stuff') table = model.Table([u'Stuff', u'Things'], 0, [ [u'wool', u'felt'], [u'cotton', u'thread'], [u'wood', u'paper'], [u'explosives', u'hilarity'], ]) eq_(feature.scenarios[0].examples[0].name, 'Some stuff') eq_(feature.scenarios[0].examples[0].table, table) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we have <Stuff>', None, None), ('when', 'When', 'we do stuff', None, None), ('then', 'Then', 'we have <Things>', None, None), ])
def test_parses_string_argument_without_stripping_empty_lines(self): # -- ISSUE 44: Parser removes comments in multiline text string. doc = u''' Feature: Multiline Scenario: Multiline Text with Comments Given a multiline argument with: """ """ And a multiline argument with: """ Alpha. Omega. """ Then empty middle lines are not stripped '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Multiline") assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, "Multiline Text with Comments") text1 = "" text2 = "Alpha.\n\nOmega." self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'a multiline argument with', text1, None), ('given', 'And', 'a multiline argument with', text2, None), ('then', 'Then', 'empty middle lines are not stripped', None, None), ])
def test_parses_feature_with_a_step_with_a_table_argument(self): doc = u''' Feature: Stuff Scenario: Doing stuff Given we classify stuff: | type of stuff | awesomeness | ridiculousness | | fluffy | large | frequent | | lint | low | high | | green | variable | awkward | Then stuff is in buckets '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") assert (len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') table = model.Table( [u'type of stuff', u'awesomeness', u'ridiculousness'], 0, [ [u'fluffy', u'large', u'frequent'], [u'lint', u'low', u'high'], [u'green', u'variable', u'awkward'], ]) self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'we classify stuff', None, table), ('then', 'Then', 'stuff is in buckets', None, None), ])
def test_parses_french(self): doc = u""" Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... Contexte: Soit I found some stuff Sc\xe9nario: test stuff Soit I am testing stuff Alors it should work Sc\xe9nario: test more stuff Soit I am testing stuff Alors it will work """.lstrip() feature = parser.parse_feature(doc, 'fr') eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert (feature.background) self.compare_steps(feature.background.steps, [ ('given', 'Soit', 'I found some stuff', None, None), ]) assert (len(feature.scenarios) == 2) eq_(feature.scenarios[0].name, 'test stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Soit', 'I am testing stuff', None, None), ('then', 'Alors', 'it should work', None, None), ])
def test_issue(): """Verifies that issue #725 is fixed.""" text = u''' Feature: ScenarioOutline with description Scenario Outline: SO_1 Description line 1 for ScenarioOutline. Description line 2 for ScenarioOutline. Given a step with "<name>" Examples: | name | | Alice | | Bob | '''.lstrip() feature = parse_feature(text) assert len(feature.scenarios) == 1 scenario_outline_1 = feature.scenarios[0] assert len(scenario_outline_1.scenarios) == 2 # -- HINT: Last line triggers building of the Scenarios from ScenarioOutline. expected_description = [ "Description line 1 for ScenarioOutline.", "Description line 2 for ScenarioOutline.", ] assert scenario_outline_1.description == expected_description assert scenario_outline_1.scenarios[0].description == expected_description assert scenario_outline_1.scenarios[1].description == expected_description
def test_parses_feature_with_description_and_background_and_scenario(self): doc = u""" Feature: Stuff Oh my god, it's full of stuff... Background: Given I found some stuff Scenario: Doing stuff Given there is stuff When I do stuff Then stuff happens """.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."]) assert(feature.background) self.compare_steps(feature.background.steps, [ ('given', 'Given', 'I found some stuff', None, None), ]) assert(len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, 'Doing stuff') self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'there is stuff', None, None), ('when', 'When', 'I do stuff', None, None), ('then', 'Then', 'stuff happens', None, None), ])
def test_parses_string_argument_without_stripping_empty_lines(self): # -- ISSUE 44: Parser removes comments in multiline text string. doc = u''' Feature: Multiline Scenario: Multiline Text with Comments Given a multiline argument with: """ """ And a multiline argument with: """ Alpha. Omega. """ Then empty middle lines are not stripped '''.lstrip() feature = parser.parse_feature(doc) eq_(feature.name, "Multiline") assert(len(feature.scenarios) == 1) eq_(feature.scenarios[0].name, "Multiline Text with Comments") text1 = "" text2 = "Alpha.\n\nOmega." self.compare_steps(feature.scenarios[0].steps, [ ('given', 'Given', 'a multiline argument with', text1, None), ('given', 'And', 'a multiline argument with', text2, None), ('then', 'Then', 'empty middle lines are not stripped', None, None), ])
def _parse_file(filename, language=None): with open(filename, 'rb') as f: # file encoding is assumed to be utf8. Oh, yes. data = f.read().decode('utf8') # change a trailing line backslash and space both sides of it into a space # this make it prettier to use long steps data = re.sub('\\s*\\\\\n\\s*', ' ', data) return parser.parse_feature(data, language, filename)
def test_whitespace_in_the_language_comment_is_flexible_4(self): doc = u""" # language: lv F\u012b\u010da: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_language_comment_wins_over_commandline(self): doc = u""" # language: fr Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc, language="de") eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_first_line_comment_sets_language(self): doc = u""" # language: fr Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_whitespace_in_the_language_comment_is_flexible_2(self): doc = u""" # language:de Funktionalit\xe4t: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_parses_feature_description(self): doc = u""" Feature: Stuff In order to thing As an entity I want to do stuff """.strip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["In order to thing", "As an entity", "I want to do stuff"])
def test_parses_rule(self): text = u''' Feature: With Rule A feature description line 1. A feature description line 2. Rule: R1 Background: R1.Background_1 Given background step 1 When background step 2 Scenario: R1.Scenario_1 Given scenario step 1 When scenario step 2 Then scenario step 3 '''.lstrip() feature = parse_feature(text) rule1 = feature.rules[0] rule1_scenario1 = rule1.scenarios[0] assert feature.name == "With Rule" assert feature.description == [ "A feature description line 1.", "A feature description line 2.", ] assert feature.background is None assert len(feature.rules) == 1 assert len(feature.scenarios) == 0 assert rule1.name == "R1" assert rule1.tags == [] assert rule1.parent is feature assert rule1.feature is feature assert rule1.background is not None assert_compare_steps(rule1.background.steps, [ ("given", "Given", "background step 1", None, None), ("when", "When", "background step 2", None, None), ]) assert len(rule1.scenarios) == 1 assert rule1_scenario1.background is rule1.background assert_compare_steps(rule1_scenario1.steps, [ ("given", "Given", "scenario step 1", None, None), ("when", "When", "scenario step 2", None, None), ("then", "Then", "scenario step 3", None, None), ]) assert_compare_steps(rule1_scenario1.all_steps, [ ("given", "Given", "background step 1", None, None), ("when", "When", "background step 2", None, None), ("given", "Given", "scenario step 1", None, None), ("when", "When", "scenario step 2", None, None), ("then", "Then", "scenario step 3", None, None), ])
def test_select_run_items_by_line__entity_line_selects_entity(self, filename): feature_text = feature_file_map[filename] feature = parse_feature(feature_text, filename=filename) line_database = FeatureLineDatabase.make(feature) last_line = 0 all_run_items = feature.walk_scenarios(with_outlines=True, with_rules=True) for run_item in all_run_items: selected = line_database.select_run_item_by_line(run_item.location.line) assert selected is run_item assert last_line < selected.location.line last_line = run_item.location.line
def test_parses_feature_with_more_tags_and_comment(self): doc = u""" @foo @bar @baz @qux @winkle_pickers # Comment: @number8 Feature: Stuff In order to thing As an entity I want to do stuff """.strip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["In order to thing", "As an entity", "I want to do stuff"]) eq_(feature.tags, [model.Tag(name, 1) for name in (u"foo", u"bar", u"baz", u"qux", u"winkle_pickers")])
def test_select_run_items_by_line__line_before_entity_selects_last_entity(self, filename): feature_text = feature_file_map[filename] feature = parse_feature(feature_text, filename=filename) line_database = FeatureLineDatabase.make(feature) all_run_items = feature.walk_scenarios(with_outlines=True, with_rules=True) last_run_item = feature for run_item in all_run_items: predecessor_line = run_item.location.line - 1 selected = line_database.select_run_item_by_line(predecessor_line) assert selected is last_run_item assert selected is not run_item last_run_item = run_item
def test_multiple_language_comments(self): # -- LAST LANGUAGE is used. doc = u""" # language: en # language: fr Fonctionnalit\xe9: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_whitespace_before_first_line_comment_still_sets_language(self): doc = u""" # language: cs Po\u017eadavek: testing stuff Oh my god, it's full of stuff... """ feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])
def test_parses_feature_with_a_tag_and_comment(self): doc = u""" @foo # Comment: ... Feature: Stuff In order to thing As an entity I want to do stuff """.strip() feature = parser.parse_feature(doc) eq_(feature.name, "Stuff") eq_(feature.description, ["In order to thing", "As an entity", "I want to do stuff"]) eq_(feature.tags, [model.Tag(u'foo', 1)])
def test_defaults_to_DEFAULT_LANGUAGE(self): feature_kwd = i18n.languages[parser.DEFAULT_LANGUAGE]['feature'][0] doc = u""" @wombles # language: cs %s: testing stuff Oh my god, it's full of stuff... """ % feature_kwd feature = parser.parse_feature(doc) eq_(feature.name, "testing stuff") eq_(feature.description, ["Oh my god, it's full of stuff..."])