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]],
)
| 143 | ], |
| 144 | ) |
| 145 | def 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( |
nothing calls this directly
no test coverage detected
searching dependent graphs…