From 0f49a44f26f0839bff02c8d0896e64ec371c5c60 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 16 Nov 2017 16:33:46 +0200 Subject: [PATCH 1/2] bpo-31324: Optimize support._match_test(). --- Lib/test/support/__init__.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 527cf7fbf95328..4648593b78ca34 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1900,21 +1900,22 @@ def _run_suite(suite): raise TestFailed(err) +_match_tests = None +_match_test1 = None + def _match_test(test): - global match_tests + global _match_tests, _match_test1 if match_tests is None: return True + if match_tests != _match_tests: + match_tests_re = '|'.join(map(fnmatch.translate, match_tests)) + _match_test1 = re.compile(match_tests_re, re.I).match + _match_tests = match_tests[:] test_id = test.id() - - for match_test in match_tests: - if fnmatch.fnmatchcase(test_id, match_test): - return True - - for name in test_id.split("."): - if fnmatch.fnmatchcase(name, match_test): - return True - return False + if _match_test1(test_id): + return True + return any(map(_match_test1, test_id.split("."))) def run_unittest(*classes): From 75990b1fc2f03eb74075785d74d80b6872a509ba Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 16 Nov 2017 16:45:10 +0200 Subject: [PATCH 2/2] No re.I flag. --- Lib/test/support/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 4648593b78ca34..7fdc219305c7f1 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1910,7 +1910,7 @@ def _match_test(test): return True if match_tests != _match_tests: match_tests_re = '|'.join(map(fnmatch.translate, match_tests)) - _match_test1 = re.compile(match_tests_re, re.I).match + _match_test1 = re.compile(match_tests_re).match _match_tests = match_tests[:] test_id = test.id() if _match_test1(test_id):