示例#1
0
    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)
示例#2
0
    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)
示例#3
0
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)
示例#4
0
 def test_del(self):
     reply = controller.Reply(47)
     with tutils.raises(ControlException):
         reply.__del__()
     reply.handle()
     reply.ack()
     reply.take()
     reply.commit()
示例#5
0
 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()
示例#6
0
 def test_commit_no_reply(self):
     reply = controller.Reply(46)
     reply.handle()
     reply.take()
     with tutils.raises(ControlException):
         reply.commit()
     reply.ack()
     reply.commit()
示例#7
0
 def test_commit_no_reply(self):
     reply = controller.Reply(46)
     reply.handle()
     reply.take()
     with tutils.raises(ControlException):
         reply.commit()
     reply.ack()
     reply.commit()
示例#8
0
 def test_del(self):
     reply = controller.Reply(47)
     with tutils.raises(ControlException):
         reply.__del__()
     reply.handle()
     reply.ack()
     reply.take()
     reply.commit()
示例#9
0
 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()
示例#10
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()
示例#11
0
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()
示例#12
0
 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
示例#13
0
    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"
示例#14
0
    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"
示例#15
0
 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
示例#16
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")
示例#17
0
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")
示例#18
0
    def test_empty_command(self):
        with tutils.raises(ScriptException):
            Script.parse_command("")

        with tutils.raises(ScriptException):
            Script.parse_command("  ")
示例#19
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()
示例#20
0
    def test_empty_command(self):
        with tutils.raises(ScriptException):
            Script.parse_command("")

        with tutils.raises(ScriptException):
            Script.parse_command("  ")
示例#21
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()