mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-111165: Move test running code from test.support to libregrtest (GH-111166)
Remove no longer used functions run_unittest() and run_doctest() from the test.support module.
This commit is contained in:
parent
a8a89fcd1f
commit
f6a45a03d0
12 changed files with 266 additions and 342 deletions
|
@ -22,11 +22,13 @@ import tempfile
|
|||
import textwrap
|
||||
import unittest
|
||||
from test import support
|
||||
from test.support import os_helper, TestStats, without_optimizer
|
||||
from test.support import os_helper, without_optimizer
|
||||
from test.libregrtest import cmdline
|
||||
from test.libregrtest import main
|
||||
from test.libregrtest import setup
|
||||
from test.libregrtest import utils
|
||||
from test.libregrtest.filter import set_match_tests, match_test
|
||||
from test.libregrtest.result import TestStats
|
||||
from test.libregrtest.utils import normalize_test_name
|
||||
|
||||
if not support.has_subprocess_support:
|
||||
|
@ -2182,6 +2184,120 @@ class TestUtils(unittest.TestCase):
|
|||
format_resources((*ALL_RESOURCES, "tzdata")),
|
||||
'resources: all,tzdata')
|
||||
|
||||
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')
|
||||
test_copy = Test('test.test_shutil.TestCopy.test_copy')
|
||||
|
||||
# Test acceptance
|
||||
with support.swap_attr(support, '_test_matchers', ()):
|
||||
# match all
|
||||
set_match_tests([])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
|
||||
# match all using None
|
||||
set_match_tests(None)
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
|
||||
# match the full test identifier
|
||||
set_match_tests([(test_access.id(), True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
|
||||
# match the module name
|
||||
set_match_tests([('test_os', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
self.assertFalse(match_test(test_copy))
|
||||
|
||||
# Test '*' pattern
|
||||
set_match_tests([('test_*', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
|
||||
# Test case sensitivity
|
||||
set_match_tests([('filetests', True)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
set_match_tests([('FileTests', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
|
||||
# Test pattern containing '.' and a '*' metacharacter
|
||||
set_match_tests([('*test_os.*.test_*', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
self.assertFalse(match_test(test_copy))
|
||||
|
||||
# Multiple patterns
|
||||
set_match_tests([(test_access.id(), True), (test_chdir.id(), True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
self.assertFalse(match_test(test_copy))
|
||||
|
||||
set_match_tests([('test_access', True), ('DONTMATCH', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
|
||||
# Test rejection
|
||||
with support.swap_attr(support, '_test_matchers', ()):
|
||||
# match the full test identifier
|
||||
set_match_tests([(test_access.id(), False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
|
||||
# match the module name
|
||||
set_match_tests([('test_os', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
self.assertTrue(match_test(test_copy))
|
||||
|
||||
# Test '*' pattern
|
||||
set_match_tests([('test_*', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
|
||||
# Test case sensitivity
|
||||
set_match_tests([('filetests', False)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
set_match_tests([('FileTests', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
|
||||
# Test pattern containing '.' and a '*' metacharacter
|
||||
set_match_tests([('*test_os.*.test_*', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
self.assertTrue(match_test(test_copy))
|
||||
|
||||
# Multiple patterns
|
||||
set_match_tests([(test_access.id(), False), (test_chdir.id(), False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
self.assertTrue(match_test(test_copy))
|
||||
|
||||
set_match_tests([('test_access', False), ('DONTMATCH', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
|
||||
# Test mixed filters
|
||||
with support.swap_attr(support, '_test_matchers', ()):
|
||||
set_match_tests([('*test_os', False), ('test_access', True)])
|
||||
self.assertTrue(match_test(test_access))
|
||||
self.assertFalse(match_test(test_chdir))
|
||||
self.assertTrue(match_test(test_copy))
|
||||
|
||||
set_match_tests([('*test_os', True), ('test_access', False)])
|
||||
self.assertFalse(match_test(test_access))
|
||||
self.assertTrue(match_test(test_chdir))
|
||||
self.assertFalse(match_test(test_copy))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue