File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2106,6 +2106,21 @@ def make_app(isatty: bool, empty_input: bool = False):
21062106 assert not out
21072107
21082108
2109+ def test_custom_stdout () -> None :
2110+ # Create a custom file-like object (e.g., an in-memory string buffer)
2111+ custom_output = io .StringIO ()
2112+
2113+ # Instantiate cmd2.Cmd with the custom_output as stdout
2114+ my_app = cmd2 .Cmd (stdout = custom_output )
2115+
2116+ # Simulate a command
2117+ my_app .onecmd ('help' )
2118+
2119+ # Retrieve the output from the custom_output buffer
2120+ captured_output = custom_output .getvalue ()
2121+ assert 'history' in captured_output
2122+
2123+
21092124def test_read_command_line_eof (base_app , monkeypatch ) -> None :
21102125 read_input_mock = mock .MagicMock (name = 'read_input' , side_effect = EOFError )
21112126 monkeypatch .setattr ("cmd2.Cmd.read_input" , read_input_mock )
You can’t perform that action at this time.
0 commit comments