Example #1
0
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")
Example #2
0
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")
Example #3
0
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()
Example #4
0
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)
Example #5
0
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()