def test_no_script_file(self): with tutils.raises("not found"): Script.parse_command("notfound") with tutils.tmpdir() as dir: with tutils.raises("not a file"): Script.parse_command(dir)
def test_simple(): with tutils.tmpdir(): with open("foo.py", "w"): pass script = mock.Mock() script.filename = "foo.py" e = Event() def _onchange(): e.set() watch(script, _onchange) with tutils.raises("already observed"): watch(script, _onchange) # Some reloaders don't register a change directly after watching, because they first need to initialize. # To test if watching works at all, we do repeated writes every 100ms. for _ in range(100): with open("foo.py", "a") as f: f.write(".") if e.wait(0.1): break else: raise AssertionError("No change detected.") unwatch(script)
def test_del(self): reply = controller.Reply(47) with tutils.raises(ControlException): reply.__del__() reply.handle() reply.ack() reply.take() reply.commit()
def test_double_send(self): reply = controller.Reply(47) reply.handle() reply.send(1) with tutils.raises(ControlException): reply.send(2) reply.take() reply.commit()
def test_commit_no_reply(self): reply = controller.Reply(46) reply.handle() reply.take() with tutils.raises(ControlException): reply.commit() reply.ack() reply.commit()
def test_script_exception(): with tutils.chdir(tutils.test_data.path("data/scripts")): s = Script("syntaxerr.py", None) with tutils.raises(ScriptException): s.load() s = Script("starterr.py", None) with tutils.raises(ScriptException): s.load() s = Script("a.py", None) s.load() with tutils.raises(ScriptException): s.load() s = Script("a.py", None) with tutils.raises(ScriptException): s.run("here") with tutils.raises(ScriptException): with Script("reqerr.py", None) as s: s.run("request", None) s = Script("unloaderr.py", None) s.load() with tutils.raises(ScriptException): s.unload()
def test_script_exception(): with tutils.chdir(tutils.test_data.path("scripts")): s = Script("syntaxerr.py", None) with tutils.raises(ScriptException): s.load() s = Script("starterr.py", None) with tutils.raises(ScriptException): s.load() s = Script("a.py", None) s.load() with tutils.raises(ScriptException): s.load() s = Script("a.py", None) with tutils.raises(ScriptException): s.run("here") with tutils.raises(ScriptException): with Script("reqerr.py", None) as s: s.run("request", None) s = Script("unloaderr.py", None) s.load() with tutils.raises(ScriptException): s.unload()
def test_state_transitions(self): states = {"unhandled", "handled", "taken", "committed"} accept = {"handle": {"unhandled"}, "take": {"handled"}, "commit": {"taken"}, "ack": {"handled", "taken"}} for fn, ok in accept.items(): for state in states: r = controller.Reply(48) r._state = state if fn == "commit": r.value = 49 if state in ok: getattr(r, fn)() else: with tutils.raises(ControlException): getattr(r, fn)() r._state = "committed" # hide warnings on deletion
def test_simple(self): reply = controller.Reply(42) assert reply.state == "unhandled" reply.handle() assert reply.state == "handled" reply.send("foo") assert reply.value == "foo" reply.take() assert reply.state == "taken" with tutils.raises(queue.Empty): reply.q.get_nowait() reply.commit() assert reply.state == "committed" assert reply.q.get() == "foo"
def test_state_transitions(self): states = {"unhandled", "handled", "taken", "committed"} accept = { "handle": {"unhandled"}, "take": {"handled"}, "commit": {"taken"}, "ack": {"handled", "taken"}, } for fn, ok in accept.items(): for state in states: r = controller.Reply(48) r._state = state if fn == "commit": r.value = 49 if state in ok: getattr(r, fn)() else: with tutils.raises(ControlException): getattr(r, fn)() r._state = "committed" # hide warnings on deletion
def test_simple(): with tutils.chdir(tutils.test_data.path("data/scripts")): s = Script("a.py --var 42", None) assert s.filename == "a.py" assert s.ns is None s.load() assert s.ns["var"] == 42 s.run("here") assert s.ns["var"] == 43 s.unload() assert s.ns is None with tutils.raises(ScriptException): s.run("here") with Script("a.py --var 42", None) as s: s.run("here")
def test_simple(): with tutils.chdir(tutils.test_data.path("scripts")): s = Script("a.py --var 42", None) assert s.filename == "a.py" assert s.ns is None s.load() assert s.ns["var"] == 42 s.run("here") assert s.ns["var"] == 43 s.unload() assert s.ns is None with tutils.raises(ScriptException): s.run("here") with Script("a.py --var 42", None) as s: s.run("here")
def test_empty_command(self): with tutils.raises(ScriptException): Script.parse_command("") with tutils.raises(ScriptException): Script.parse_command(" ")
def test_concurrent_err(): s = Script(tutils.test_data.path("scripts/concurrent_decorator_err.py"), None) with tutils.raises( "Concurrent decorator not supported for 'start' method"): s.load()
def test_concurrent_err(): s = Script(tutils.test_data.path("scripts/concurrent_decorator_err.py"), None) with tutils.raises("Concurrent decorator not supported for 'start' method"): s.load()