diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2012-07-07 17:02:22 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2012-07-07 17:02:22 +0200 |
commit | af1adbeedd9717fa8cfd47b3fa248a8169d7ef8e (patch) | |
tree | 20ee806096403540b838c180477a2b14318132bb /Lib/test/test_argparse.py | |
parent | 3008ec070f40974790f6a85f7ceabf0876950abf (diff) | |
download | cpython-git-af1adbeedd9717fa8cfd47b3fa248a8169d7ef8e.tar.gz |
Issue #13248: argparse: Remove obsolete argument "version" of ArgumentParser.
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index f4567096d8..e69cc40d8d 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -1323,20 +1323,21 @@ class TestParserDefaultSuppress(ParserTestCase): class TestParserDefault42(ParserTestCase): """Test actions with a parser-level default of 42""" - parser_signature = Sig(argument_default=42, version='1.0') + parser_signature = Sig(argument_default=42) argument_signatures = [ + Sig('--version', action='version', version='1.0'), Sig('foo', nargs='?'), Sig('bar', nargs='*'), Sig('--baz', action='store_true'), ] failures = ['-x'] successes = [ - ('', NS(foo=42, bar=42, baz=42)), - ('a', NS(foo='a', bar=42, baz=42)), - ('a b', NS(foo='a', bar=['b'], baz=42)), - ('--baz', NS(foo=42, bar=42, baz=True)), - ('a --baz', NS(foo='a', bar=42, baz=True)), - ('--baz a b', NS(foo='a', bar=['b'], baz=True)), + ('', NS(foo=42, bar=42, baz=42, version=42)), + ('a', NS(foo='a', bar=42, baz=42, version=42)), + ('a b', NS(foo='a', bar=['b'], baz=42, version=42)), + ('--baz', NS(foo=42, bar=42, baz=True, version=42)), + ('a --baz', NS(foo='a', bar=42, baz=True, version=42)), + ('--baz a b', NS(foo='a', bar=['b'], baz=True, version=42)), ] @@ -2896,10 +2897,9 @@ class TestHelpFormattingMetaclass(type): parser_text = sfile.getvalue() self._test(tester, parser_text) - # add tests for {format,print}_{usage,help,version} + # add tests for {format,print}_{usage,help} for func_suffix, std_name in [('usage', 'stdout'), - ('help', 'stdout'), - ('version', 'stderr')]: + ('help', 'stdout')]: AddTests(cls, func_suffix, std_name) bases = TestCase, @@ -2910,8 +2910,9 @@ class TestHelpBiggerOptionals(HelpTestCase): """Make sure that argument help aligns when options are longer""" parser_signature = Sig(prog='PROG', description='DESCRIPTION', - epilog='EPILOG', version='0.1') + epilog='EPILOG') argument_signatures = [ + Sig('-v', '--version', action='version', version='0.1'), Sig('-x', action='store_true', help='X HELP'), Sig('--y', help='Y HELP'), Sig('foo', help='FOO HELP'), @@ -2946,8 +2947,9 @@ class TestHelpBiggerOptionalGroups(HelpTestCase): """Make sure that argument help aligns when options are longer""" parser_signature = Sig(prog='PROG', description='DESCRIPTION', - epilog='EPILOG', version='0.1') + epilog='EPILOG') argument_signatures = [ + Sig('-v', '--version', action='version', version='0.1'), Sig('-x', action='store_true', help='X HELP'), Sig('--y', help='Y HELP'), Sig('foo', help='FOO HELP'), @@ -3114,9 +3116,9 @@ HHAAHHH class TestHelpWrappingLongNames(HelpTestCase): """Make sure that text after long names starts on the next line""" - parser_signature = Sig(usage='USAGE', description= 'D D' * 30, - version='V V'*30) + parser_signature = Sig(usage='USAGE', description= 'D D' * 30) argument_signatures = [ + Sig('-v', '--version', action='version', version='V V' * 30), Sig('-x', metavar='X' * 25, help='XH XH' * 20), Sig('y', metavar='y' * 25, help='YH YH' * 20), ] @@ -3719,8 +3721,9 @@ class TestHelpNoHelpOptional(HelpTestCase): class TestHelpVersionOptional(HelpTestCase): """Test that the --version argument can be suppressed help messages""" - parser_signature = Sig(prog='PROG', version='1.0') + parser_signature = Sig(prog='PROG') argument_signatures = [ + Sig('-v', '--version', action='version', version='1.0'), Sig('--foo', help='foo help'), Sig('spam', help='spam help'), ] @@ -3953,8 +3956,8 @@ class TestHelpVersionAction(HelpTestCase): class TestHelpSubparsersOrdering(HelpTestCase): """Test ordering of subcommands in help matches the code""" parser_signature = Sig(prog='PROG', - description='display some subcommands', - version='0.1') + description='display some subcommands') + argument_signatures = [Sig('-v', '--version', action='version', version='0.1')] subparsers_signatures = [Sig(name=name) for name in ('a', 'b', 'c', 'd', 'e')] @@ -3982,8 +3985,8 @@ class TestHelpSubparsersOrdering(HelpTestCase): class TestHelpSubparsersWithHelpOrdering(HelpTestCase): """Test ordering of subcommands in help matches the code""" parser_signature = Sig(prog='PROG', - description='display some subcommands', - version='0.1') + description='display some subcommands') + argument_signatures = [Sig('-v', '--version', action='version', version='0.1')] subcommand_data = (('a', 'a subcommand help'), ('b', 'b subcommand help'), @@ -4280,32 +4283,28 @@ class TestOptionalsHelpVersionActions(TestCase): parser.format_help(), self._get_error(parser.parse_args, args_str.split()).stdout) - def assertPrintVersionExit(self, parser, args_str): - self.assertEqual( - parser.format_version(), - self._get_error(parser.parse_args, args_str.split()).stderr) - def assertArgumentParserError(self, parser, *args): self.assertRaises(ArgumentParserError, parser.parse_args, args) def test_version(self): - parser = ErrorRaisingArgumentParser(version='1.0') + parser = ErrorRaisingArgumentParser() + parser.add_argument('-v', '--version', action='version', version='1.0') self.assertPrintHelpExit(parser, '-h') self.assertPrintHelpExit(parser, '--help') - self.assertPrintVersionExit(parser, '-v') - self.assertPrintVersionExit(parser, '--version') + self.assertRaises(AttributeError, getattr, parser, 'format_version') def test_version_format(self): - parser = ErrorRaisingArgumentParser(prog='PPP', version='%(prog)s 3.5') + parser = ErrorRaisingArgumentParser(prog='PPP') + parser.add_argument('-v', '--version', action='version', version='%(prog)s 3.5') msg = self._get_error(parser.parse_args, ['-v']).stderr self.assertEqual('PPP 3.5\n', msg) def test_version_no_help(self): - parser = ErrorRaisingArgumentParser(add_help=False, version='1.0') + parser = ErrorRaisingArgumentParser(add_help=False) + parser.add_argument('-v', '--version', action='version', version='1.0') self.assertArgumentParserError(parser, '-h') self.assertArgumentParserError(parser, '--help') - self.assertPrintVersionExit(parser, '-v') - self.assertPrintVersionExit(parser, '--version') + self.assertRaises(AttributeError, getattr, parser, 'format_version') def test_version_action(self): parser = ErrorRaisingArgumentParser(prog='XXX') @@ -4325,12 +4324,13 @@ class TestOptionalsHelpVersionActions(TestCase): parser.add_argument('-x', action='help') parser.add_argument('-y', action='version') self.assertPrintHelpExit(parser, '-x') - self.assertPrintVersionExit(parser, '-y') self.assertArgumentParserError(parser, '-v') self.assertArgumentParserError(parser, '--version') + self.assertRaises(AttributeError, getattr, parser, 'format_version') def test_help_version_extra_arguments(self): - parser = ErrorRaisingArgumentParser(version='1.0') + parser = ErrorRaisingArgumentParser() + parser.add_argument('--version', action='version', version='1.0') parser.add_argument('-x', action='store_true') parser.add_argument('y') @@ -4342,8 +4342,7 @@ class TestOptionalsHelpVersionActions(TestCase): format = '%s %%s %s' % (prefix, suffix) self.assertPrintHelpExit(parser, format % '-h') self.assertPrintHelpExit(parser, format % '--help') - self.assertPrintVersionExit(parser, format % '-v') - self.assertPrintVersionExit(parser, format % '--version') + self.assertRaises(AttributeError, getattr, parser, 'format_version') # ====================== @@ -4398,7 +4397,7 @@ class TestStrings(TestCase): parser = argparse.ArgumentParser(prog='PROG') string = ( "ArgumentParser(prog='PROG', usage=None, description=None, " - "version=None, formatter_class=%r, conflict_handler='error', " + "formatter_class=%r, conflict_handler='error', " "add_help=True)" % argparse.HelpFormatter) self.assertStringEqual(parser, string) @@ -4760,13 +4759,7 @@ class TestImportStar(TestCase): self.assertEqual(sorted(items), sorted(argparse.__all__)) def test_main(): - # silence warnings about version argument - these are expected - with support.check_warnings( - ('The "version" argument to ArgumentParser is deprecated.', - DeprecationWarning), - ('The (format|print)_version method is deprecated', - DeprecationWarning)): - support.run_unittest(__name__) + support.run_unittest(__name__) # Remove global references to avoid looking like we have refleaks. RFile.seen = {} WFile.seen = set() |