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_parse_windows(self): with tutils.chdir(tutils.test_data.dirname): assert Script.parse_command("data\\scripts\\a.py") == [ "data\\scripts\\a.py" ] assert Script.parse_command( "data\\scripts\\a.py 'foo \\ bar'") == [ "data\\scripts\\a.py", 'foo \\ bar' ]
def test_parse_args(self): with tutils.chdir(tutils.test_data.dirname): assert Script.parse_command("scripts/a.py") == ["scripts/a.py"] assert Script.parse_command("scripts/a.py foo bar") == [ "scripts/a.py", "foo", "bar" ] assert Script.parse_command("scripts/a.py 'foo bar'") == [ "scripts/a.py", "foo bar" ]
def test_concurrent(): with Script(tutils.test_data.path("data/scripts/concurrent_decorator.py"), None) as s: f1, f2 = Thing(), Thing() s.run("request", f1) s.run("request", f2) start = time.time() while time.time() - start < 5: if f1.reply.acked and f2.reply.acked: return raise ValueError("Script never acked")
def test_concurrent(): with Script(tutils.test_data.path("data/scripts/concurrent_decorator.py"), None) as s: def reply(): reply.acked.set() reply.acked = Event() f1, f2 = Dummy(reply), Dummy(reply) s.run("request", f1) f1.reply() s.run("request", f2) f2.reply() assert f1.reply.acked == reply.acked assert not reply.acked.is_set() assert reply.acked.wait(10)
def test_empty_command(self): with tutils.raises(ScriptException): Script.parse_command("") with tutils.raises(ScriptException): Script.parse_command(" ")
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_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_parse_windows(self): with tutils.chdir(tutils.test_data.dirname): assert Script.parse_command("scripts\\a.py") == ["scripts\\a.py"] assert Script.parse_command("scripts\\a.py 'foo \\ bar'") == ["scripts\\a.py", 'foo \\ bar']
def test_parse_args(self): with tutils.chdir(tutils.test_data.dirname): assert Script.parse_command("scripts/a.py") == ["scripts/a.py"] assert Script.parse_command("scripts/a.py foo bar") == ["scripts/a.py", "foo", "bar"] assert Script.parse_command("scripts/a.py 'foo bar'") == ["scripts/a.py", "foo bar"]
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_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_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()