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

Method test_multiple_argument_option

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

Source from the content-addressed store, hash-verified

6547 self.assertEqual(NS(foo=None, bar=['a', 'b', '--', 'c', '--foo', 'd']), args)
6548
6549 def test_multiple_argument_option(self):
6550 parser = argparse.ArgumentParser(exit_on_error=False)
6551 parser.add_argument('-f', '--foo', nargs='*')
6552 parser.add_argument('bar', nargs='*')
6553
6554 args = parser.parse_args(['--foo=--'])
6555 self.assertEqual(NS(foo=['--'], bar=[]), args)
6556 args = parser.parse_args(['--foo', '--'])
6557 self.assertEqual(NS(foo=[], bar=[]), args)
6558 args = parser.parse_args(['-f--'])
6559 self.assertEqual(NS(foo=['--'], bar=[]), args)
6560 args = parser.parse_args(['-f', '--'])
6561 self.assertEqual(NS(foo=[], bar=[]), args)
6562 args = parser.parse_args(['--foo', 'a', 'b', '--', 'c', 'd'])
6563 self.assertEqual(NS(foo=['a', 'b'], bar=['c', 'd']), args)
6564 args = parser.parse_args(['a', 'b', '--foo', 'c', 'd'])
6565 self.assertEqual(NS(foo=['c', 'd'], bar=['a', 'b']), args)
6566 args = parser.parse_args(['a', '--', 'b', '--foo', 'c', 'd'])
6567 self.assertEqual(NS(foo=None, bar=['a', 'b', '--foo', 'c', 'd']), args)
6568 args, argv = parser.parse_known_args(['a', 'b', '--foo', 'c', '--', 'd'])
6569 self.assertEqual(NS(foo=['c'], bar=['a', 'b']), args)
6570 self.assertEqual(argv, ['--', 'd'])
6571
6572 def test_multiple_double_dashes(self):
6573 parser = argparse.ArgumentParser(exit_on_error=False)

Callers

nothing calls this directly

Calls 5

parse_argsMethod · 0.95
parse_known_argsMethod · 0.95
NSClass · 0.70
add_argumentMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected