mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
enable running of argparse tests and fix two that failed in the new environment
This commit is contained in:
parent
d2decd9965
commit
036fae39ac
1 changed files with 11 additions and 4 deletions
|
|
@ -21,6 +21,8 @@ import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from test import test_support
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -1951,6 +1953,8 @@ class TestParentParsers(TestCase):
|
||||||
group.add_argument('-a', action='store_true')
|
group.add_argument('-a', action='store_true')
|
||||||
group.add_argument('-b', action='store_true')
|
group.add_argument('-b', action='store_true')
|
||||||
|
|
||||||
|
self.main_program = os.path.basename(sys.argv[0])
|
||||||
|
|
||||||
def test_single_parent(self):
|
def test_single_parent(self):
|
||||||
parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent])
|
parser = ErrorRaisingArgumentParser(parents=[self.wxyz_parent])
|
||||||
self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()),
|
self.assertEqual(parser.parse_args('-y 1 2 --w 3'.split()),
|
||||||
|
|
@ -2043,7 +2047,7 @@ class TestParentParsers(TestCase):
|
||||||
parser = ErrorRaisingArgumentParser(parents=parents)
|
parser = ErrorRaisingArgumentParser(parents=parents)
|
||||||
parser_help = parser.format_help()
|
parser_help = parser.format_help()
|
||||||
self.assertEqual(parser_help, textwrap.dedent('''\
|
self.assertEqual(parser_help, textwrap.dedent('''\
|
||||||
usage: test_argparse.py [-h] [-b B] [--d D] [--w W] [-y Y] a z
|
usage: {} [-h] [-b B] [--d D] [--w W] [-y Y] a z
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
a
|
a
|
||||||
|
|
@ -2059,7 +2063,7 @@ class TestParentParsers(TestCase):
|
||||||
|
|
||||||
x:
|
x:
|
||||||
-y Y
|
-y Y
|
||||||
'''))
|
'''.format(self.main_program)))
|
||||||
|
|
||||||
def test_groups_parents(self):
|
def test_groups_parents(self):
|
||||||
parent = ErrorRaisingArgumentParser(add_help=False)
|
parent = ErrorRaisingArgumentParser(add_help=False)
|
||||||
|
|
@ -2076,7 +2080,7 @@ class TestParentParsers(TestCase):
|
||||||
|
|
||||||
parser_help = parser.format_help()
|
parser_help = parser.format_help()
|
||||||
self.assertEqual(parser_help, textwrap.dedent('''\
|
self.assertEqual(parser_help, textwrap.dedent('''\
|
||||||
usage: test_argparse.py [-h] [-w W] [-x X] [-y Y | -z Z]
|
usage: {} [-h] [-w W] [-x X] [-y Y | -z Z]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
@ -2088,7 +2092,7 @@ class TestParentParsers(TestCase):
|
||||||
|
|
||||||
-w W
|
-w W
|
||||||
-x X
|
-x X
|
||||||
'''))
|
'''.format(self.main_program)))
|
||||||
|
|
||||||
# ==============================
|
# ==============================
|
||||||
# Mutually exclusive group tests
|
# Mutually exclusive group tests
|
||||||
|
|
@ -4199,6 +4203,9 @@ class TestImportStar(TestCase):
|
||||||
for name in argparse.__all__:
|
for name in argparse.__all__:
|
||||||
self.failUnless(hasattr(argparse, name))
|
self.failUnless(hasattr(argparse, name))
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
test_support.run_unittest(__name__)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue