Skip to content

Commit 398ef08

Browse files
committed
Skip tests on windows that use termios
Also: - Add test for get_bottom_toolbar with a very narrow terminal
1 parent 4b93535 commit 398ef08

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_cmd2.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,7 @@ def test_ppaged_no_pager(outsim_app) -> None:
28042804
assert out == msg + end
28052805

28062806

2807+
@pytest.mark.skipif(sys.platform.startswith('win'), reason="termios is not available on Windows")
28072808
@pytest.mark.parametrize('has_tcsetpgrp', [True, False])
28082809
def test_ppaged_terminal_restoration(outsim_app, monkeypatch, has_tcsetpgrp) -> None:
28092810
"""Test terminal restoration in ppaged() after pager exits."""
@@ -2857,6 +2858,7 @@ def test_ppaged_terminal_restoration(outsim_app, monkeypatch, has_tcsetpgrp) ->
28572858
termios_mock.tcsetattr.assert_called_once_with(0, termios_mock.TCSANOW, dummy_settings)
28582859

28592860

2861+
@pytest.mark.skipif(sys.platform.startswith('win'), reason="termios is not available on Windows")
28602862
def test_ppaged_terminal_restoration_exceptions(outsim_app, monkeypatch) -> None:
28612863
"""Test that terminal restoration in ppaged() handles exceptions gracefully."""
28622864
# Make it look like we're in a terminal
@@ -2900,6 +2902,7 @@ def test_ppaged_terminal_restoration_exceptions(outsim_app, monkeypatch) -> None
29002902
assert termios_mock.tcsetattr.called
29012903

29022904

2905+
@pytest.mark.skipif(sys.platform.startswith('win'), reason="termios is not available on Windows")
29032906
def test_ppaged_terminal_restoration_no_settings(outsim_app, monkeypatch) -> None:
29042907
"""Test that terminal restoration in ppaged() is skipped if no settings are saved."""
29052908
# Make it look like we're in a terminal
@@ -2933,6 +2936,7 @@ def test_ppaged_terminal_restoration_no_settings(outsim_app, monkeypatch) -> Non
29332936
assert not termios_mock.tcsetattr.called
29342937

29352938

2939+
@pytest.mark.skipif(sys.platform.startswith('win'), reason="termios is not available on Windows")
29362940
def test_ppaged_terminal_restoration_oserror(outsim_app, monkeypatch) -> None:
29372941
"""Test that terminal restoration in ppaged() handles OSError gracefully."""
29382942
# Make it look like we're in a terminal
@@ -3788,3 +3792,22 @@ def my_pre_prompt():
37883792
base_app.read_input("prompt> ")
37893793

37903794
assert loop_check['running']
3795+
3796+
3797+
def test_get_bottom_toolbar_narrow_terminal(base_app, monkeypatch):
3798+
"""Test get_bottom_toolbar when terminal is too narrow for calculated padding"""
3799+
import shutil
3800+
3801+
base_app.bottom_toolbar = True
3802+
monkeypatch.setattr(sys, 'argv', ['myapp.py'])
3803+
3804+
# Mock shutil.get_terminal_size to return a very small width (e.g. 5)
3805+
# Calculated padding_size = 5 - len('myapp.py') - len(now) - 1
3806+
# Since len(now) is ~29, this will definitely be < 1
3807+
monkeypatch.setattr(shutil, 'get_terminal_size', lambda: os.terminal_size((5, 20)))
3808+
3809+
toolbar = base_app.get_bottom_toolbar()
3810+
assert isinstance(toolbar, list)
3811+
3812+
# The padding (index 1) should be exactly 1 space
3813+
assert toolbar[1] == ('', ' ')

0 commit comments

Comments
 (0)