Example #1
0
def test_runner_should_shuffle_scenarios_in_a_scenario_container_if_shuffle_scenarios_flag_set(
        hook_registry, default_config, mocker):
    """
    The Runner should shuffle the Scenarios within a Scenario Container before
    running them if the shuffle Scenarios flag is set
    """
    # given
    default_config.shuffle_scenarios = True

    runner = Runner(default_config, None, hook_registry)
    runner.run_scenario = mocker.MagicMock()

    scenario_container_mock = mocker.MagicMock(name="Rule")
    scenario = mocker.MagicMock(name="Scenario")
    scenario_container_mock.examples = [scenario]

    mocker.patch("random.sample")

    # when
    runner.run_scenario_container(scenario_container_mock)

    # then
    import random

    random.sample.assert_called_once_with(
        scenario_container_mock.examples,
        len(scenario_container_mock.examples))
Example #2
0
def test_runner_should_exit_for_failed_scenario_in_scenario_container_if_early_exit_flag_is_set(
        hook_registry, default_config, mocker):
    """
    The Runner should exit for a failed Scenario in
    Scenario Container if the early exit flag is set
    """
    # given
    default_config.early_exit = True

    runner = Runner(default_config, None, hook_registry)
    runner.run_scenario = mocker.MagicMock()
    runner.run_scenario.side_effect = [
        State.PASSED, State.FAILED, State.PASSED
    ]

    scenario_container_mock = mocker.MagicMock(name="Scenario Container")
    first_scenario = mocker.MagicMock(name="First Scenario")
    second_scenario = mocker.MagicMock(name="Second Scenario")
    third_scenario = mocker.MagicMock(name="Third Scenario")
    scenario_container_mock.examples = [
        first_scenario, second_scenario, third_scenario
    ]

    # when
    runner.run_scenario_container(scenario_container_mock)

    # then
    runner.run_scenario.assert_has_calls(
        [call(first_scenario), call(second_scenario)])
Example #3
0
def test_runner_should_iterate_all_scenarios_when_running_a_scenario_container(
        hook_registry, default_config, mocker):
    """The Runner should iterate all Scenarios when running a Scenario Container"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_scenario = mocker.MagicMock()

    scenario_container_mock = mocker.MagicMock(name="Scenario Container")
    first_scenario = mocker.MagicMock(name="First Scenario")
    second_scenario = mocker.MagicMock(name="Second Scenario")
    scenario_container_mock.examples = [first_scenario, second_scenario]

    # when
    runner.run_scenario_container(scenario_container_mock)

    # then
    runner.run_scenario.assert_has_calls(
        [call(first_scenario), call(second_scenario)])
Example #4
0
def test_runner_should_only_run_scenario_in_a_scenario_container_which_need_to_be_run(
        hook_registry, default_config, mocker):
    """The Runner should only run Scenarios in a Scenario Container which need to be run"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_scenario = mocker.MagicMock()

    scenario_container_mock = mocker.MagicMock(name="Scenario Container")
    first_scenario = mocker.MagicMock(name="First Scenario")
    first_scenario.has_to_run.return_value = True
    second_scenario = mocker.MagicMock(name="Second Scenario")
    second_scenario.has_to_run.return_value = False
    third_scenario = mocker.MagicMock(name="Third Scenario")
    third_scenario.has_to_run.return_value = True
    scenario_container_mock.examples = [
        first_scenario, second_scenario, third_scenario
    ]

    # when
    runner.run_scenario_container(scenario_container_mock)

    # then
    runner.run_scenario.assert_has_calls(
        [call(first_scenario), call(third_scenario)])
Example #5
0
def test_runner_should_run_scenario_loop_and_outline_as_scenario_container(
        scenario_container_type, hook_registry, default_config, mocker):
    """The Runner should run a ScenarioLoop and ScenarioOutline as a Scenario Container"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_scenario_container = mocker.MagicMock()

    rule_mock = mocker.MagicMock(name="Rule")
    scenario = mocker.MagicMock(name=scenario_container_type.__name__,
                                spec=scenario_container_type)
    rule_mock.scenarios = [scenario]

    # when
    runner.run_rule(rule_mock)

    # then
    runner.run_scenario_container.assert_has_calls([call(scenario)])