Пример #1
0
def add_two_rollback(ctx: Context) -> Context:
    n = ctx["n"]

    result = ctx.get("result", n)

    ctx.update(result=result - 2)
    return ctx
Пример #2
0
def add_two(ctx: Context) -> Context:
    n = ctx["n"]

    result = ctx.get("result", n)

    ctx.update(result=result + 2)
    return ctx
Пример #3
0
def test_can_roll_back_function():
    ctx = Context.make({"n": 4})
    organizer = Organizer([add_two, add_three, fail_context])
    result_ctx = organizer.run(ctx)

    assert ctx.is_failure
    assert result_ctx["result"] == 7
Пример #4
0
def test_can_run_functions():
    ctx = Context.make({"n": 4})
    organizer = Organizer([add_two, add_three])
    result_ctx = organizer.run(ctx)

    assert ctx.is_success
    assert result_ctx["result"] == 9
Пример #5
0
def test_can_run_functions_with_failure():
    ctx = Context.make({"n": 4})
    organizer = Organizer([add_two, fail_context, add_three])
    result_ctx = organizer.run(ctx)

    assert ctx.is_failure
    assert result_ctx["result"] == 6
Пример #6
0
def add_two(ctx: Context) -> Context:
    number = ctx.get("n", 0)

    ctx["result"] = number + 2

    return ctx
Пример #7
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("I don't like what I see here")
    raise Organizer.ContextFailed(fail_context)
Пример #8
0
def ctx() -> Context:
    return Context.make()
Пример #9
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("I don't like what I see here")
    return ctx
Пример #10
0
def skip_rest(ctx: Context) -> Context:
    ctx.skip("No need to run the rest")
    return ctx
Пример #11
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("Something went wrong...")
    return ctx
Пример #12
0
def test_can_fail_with_a_message(ctx: Context) -> None:
    ctx.fail("An error occurred")
    assert ctx.is_failure
    assert ctx.message == "An error occurred"
Пример #13
0
def test_can_be_pushed_into_a_skipped_state(ctx: Context) -> None:
    ctx.skip("No need to run the rest")
    assert ctx.is_skipped
    assert ctx.message == "No need to run the rest"
Пример #14
0
def test_can_be_pushed_into_a_failure_state(ctx: Context) -> None:
    ctx.fail()
    assert ctx.is_failure
Пример #15
0
def test_fn__will_not_execute_if_in_failed_state(ctx: Context) -> None:
    ctx.fail()
    ctx["n"] = 3
    add_two(ctx)

    assert "result" not in ctx.keys()