MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_ppaged_terminal_restoration_no_settings

Function test_ppaged_terminal_restoration_no_settings

tests/test_cmd2.py:3389–3419  ·  view source on GitHub ↗

Test that terminal restoration in ppaged() is skipped if no settings are saved.

(outsim_app, monkeypatch)

Source from the content-addressed store, hash-verified

3387
3388@pytest.mark.skipif(sys.platform.startswith("win"), reason="termios is not available on Windows")
3389def test_ppaged_terminal_restoration_no_settings(outsim_app, monkeypatch) -> None:
3390 """Test that terminal restoration in ppaged() is skipped if no settings are saved."""
3391 # Make it look like we're in a terminal
3392 stdin_mock = mock.MagicMock()
3393 stdin_mock.isatty.return_value = True
3394 stdin_mock.fileno.return_value = 0
3395 monkeypatch.setattr(outsim_app, "stdin", stdin_mock)
3396
3397 stdout_mock = mock.MagicMock()
3398 stdout_mock.isatty.return_value = True
3399 monkeypatch.setattr(outsim_app, "stdout", stdout_mock)
3400
3401 if not sys.platform.startswith("win") and os.environ.get("TERM") is None:
3402 monkeypatch.setenv("TERM", "simulated")
3403
3404 # Mock termios
3405 termios_mock = mock.MagicMock()
3406 monkeypatch.setitem(sys.modules, "termios", termios_mock)
3407
3408 # Mock subprocess.Popen
3409 popen_mock = mock.MagicMock(name="Popen")
3410 monkeypatch.setattr("subprocess.Popen", popen_mock)
3411
3412 # Ensure initial termios settings is None
3413 outsim_app._initial_termios_settings = None
3414
3415 # Call ppaged
3416 outsim_app.ppaged("Test")
3417
3418 # Verify tcsetattr was NOT called
3419 assert not termios_mock.tcsetattr.called
3420
3421
3422@pytest.mark.skipif(sys.platform.startswith("win"), reason="termios is not available on Windows")

Callers

nothing calls this directly

Calls 2

ppagedMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…