()
| 50 | |
| 51 | |
| 52 | def test_lazy_choices_help(): |
| 53 | mock = Mock() |
| 54 | getter = mock.getter |
| 55 | getter.return_value = ['a', 'b', 'c'] |
| 56 | |
| 57 | help_formatter = mock.help_formatter |
| 58 | help_formatter.return_value = '<my help>' |
| 59 | |
| 60 | parser = ArgumentParser() |
| 61 | parser.register('action', 'lazy_choices', LazyChoices) |
| 62 | parser.add_argument( |
| 63 | '--lazy-option', |
| 64 | default='a', |
| 65 | metavar='SYMBOL', |
| 66 | action='lazy_choices', |
| 67 | getter=getter, |
| 68 | help_formatter=help_formatter, |
| 69 | cache=False # for test purposes |
| 70 | ) |
| 71 | |
| 72 | # Parser initialization doesn't call it. |
| 73 | getter.assert_not_called() |
| 74 | |
| 75 | # If we don't use `--help`, we don't use it. |
| 76 | parser.parse_args([]) |
| 77 | getter.assert_not_called() |
| 78 | help_formatter.assert_not_called() |
| 79 | |
| 80 | parser.parse_args(['--lazy-option', 'b']) |
| 81 | help_formatter.assert_not_called() |
| 82 | |
| 83 | # If we use --help, then we call it with styles |
| 84 | with pytest.raises(SystemExit): |
| 85 | parser.parse_args(['--help']) |
| 86 | help_formatter.assert_called_once_with(['a', 'b', 'c'], isolation_mode=False) |
nothing calls this directly
no test coverage detected