Skip to content

Commit 3140cac

Browse files
authored
Merge pull request #1795 from dbcli/RW/add-ptoolkit-utils-tests
Add tests for `mycli/packages/ptoolkit/utils.py`
2 parents 42007a7 + dc1707e commit 3140cac

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Internal
2020
---------
2121
* Add an `AGENTS.md`.
2222
* Refactor `find_matches()` into smaller logical units.
23-
* Increase test coverage.
23+
* Greatly increase test coverage.
2424
* Remove some unused code.
2525
* Better label Codex PR reviews.
2626
* Improve gitignored files.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from dataclasses import dataclass, field
2+
from typing import Any, cast
3+
4+
from mycli.packages.ptoolkit import utils as ptoolkit_utils
5+
6+
7+
@dataclass
8+
class DummyApp:
9+
print_calls: list[str] = field(default_factory=list)
10+
11+
def print_text(self, text: str) -> None:
12+
self.print_calls.append(text)
13+
14+
15+
def test_safe_invalidate_display_runs_empty_terminal_print(monkeypatch) -> None:
16+
app = DummyApp()
17+
callbacks: list[object] = []
18+
19+
def fake_run_in_terminal(callback) -> None:
20+
callbacks.append(callback)
21+
callback()
22+
23+
monkeypatch.setattr(ptoolkit_utils, 'run_in_terminal', fake_run_in_terminal)
24+
25+
ptoolkit_utils.safe_invalidate_display(cast(Any, app))
26+
27+
assert len(callbacks) == 1
28+
assert app.print_calls == ['']
29+
30+
31+
def test_safe_invalidate_display_swallows_runtime_error(monkeypatch) -> None:
32+
app = DummyApp()
33+
34+
def fail_run_in_terminal(_callback) -> None:
35+
raise RuntimeError('application is exiting')
36+
37+
monkeypatch.setattr(ptoolkit_utils, 'run_in_terminal', fail_run_in_terminal)
38+
39+
ptoolkit_utils.safe_invalidate_display(cast(Any, app))
40+
41+
assert app.print_calls == []

0 commit comments

Comments
 (0)