MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_required_exclusive

Method test_required_exclusive

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

Source from the content-addressed store, hash-verified

6586 self.assertRegex(str(cm.exception), r'\.\.\.')
6587
6588 def test_required_exclusive(self):
6589 # required mutually exclusive group; intermixed works fine
6590 parser = argparse.ArgumentParser(prog='PROG', exit_on_error=False)
6591 group = parser.add_mutually_exclusive_group(required=True)
6592 group.add_argument('--foo', action='store_true', help='FOO')
6593 group.add_argument('--spam', help='SPAM')
6594 parser.add_argument('badger', nargs='*', default='X', help='BADGER')
6595 args = parser.parse_intermixed_args('--foo 1 2'.split())
6596 self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
6597 args = parser.parse_intermixed_args('1 --foo 2'.split())
6598 self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
6599 self.assertRaisesRegex(argparse.ArgumentError,
6600 'one of the arguments --foo --spam is required',
6601 parser.parse_intermixed_args, '1 2'.split())
6602 self.assertEqual(group.required, True)
6603
6604 def test_required_exclusive_with_positional(self):
6605 # 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