diff --git a/cli/src/zshell/subcommands/preset.py b/cli/src/zshell/subcommands/preset.py deleted file mode 100644 index c457d92..0000000 --- a/cli/src/zshell/subcommands/preset.py +++ /dev/null @@ -1,13 +0,0 @@ -# import json -# import typer -# from zshell.assets.schemes.catppuccin import catppuccin -# -# app = typer.Typer() -# -# SCHEMES = catppuccin.variants.flavors -# -# -# @app.command() -# def set(): - -# TODO: Currently unsused diff --git a/cli/src/zshell/subcommands/record.py b/cli/src/zshell/subcommands/record.py deleted file mode 100644 index 328e2bf..0000000 --- a/cli/src/zshell/subcommands/record.py +++ /dev/null @@ -1,16 +0,0 @@ -# import typer -# import subprocess -# -# from typing import Optional -# -# app = typer.Typer() -# -# RECORDER = "gpu-screen-recorder" -# HOME = str(os.getenv("HOME")) -# CONFIG = Path(HOME + "/.config/zshell/config.json") -# -# -# @app.command() -# def start(): - -# TODO: Currently unused diff --git a/cli/src/zshell/subcommands/shell.py b/cli/src/zshell/subcommands/shell.py index 03514e9..c6a8587 100644 --- a/cli/src/zshell/subcommands/shell.py +++ b/cli/src/zshell/subcommands/shell.py @@ -16,6 +16,12 @@ def start(no_daemon: bool = False): subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), check=True) +@app.command() +def restart(no_daemon: bool = False): + subprocess.run(args + ["kill"], check=False) + subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), check=True) + + @app.command() def show(): subprocess.run(args + ["ipc"] + ["show"], check=True) @@ -33,4 +39,4 @@ def lock(): @app.command() def call(target: str, method: str, method_args: list[str] = typer.Argument(None)): - subprocess.run(args + ["ipc"] + ["call"] + [target] + [method] + method_args, check=True) + subprocess.run(args + ["ipc"] + ["call"] + [target] + [method] + (method_args or []), check=True) diff --git a/cli/tests/test_shell.py b/cli/tests/test_shell.py new file mode 100644 index 0000000..0092e25 --- /dev/null +++ b/cli/tests/test_shell.py @@ -0,0 +1,91 @@ +from __future__ import annotations + +import subprocess +from unittest.mock import patch, call +from zshell.subcommands.shell import app + + +def invoke(*args: str) -> None: + from typer.testing import CliRunner + runner = CliRunner() + result = runner.invoke(app, args) + if result.exit_code != 0: + raise RuntimeError(result.output) + return result + + +class TestKill: + @patch("zshell.subcommands.shell.subprocess.run") + def test_kill_runs_qs_kill(self, mock_run): + invoke("kill") + mock_run.assert_called_once_with(["qs", "-c", "zshell", "kill"], check=True) + + +class TestStart: + @patch("zshell.subcommands.shell.subprocess.run") + def test_start_default_daemon(self, mock_run): + invoke("start") + mock_run.assert_called_once_with(["qs", "-c", "zshell", "-n", "-d"], check=True) + + @patch("zshell.subcommands.shell.subprocess.run") + def test_start_no_daemon(self, mock_run): + invoke("start", "--no-daemon") + mock_run.assert_called_once_with(["qs", "-c", "zshell", "-n"], check=True) + + +class TestShow: + @patch("zshell.subcommands.shell.subprocess.run") + def test_show_runs_ipc_show(self, mock_run): + invoke("show") + mock_run.assert_called_once_with(["qs", "-c", "zshell", "ipc", "show"], check=True) + + +class TestLog: + @patch("zshell.subcommands.shell.subprocess.run") + def test_log_runs_qs_log(self, mock_run): + invoke("log") + mock_run.assert_called_once_with(["qs", "-c", "zshell", "log"], check=True) + + +class TestLock: + @patch("zshell.subcommands.shell.subprocess.run") + def test_lock_runs_ipc_call_lock(self, mock_run): + invoke("lock") + mock_run.assert_called_once_with( + ["qs", "-c", "zshell", "ipc", "call", "lock", "lock"], check=True + ) + + +class TestCall: + @patch("zshell.subcommands.shell.subprocess.run") + def test_call_no_args(self, mock_run): + invoke("call", "target", "method") + mock_run.assert_called_once_with( + ["qs", "-c", "zshell", "ipc", "call", "target", "method"], check=True + ) + + @patch("zshell.subcommands.shell.subprocess.run") + def test_call_with_args(self, mock_run): + invoke("call", "target", "method", "arg1", "arg2") + mock_run.assert_called_once_with( + ["qs", "-c", "zshell", "ipc", "call", "target", "method", "arg1", "arg2"], + check=True, + ) + + +class TestRestart: + @patch("zshell.subcommands.shell.subprocess.run") + def test_restart_kills_then_starts_daemon(self, mock_run): + invoke("restart") + assert mock_run.call_args_list == [ + call(["qs", "-c", "zshell", "kill"], check=False), + call(["qs", "-c", "zshell", "-n", "-d"], check=True), + ] + + @patch("zshell.subcommands.shell.subprocess.run") + def test_restart_no_daemon(self, mock_run): + invoke("restart", "--no-daemon") + assert mock_run.call_args_list == [ + call(["qs", "-c", "zshell", "kill"], check=False), + call(["qs", "-c", "zshell", "-n"], check=True), + ]