summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_test_support.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-23 17:34:59 (GMT)
committerGitHub <noreply@github.com>2017-11-23 17:34:59 (GMT)
commit35d99830f1878867e3964577741d9a2d5a7fc8f7 (patch)
tree70d12e581f7eb018cb0441a874a998a584f8b522 /Lib/test/test_test_support.py
parent2d5890eda62477982361405d3486e57f590c78ae (diff)
downloadcpython-35d99830f1878867e3964577741d9a2d5a7fc8f7.zip
cpython-35d99830f1878867e3964577741d9a2d5a7fc8f7.tar.gz
cpython-35d99830f1878867e3964577741d9a2d5a7fc8f7.tar.bz2
bpo-31324: Optimize support._match_test() (#4523) (#4524)
* 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> (cherry picked from commit 803ddd8ce22f0de3ab42fb98a225a704c000ef06) * bpo-31324: Fix test.support.set_match_tests(None) (#4505) (cherry picked from commit bb11c3c967afaf263e00844d4ab461b7fafd6d36) (cherry picked from commit 70b2f8797146a56a6880743424f0bedf4fc30c62)
Diffstat (limited to 'Lib/test/test_test_support.py')
-rw-r--r--Lib/test/test_test_support.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/Lib/test/test_test_support.py b/Lib/test/test_test_support.py
index 4c4c626..1b62ac9 100644
--- a/Lib/test/test_test_support.py
+++ b/Lib/test/test_test_support.py
@@ -330,6 +330,64 @@ class TestSupport(unittest.TestCase):
del D["y"]
self.assertNotIn("y", D)
+ 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 all using None
+ support.set_match_tests(None)
+ 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