def test_creating_a_concrete_background_instance(): """ Test creating a concrete Background instance """ # given & when background = Background( "Background", "I am a Background", "foo.feature", 1, parent=None ) # add some Steps background.steps.append(Step(1, "Foo", "foo.feature", 2, background, False)) background.steps.append(Step(2, "Foo", "foo.feature", 3, background, False)) # when instance = background.create_instance() # then assert len(instance.steps) == 2 assert background.steps[0] != instance.steps[0] assert background.steps[1] != instance.steps[1]
def test_creating_a_concrete_background_instance(): """ Test creating a concrete Background instance """ # given & when background = Background("Background", "I am a Background", "foo.feature", 1, parent=None) # add some Steps background.steps.append(Step(1, "Foo", "foo.feature", 2, background, False)) background.steps.append(Step(2, "Foo", "foo.feature", 3, background, False)) # when instance = background.create_instance() # then assert len(instance.steps) == 2 assert background.steps[0] != instance.steps[0] assert background.steps[1] != instance.steps[1]
def test_building_scenariooutline_scenarios_with_background(mocker): """ Test building Scenarios from a Scenario Outline Example including a Background """ # given background = Background( "Background", "I am a Background", "foo.feature", 1, parent=None ) # add some Steps background.steps.extend( [ Step(1, "Foo", "foo.feature", 2, background, False), Step(2, "Foo", "foo.feature", 3, background, False), ] ) scenario_outline = ScenarioOutline( 1, "Scenario Outline", "Examples", "I am a Scenario Outline", "foo.feature", 1, parent=None, tags=None, preconditions=None, background=background, ) # add steps scenario_outline.steps.extend( [ mocker.MagicMock(sentence="Given I have <foo>", path="foo.feature"), mocker.MagicMock(sentence="And I have <bar>", path="foo.feature"), mocker.MagicMock(sentence="When I add those", path="foo.feature"), ] ) # add examples scenario_outline.examples_header = ["foo", "bar"] scenario_outline.examples = [ # row 0 ScenarioOutline.Example(["1", "2"], "foo.feature", 1), # row 3 ScenarioOutline.Example(["3", "4"], "foo.feature", 2), ] # when - build the scenarios scenario_outline.build_scenarios() # then - expect ExampleScenarios to have background copy assigned assert scenario_outline.scenarios[0].background.sentence == "I am a Background" assert scenario_outline.scenarios[1].background.sentence == "I am a Background"
def test_building_scenariooutline_scenarios_with_background(mocker): """ Test building Scenarios from a Scenario Outline Example including a Background """ # given background = Background('Background', 'I am a Background', 'foo.feature', 1, parent=None) # add some Steps background.steps.extend([ Step(1, 'Foo', 'foo.feature', 2, background, False), Step(2, 'Foo', 'foo.feature', 3, background, False) ]) scenario_outline = ScenarioOutline(1, 'Scenario Outline', 'Examples', 'I am a Scenario Outline', 'foo.feature', 1, parent=None, tags=None, preconditions=None, background=background) # add steps scenario_outline.steps.extend([ mocker.MagicMock(sentence='Given I have <foo>', path='foo.feature'), mocker.MagicMock(sentence='And I have <bar>', path='foo.feature'), mocker.MagicMock(sentence='When I add those', path='foo.feature') ]) # add examples scenario_outline.examples_header = ['foo', 'bar'] scenario_outline.examples = [ # row 0 ScenarioOutline.Example(['1', '2'], 'foo.feature', 1), # row 3 ScenarioOutline.Example(['3', '4'], 'foo.feature', 2), ] # when - build the scenarios scenario_outline.build_scenarios() # then - expect ExampleScenarios to have background copy assigned assert scenario_outline.scenarios[ 0].background.sentence == 'I am a Background' assert scenario_outline.scenarios[ 1].background.sentence == 'I am a Background'
def test_creating_simple_background(): """ Test creating a simple Background """ # given & when background = Background("Background", "I am a Background", "foo.feature", 1, parent=None) # then assert background.id is None assert background.keyword == "Background" assert background.sentence == "I am a Background" assert background.path == "foo.feature" assert background.line == 1 assert background.parent is None
def test_creating_simple_background(): """ Test creating a simple Background """ # given & when background = Background('Background', 'I am a Background', 'foo.feature', 1, parent=None) # then assert background.id is None assert background.keyword == 'Background' assert background.sentence == 'I am a Background' assert background.path == 'foo.feature' assert background.line == 1 assert background.parent is None
def test_building_scenarioloop_scenarios_with_background(mocker): """ Test building Scenarios from a Scenario Loop including a Background """ # given background = Background("Background", "I am a Background", "foo.feature", 1, parent=None) # add some Steps background.steps.extend([ Step(1, "Foo", "foo.feature", 2, background, False), Step(2, "Foo", "foo.feature", 3, background, False), ]) scenario_loop = ScenarioLoop( 1, "Scenario Loop", "Iterations", "I am a Scenario Loop", "foo.feature", 1, parent=None, tags=None, preconditions=None, background=background, ) # add steps scenario_loop.steps.extend([ mocker.MagicMock(sentence="Given I have 1", path="foo.feature"), mocker.MagicMock(sentence="And I have 2", path="foo.feature"), mocker.MagicMock(sentence="When I add those", path="foo.feature"), ]) # set iterations scenario_loop.iterations = 2 # when - build the scenarios scenario_loop.build_scenarios() # then - expect ExampleScenarios to have background copy assigned assert scenario_loop.scenarios[ 0].background.sentence == "I am a Background" assert scenario_loop.scenarios[ 1].background.sentence == "I am a Background"
def test_building_scenarioloop_scenarios_with_background(mocker): """ Test building Scenarios from a Scenario Loop including a Background """ # given background = Background('Background', 'I am a Background', 'foo.feature', 1, parent=None) # add some Steps background.steps.extend([ Step(1, 'Foo', 'foo.feature', 2, background, False), Step(2, 'Foo', 'foo.feature', 3, background, False) ]) scenario_loop = ScenarioLoop(1, 'Scenario Loop', 'Iterations', 'I am a Scenario Loop', 'foo.feature', 1, parent=None, tags=None, preconditions=None, background=background) # add steps scenario_loop.steps.extend([ mocker.MagicMock(sentence='Given I have 1', path='foo.feature'), mocker.MagicMock(sentence='And I have 2', path='foo.feature'), mocker.MagicMock(sentence='When I add those', path='foo.feature') ]) # set iterations scenario_loop.iterations = 2 # when - build the scenarios scenario_loop.build_scenarios() # then - expect ExampleScenarios to have background copy assigned assert scenario_loop.scenarios[ 0].background.sentence == 'I am a Background' assert scenario_loop.scenarios[ 1].background.sentence == 'I am a Background'
def test_scenario_after_parse_logic(mocker): """ Test logic which is used to complete the parsing of Scenario """ # given background = Background(1, "Background", "I am a Background", "foo.feature", 1) precondition_scenario = Scenario(2, "Scenario", "I am a Scenario", "foo.feature", 1, parent=None) scenario = Scenario( 1, "Scenario", "I am a Scenario", "foo.feature", 1, parent=None, tags=None, preconditions=[precondition_scenario], background=background, ) # add Steps to this Scenario scenario.steps.extend( [mocker.MagicMock(id=99, as_background=False, as_precondition=False)]) # set Scenario Step parents for step in scenario.steps: step.parent = scenario # add Steps to the Background background.steps.extend([ mocker.MagicMock(id=5, as_background=False, as_precondition=False), mocker.MagicMock(id=6, as_background=False, as_precondition=False), mocker.MagicMock(id=66, as_background=False, as_precondition=False), ]) # set Background Step parents for background_step in background.steps: background_step.parent = background # add Steps to the precondition Scenario precondition_scenario.steps.extend([ mocker.MagicMock(id=5, as_background=False, as_precondition=False), mocker.MagicMock(id=77, as_background=False, as_precondition=False), ]) # set Precondition Scenario Step parents for step in precondition_scenario.steps: step.parent = precondition_scenario # when after_parse() was not called it's not completed assert scenario.complete is False # when scenario.after_parse() steps = scenario.all_steps # then - the Scenario is completed assert scenario.complete is True # then - the step id's are in valid order assert steps[0].id == 1 assert steps[1].id == 2 assert steps[2].id == 3 assert steps[3].id == 4 assert steps[4].id == 5 assert steps[5].id == 6 # then - check as_background flags assert all(step.as_background for step in background.steps) # then - check as_precondition flags assert all(step.as_precondition for step in precondition_scenario.steps)