]> granicus.if.org Git - python/commitdiff
Issue #29035: Simplify a regex in libregrtest
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 3 Jan 2017 00:38:58 +0000 (01:38 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 3 Jan 2017 00:38:58 +0000 (01:38 +0100)
regrtest: simplify the regex used to match test names for the --fromfile
command line option.

Lib/test/libregrtest/main.py
Lib/test/test_regrtest.py

index e113ed63ddf3b69c4713be8892ae27b5d477ac7f..61a98763701d9680419e06f422f1975d2d625609 100644 (file)
@@ -179,17 +179,14 @@ class Regrtest:
             self.tests = []
             # regex to match 'test_builtin' in line:
             # '0:00:00 [  4/400] test_builtin -- test_dict took 1 sec'
-            regex = (r'(?:[0-9]+:[0-9]+:[0-9]+ *)?'
-                     r'(?:\[[0-9/ ]+\] *)?'
-                     r'(test_[a-zA-Z0-9_]+)\b(?:\.py)?')
-            regex = re.compile(regex)
+            regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
             with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
                 for line in fp:
                     line = line.split('#', 1)[0]
                     line = line.strip()
                     match = regex.search(line)
                     if match is not None:
-                        self.tests.append(match.group(1))
+                        self.tests.append(match.group())
 
         removepy(self.tests)
 
index 751df1537d2c9b33e6763f590647cef7724d166e..6d70e4d8f036d999b3bca336608854223dc3b34c 100644 (file)
@@ -676,6 +676,14 @@ class ArgsTestCase(BaseTestCase):
         output = self.run_tests('--fromfile', filename)
         self.check_executed_tests(output, tests)
 
+        # test format 'Lib/test/test_opcodes.py'
+        with open(filename, "w") as fp:
+            for name in tests:
+                print('Lib/test/%s.py' % name, file=fp)
+
+        output = self.run_tests('--fromfile', filename)
+        self.check_executed_tests(output, tests)
+
     def test_interrupted(self):
         code = TEST_INTERRUPTED
         test = self.create_test('sigint', code=code)