@@ -2058,6 +2058,19 @@ def test_poutput_ansi_terminal(outsim_app) -> None:
2058
2058
assert out == expected
2059
2059
2060
2060
2061
+ def test_broken_pipe_error (outsim_app , monkeypatch , capsys ):
2062
+ write_mock = mock .MagicMock ()
2063
+ write_mock .side_effect = BrokenPipeError
2064
+ monkeypatch .setattr ("cmd2.utils.StdSim.write" , write_mock )
2065
+
2066
+ outsim_app .broken_pipe_warning = "The pipe broke"
2067
+ outsim_app .poutput ("My test string" )
2068
+
2069
+ out , err = capsys .readouterr ()
2070
+ assert not out
2071
+ assert outsim_app .broken_pipe_warning in err
2072
+
2073
+
2061
2074
# These are invalid names for aliases and macros
2062
2075
invalid_command_name = [
2063
2076
'""' , # Blank name
@@ -2519,8 +2532,27 @@ def test_pexcept_not_exception(base_app, capsys) -> None:
2519
2532
assert err .startswith ("\x1b [91mEXCEPTION of type 'bool' occurred with message: False" )
2520
2533
2521
2534
2522
- def test_ppaged (outsim_app ) -> None :
2523
- """ppaged() will just call poutput() since a pager won't run while testing."""
2535
+ def test_ppaged_with_pager (outsim_app , monkeypatch ) -> None :
2536
+ """Force ppaged() to run the pager by mocking an actual terminal state."""
2537
+
2538
+ # Make it look like we're in a terminal
2539
+ stdin_mock = mock .MagicMock ()
2540
+ stdin_mock .isatty .return_value = True
2541
+ monkeypatch .setattr (outsim_app , "stdin" , stdin_mock )
2542
+
2543
+ stdout_mock = mock .MagicMock ()
2544
+ stdout_mock .isatty .return_value = True
2545
+ monkeypatch .setattr (outsim_app , "stdout" , stdout_mock )
2546
+
2547
+ # This will force ppaged to call Popen to run a pager
2548
+ popen_mock = mock .MagicMock (name = 'Popen' )
2549
+ monkeypatch .setattr ("subprocess.Popen" , popen_mock )
2550
+ outsim_app .ppaged ("Test" , chop = True )
2551
+ popen_mock .assert_called_once ()
2552
+
2553
+
2554
+ def test_ppaged_no_pager (outsim_app ) -> None :
2555
+ """Since we're not in a fully-functional terminal, ppaged() will just call poutput()."""
2524
2556
msg = 'testing...'
2525
2557
end = '\n '
2526
2558
outsim_app .ppaged (msg )
0 commit comments