MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_ppaged_with_pager

Function test_ppaged_with_pager

tests/test_cmd2.py:3255–3278  ·  view source on GitHub ↗

Force ppaged() to run the pager by mocking an actual terminal state.

(outsim_app, monkeypatch, chop)

Source from the content-addressed store, hash-verified

3253
3254@pytest.mark.parametrize("chop", [True, False])
3255def test_ppaged_with_pager(outsim_app, monkeypatch, chop) -> None:
3256 """Force ppaged() to run the pager by mocking an actual terminal state."""
3257
3258 # Make it look like we're in a terminal
3259 stdin_mock = mock.MagicMock()
3260 stdin_mock.isatty.return_value = True
3261 monkeypatch.setattr(outsim_app, "stdin", stdin_mock)
3262
3263 stdout_mock = mock.MagicMock()
3264 stdout_mock.isatty.return_value = True
3265 monkeypatch.setattr(outsim_app, "stdout", stdout_mock)
3266
3267 if not sys.platform.startswith("win") and os.environ.get("TERM") is None:
3268 monkeypatch.setenv("TERM", "simulated")
3269
3270 # This will force ppaged to call Popen to run a pager
3271 popen_mock = mock.MagicMock(name="Popen")
3272 monkeypatch.setattr("subprocess.Popen", popen_mock)
3273 outsim_app.ppaged("Test", chop=chop)
3274
3275 # Verify the correct pager was run
3276 expected_cmd = outsim_app.pager_chop if chop else outsim_app.pager
3277 assert len(popen_mock.call_args_list) == 1
3278 assert expected_cmd == popen_mock.call_args_list[0].args[0]
3279
3280
3281def test_ppaged_no_pager(outsim_app) -> None:

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…