Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
test.test_argparse.TestParentParsers Class Reference
Inheritance diagram for test.test_argparse.TestParentParsers:
Inheritance graph
[legend]
Collaboration diagram for test.test_argparse.TestParentParsers:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def assertArgumentParserError
def setUp
def test_single_parent
def test_single_parent_mutex
def test_single_granparent_mutex
def test_multiple_parents
def test_multiple_parents_mutex
def test_conflicting_parents
def test_conflicting_parents_mutex
def test_same_argument_name_parents
def test_subparser_parents
def test_subparser_parents_mutex
def test_parent_help
def test_groups_parents
def assertEqual

Public Attributes

 wxyz_parent
 abcd_parent
 w_parent
 z_parent
 ab_mutex_parent
 main_program

Private Member Functions

def _test_mutex_ab

Detailed Description

Tests that parsers can be created with parent parsers

Definition at line 2046 of file test_argparse.py.


Member Function Documentation

def test.test_argparse.TestParentParsers._test_mutex_ab (   self,
  parse_args 
) [private]

Definition at line 2096 of file test_argparse.py.

02096 
02097     def _test_mutex_ab(self, parse_args):
02098         self.assertEqual(parse_args([]), NS(a=False, b=False))
02099         self.assertEqual(parse_args(['-a']), NS(a=True, b=False))
02100         self.assertEqual(parse_args(['-b']), NS(a=False, b=True))
02101         self.assertArgumentParserError(parse_args, ['-a', '-b'])
02102         self.assertArgumentParserError(parse_args, ['-b', '-a'])
02103         self.assertArgumentParserError(parse_args, ['-c'])
02104         self.assertArgumentParserError(parse_args, ['-a', '-c'])
02105         self.assertArgumentParserError(parse_args, ['-b', '-c'])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2049 of file test_argparse.py.

02049 
02050     def assertArgumentParserError(self, *args, **kwargs):
02051         self.assertRaises(ArgumentParserError, *args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_argparse.TestCase.assertEqual (   self,
  obj1,
  obj2 
) [inherited]

Definition at line 22 of file test_argparse.py.

00022 
00023     def assertEqual(self, obj1, obj2):
00024         if obj1 != obj2:
00025             print('')
00026             print(repr(obj1))
00027             print(repr(obj2))
00028             print(obj1)
00029             print(obj2)
00030         super(TestCase, self).assertEqual(obj1, obj2)

Reimplemented from test.test_argparse.TestCase.

Definition at line 2052 of file test_argparse.py.

02052 
02053     def setUp(self):
02054         super().setUp()
02055         self.wxyz_parent = ErrorRaisingArgumentParser(add_help=False)
02056         self.wxyz_parent.add_argument('--w')
02057         x_group = self.wxyz_parent.add_argument_group('x')
02058         x_group.add_argument('-y')
02059         self.wxyz_parent.add_argument('z')
02060 
02061         self.abcd_parent = ErrorRaisingArgumentParser(add_help=False)
02062         self.abcd_parent.add_argument('a')
02063         self.abcd_parent.add_argument('-b')
02064         c_group = self.abcd_parent.add_argument_group('c')
02065         c_group.add_argument('--d')
02066 
02067         self.w_parent = ErrorRaisingArgumentParser(add_help=False)
02068         self.w_parent.add_argument('--w')
02069 
02070         self.z_parent = ErrorRaisingArgumentParser(add_help=False)
02071         self.z_parent.add_argument('z')
02072 
02073         # parents with mutually exclusive groups
02074         self.ab_mutex_parent = ErrorRaisingArgumentParser(add_help=False)
02075         group = self.ab_mutex_parent.add_mutually_exclusive_group()
02076         group.add_argument('-a', action='store_true')
02077         group.add_argument('-b', action='store_true')
02078 
02079         self.main_program = os.path.basename(sys.argv[0])

Here is the caller graph for this function:

Definition at line 2122 of file test_argparse.py.

02122 
02123     def test_conflicting_parents(self):
02124         self.assertRaises(
02125             argparse.ArgumentError,
02126             argparse.ArgumentParser,
02127             parents=[self.w_parent, self.wxyz_parent])

Here is the call graph for this function:

Definition at line 2128 of file test_argparse.py.

02128 
02129     def test_conflicting_parents_mutex(self):
02130         self.assertRaises(
02131             argparse.ArgumentError,
02132             argparse.ArgumentParser,
02133             parents=[self.abcd_parent, self.ab_mutex_parent])

Here is the call graph for this function:

Definition at line 2190 of file test_argparse.py.

02190 
02191     def test_groups_parents(self):
02192         parent = ErrorRaisingArgumentParser(add_help=False)
02193         g = parent.add_argument_group(title='g', description='gd')
02194         g.add_argument('-w')
02195         g.add_argument('-x')
02196         m = parent.add_mutually_exclusive_group()
02197         m.add_argument('-y')
02198         m.add_argument('-z')
02199         parser = ErrorRaisingArgumentParser(parents=[parent])
02200 
02201         self.assertRaises(ArgumentParserError, parser.parse_args,
02202             ['-y', 'Y', '-z', 'Z'])
02203 
02204         parser_help = parser.format_help()
02205         self.assertEqual(parser_help, textwrap.dedent('''\
02206             usage: {} [-h] [-w W] [-x X] [-y Y | -z Z]
02207 
02208             optional arguments:
02209               -h, --help  show this help message and exit
02210               -y Y
02211               -z Z
02212 
02213             g:
02214               gd
02215 
02216               -w W
02217               -x X
02218         '''.format(self.main_program)))
02219 
02220 # ==============================
02221 # Mutually exclusive group tests
02222 # ==============================

Here is the call graph for this function:

Definition at line 2106 of file test_argparse.py.

02106 
02107     def test_multiple_parents(self):
02108         parents = [self.abcd_parent, self.wxyz_parent]
02109         parser = ErrorRaisingArgumentParser(parents=parents)
02110         self.assertEqual(parser.parse_args('--d 1 --w 2 3 4'.split()),
02111                          NS(a='3', b=None, d='1', w='2', y=None, z='4'))

Here is the call graph for this function:

Definition at line 2112 of file test_argparse.py.

02112 
02113     def test_multiple_parents_mutex(self):
02114         parents = [self.ab_mutex_parent, self.wxyz_parent]
02115         parser = ErrorRaisingArgumentParser(parents=parents)
02116         self.assertEqual(parser.parse_args('-a --w 2 3'.split()),
02117                          NS(a=True, b=False, w='2', y=None, z='3'))
02118         self.assertArgumentParserError(
02119             parser.parse_args, '-a --w 2 3 -b'.split())
02120         self.assertArgumentParserError(
02121             parser.parse_args, '-a -b --w 2 3'.split())

Here is the call graph for this function:

Definition at line 2167 of file test_argparse.py.

02167 
02168     def test_parent_help(self):
02169         parents = [self.abcd_parent, self.wxyz_parent]
02170         parser = ErrorRaisingArgumentParser(parents=parents)
02171         parser_help = parser.format_help()
02172         self.assertEqual(parser_help, textwrap.dedent('''\
02173             usage: {} [-h] [-b B] [--d D] [--w W] [-y Y] a z
02174 
02175             positional arguments:
02176               a
02177               z
02178 
02179             optional arguments:
02180               -h, --help  show this help message and exit
02181               -b B
02182               --w W
02183 
02184             c:
02185               --d D
02186 
02187             x:
02188               -y Y
02189         '''.format(self.main_program)))

Here is the call graph for this function:

Definition at line 2134 of file test_argparse.py.

02134 
02135     def test_same_argument_name_parents(self):
02136         parents = [self.wxyz_parent, self.z_parent]
02137         parser = ErrorRaisingArgumentParser(parents=parents)
02138         self.assertEqual(parser.parse_args('1 2'.split()),
02139                          NS(w=None, y=None, z='2'))

Here is the call graph for this function:

Definition at line 2090 of file test_argparse.py.

02090 
02091     def test_single_granparent_mutex(self):
02092         parents = [self.ab_mutex_parent]
02093         parser = ErrorRaisingArgumentParser(add_help=False, parents=parents)
02094         parser = ErrorRaisingArgumentParser(parents=[parser])
02095         self._test_mutex_ab(parser.parse_args)

Here is the call graph for this function:

Definition at line 2080 of file test_argparse.py.

02080 
02081     def test_single_parent(self):
02082         parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent])
02083         self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()),
02084                          NS(w='3', y='1', z='2'))

