def test_two_steps(capsys): op = Operation(step(hello), step(world)) result = op() out, _ = capsys.readouterr() assert out == "hello\nworld\n" assert result.success
def test_step_function_args(): def func(options, params, dep): assert options["params"] == params assert options["dep"] == dep op = Operation(step(func)) op({"happy": "yes"}, dep=5)
def test_one_step(capsys): create = Operation(step(hello)) result = create() out, _ = capsys.readouterr() assert out == "hello\n" assert result.success
def test_with_failure_handler(): op = Operation(step(how_are_you), success(enjoy_your_day), failure(tell_joke)) res = op({"happy": "I am sad"}) assert res.failure assert "joke" in res assert res["joke"] == JOKE
def test_input_failure(): op = Operation(step(how_are_you), success(enjoy_your_day)) res = op({"happy": "I am sad"}) assert res.failure
def test_input_success(capsys): op = Operation(step(how_are_you), success(enjoy_your_day)) res = op({"happy": "yes"}) out, _ = capsys.readouterr() assert out == ENJOY_MSG + "\n" assert res.success
def test_fail_step(): op = Operation(step(fail)) res = op() assert res.failure
def test_fail_fast(): def must_not_be_called(options, **k): raise AssertionError("this step must not be called after fail fast!") op = Operation(step(fail, fail_fast=True), failure(must_not_be_called)) op()