Skip to content

Commit 94a6f8f

Browse files
committed
tests(textframe): Add shutil terminal size detection test
why: Verify display() uses shutil.get_terminal_size() for resize what: - Add test_terminal_resize_via_shutil test - Mock shutil.get_terminal_size to verify it's called
1 parent a52aa24 commit 94a6f8f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/textframe/test_display.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,27 @@ def test_status_line_displayed(self, mock_curses: None) -> None:
137137
if len(call[0]) >= 3 and "q:quit" in str(call[0][2])
138138
]
139139
assert len(status_calls) > 0, "Status line should be displayed"
140+
141+
def test_terminal_resize_via_shutil(self, mock_curses: None) -> None:
142+
"""Verify terminal size is queried via shutil.get_terminal_size().
143+
144+
This approach works reliably in tmux/multiplexers because it directly
145+
queries the terminal via ioctl(TIOCGWINSZ) on each loop iteration,
146+
rather than relying on curses KEY_RESIZE events.
147+
"""
148+
import os
149+
150+
frame = TextFrame(content_width=10, content_height=2)
151+
frame.set_content(["hello", "world"])
152+
153+
mock_stdscr = MagicMock()
154+
mock_stdscr.getch.return_value = ord("q")
155+
156+
# Mock shutil.get_terminal_size to return specific dimensions
157+
with patch(
158+
"libtmux.textframe.core.shutil.get_terminal_size",
159+
return_value=os.terminal_size((120, 40)),
160+
) as mock_get_size:
161+
frame._curses_display(mock_stdscr)
162+
# Verify shutil.get_terminal_size was called
163+
mock_get_size.assert_called()

0 commit comments

Comments
 (0)