]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #28409: regrtest: fix the parser of command line arguments.
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 17 Oct 2016 16:11:03 +0000 (18:11 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 17 Oct 2016 16:11:03 +0000 (18:11 +0200)
Lib/test/regrtest.py
Lib/test/test_regrtest.py
Misc/NEWS

index f1892acfb48e85cdcaf82b450c6a3f80c7ed1df1..f870854a67720e733afc128e4f9d6e2bcf15d7ba 100755 (executable)
@@ -325,9 +325,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
 
 def relative_filename(string):
@@ -373,7 +370,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!")
index a398a4f836eeadccdd0db07dd7a44024f8a3158f..ae183272a14f37528bba130f5d56fcb4ea134d57 100644 (file)
@@ -270,6 +270,16 @@ class ParseArgsTestCase(unittest.TestCase):
         self.assertEqual(ns.verbose, 0)
         self.assertEqual(ns.args, ['foo'])
 
+    def test_arg_option_arg(self):
+        ns = regrtest._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')
+
+
 
 if __name__ == '__main__':
     unittest.main()
index fd2030a03959ecc5b2ed467300670d2ea5f637ca..82cf8b04a340538c8842b80a62853f23980387ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -376,11 +376,11 @@ Library
 - Issue #27759: Fix selectors incorrectly retain invalid file descriptors.
   Patch by Mark Williams.
 
-- Issue #28368: Refuse monitoring processes if the child watcher has 
+- Issue #28368: Refuse monitoring processes if the child watcher has
   no loop attached.
   Patch by Vincent Michel.
 
-- Issue #28369: Raise RuntimeError when transport's FD is used with 
+- Issue #28369: Raise RuntimeError when transport's FD is used with
   add_reader, add_writer, etc.
 
 - Issue #28370: Speedup asyncio.StreamReader.readexactly.
@@ -432,6 +432,8 @@ C API
 Tests
 -----
 
+- Issue #28409: regrtest: fix the parser of command line arguments.
+
 - Issue #27787: Call gc.collect() before checking each test for "dangling
   threads", since the dangling threads are weak references.