|
1 | 1 | """Unit/functional testing for argparse customizations in cmd2""" |
2 | 2 |
|
3 | 3 | import argparse |
| 4 | +import sys |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 |
|
|
12 | 13 | ) |
13 | 14 | from cmd2.argparse_custom import ( |
14 | 15 | ChoicesCallable, |
| 16 | + Cmd2HelpFormatter, |
| 17 | + Cmd2RichArgparseConsole, |
15 | 18 | generate_range_error, |
16 | 19 | ) |
17 | 20 |
|
@@ -355,28 +358,29 @@ def test_completion_items_as_choices(capsys) -> None: |
355 | 358 | assert 'invalid choice: 3 (choose from 1, 2)' in err |
356 | 359 |
|
357 | 360 |
|
358 | | -def test_formatter_coverage(mocker) -> None: |
359 | | - import sys |
360 | | - |
361 | | - from cmd2.argparse_custom import ( |
362 | | - Cmd2HelpFormatter, |
363 | | - Cmd2RichArgparseConsole, |
364 | | - ) |
365 | | - |
366 | | - # Line 1031: self._console = console (inside console.setter) |
| 361 | +def test_formatter_console() -> None: |
| 362 | + # self._console = console (inside console.setter) |
367 | 363 | formatter = Cmd2HelpFormatter(prog='test') |
368 | 364 | new_console = Cmd2RichArgparseConsole() |
369 | 365 | formatter.console = new_console |
370 | 366 | assert formatter._console is new_console |
371 | 367 |
|
372 | | - # Line 1041: return (inside _set_color if sys.version_info < (3, 14)) |
| 368 | + |
| 369 | +@pytest.mark.skipif( |
| 370 | + sys.version_info < (3, 14), |
| 371 | + reason="Argparse didn't support color until Python 3.14", |
| 372 | +) |
| 373 | +def test_formatter_set_color(mocker) -> None: |
| 374 | + formatter = Cmd2HelpFormatter(prog='test') |
| 375 | + |
| 376 | + # return (inside _set_color if sys.version_info < (3, 14)) |
373 | 377 | mocker.patch('cmd2.argparse_custom.sys.version_info', (3, 13, 0)) |
374 | 378 | # This should return early without calling super()._set_color |
375 | 379 | mock_set_color = mocker.patch('rich_argparse.RichHelpFormatter._set_color') |
376 | 380 | formatter._set_color(True) |
377 | 381 | mock_set_color.assert_not_called() |
378 | 382 |
|
379 | | - # Line 1045 and 1047: except TypeError and super()._set_color(color) |
| 383 | + # except TypeError and super()._set_color(color) |
380 | 384 | mocker.patch('cmd2.argparse_custom.sys.version_info', (3, 15, 0)) |
381 | 385 |
|
382 | 386 | # Reset mock and make it raise TypeError when called with kwargs |
|
0 commit comments