Here is the call graph for this function:

Definition at line 2085 of file test_argparse.py.

02085 
02086     def test_single_parent_mutex(self):
02087         self._test_mutex_ab(self.ab_mutex_parent.parse_args)
02088         parser = ErrorRaisingArgumentParser(parents=[self.ab_mutex_parent])
02089         self._test_mutex_ab(parser.parse_args)

Here is the call graph for this function:

Definition at line 2140 of file test_argparse.py.

02140 
02141     def test_subparser_parents(self):
02142         parser = ErrorRaisingArgumentParser()
02143         subparsers = parser.add_subparsers()
02144         abcde_parser = subparsers.add_parser('bar', parents=[self.abcd_parent])
02145         abcde_parser.add_argument('e')
02146         self.assertEqual(parser.parse_args('bar -b 1 --d 2 3 4'.split()),
02147                          NS(a='3', b='1', d='2', e='4'))

Here is the call graph for this function:

Definition at line 2148 of file test_argparse.py.

02148 
02149     def test_subparser_parents_mutex(self):
02150         parser = ErrorRaisingArgumentParser()
02151         subparsers = parser.add_subparsers()
02152         parents = [self.ab_mutex_parent]
02153         abc_parser = subparsers.add_parser('foo', parents=parents)
02154         c_group = abc_parser.add_argument_group('c_group')
02155         c_group.add_argument('c')
02156         parents = [self.wxyz_parent, self.ab_mutex_parent]
02157         wxyzabe_parser = subparsers.add_parser('bar', parents=parents)
02158         wxyzabe_parser.add_argument('e')
02159         self.assertEqual(parser.parse_args('foo -a 4'.split()),
02160                          NS(a=True, b=False, c='4'))
02161         self.assertEqual(parser.parse_args('bar -b  --w 2 3 4'.split()),
02162                          NS(a=False, b=True, w='2', y=None, z='3', e='4'))
02163         self.assertArgumentParserError(
02164             parser.parse_args, 'foo -a -b 4'.split())
02165         self.assertArgumentParserError(
02166             parser.parse_args, 'bar -b -a 4'.split())

Here is the call graph for this function:


Member Data Documentation

Definition at line 2073 of file test_argparse.py.

Definition at line 2060 of file test_argparse.py.

Definition at line 2078 of file test_argparse.py.

Definition at line 2066 of file test_argparse.py.

Definition at line 2054 of file test_argparse.py.

Definition at line 2069 of file test_argparse.py.


The documentation for this class was generated from the following file: