def scenario_loop(self, subtree): """Transform the ``scenario_outline``-subtree for the radish AST""" # consume Feature Tags tags = list(itertools.takewhile(lambda t: isinstance(t, Tag), subtree)) keyword = subtree[len(tags)] short_description = subtree[len(tags) + 1] steps = list( itertools.takewhile(lambda s: isinstance(s, Step), subtree[len(tags) + 2:])) iterations = subtree[len(tags) + 2 + len(steps)] scenario_loop = ScenarioLoop( self.__scenario_id, keyword, short_description, tags, self.featurefile_path, short_description.line, steps, iterations, ) # increment scenario id and reset step id for the next scenario self.__scenario_id += 1 + iterations self.__step_id = 1 self.__step_keyword_ctx = None return scenario_loop
def test_scenarioloop_build_examples_from_iterations(): """A ScenarioLoop should build its Examples from the given amount of Iterations""" # given & when scenario = ScenarioLoop(1, "Scenario Loop", "My ScenarioLoop", [], None, None, [], 2) # two examples # then assert len(scenario.examples) == 2
def test_scenarioloop_set_rule_on_all_examples(mocker): """A ScenarioLoop should forward a set Rule to all its Examples""" # given rule_mock = mocker.MagicMock(name="Rule") scenario = ScenarioLoop(1, "Scenario Loop", "My ScenarioLoop", [], None, None, [], 0) first_example = mocker.MagicMock(name="First Example") second_example = mocker.MagicMock(name="Second Example") scenario.examples = [first_example, second_example] # when scenario.set_rule(rule_mock) # then assert scenario.rule is rule_mock first_example.set_rule.assert_called_once_with(rule_mock) second_example.set_rule.assert_called_once_with(rule_mock)
def test_scenarioloop_set_background_on_all_examples(mocker): """A ScenarioLoop should forward a set Background to all its Examples""" # given background_mock = mocker.MagicMock(name="Background") scenario = ScenarioLoop(1, "Scenario Loop", "My ScenarioLoop", [], None, None, [], 0) first_example = mocker.MagicMock(name="First Example") second_example = mocker.MagicMock(name="Second Example") scenario.examples = [first_example, second_example] # when scenario.set_background(background_mock) # then assert scenario.background is not None first_example.set_background.assert_called_once_with(background_mock) second_example.set_background.assert_called_once_with(background_mock)
def test_scenarioloop_should_build_examples_with_info_in_short_description(): """A ScenarioLoop should build its Examples with the Iteration id in the short description""" # given & when scenario = ScenarioLoop(1, "Scenario Loop", "My ScenarioLoop", [], None, None, [], 2) # then assert scenario.examples[ 0].short_description == "My ScenarioLoop [Iteration: 1]" assert scenario.examples[ 1].short_description == "My ScenarioLoop [Iteration: 2]"
def test_scenario_should_correctly_evaluate_if_it_has_to_be_run( mocker, tagexpression, scenario_ids, expected_has_to_run): """Test that a Scenario should correctly evaluate if it has to be run or not""" # given feature_mock = mocker.MagicMock(tags=[Tag("tag-c", None, None)]) scenario = ScenarioLoop( 1, "Scenario Loop", "My ScenarioLoop", [Tag("tag-a", None, None), Tag("tag-b", None, None)], None, None, [], 2, ) scenario.set_feature(feature_mock) # when has_to_run = scenario.has_to_run(tagexpression, scenario_ids) # then assert has_to_run == expected_has_to_run
def test_scenarioloop_should_build_examples_with_copied_steps(mocker): """A ScenarioLoop should build its Example with a copy of its own Steps""" # given & when scenario = ScenarioLoop( 1, "Scenario Loop", "My ScenarioLoop", [], None, None, [ mocker.MagicMock(name="First Step"), mocker.MagicMock(name="Second Step") ], 2, ) # then assert len(scenario.examples[0].steps) == 2 assert len(scenario.examples[1].steps) == 2 assert scenario.steps is not scenario.examples[0].steps assert scenario.steps is not scenario.examples[1].steps