def test_sequential_state(capsys): ps1 = PrintState("ps1", "Print1") ps2 = PrintState("ps1", "Print2") ps3 = PrintState("ps1", "Print3") es = IdleState("endState") sm = SequentialState("sm", children=[ps2, ps3]) sm.add_children(ps1) sm.add_transition_on_success(es) exe = Machine("xe", sm, end_state_ids=["endState"], rate=10) exe.run() assert capsys.readouterr().out == "Print2\nPrint3\nPrint1\n"
def test_exception_in_sequential_state(capsys): error_text = "IndexErrorInTestEXCEPTION" class RaiseExceptionState(State): def execute(self, board): raise IndexError(error_text) ps1 = PrintState("ps1", "Print1") ps2 = PrintState("ps1", "Print2") ps3 = PrintState("ps1", "Print3") rs = RaiseExceptionState("rs1") es = IdleState("endState") sm = SequentialState("sm", children=[ps2, ps3, rs]) sm.add_children(ps1) sm.add_transition_on_success(es) exe = Machine("xe", sm, end_state_ids=["endState"]) exe.run() assert capsys.readouterr().out == "Print2\nPrint3\n" assert str(exe._internal_exception) == error_text assert exe._exception_raised_state_name == "xe.sm.rs1"