Skip to content

Commit 340b688

Browse files
committed
Add missing unit test for custom stdout
1 parent cf9b7c5 commit 340b688

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_cmd2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
21092124
def 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)

0 commit comments

Comments
 (0)