Пример #1
0
def test_allow_errors():
    state = prepare_state("")
    state.reporter.errors = ["Error"]
    EagerChain(chainable_functions=sct_ctx,
               state=state).allow_errors().success_msg("Good")
    sct_payload = state.reporter.build_final_payload()
    assert sct_payload["correct"] is True
    assert sct_payload["message"] == "Good"
Пример #2
0
def test_success_msg_pass_ex():
    state = prepare_state("")
    EagerChain(chainable_functions=sct_ctx,
               state=state).success_msg("NEW SUCCESS MSG")

    sct_payload = state.reporter.build_final_payload()
    assert sct_payload["correct"] is True
    assert sct_payload["message"] == "NEW SUCCESS MSG"
Пример #3
0
def test_no_allow_errors():
    state = prepare_state("")
    state.reporter.errors = ["Error"]
    EagerChain(chainable_functions=sct_ctx, state=state).success_msg("Good")
    sct_payload = state.reporter.build_final_payload()
    assert sct_payload["correct"] is False
    assert (sct_payload["message"] ==
            "Your code generated an error. Fix it and try again!")
Пример #4
0
def test_has_chosen_chain_fail():
    state = prepare_state("selected_option = 2")
    with pytest.raises(TF, match="bad"):
        EagerChain(chainable_functions=sct_ctx,
                   state=state).has_chosen(1, ["good", "bad"])
Пример #5
0
def test_has_chosen_chain_pass():
    state = prepare_state("selected_option = 1")
    EagerChain(chainable_functions=sct_ctx,
               state=state).has_chosen(1, ["good", "bad"])
    assert state.reporter.build_final_payload()["message"] == "good"
Пример #6
0
def Ex(state=None):
    return EagerChain(state=state or State.root_state, chainable_functions=sct_dict)
Пример #7
0
def test_ex_sct_copy_pos(addx):
    assert EagerChain(ChainedCall(addx, ("x", )),
                      state="state")._state == "statex"
Пример #8
0
def test_ex_sct_copy_kw(addx):
    assert (EagerChain(ChainedCall(addx, kwargs={"x": "x"}),
                       state="state")._state == "statex")