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

Function test_parser_implicit_output_to

tests/test_argparse_utils.py:702–725  ·  view source on GitHub ↗

Test that print_help() and print_usage() use thread-local context when no file is provided.

(mocker: MockerFixture)

Source from the content-addressed store, hash-verified

700
701
702def test_parser_implicit_output_to(mocker: MockerFixture) -> None:
703 """Test that print_help() and print_usage() use thread-local context when no file is provided."""
704 import io
705
706 parser = Cmd2ArgumentParser(prog="test")
707 buf = io.StringIO()
708
709 mock_formatter_class = mocker.patch("cmd2.argparse_utils.Cmd2HelpFormatter", autospec=True)
710 parser.formatter_class = mock_formatter_class
711 mock_formatter_class.return_value.format_help.return_value = "Help/Usage Text"
712
713 # Shadow the output file
714 with parser.output_to(buf):
715 # Call print_help without a file argument
716 parser.print_help()
717 # Verify Cmd2HelpFormatter was instantiated with file=buf (from thread-local)
718 mock_formatter_class.assert_called_with(prog="test", file=buf)
719
720 mock_formatter_class.reset_mock()
721
722 # Call print_usage without a file argument
723 parser.print_usage()
724 # Verify Cmd2HelpFormatter was instantiated with file=buf (from thread-local)
725 mock_formatter_class.assert_called_with(prog="test", file=buf)
726
727
728@with_ansi_style(ru.AllowStyle.NEVER)

Callers

nothing calls this directly

Calls 4

output_toMethod · 0.95
print_helpMethod · 0.95
print_usageMethod · 0.95
Cmd2ArgumentParserClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…