def test_step_fail_to_run_if_no_step_impl(): """A Step should fail to run if it has no Step Implementation assigned to it""" # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) # then with pytest.raises(RadishError): # when step.run(None)
def test_step_fail_to_run_if_already_run(mocker): """A Step should fail to run if it was already run / has another state then UNTESTED""" # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step.assign_implementation(step_impl_mock, step_impl_match_mock) step.state = State.PASSED # then with pytest.raises(RadishError): # when step.run(None)
def test_step_should_evaluate_its_matched_step_impl_arguments(mocker): """A Step should evlauate the arguments of its matched Step Implementation""" # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = ([], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then step_impl_match_mock.evaluate.assert_called_once_with()
def test_step_should_change_state_to_passed_if_step_impl_func_not_raised(mocker): """ A Step should change its State to PASSED if the ran Step Implementation function did not raise any Exception """ # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = ([], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then assert step.state is State.PASSED
def test_step_fail_if_step_impl_func_raises(mocker): """A Step should fail if the Step Implementation function raised an Exception""" # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step.fail = mocker.MagicMock(name="Step fail function") step_impl_mock = mocker.MagicMock(name="Step Impl") exception = Exception("buuh!") step_impl_mock.func.side_effect = exception step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = ([], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then step.fail.assert_called_once_with(exception)
def test_step_should_pass_evaluated_args_to_step_impl_func(mocker): """ A Step should pass the evaluated args from the Step Implementation match function to the Step Implementation function. """ # given step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = (["foo", "bar"], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then step_impl_mock.func.assert_called_once_with(step, "foo", "bar")
def test_step_should_not_set_passed_state_if_state_changed_during_run(mocker): """A Step should not set its State to PASSED if the state was changed during the run""" # given def step_change_state(step): step.skip() step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_mock.func = step_change_state step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = ([], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then assert step.state is State.SKIPPED
def test_step_should_set_state_to_running_before_running_step_impl(mocker): """A Step should set its State to RUNNING before it runs the Step Implementation function""" # given class WrapperForMockerSpy: def step_func(self, step): assert step.state is State.RUNNING w = WrapperForMockerSpy() mocker.spy(w, "step_func") step = Step(1, "keyword", "used_keyword", "text", None, None, None, None) step_impl_mock = mocker.MagicMock(name="Step Impl") step_impl_mock.func = w.step_func step_impl_match_mock = mocker.MagicMock(name="Step Impl Match") step_impl_match_mock.evaluate.return_value = ([], {}) step.assign_implementation(step_impl_mock, step_impl_match_mock) # when step.run(None) # then w.step_func.assert_called_once_with(step)