Test that print_help() and print_usage() use thread-local context when no file is provided.
(mocker: MockerFixture)
| 700 | |
| 701 | |
| 702 | def 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…