Beispiel #1
0
    def test_command_called(self):
        x = 0

        @cmd
        def some_command(arg: int):
            nonlocal x
            x = arg

        run_command("some_command 1")
        assert x == 1
        run_command("some_command 2")
        assert x == 2
Beispiel #2
0
    def test_context(self):
        x = None

        @cmd
        def some_other_command():
            nonlocal x
            x = THREAD_LOCAL.command

        @cmd
        def some_command():
            run_command("some_other_command")

        run_command("some_command")
        assert x.name == "some_other_command"
        assert x.parent.name == "some_command"
        assert "result" in repr(x)
Beispiel #3
0
def test_integration(monkeypatch, tmpdir):
    from ht3.command import run_command
    from ht3.scripts import add_scripts, load_scripts

    f = str(tmpdir.join("history"))
    monkeypatch.setattr(ht3.history, "get_history_file",
                        lambda: pathlib.Path(f))

    add_scripts(pkg_resources.resource_filename(__name__, "test_scripts"))
    load_scripts()
    result = run_command("test Yes")
    assert result == "Integration Tests ran"
Beispiel #4
0
def handle_socket(sock, addr):
    ht3.lib.THREAD_LOCAL.frontentd = "{}({})".format(__name__, addr)
    with sock:
        sock.settimeout(0.1)
        with sock.makefile("wrb") as sock_file:
            try:
                cmd, string = pickle.load(sock_file)
                if cmd == "COMMAND":
                    r = run_command(string)
                    try:
                        obj = ("OK", "RESULT", r)
                        pickle.dump(obj, sock_file)
                    except Exception:
                        obj = ("OK", "REPR", repr(r))
                        pickle.dump(obj, sock_file)
                elif cmd == "COMPLETE":
                    for c in complete_command_with_args(string):
                        obj = ("OK", "COMPLETION", c)
                        pickle.dump(obj, sock_file)
                    obj = ("OK", "COMPLETION-DONE", None)
                    pickle.dump(obj, sock_file)
                elif cmd == "PING":
                    obj = ("OK", "PONG", None)
                    pickle.dump(obj, sock_file)
                else:
                    obj = ("BAD-COMMAND", cmd)
                    pickle.dump(obj, sock_file)
            except (BrokenPipeError, EOFError, socket.timeout):
                pass
            except SystemExit:
                obj = ("OK", "EXIT", None)
                pickle.dump(obj, sock_file)
                raise
            except Exception as e:
                obj = ("EXCEPTION", e, None)
                try:
                    pickle.dump(obj, sock_file)
                except Exception:
                    pass
                ht3.lib.EXCEPTION_HOOK(exception=e)
Beispiel #5
0
 def some_command():
     run_command("some_other_command")