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"
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"
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!")
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"])
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"
def Ex(state=None): return EagerChain(state=state or State.root_state, chainable_functions=sct_dict)
def test_ex_sct_copy_pos(addx): assert EagerChain(ChainedCall(addx, ("x", )), state="state")._state == "statex"
def test_ex_sct_copy_kw(addx): assert (EagerChain(ChainedCall(addx, kwargs={"x": "x"}), state="state")._state == "statex")