summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-10-17 18:15:07 +0200
committerVictor Stinner <victor.stinner@gmail.com>2016-10-17 18:15:07 +0200
commit8f5dd35d8e5229cb78c5bee47fc6a31a0a36fc5a (patch)
tree9c8769e7035ad5e3abaebe6eb3b11a48660dcd1e
parent83903bb8ccfa7b54b4d7a292b7e8fd2d6e01af66 (diff)
parenta506a93b0b6602be1613cee752d62feca41bee24 (diff)
downloadcpython-git-8f5dd35d8e5229cb78c5bee47fc6a31a0a36fc5a.tar.gz
Merge 3.7: Issue #28409: regrtest: fix the parser of command line arguments.
-rw-r--r--Lib/test/libregrtest/cmdline.py11
-rw-r--r--Lib/test/test_regrtest.py9
-rw-r--r--Misc/NEWS2
3 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py
index c9e2f3d060..891b00c753 100644
--- a/Lib/test/libregrtest/cmdline.py
+++ b/Lib/test/libregrtest/cmdline.py
@@ -242,9 +242,6 @@ def _create_parser():
group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
help='enable Profile Guided Optimization training')
- parser.add_argument('args', nargs='*',
- help=argparse.SUPPRESS)
-
return parser
@@ -294,7 +291,13 @@ def _parse_args(args, **kwargs):
ns.use_resources = []
parser = _create_parser()
- parser.parse_args(args=args, namespace=ns)
+ # Issue #14191: argparse doesn't support "intermixed" positional and
+ # optional arguments. Use parse_known_args() as workaround.
+ ns.args = parser.parse_known_args(args=args, namespace=ns)[1]
+ for arg in ns.args:
+ if arg.startswith('-'):
+ parser.error("unrecognized arguments: %s" % arg)
+ sys.exit(1)
if ns.single and ns.fromfile:
parser.error("-s and -f don't go together!")
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 5de2a6f12e..d43160470f 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -299,6 +299,15 @@ class ParseArgsTestCase(unittest.TestCase):
self.assertEqual(ns.verbose, 0)
self.assertEqual(ns.args, ['foo'])
+ def test_arg_option_arg(self):
+ ns = libregrtest._parse_args(['test_unaryop', '-v', 'test_binop'])
+ self.assertEqual(ns.verbose, 1)
+ self.assertEqual(ns.args, ['test_unaryop', 'test_binop'])
+
+ def test_unknown_option(self):
+ self.checkError(['--unknown-option'],
+ 'unrecognized arguments: --unknown-option')
+
class BaseTestCase(unittest.TestCase):
TEST_UNIQUE_ID = 1
diff --git a/Misc/NEWS b/Misc/NEWS
index dfbf1677d6..e0ec447487 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -312,6 +312,8 @@ Tools/Demos
Tests
-----
+- Issue #28409: regrtest: fix the parser of command line arguments.
+
- Issue #28217: Adds _testconsole module to test console input.