Exemple #1
0
def add_two_rollback(ctx: Context) -> Context:
    n = ctx["n"]

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

    ctx.update(result=result - 2)
    return ctx
Exemple #2
0
def add_two(ctx: Context) -> Context:
    n = ctx["n"]

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

    ctx.update(result=result + 2)
    return ctx
Exemple #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
Exemple #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
Exemple #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
Exemple #6
0
def add_two(ctx: Context) -> Context:
    number = ctx.get("n", 0)

    ctx["result"] = number + 2

    return ctx
Exemple #7
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("I don't like what I see here")
    raise Organizer.ContextFailed(fail_context)
Exemple #8
0
def ctx() -> Context:
    return Context.make()
Exemple #9
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("I don't like what I see here")
    return ctx
Exemple #10
0
def skip_rest(ctx: Context) -> Context:
    ctx.skip("No need to run the rest")
    return ctx
Exemple #11
0
def fail_context(ctx: Context) -> Context:
    ctx.fail("Something went wrong...")
    return ctx
Exemple #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"
Exemple #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"
Exemple #14
0
def test_can_be_pushed_into_a_failure_state(ctx: Context) -> None:
    ctx.fail()
    assert ctx.is_failure
Exemple #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()