def test_moler_test_exception_no_exception(): ConnectionObserver.get_unraised_exceptions() from moler.cmd.unix.ls import Ls cmd = Ls(connection=None) cmd.set_exception("wrong exception") with pytest.raises(MolerStatusException): moler_test_not_raise_exception_when_no_steps_end_for_global_method()
def test_connection_observer_exception_do_not_remove(): ConnectionObserver.get_unraised_exceptions(True) time.sleep(0.1) from moler.cmd.unix.ls import Ls from moler.exceptions import CommandTimeout cmd = Ls(None) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions) cmd.set_exception(CommandTimeout(cmd, 0.1)) active_exceptions = ConnectionObserver.get_unraised_exceptions(False) assert 1 == len(active_exceptions) cmd = Ls(None) cmd.set_exception(CommandTimeout(cmd, 0.1)) active_exceptions = ConnectionObserver.get_unraised_exceptions(False) assert 2 == len(active_exceptions) active_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 2 == len(active_exceptions) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions)
def test_connection_observer_one_exception(): ConnectionObserver.get_unraised_exceptions(True) time.sleep(0.1) from moler.cmd.unix.ls import Ls from moler.exceptions import CommandTimeout cmd = Ls(None) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions) cmd.set_exception(CommandTimeout(cmd, 0.1)) active_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 1 == len(active_exceptions) try: cmd.result() except CommandTimeout: pass none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions)
def test_connection_observer_exception_do_not_remove(): ConnectionObserver.get_unraised_exceptions(True) time.sleep(0.1) from moler.cmd.unix.ls import Ls from moler.exceptions import CommandTimeout from moler.exceptions import WrongUsage cmd = Ls(None) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions) cmd.set_exception(CommandTimeout(cmd, 0.1)) cmd._is_done = True active_exceptions = ConnectionObserver.get_unraised_exceptions(False) assert 1 == len(active_exceptions) cmd = Ls(None) ctoe = CommandTimeout(cmd, 0.1) cwue = WrongUsage(cmd, "Another exception") cmd.set_exception(ctoe) cmd._is_done = True cmd.set_exception(cwue) active_exceptions = ConnectionObserver.get_unraised_exceptions(False) assert ctoe == active_exceptions[1] assert 2 == len(active_exceptions) active_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 2 == len(active_exceptions) none_exceptions = ConnectionObserver.get_unraised_exceptions(True) assert 0 == len(none_exceptions)