chore: format test files
C++ / fmt (pull_request) Successful in 4s
JS/TS / fmt (pull_request) Successful in 15s
JS/TS / lint (pull_request) Successful in 19s
Python / lint (pull_request) Successful in 32s
Python / fmt (pull_request) Failing after 37s
Python / test (pull_request) Successful in 54s
C++ / build (pull_request) Successful in 1m57s
Rust / fmt (pull_request) Successful in 1m16s
Rust / build (pull_request) Successful in 1m56s
Python / buildcheck (pull_request) Successful in 2m44s
Rust / clippy (pull_request) Successful in 1m56s
C++ / clang-tidy (pull_request) Successful in 3m46s

This commit is contained in:
2026-07-08 17:01:25 +02:00
parent 9300da258e
commit 0ae6d6fc55
2 changed files with 283 additions and 214 deletions
+42 -14
View File
@@ -1,7 +1,8 @@
from __future__ import annotations from __future__ import annotations
import pytest
from pathlib import Path from pathlib import Path
import pytest
from zshell.utils import schemepalettes as sp from zshell.utils import schemepalettes as sp
@@ -12,8 +13,12 @@ def tmp_schemes(tmp_path: Path) -> Path:
gmedium = schemes / "gruvbox" / "medium" gmedium = schemes / "gruvbox" / "medium"
gmedium.mkdir(parents=True) gmedium.mkdir(parents=True)
(gmedium / "dark.txt").write_text("background 101415\nonBackground e0e3e4\nprimary 81d3e0\nsurface 1c2021\n") (gmedium / "dark.txt").write_text(
(gmedium / "light.txt").write_text("background fbf1c7\nonBackground 3c3836\nprimary 6b5f10\nsurface fbf1c7\n") "background 101415\nonBackground e0e3e4\nprimary 81d3e0\nsurface 1c2021\n"
)
(gmedium / "light.txt").write_text(
"background fbf1c7\nonBackground 3c3836\nprimary 6b5f10\nsurface fbf1c7\n"
)
ghard = schemes / "gruvbox" / "hard" ghard = schemes / "gruvbox" / "hard"
ghard.mkdir(parents=True) ghard.mkdir(parents=True)
@@ -21,14 +26,24 @@ def tmp_schemes(tmp_path: Path) -> Path:
cmocha = schemes / "catppuccin" / "mocha" cmocha = schemes / "catppuccin" / "mocha"
cmocha.mkdir(parents=True) cmocha.mkdir(parents=True)
(cmocha / "dark.txt").write_text("background 1e1e2e\nprimary cba6f7\nsecondary 756294\nsurface 313244\n") (cmocha / "dark.txt").write_text(
(cmocha / "mauve-dark.txt").write_text("background 1e1e2e\nprimary cba6f7\nsecondary 756294\nsurface 313244\n") "background 1e1e2e\nprimary cba6f7\nsecondary 756294\nsurface 313244\n"
(cmocha / "green-dark.txt").write_text("background 1e1e2e\nprimary a6e3a1\nsecondary 5b8964\nsurface 313244\n") )
(cmocha / "mauve-dark.txt").write_text(
"background 1e1e2e\nprimary cba6f7\nsecondary 756294\nsurface 313244\n"
)
(cmocha / "green-dark.txt").write_text(
"background 1e1e2e\nprimary a6e3a1\nsecondary 5b8964\nsurface 313244\n"
)
clatte = schemes / "catppuccin" / "latte" clatte = schemes / "catppuccin" / "latte"
clatte.mkdir(parents=True) clatte.mkdir(parents=True)
(clatte / "light.txt").write_text("background eff1f5\nprimary 8839ef\nsecondary c2b8d0\nsurface ccd0da\n") (clatte / "light.txt").write_text(
(clatte / "mauve-light.txt").write_text("background eff1f5\nprimary 8839ef\nsecondary c2b8d0\nsurface ccd0da\n") "background eff1f5\nprimary 8839ef\nsecondary c2b8d0\nsurface ccd0da\n"
)
(clatte / "mauve-light.txt").write_text(
"background eff1f5\nprimary 8839ef\nsecondary c2b8d0\nsurface ccd0da\n"
)
cextra = schemes / "extra" / "default" cextra = schemes / "extra" / "default"
cextra.mkdir(parents=True) cextra.mkdir(parents=True)
@@ -81,13 +96,17 @@ class TestDiscoverSchemes:
def test_variant_has_modes(self): def test_variant_has_modes(self):
schemes = sp._discover_schemes() schemes = sp._discover_schemes()
gmedium = next(v for v in schemes["gruvbox"].variants if v.id == "medium") gmedium = next(
v for v in schemes["gruvbox"].variants if v.id == "medium"
)
assert "dark" in gmedium.modes assert "dark" in gmedium.modes
assert "light" in gmedium.modes assert "light" in gmedium.modes
def test_catppuccin_has_accents(self): def test_catppuccin_has_accents(self):
schemes = sp._discover_schemes() schemes = sp._discover_schemes()
mocha = next(v for v in schemes["catppuccin"].variants if v.id == "mocha") mocha = next(
v for v in schemes["catppuccin"].variants if v.id == "mocha"
)
assert "mauve" in mocha.accents assert "mauve" in mocha.accents
assert "green" in mocha.accents assert "green" in mocha.accents
assert "rosewater" in mocha.accents assert "rosewater" in mocha.accents
@@ -95,7 +114,9 @@ class TestDiscoverSchemes:
def test_non_accent_scheme_has_no_accents(self): def test_non_accent_scheme_has_no_accents(self):
schemes = sp._discover_schemes() schemes = sp._discover_schemes()
gmedium = next(v for v in schemes["gruvbox"].variants if v.id == "medium") gmedium = next(
v for v in schemes["gruvbox"].variants if v.id == "medium"
)
assert gmedium.accents == () assert gmedium.accents == ()
@@ -124,11 +145,15 @@ class TestGetPalette:
sp.get_palette("nope", "medium", "dark") sp.get_palette("nope", "medium", "dark")
def test_unknown_variant_raises(self): def test_unknown_variant_raises(self):
with pytest.raises(KeyError, match="Unknown variant 'bogus' for scheme 'gruvbox'"): with pytest.raises(
KeyError, match="Unknown variant 'bogus' for scheme 'gruvbox'"
):
sp.get_palette("gruvbox", "bogus", "dark") sp.get_palette("gruvbox", "bogus", "dark")
def test_unknown_accent_falls_back(self): def test_unknown_accent_falls_back(self):
pal = sp.get_palette("catppuccin", "mocha", "dark", accent="nonexistent") pal = sp.get_palette(
"catppuccin", "mocha", "dark", accent="nonexistent"
)
assert pal.accent == "nonexistent" assert pal.accent == "nonexistent"
assert pal.colors["primary"] is not None assert pal.colors["primary"] is not None
@@ -164,4 +189,7 @@ class TestResolvePreset:
assert sp.resolve_preset("default") == ("default", "default") assert sp.resolve_preset("default") == ("default", "default")
def test_edge_spaces(self): def test_edge_spaces(self):
assert sp.resolve_preset(" catppuccin : mocha ") == (" catppuccin ", " mocha ") assert sp.resolve_preset(" catppuccin : mocha ") == (
" catppuccin ",
" mocha ",
)
+56 -15
View File
@@ -1,7 +1,7 @@
from __future__ import annotations from __future__ import annotations
from subprocess import CompletedProcess from subprocess import CompletedProcess
from unittest.mock import patch, call from unittest.mock import call, patch
from typer.testing import CliRunner from typer.testing import CliRunner
from zshell.subcommands.shell import app from zshell.subcommands.shell import app
@@ -21,11 +21,15 @@ class TestKill:
def test_kill_runs_qs_kill_success(self, mock_run): def test_kill_runs_qs_kill_success(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"Killed abc\n") mock_run.return_value = CompletedProcess([], 0, b"", b"Killed abc\n")
invoke("kill") invoke("kill")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "kill"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "kill"], capture_output=True
)
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_kill_no_instance_errors(self, mock_run): def test_kill_no_instance_errors(self, mock_run):
mock_run.return_value = CompletedProcess([], 255, b"", b"No running instances\n") mock_run.return_value = CompletedProcess(
[], 255, b"", b"No running instances\n"
)
result = runner.invoke(app, ["kill"]) result = runner.invoke(app, ["kill"])
assert result.exit_code != 0 assert result.exit_code != 0
assert "No running instance to kill" in result.output assert "No running instance to kill" in result.output
@@ -34,19 +38,32 @@ class TestKill:
class TestStart: class TestStart:
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_start_default_daemon(self, mock_run): def test_start_default_daemon(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"Launching config\n") mock_run.return_value = CompletedProcess(
[], 0, b"", b"Launching config\n"
)
invoke("start") invoke("start")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "-n", "-d"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "-n", "-d"], capture_output=True
)
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_start_no_daemon(self, mock_run): def test_start_no_daemon(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"Launching config\n") mock_run.return_value = CompletedProcess(
[], 0, b"", b"Launching config\n"
)
invoke("start", "--no-daemon") invoke("start", "--no-daemon")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "-n"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "-n"], capture_output=True
)
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_start_already_running_errors(self, mock_run): def test_start_already_running_errors(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"An instance of this configuration is already running.\n", b"") mock_run.return_value = CompletedProcess(
[],
0,
b"An instance of this configuration is already running.\n",
b"",
)
result = runner.invoke(app, ["start"]) result = runner.invoke(app, ["start"])
assert result.exit_code != 0 assert result.exit_code != 0
assert "already running" in result.output assert "already running" in result.output
@@ -62,10 +79,14 @@ class TestStart:
class TestShow: class TestShow:
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_show_runs_ipc_show(self, mock_run): def test_show_runs_ipc_show(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"target visibilities\n", b"") mock_run.return_value = CompletedProcess(
[], 0, b"target visibilities\n", b""
)
result = invoke("show") result = invoke("show")
assert "target visibilities" in result.output assert "target visibilities" in result.output
mock_run.assert_called_once_with(["qs", "-c", "zshell", "ipc", "show"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "ipc", "show"], capture_output=True
)
class TestLog: class TestLog:
@@ -73,7 +94,9 @@ class TestLog:
def test_log_runs_qs_log(self, mock_run): def test_log_runs_qs_log(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"log output\n", b"") mock_run.return_value = CompletedProcess([], 0, b"log output\n", b"")
invoke("log") invoke("log")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "log"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "log"], capture_output=True
)
class TestLock: class TestLock:
@@ -81,7 +104,10 @@ class TestLock:
def test_lock_runs_ipc_call_lock(self, mock_run): def test_lock_runs_ipc_call_lock(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"") mock_run.return_value = CompletedProcess([], 0, b"", b"")
invoke("lock") invoke("lock")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "ipc", "call", "lock", "lock"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "ipc", "call", "lock", "lock"],
capture_output=True,
)
class TestCall: class TestCall:
@@ -89,14 +115,27 @@ class TestCall:
def test_call_no_args(self, mock_run): def test_call_no_args(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"") mock_run.return_value = CompletedProcess([], 0, b"", b"")
invoke("call", "target", "method") invoke("call", "target", "method")
mock_run.assert_called_once_with(["qs", "-c", "zshell", "ipc", "call", "target", "method"], capture_output=True) mock_run.assert_called_once_with(
["qs", "-c", "zshell", "ipc", "call", "target", "method"],
capture_output=True,
)
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_call_with_args(self, mock_run): def test_call_with_args(self, mock_run):
mock_run.return_value = CompletedProcess([], 0, b"", b"") mock_run.return_value = CompletedProcess([], 0, b"", b"")
invoke("call", "target", "method", "arg1", "arg2") invoke("call", "target", "method", "arg1", "arg2")
mock_run.assert_called_once_with( mock_run.assert_called_once_with(
["qs", "-c", "zshell", "ipc", "call", "target", "method", "arg1", "arg2"], [
"qs",
"-c",
"zshell",
"ipc",
"call",
"target",
"method",
"arg1",
"arg2",
],
capture_output=True, capture_output=True,
) )
@@ -106,7 +145,9 @@ class TestRestart:
@patch("zshell.subcommands.shell.subprocess.run") @patch("zshell.subcommands.shell.subprocess.run")
def test_restart_kills_then_starts(self, mock_run, mock_start): def test_restart_kills_then_starts(self, mock_run, mock_start):
mock_run.side_effect = [ mock_run.side_effect = [
CompletedProcess([], 0, b"", b"Killed abc\n"), # first kill (captured) CompletedProcess(
[], 0, b"", b"Killed abc\n"
), # first kill (captured)
CompletedProcess([], 255, b"", b""), # poll → no instance CompletedProcess([], 255, b"", b""), # poll → no instance
] ]
invoke("restart") invoke("restart")