Back to index

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

List of all members.

Public Member Functions

def assertTypeError
def assertValueError
def test_invalid_keyword_arguments
def test_missing_destination
def test_invalid_option_strings
def test_invalid_type
def test_invalid_action
def test_multiple_dest
def test_no_argument_actions
def test_no_argument_no_const_actions
def test_more_than_one_argument_actions
def test_required_const_actions
def test_parsers_action_missing_params
def test_required_positional
def test_user_defined_action
def assertEqual
def setUp

Detailed Description

Test a bunch of invalid Argument constructors

Definition at line 4024 of file test_argparse.py.


Member Function Documentation

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)

Definition at line 4027 of file test_argparse.py.

04027 
04028     def assertTypeError(self, *args, **kwargs):
04029         parser = argparse.ArgumentParser()
04030         self.assertRaises(TypeError, parser.add_argument,
04031                           *args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4032 of file test_argparse.py.

04032 
04033     def assertValueError(self, *args, **kwargs):
04034         parser = argparse.ArgumentParser()
04035         self.assertRaises(ValueError, parser.add_argument,
04036                           *args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_argparse.TestCase.setUp (   self) [inherited]

Reimplemented in test.test_argparse.TestParentParsers, and test.test_argparse.TestAddSubparsers.

Definition at line 31 of file test_argparse.py.

00031 
00032     def setUp(self):
00033         # The tests assume that line wrapping occurs at 80 columns, but this
00034         # behaviour can be overridden by setting the COLUMNS environment
00035         # variable.  To ensure that this assumption is true, unset COLUMNS.
00036         env = support.EnvironmentVarGuard()
00037         env.unset("COLUMNS")
00038         self.addCleanup(env.__exit__)
00039 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4056 of file test_argparse.py.

04056 
04057     def test_invalid_action(self):
04058         self.assertValueError('-x', action='foo')
04059         self.assertValueError('foo', action='baz')
04060         self.assertValueError('--foo', action=('store', 'append'))
04061         parser = argparse.ArgumentParser()
04062         try:
04063             parser.add_argument("--foo", action="store-true")
04064         except ValueError:
04065             e = sys.exc_info()[1]
04066             expected = 'unknown action'
04067             msg = 'expected %r, found %r' % (expected, e)
04068             self.assertTrue(expected in str(e), msg)

Here is the call graph for this function:

Definition at line 4037 of file test_argparse.py.

04037 
04038     def test_invalid_keyword_arguments(self):
04039         self.assertTypeError('-x', bar=None)
04040         self.assertTypeError('-y', callback='foo')
04041         self.assertTypeError('-y', callback_args=())
04042         self.assertTypeError('-y', callback_kwargs={})

Here is the call graph for this function:

Definition at line 4048 of file test_argparse.py.

04048 
04049     def test_invalid_option_strings(self):
04050         self.assertValueError('--')
04051         self.assertValueError('---')

Here is the call graph for this function:

Definition at line 4052 of file test_argparse.py.

04052 
04053     def test_invalid_type(self):
04054         self.assertValueError('--foo', type='int')
04055         self.assertValueError('--foo', type=(int, float))

Here is the call graph for this function:

Definition at line 4043 of file test_argparse.py.

04043 
04044     def test_missing_destination(self):
04045         self.assertTypeError()
04046         for action in ['append', 'store']:
04047             self.assertTypeError(action=action)

Here is the call graph for this function:

Definition at line 4097 of file test_argparse.py.

04097 
04098     def test_more_than_one_argument_actions(self):
04099         for action in ['store', 'append']:
04100 
04101             # nargs=0 is disallowed
04102             self.assertValueError('-x', nargs=0, action=action)
04103             self.assertValueError('spam', nargs=0, action=action)
04104 
04105             # const is disallowed with non-optional arguments
04106             for nargs in [1, '*', '+']:
04107                 self.assertValueError('-x', const='foo',
04108                                       nargs=nargs, action=action)
04109                 self.assertValueError('spam', const='foo',
04110                                       nargs=nargs, action=action)

Here is the call graph for this function:

Definition at line 4069 of file test_argparse.py.

04069 
04070     def test_multiple_dest(self):
04071         parser = argparse.ArgumentParser()
04072         parser.add_argument(dest='foo')
04073         try:
04074             parser.add_argument('bar', dest='baz')
04075         except ValueError:
04076             e = sys.exc_info()[1]
04077             expected = 'dest supplied twice for positional argument'
04078             msg = 'expected %r, found %r' % (expected, e)
04079             self.assertTrue(expected in str(e), msg)

Here is the call graph for this function:

Definition at line 4080 of file test_argparse.py.

04080 
04081     def test_no_argument_actions(self):
04082         for action in ['store_const', 'store_true', 'store_false',
04083                        'append_const', 'count']:
04084             for attrs in [dict(type=int), dict(nargs='+'),
04085                           dict(choices='ab')]:
04086                 self.assertTypeError('-x', action=action, **attrs)

Here is the call graph for this function:

Definition at line 4087 of file test_argparse.py.

04087 
04088     def test_no_argument_no_const_actions(self):
04089         # options with zero arguments
04090         for action in ['store_true', 'store_false', 'count']:
04091 
04092             # const is always disallowed
04093             self.assertTypeError('-x', const='foo', action=action)
04094 
04095             # nargs is always disallowed
04096             self.assertTypeError('-x', nargs='*', action=action)

Here is the call graph for this function:

Definition at line 4117 of file test_argparse.py.

04117 
04118     def test_parsers_action_missing_params(self):
04119         self.assertTypeError('command', action='parsers')
04120         self.assertTypeError('command', action='parsers', prog='PROG')
04121         self.assertTypeError('command', action='parsers',
04122                              parser_class=argparse.ArgumentParser)

Here is the call graph for this function:

Definition at line 4111 of file test_argparse.py.

04111 
04112     def test_required_const_actions(self):
04113         for action in ['store_const', 'append_const']:
04114 
04115             # nargs is always disallowed
04116             self.assertTypeError('-x', nargs='+', action=action)

Here is the call graph for this function:

Definition at line 4123 of file test_argparse.py.

04123 
04124     def test_required_positional(self):
04125         self.assertTypeError('foo', required=True)

Here is the call graph for this function:

Definition at line 4126 of file test_argparse.py.

04126 
04127     def test_user_defined_action(self):
04128 
04129         class Success(Exception):
04130             pass
04131 
04132         class Action(object):
04133 
04134             def __init__(self,
04135                          option_strings,
04136                          dest,
04137                          const,
04138                          default,
04139                          required=False):
04140                 if dest == 'spam':
04141                     if const is Success:
04142                         if default is Success:
04143                             raise Success()
04144 
04145             def __call__(self, *args, **kwargs):
04146                 pass
04147 
04148         parser = argparse.ArgumentParser()
04149         self.assertRaises(Success, parser.add_argument, '--spam',
04150                           action=Action, default=Success, const=Success)
04151         self.assertRaises(Success, parser.add_argument, 'spam',
04152                           action=Action, default=Success, const=Success)
04153 
04154 # ================================
04155 # Actions returned by add_argument
04156 # ================================


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