summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_support.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-21 23:34:02 (GMT)
committerGitHub <noreply@github.com>2017-11-21 23:34:02 (GMT)
commit803ddd8ce22f0de3ab42fb98a225a704c000ef06 (patch)
treea4193e3e3380dbe654b556042f4a6fc00f48a97e /Lib/test/test_support.py
parent431665bf1971e66c51f59abf0693f700ff7919e8 (diff)
downloadcpython-803ddd8ce22f0de3ab42fb98a225a704c000ef06.zip
cpython-803ddd8ce22f0de3ab42fb98a225a704c000ef06.tar.gz
cpython-803ddd8ce22f0de3ab42fb98a225a704c000ef06.tar.bz2
bpo-31324: Optimize support._match_test() (#4421)
* Rename support._match_test() to support.match_test(): make it public * Remove support.match_tests global variable. It is replaced with a new support.set_match_tests() function, so match_test() doesn't have to check each time if patterns were modified. * Rewrite match_test(): use different code paths depending on the kind of patterns for best performances. Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r--Lib/test/test_support.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 4a577ef..4756def 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -483,6 +483,59 @@ class TestSupport(unittest.TestCase):
with self.subTest(opts=opts):
self.check_options(opts, 'optim_args_from_interpreter_flags')
+ def test_match_test(self):
+ class Test:
+ def __init__(self, test_id):
+ self.test_id = test_id
+
+ def id(self):
+ return self.test_id
+
+ test_access = Test('test.test_os.FileTests.test_access')
+ test_chdir = Test('test.test_os.Win32ErrorTests.test_chdir')
+
+ with support.swap_attr(support, '_match_test_func', None):
+ # match all
+ support.set_match_tests([])
+ self.assertTrue(support.match_test(test_access))
+ self.assertTrue(support.match_test(test_chdir))
+
+ # match the full test identifier
+ support.set_match_tests([test_access.id()])
+ self.assertTrue(support.match_test(test_access))
+ self.assertFalse(support.match_test(test_chdir))
+
+ # match the module name
+ support.set_match_tests(['test_os'])
+ self.assertTrue(support.match_test(test_access))
+ self.assertTrue(support.match_test(test_chdir))
+
+ # Test '*' pattern
+ support.set_match_tests(['test_*'])
+ self.assertTrue(support.match_test(test_access))
+ self.assertTrue(support.match_test(test_chdir))
+
+ # Test case sensitivity
+ support.set_match_tests(['filetests'])
+ self.assertFalse(support.match_test(test_access))
+ support.set_match_tests(['FileTests'])
+ self.assertTrue(support.match_test(test_access))
+
+ # Test pattern containing '.' and a '*' metacharacter
+ support.set_match_tests(['*test_os.*.test_*'])
+ self.assertTrue(support.match_test(test_access))
+ self.assertTrue(support.match_test(test_chdir))
+
+ # Multiple patterns
+ support.set_match_tests([test_access.id(), test_chdir.id()])
+ self.assertTrue(support.match_test(test_access))
+ self.assertTrue(support.match_test(test_chdir))
+
+ support.set_match_tests(['test_access', 'DONTMATCH'])
+ self.assertTrue(support.match_test(test_access))
+ self.assertFalse(support.match_test(test_chdir))
+
+
# XXX -follows a list of untested API
# make_legacy_pyc
# is_resource_enabled