mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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>
This commit is contained in:
parent
431665bf19
commit
803ddd8ce2
4 changed files with 111 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue