Esempio n. 1
0
def test_runner_should_call_hooks_when_running_a_step(hook_registry,
                                                      default_config, mocker):
    """The Runner should call the ``each_step`` hooks when running a Step"""
    # given
    runner = Runner(default_config, None, hook_registry)
    step_mock = mocker.MagicMock(name="Step")

    # when
    runner.run_step(step_mock)

    # then
    hook_registry.call.assert_has_calls([
        call("each_step", "before", False, step_mock),
        call("each_step", "after", False, step_mock),
    ])
Esempio n. 2
0
def test_runner_should_fail_step_when_it_cannot_be_matched(
        hook_registry, default_config, mocker):
    """The Runner should fail a Step when it cannot be matched with any Step Implementation"""
    runner = Runner(default_config, None, hook_registry)
    step_mock = mocker.MagicMock(name="Step")

    matcher_mock = mocker.patch("radish.runner.matcher")
    match_exc = RadishError("buuh!")
    matcher_mock.match_step.side_effect = match_exc

    # when
    runner.run_step(step_mock)

    # then
    step_mock.fail.assert_called_once_with(match_exc)
Esempio n. 3
0
def test_runner_should_continue_running_steps_when_step_is_skipped_or_pending(
        hook_registry, default_config, mocker):
    """The Runner should continue running Steps after a Step is skipped"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_step = mocker.MagicMock()
    runner.run_step.side_effect = [
        State.PASSED,
        State.SKIPPED,
        State.PENDING,
        State.PASSED,
    ]

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background = None
    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    third_step = mocker.MagicMock(name="Third Step")
    fourth_step = mocker.MagicMock(name="Fourth Step")
    scenario_mock.steps = [first_step, second_step, third_step, fourth_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([
        call(first_step),
        call(second_step),
        call(third_step),
        call(fourth_step)
    ])
Esempio n. 4
0
def test_runner_should_run_step_after_being_matched_in_normal_mode(
        hook_registry, default_config, mocker):
    """
    The Runner should run a Step after it's being
    successfully matched with a Step Implementation
    in the normal mode.
    """
    # given
    runner = Runner(default_config, None, hook_registry)
    step_mock = mocker.MagicMock(name="Step")

    mocker.patch("radish.runner.matcher")

    # when
    runner.run_step(step_mock)

    # then
    step_mock.run.assert_called_once_with(ANY)
Esempio n. 5
0
def test_runner_should_not_run_nor_debug_step_after_being_matched_in_dry_run_mode(
        hook_registry, default_config, mocker):
    """
    The Runner should not run nor debug a Step after it's being
    successfully matched with a Step Implementation in the dry run mode.
    """
    # given
    default_config.dry_run_mode = True

    runner = Runner(default_config, None, hook_registry)
    step_mock = mocker.MagicMock(name="Step")

    mocker.patch("radish.runner.matcher")

    # when
    runner.run_step(step_mock)

    # then
    step_mock.run.assert_not_called()
    step_mock.debug.assert_not_called()
Esempio n. 6
0
    def test_running_a_step(self):
        """
            Test running a step
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        step = Step(1, "Some step", "somefile.feature", 3, None, True)
        step.definition_func = some_step
        step.arguments = tuple()
        step.keyword_arguments = {}

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        runner.run_step(step)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
Esempio n. 7
0
def test_should_call_hooks_in_correct_order(hookregistry, mocker):
    """
    Test that hooks are called in correct order.

    Correct order meaning:
        * before hooks: ascending order
        * after hooks: descending order
    """
    # given
    runner = Runner(hookregistry)

    # register hooks
    data = []

    def first_before_stub(*args):
        data.append(1)

    def first_after_stub(*args):
        data.append(1)

    def second_before_stub(*args):
        data.append(2)

    def second_after_stub(*args):
        data.append(2)

    hookregistry.register("before", "each_step", second_before_stub, order=2)
    hookregistry.register("after", "each_step", second_after_stub, order=2)
    hookregistry.register("before", "each_step", first_before_stub, order=1)
    hookregistry.register("after", "each_step", first_after_stub, order=1)

    # setup dummy step
    step = mocker.MagicMock()

    # when
    runner.run_step(step)

    # then
    assert data == [1, 2, 2, 1]
Esempio n. 8
0
def test_should_call_hooks_in_correct_order(hookregistry, mocker):
    """
    Test that hooks are called in correct order.

    Correct order meaning:
        * before hooks: ascending order
        * after hooks: descending order
    """
    # given
    runner = Runner(hookregistry)

    # register hooks
    data = []

    def first_before_stub(*args):
        data.append(1)

    def first_after_stub(*args):
        data.append(1)

    def second_before_stub(*args):
        data.append(2)

    def second_after_stub(*args):
        data.append(2)

    hookregistry.register("before", "each_step", second_before_stub, order=2)
    hookregistry.register("after", "each_step", second_after_stub, order=2)
    hookregistry.register("before", "each_step", first_before_stub, order=1)
    hookregistry.register("after", "each_step", first_after_stub, order=1)

    # setup dummy step
    step = mocker.MagicMock()

    # when
    runner.run_step(step)

    # then
    assert data == [1, 2, 2, 1]
Esempio n. 9
0
def test_run_single_step_show_only(hookregistry, mocker):
    """
    Test running single step when show only mode is on
    """
    # given
    runner = Runner(hookregistry, show_only=True)
    step = mocker.MagicMock()
    step.run.return_value = Step.State.FAILED

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == 0
    assert step.run.call_count == 0
Esempio n. 10
0
def test_run_single_step(run_state, expected_returncode, hookregistry, mocker):
    """
    Test running a single Step
    """
    # given
    runner = Runner(hookregistry)
    step = mocker.MagicMock()
    step.run.return_value = run_state

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == expected_returncode
    assert step.run.call_count == 1
Esempio n. 11
0
def test_run_single_step_show_only(hookregistry, mocker):
    """
    Test running single step when show only mode is on
    """
    # given
    runner = Runner(hookregistry, show_only=True)
    step = mocker.MagicMock()
    step.run.return_value = Step.State.FAILED

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == 0
    assert step.run.call_count == 0
Esempio n. 12
0
def test_run_single_step(run_state, expected_returncode, hookregistry, mocker):
    """
    Test running a single Step
    """
    # given
    runner = Runner(hookregistry)
    step = mocker.MagicMock()
    step.run.return_value = run_state

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == expected_returncode
    assert step.run.call_count == 1
Esempio n. 13
0
def test_runner_should_iterate_all_steps_in_a_scenario(hook_registry,
                                                       default_config, mocker):
    """The Runner should iterate all Steps in a Scenario"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_step = mocker.MagicMock()
    runner.run_step.return_value = State.PASSED

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background = None
    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    scenario_mock.steps = [first_step, second_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([call(first_step), call(second_step)])
Esempio n. 14
0
def test_debug_single_step(debug_state, expected_returncode, world_config,
                           hookregistry, mocker):
    """
    Test debugging a single Step
    """
    # given
    runner = Runner(hookregistry)
    step = mocker.MagicMock()
    step.debug.return_value = debug_state

    # set debug mode
    world_config.debug_steps = True

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == expected_returncode
    assert step.debug.call_count == 1
Esempio n. 15
0
def test_runner_should_stop_running_steps_after_first_failed(
        hook_registry, default_config, mocker):
    """The Runner should stop running Steps after the first Step failed in normal mode"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_step = mocker.MagicMock()
    runner.run_step.side_effect = [State.PASSED, State.FAILED]

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background = None
    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    scenario_mock.steps = [first_step, second_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([call(first_step)])
Esempio n. 16
0
def test_debug_single_step(
    debug_state, expected_returncode, world_config, hookregistry, mocker
):
    """
    Test debugging a single Step
    """
    # given
    runner = Runner(hookregistry)
    step = mocker.MagicMock()
    step.debug.return_value = debug_state

    # set debug mode
    world_config.debug_steps = True

    # when
    returncode = runner.run_step(step)

    # then
    assert returncode == expected_returncode
    assert step.debug.call_count == 1
Esempio n. 17
0
def test_runner_should_only_not_run_steps_in_a_scenario_if_background_not_passed(
        hook_registry, default_config, mocker):
    """
    The Runner should not run Steps in a Scenario
    if the Background is available and did not pass.
    """
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_step = mocker.MagicMock()
    runner.run_step.return_value = State.PASSED

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background.state = State.FAILED
    first_step = mocker.MagicMock(name="First Step")
    scenario_mock.steps = [first_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_not_called()
Esempio n. 18
0
def test_runner_should_run_all_steps_even_when_failed_in_dry_run_mode(
        hook_registry, default_config, mocker):
    """The Runner should runn all Steps even when one failed in the dry run mode"""
    # given
    default_config.dry_run_mode = True

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

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background = None
    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    scenario_mock.steps = [first_step, second_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([call(first_step), call(second_step)])
Esempio n. 19
0
    def test_running_a_step(self):
        """
            Test running a step
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        step = Step(1, "Some step", "somefile.feature", 3, None, True)
        step.definition_func = some_step
        step.arguments = tuple()
        step.keyword_arguments = {}

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        returncode = runner.run_step(step)
        returncode.should.be.equal(0)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
Esempio n. 20
0
def test_runner_should_abort_if_step_is_still_running_after_running_it(
        hook_registry, default_config, mocker):
    """The Runner should abort if a Steps State is still running after its ran"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_step = mocker.MagicMock()
    runner.run_step.side_effect = [State.PASSED, State.RUNNING, State.PASSED]

    scenario_mock = mocker.MagicMock(name="Scenario")
    scenario_mock.background = None
    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    third_step = mocker.MagicMock(name="Third Step")
    scenario_mock.steps = [first_step, second_step, third_step]

    # then
    with pytest.raises(RadishError):
        # when
        runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([call(first_step), call(second_step)])
Esempio n. 21
0
def test_runner_should_run_steps_from_a_background(hook_registry,
                                                   default_config, mocker):
    """The Runner should run all Steps from a Background before running the Scenario steps"""
    # given
    default_config.dry_run_mode = True

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

    scenario_mock = mocker.MagicMock(name="Scenario")

    first_background_step = mocker.MagicMock(name="First Background Step")
    second_background_step = mocker.MagicMock(name="Second Background Step")
    scenario_mock.background.steps = [
        first_background_step, second_background_step
    ]
    scenario_mock.background.state = State.PASSED

    first_step = mocker.MagicMock(name="First Step")
    second_step = mocker.MagicMock(name="Second Step")
    scenario_mock.steps = [first_step, second_step]

    # when
    runner.run_scenario(scenario_mock)

    # then
    runner.run_step.assert_has_calls([
        call(first_background_step),
        call(second_background_step),
        call(first_step),
        call(second_step),
    ])