MCPcopy Index your code
hub / github.com/python/cpython / test_required_exclusive

Method test_required_exclusive

Lib/test/test_argparse.py:6721–6735  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

6719 self.assertRegex(str(cm.exception), r'\.\.\.')
6720
6721 def test_required_exclusive(self):
6722 # required mutually exclusive group; intermixed works fine
6723 parser = argparse.ArgumentParser(prog='PROG', exit_on_error=False)
6724 group = parser.add_mutually_exclusive_group(required=True)
6725 group.add_argument('--foo', action='store_true', help='FOO')
6726 group.add_argument('--spam', help='SPAM')
6727 parser.add_argument('badger', nargs='*', default='X', help='BADGER')
6728 args = parser.parse_intermixed_args('--foo 1 2'.split())
6729 self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
6730 args = parser.parse_intermixed_args('1 --foo 2'.split())
6731 self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
6732 self.assertRaisesRegex(argparse.ArgumentError,
6733 'one of the arguments --foo --spam is required',
6734 parser.parse_intermixed_args, '1 2'.split())
6735 self.assertEqual(group.required, True)
6736
6737 def test_required_exclusive_with_positional(self):
6738 # required mutually exclusive group with positional argument

Callers

nothing calls this directly

Calls 7

parse_intermixed_argsMethod · 0.95
assertRaisesRegexMethod · 0.80
NSClass · 0.70
add_argumentMethod · 0.45
splitMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected