Skip to content

Commit a39b929

Browse files
committed
Fixing tests on Windows.
1 parent 38b4e62 commit a39b929

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

tests/test_cmd2.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,10 @@ def test_echo(capsys) -> None:
19001900
assert out.startswith(f'{app.prompt}{commands[0]}\nUsage: history')
19011901

19021902

1903+
@pytest.mark.skipif(
1904+
sys.platform.startswith('win'),
1905+
reason="Don't have a real Windows console with how we are currently running tests in GitHub Actions",
1906+
)
19031907
def test_read_raw_input_tty(base_app: cmd2.Cmd) -> None:
19041908
with create_pipe_input() as pipe_input:
19051909
base_app.session = PromptSession(
@@ -3617,24 +3621,27 @@ def test_no_console_screen_buffer_error_dummy():
36173621
def test_read_command_line_dynamic_prompt(base_app: cmd2.Cmd) -> None:
36183622
"""Test that _read_command_line uses a dynamic prompt when provided prompt matches app.prompt"""
36193623

3620-
# Set input to something other than DummyInput so _read_raw_input() will go down the TTY route.
3621-
mock_session = mock.MagicMock()
3622-
mock_session.input = mock.MagicMock()
3623-
base_app.session = mock_session
3624-
base_app._read_command_line(base_app.prompt)
3625-
3626-
# Check that mock_prompt was called with a callable for the prompt
3627-
# args[0] should be the prompt_to_use
3628-
args, _ = mock_session.prompt.call_args
3629-
prompt_arg = args[0]
3630-
assert callable(prompt_arg)
3631-
3632-
# Verify the callable returns the expected ANSI formatted prompt
3633-
from prompt_toolkit.formatted_text import ANSI
3634-
3635-
result = prompt_arg()
3636-
assert isinstance(result, ANSI)
3637-
assert result.value == ANSI(base_app.prompt).value
3624+
# Mock patch_stdout to prevent it from attempting to access the Windows
3625+
# console buffer in a Windows test environment.
3626+
with mock.patch('prompt_toolkit.patch_stdout.patch_stdout', return_value=mock.MagicMock()):
3627+
# Set input to something other than DummyInput so _read_raw_input()
3628+
# will go down the TTY route.
3629+
mock_session = mock.MagicMock()
3630+
mock_session.input = mock.MagicMock()
3631+
base_app.session = mock_session
3632+
base_app._read_command_line(base_app.prompt)
3633+
3634+
# Check that mock_prompt was called with a callable for the prompt
3635+
args, _ = mock_session.prompt.call_args
3636+
prompt_arg = args[0]
3637+
assert callable(prompt_arg)
3638+
3639+
# Verify the callable returns the expected ANSI formatted prompt
3640+
from prompt_toolkit.formatted_text import ANSI
3641+
3642+
result = prompt_arg()
3643+
assert isinstance(result, ANSI)
3644+
assert result.value == ANSI(base_app.prompt).value
36383645

36393646

36403647
def test_read_input_history_isolation(base_app: cmd2.Cmd) -> None:

0 commit comments

Comments
 (0)