Back to index

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

List of all members.

Public Member Functions

def assertPrintHelpExit
def assertPrintVersionExit
def assertArgumentParserError
def test_version
def test_version_format
def test_version_no_help
def test_version_action
def test_no_help
def test_alternate_help_version
def test_help_version_extra_arguments
def assertEqual
def setUp

Private Member Functions

def _get_error

Detailed Description

Test the help and version actions

Definition at line 4232 of file test_argparse.py.


Member Function Documentation

def test.test_argparse.TestOptionalsHelpVersionActions._get_error (   self,
  func,
  args,
  kwargs 
) [private]

Definition at line 4235 of file test_argparse.py.

04235 
04236     def _get_error(self, func, *args, **kwargs):
04237         try:
04238             func(*args, **kwargs)
04239         except ArgumentParserError:
04240             return sys.exc_info()[1]
04241         else:
04242             self.assertRaises(ArgumentParserError, func, *args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4253 of file test_argparse.py.

04253 
04254     def assertArgumentParserError(self, parser, *args):
04255         self.assertRaises(ArgumentParserError, parser.parse_args, args)

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)

Definition at line 4243 of file test_argparse.py.

04243 
04244     def assertPrintHelpExit(self, parser, args_str):
04245         self.assertEqual(
04246             parser.format_help(),
04247             self._get_error(parser.parse_args, args_str.split()).stdout)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 4248 of file test_argparse.py.

04248 
04249     def assertPrintVersionExit(self, parser, args_str):
04250         self.assertEqual(
04251             parser.format_version(),
04252             self._get_error(parser.parse_args, args_str.split()).stderr)

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 4288 of file test_argparse.py.

04288 
04289     def test_alternate_help_version(self):
04290         parser = ErrorRaisingArgumentParser()
04291         parser.add_argument('-x', action='help')
04292         parser.add_argument('-y', action='version')
04293         self.assertPrintHelpExit(parser, '-x')
04294         self.assertPrintVersionExit(parser, '-y')
04295         self.assertArgumentParserError(parser, '-v')
04296         self.assertArgumentParserError(parser, '--version')

Here is the call graph for this function:

Definition at line 4297 of file test_argparse.py.

04297 
04298     def test_help_version_extra_arguments(self):
04299         parser = ErrorRaisingArgumentParser(version='1.0')
04300         parser.add_argument('-x', action='store_true')
04301         parser.add_argument('y')
04302 
04303         # try all combinations of valid prefixes and suffixes
04304         valid_prefixes = ['', '-x', 'foo', '-x bar', 'baz -x']
04305         valid_suffixes = valid_prefixes + ['--bad-option', 'foo bar baz']
04306         for prefix in valid_prefixes:
04307             for suffix in valid_suffixes:
04308                 format = '%s %%s %s' % (prefix, suffix)
04309             self.assertPrintHelpExit(parser, format % '-h')
04310             self.assertPrintHelpExit(parser, format % '--help')
04311             self.assertPrintVersionExit(parser, format % '-v')
04312             self.assertPrintVersionExit(parser, format % '--version')
04313 
04314 
04315 # ======================
04316 # str() and repr() tests
04317 # ======================

Here is the call graph for this function:

Definition at line 4281 of file test_argparse.py.

04281 
04282     def test_no_help(self):
04283         parser = ErrorRaisingArgumentParser(add_help=False)
04284         self.assertArgumentParserError(parser, '-h')
04285         self.assertArgumentParserError(parser, '--help')
04286         self.assertArgumentParserError(parser, '-v')
04287         self.assertArgumentParserError(parser, '--version')

Here is the call graph for this function:

Definition at line 4256 of file test_argparse.py.

04256 
04257     def test_version(self):
04258         parser = ErrorRaisingArgumentParser(version='1.0')
04259         self.assertPrintHelpExit(parser, '-h')
04260         self.assertPrintHelpExit(parser, '--help')
04261         self.assertPrintVersionExit(parser, '-v')
04262         self.assertPrintVersionExit(parser, '--version')

Here is the call graph for this function:

Definition at line 4275 of file test_argparse.py.

04275 
04276     def test_version_action(self):
04277         parser = ErrorRaisingArgumentParser(prog='XXX')
04278         parser.add_argument('-V', action='version', version='%(prog)s 3.7')
04279         msg = self._get_error(parser.parse_args, ['-V']).stderr
04280         self.assertEqual('XXX 3.7\n', msg)

Here is the call graph for this function:

Definition at line 4263 of file test_argparse.py.

04263 
04264     def test_version_format(self):
04265         parser = ErrorRaisingArgumentParser(prog='PPP', version='%(prog)s 3.5')
04266         msg = self._get_error(parser.parse_args, ['-v']).stderr
04267         self.assertEqual('PPP 3.5\n', msg)

Here is the call graph for this function:

Definition at line 4268 of file test_argparse.py.

04268 
04269     def test_version_no_help(self):
04270         parser = ErrorRaisingArgumentParser(add_help=False, version='1.0')
04271         self.assertArgumentParserError(parser, '-h')
04272         self.assertArgumentParserError(parser, '--help')
04273         self.assertPrintVersionExit(parser, '-v')
04274         self.assertPrintVersionExit(parser, '--version')

Here is the call graph for this function:


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