From 5bfbdcb5765fd4eb57d13c67169bb3c2706ead75 Mon Sep 17 00:00:00 2001 From: historia Date: Sun, 23 Aug 2026 23:48:25 -0400 Subject: feat: audiobook.py tui: convert, modify, or install backends --- tests/test_tui.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/test_tui.py') diff --git a/tests/test_tui.py b/tests/test_tui.py index 94fb638..ba6f99f 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -1,4 +1,4 @@ -"""Tests for the DOS-style curses TUI widgets in tools/tui.py. +"""Tests for the DOS-style curses TUI widgets in tui.py. The widget module imports curses lazily, so these tests swap the curses module for a small fake (patched into sys.modules) and drive @@ -14,7 +14,7 @@ import unittest from pathlib import Path from unittest.mock import patch -from tools import tui +import tui class FakeCurses: @@ -73,6 +73,9 @@ class FakeCurses: def curs_set(self, visibility): pass + def endwin(self): + pass + class FakeScreen: """Recording curses window; getch() replays scripted keys.""" @@ -105,6 +108,9 @@ class FakeScreen: def hline(self, y, x, ch, n, attr=0): pass + def redrawwin(self): + pass + def getch(self): if not self.keys: raise AssertionError("the script ran out of keys") @@ -469,5 +475,32 @@ class CheckboxTreeTests(TuiTestCase): back_value=marker) +class SuspendTests(TuiTestCase): + """tui.suspend leaves curses, runs code, then repaints.""" + + def test_suspend_runs_block_and_restores(self): + ran = [] + with tui.suspend(self.screen): + ran.append("inside") + self.assertEqual(ran, ["inside"]) + + def test_suspend_always_restores_on_exception(self): + class Boom(Exception): + pass + with self.assertRaises(Boom): + with tui.suspend(self.screen): + raise Boom() + + +class FlashTests(TuiTestCase): + """tui.flash shows a notice until any key is pressed.""" + + def test_notice_dismissed_by_any_key(self): + screen = FakeScreen(keys=[10]) + # Should return (None) after consuming one key; not raise. + tui.flash(screen, "a notice", kind="warn") + self.assertEqual(screen.keys, []) + + if __name__ == "__main__": unittest.main() -- cgit v1.2.3