diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 18:25:59 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 18:25:59 +0100 |
| commit | 7f99167f0b6a3c83bf77e20bc5e03942b901fb71 (patch) | |
| tree | 6b60263b6f702e6088eae30087c6dfa2a5a71f4c /tests | |
| parent | 03e2adab3fb58532ba1e32c2f01a9ec14f11e484 (diff) | |
| download | deck-it-7f99167f0b6a3c83bf77e20bc5e03942b901fb71.tar.gz deck-it-7f99167f0b6a3c83bf77e20bc5e03942b901fb71.zip | |
fix: OBS idle timeout, payload validation, workspace list
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_llm.py | 9 | ||||
| -rw-r--r-- | tests/test_obs.py | 9 | ||||
| -rw-r--r-- | tests/test_obsclient.py | 22 | ||||
| -rw-r--r-- | tests/test_server.py | 7 | ||||
| -rw-r--r-- | tests/test_theme.py | 10 | ||||
| -rw-r--r-- | tests/test_windows.py | 10 |
6 files changed, 65 insertions, 2 deletions
diff --git a/tests/test_llm.py b/tests/test_llm.py index 759666c..9cdfcf6 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -27,6 +27,15 @@ class Up(unittest.TestCase): self.assertEqual(st["claude"]["context_pct"], 12) self.assertEqual(st["opencode"]["total_cost"], 1.5) + def test_handles_the_real_latest_shape(self): + data = {"/api/claude_limits": {"latest": {"context_pct": 42, "five_hour_pct": 10}}, + "/api/claude_session": {}, + "/api/summary": {}} + st = llm.make({"llm": {"url": "http://x"}, + "fetch": lambda u, timeout=2: data[u]}).state() + self.assertEqual(st["claude"]["context_pct"], 42) + self.assertEqual(st["claude"]["five_hour_pct"], 10) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_obs.py b/tests/test_obs.py index 876d48b..aeb0791 100644 --- a/tests/test_obs.py +++ b/tests/test_obs.py @@ -39,7 +39,14 @@ class Actions(unittest.TestCase): def test_state_offline(self): class Off: connected = False - self.assertEqual(obs.make({"client": Off()}).state(), {"connected": False}) + st = obs.make({"client": Off()}).state() + self.assertFalse(st["connected"]) + self.assertIn("error", st) + + def test_record_requires_a_bool(self): + for bad in ({}, {"on": "false"}, {"on": 1}): + with self.assertRaises(obs.ModuleError, msg=bad): + self.m.actions["record"](bad) class Serialized(unittest.TestCase): diff --git a/tests/test_obsclient.py b/tests/test_obsclient.py index 7d1a5ca..54eadd1 100644 --- a/tests/test_obsclient.py +++ b/tests/test_obsclient.py @@ -25,5 +25,27 @@ class Disconnected(unittest.TestCase): oc.ObsClient(host="127.0.0.1", port=4455, password="").request("GetVersion") +class RecvLoop(unittest.TestCase): + def test_a_recv_timeout_does_not_end_the_loop(self): + import websocket + + class FakeWS: + calls = 0 + + def recv(self): + FakeWS.calls += 1 + if FakeWS.calls <= 3: + raise websocket.WebSocketTimeoutException("idle") + raise RuntimeError("closed") + + c = oc.ObsClient() + c.ws = FakeWS() + c.connected = True + c._recv_loop() + # It kept calling recv past three idle timeouts; a timeout must not + # look like a closed socket. + self.assertEqual(FakeWS.calls, 4) + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_server.py b/tests/test_server.py index 1583ad2..bf571a6 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -38,7 +38,8 @@ class Server(unittest.TestCase): srv.TOKEN = TOKEN srv.REGISTRY = mod.Registry([ mod.Module("demo", "Demo", lambda: {"ok": True}, - {"ping": lambda body: {"got": body.get("n")}}), + {"ping": lambda body: {"got": body.get("n")}, + "boom": lambda body: int(body.get("x"))}), ]) cls.server = srv.UnixHTTPServer(cls.sock, srv.Handler) threading.Thread(target=cls.server.serve_forever, daemon=True).start() @@ -86,6 +87,10 @@ class Server(unittest.TestCase): {**HOST, **ORIGIN, "Content-Type": "application/json"}, big) self.assertEqual(status, 400) + def test_rejects_wrong_typed_body(self): + h = {**HOST, **ORIGIN, "Content-Type": "application/json"} + self.assertEqual(self.req("POST", "/api/demo/boom", h, '{"x": null}')[0], 400) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_theme.py b/tests/test_theme.py index 5f2f533..6530af5 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -29,6 +29,16 @@ class Theme(unittest.TestCase): self.assertIn("--udt-base: #24273a", out) self.assertIn("--udt-accent:", out) # fallback accent + def test_load_falls_back_when_files_are_missing(self): + saved = (theme.PALETTE_PATH, theme.ACCENT_PATH) + theme.PALETTE_PATH = Path("/nonexistent/palette.rasi") + theme.ACCENT_PATH = Path("/nonexistent/accent.rasi") + try: + out = theme.load() + finally: + theme.PALETTE_PATH, theme.ACCENT_PATH = saved + self.assertIn("--udt-base: #24273a", out) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_windows.py b/tests/test_windows.py index 1573a77..6aa7925 100644 --- a/tests/test_windows.py +++ b/tests/test_windows.py @@ -18,6 +18,16 @@ class Commands(unittest.TestCase): self.assertIsNone(windows.ADDR.fullmatch("0x1;rm")) self.assertTrue(windows.ADDR.fullmatch("0x55897e5c0800")) + def test_state_lists_all_workspaces(self): + responses = { + ("hyprctl", "clients", "-j"): "[]", + ("hyprctl", "activewindow", "-j"): "{}", + ("hyprctl", "monitors", "-j"): "[]", + ("hyprctl", "workspaces", "-j"): '[{"id": 1}, {"id": 2}, {"id": 5}]', + } + st = windows._state(lambda cmd: responses[tuple(cmd)]) + self.assertEqual(st["workspaces"], [1, 2, 5]) + if __name__ == "__main__": unittest.main() |
