MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_rich_metavar_parts

Function test_rich_metavar_parts

tests/test_argparse_utils.py:145–166  ·  view source on GitHub ↗

Test cmd2's override of _rich_metavar_parts which handles custom nargs formats. :param nargs: the arguments nargs value :param expected_parts: list to compare to _rich_metavar_parts's return value Each element in this list is a 2-item tuple.

(
    nargs: int | tuple[int, int | float],
    expected_parts: list[tuple[str, bool]],
)

Source from the content-addressed store, hash-verified

143 ],
144)
145def test_rich_metavar_parts(
146 nargs: int | tuple[int, int | float],
147 expected_parts: list[tuple[str, bool]],
148) -> None:
149 """
150 Test cmd2's override of _rich_metavar_parts which handles custom nargs formats.
151
152 :param nargs: the arguments nargs value
153 :param expected_parts: list to compare to _rich_metavar_parts's return value
154
155 Each element in this list is a 2-item tuple.
156 item 1: one part of the argument string outputted by _format_args
157 item 2: boolean stating whether rich-argparse should color this part
158 """
159 parser = Cmd2ArgumentParser()
160 help_formatter = parser._get_formatter()
161
162 action = parser.add_argument("arg", nargs=nargs) # type: ignore[arg-type]
163 default_metavar = help_formatter._get_default_metavar_for_positional(action)
164
165 parts = help_formatter._rich_metavar_parts(action, default_metavar)
166 assert list(parts) == expected_parts
167
168
169@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 3

_get_formatterMethod · 0.95
Cmd2ArgumentParserClass · 0.90
_rich_metavar_partsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…