Skip to content

Commit 7c0c2c6

Browse files
committed
Added test coverage.
1 parent 922f995 commit 7c0c2c6

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

tests/test_argparse_custom.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_text_group_direct_plain() -> None:
4949
assert " Some text" in output
5050

5151

52-
def test_text_group_in_parser(capsys) -> None:
53-
"""Print a TextGroup using argparse."""
52+
def test_text_group_in_parser_cmd2(capsys) -> None:
53+
"""Print a TextGroup with argparse using a Cmd2RichArgparseConsole."""
5454
parser = Cmd2ArgumentParser(prog="test")
5555
parser.epilog = argparse_custom.TextGroup("Notes", "Some text")
5656

@@ -62,6 +62,29 @@ def test_text_group_in_parser(capsys) -> None:
6262
assert " Some text" in out
6363

6464

65+
def test_text_group_in_parser_plain(capsys) -> None:
66+
"""Print a TextGroup with argparse not using a Cmd2RichArgparseConsole."""
67+
68+
class CustomParser(Cmd2ArgumentParser):
69+
from typing import Any
70+
71+
def _get_formatter(self, **kwargs: Any) -> Cmd2HelpFormatter:
72+
"""Overwrite the formatter's console with a plain one."""
73+
formatter = super()._get_formatter(**kwargs)
74+
formatter.console = Console()
75+
return formatter
76+
77+
parser = CustomParser(prog="test")
78+
parser.epilog = argparse_custom.TextGroup("Notes", "Some text")
79+
80+
# Render help
81+
parser.print_help()
82+
out, _ = capsys.readouterr()
83+
84+
assert "Notes:" in out
85+
assert " Some text" in out
86+
87+
6588
class ApCustomTestApp(cmd2.Cmd):
6689
"""Test app for cmd2's argparse customization"""
6790

0 commit comments

Comments
 (0)