mirror of https://github.com/python/cpython
gh-93839: Move Lib/unttest/test/ to Lib/test/test_unittest/ (#94043)
* Move Lib/unittest/test/ to Lib/test/test_unittest/ * Remove Lib/test/test_unittest.py * Replace unittest.test with test.test_unittest * Remove unittest.load_tests() * Rewrite unittest __init__.py and __main__.py * Update build system, CODEOWNERS, and wasm_assets.py
This commit is contained in:
parent
d82e0bfe8b
commit
c735d54534
|
@ -97,7 +97,7 @@ Lib/ast.py @isidentical
|
|||
|
||||
# Mock
|
||||
/Lib/unittest/mock.py @cjw296
|
||||
/Lib/unittest/test/testmock/* @cjw296
|
||||
/Lib/test/test_unittest/testmock/* @cjw296
|
||||
|
||||
# SQLite 3
|
||||
**/*sqlite* @berkerpeksag @erlend-aasland
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import unittest.test
|
||||
|
||||
from test import support
|
||||
|
||||
|
||||
def load_tests(*_):
|
||||
# used by unittest
|
||||
return unittest.test.suite()
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
support.reap_children()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
|
@ -0,0 +1,6 @@
|
|||
import os.path
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
|
@ -15,7 +15,7 @@ from test import support
|
|||
|
||||
import unittest
|
||||
|
||||
from unittest.test.support import (
|
||||
from test.test_unittest.support import (
|
||||
TestEquality, TestHashing, LoggingResult, LegacyLoggingResult,
|
||||
ResultWithNoStartTestRunStopTestRun
|
||||
)
|
|
@ -10,7 +10,7 @@ import test.test_importlib.util
|
|||
|
||||
import unittest
|
||||
import unittest.mock
|
||||
import unittest.test
|
||||
import test.test_unittest
|
||||
|
||||
|
||||
class TestableTestProgram(unittest.TestProgram):
|
||||
|
@ -789,7 +789,7 @@ class TestDiscovery(unittest.TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
|
||||
tests = [self]
|
||||
expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))
|
||||
expectedPath = os.path.abspath(os.path.dirname(test.test_unittest.__file__))
|
||||
|
||||
self.wasRun = False
|
||||
def _find_tests(start_dir, pattern):
|
||||
|
@ -797,7 +797,7 @@ class TestDiscovery(unittest.TestCase):
|
|||
self.assertEqual(start_dir, expectedPath)
|
||||
return tests
|
||||
loader._find_tests = _find_tests
|
||||
suite = loader.discover('unittest.test')
|
||||
suite = loader.discover('test.test_unittest')
|
||||
self.assertTrue(self.wasRun)
|
||||
self.assertEqual(suite._tests, tests)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from unittest.test.support import LoggingResult
|
||||
from test.test_unittest.support import LoggingResult
|
||||
|
||||
|
||||
class Test_FunctionTestCase(unittest.TestCase):
|
|
@ -716,7 +716,7 @@ class Test_TestLoader(unittest.TestCase):
|
|||
# We're going to try to load this module as a side-effect, so it
|
||||
# better not be loaded before we try.
|
||||
#
|
||||
module_name = 'unittest.test.dummy'
|
||||
module_name = 'test.test_unittest.dummy'
|
||||
sys.modules.pop(module_name, None)
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
|
@ -844,7 +844,7 @@ class Test_TestLoader(unittest.TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
|
||||
suite = loader.loadTestsFromNames(
|
||||
['unittest.loader.sdasfasfasdf', 'unittest.test.dummy'])
|
||||
['unittest.loader.sdasfasfasdf', 'test.test_unittest.dummy'])
|
||||
error, test = self.check_deferred_error(loader, list(suite)[0])
|
||||
expected = "module 'unittest.loader' has no attribute 'sdasfasfasdf'"
|
||||
self.assertIn(
|
||||
|
@ -1141,7 +1141,7 @@ class Test_TestLoader(unittest.TestCase):
|
|||
# We're going to try to load this module as a side-effect, so it
|
||||
# better not be loaded before we try.
|
||||
#
|
||||
module_name = 'unittest.test.dummy'
|
||||
module_name = 'test.test_unittest.dummy'
|
||||
sys.modules.pop(module_name, None)
|
||||
|
||||
loader = unittest.TestLoader()
|
|
@ -5,8 +5,8 @@ import sys
|
|||
import subprocess
|
||||
from test import support
|
||||
import unittest
|
||||
import unittest.test
|
||||
from unittest.test.test_result import BufferedWriter
|
||||
import test.test_unittest
|
||||
from test.test_unittest.test_result import BufferedWriter
|
||||
|
||||
|
||||
class Test_TestProgram(unittest.TestCase):
|
||||
|
@ -15,7 +15,7 @@ class Test_TestProgram(unittest.TestCase):
|
|||
loader = unittest.TestLoader()
|
||||
|
||||
tests = [self]
|
||||
expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__))
|
||||
expectedPath = os.path.abspath(os.path.dirname(test.test_unittest.__file__))
|
||||
|
||||
self.wasRun = False
|
||||
def _find_tests(start_dir, pattern):
|
||||
|
@ -23,7 +23,7 @@ class Test_TestProgram(unittest.TestCase):
|
|||
self.assertEqual(start_dir, expectedPath)
|
||||
return tests
|
||||
loader._find_tests = _find_tests
|
||||
suite = loader.discover('unittest.test')
|
||||
suite = loader.discover('test.test_unittest')
|
||||
self.assertTrue(self.wasRun)
|
||||
self.assertEqual(suite._tests, tests)
|
||||
|
||||
|
@ -93,10 +93,10 @@ class Test_TestProgram(unittest.TestCase):
|
|||
sys.argv = ['faketest']
|
||||
runner = FakeRunner()
|
||||
program = unittest.TestProgram(testRunner=runner, exit=False,
|
||||
defaultTest='unittest.test',
|
||||
defaultTest='test.test_unittest',
|
||||
testLoader=self.FooBarLoader())
|
||||
sys.argv = old_argv
|
||||
self.assertEqual(('unittest.test',), program.testNames)
|
||||
self.assertEqual(('test.test_unittest',), program.testNames)
|
||||
|
||||
def test_defaultTest_with_iterable(self):
|
||||
class FakeRunner(object):
|
||||
|
@ -109,10 +109,10 @@ class Test_TestProgram(unittest.TestCase):
|
|||
runner = FakeRunner()
|
||||
program = unittest.TestProgram(
|
||||
testRunner=runner, exit=False,
|
||||
defaultTest=['unittest.test', 'unittest.test2'],
|
||||
defaultTest=['test.test_unittest', 'test.test_unittest2'],
|
||||
testLoader=self.FooBarLoader())
|
||||
sys.argv = old_argv
|
||||
self.assertEqual(['unittest.test', 'unittest.test2'],
|
||||
self.assertEqual(['test.test_unittest', 'test.test_unittest2'],
|
||||
program.testNames)
|
||||
|
||||
def test_NonExit(self):
|
|
@ -8,7 +8,7 @@ from test import support
|
|||
import unittest
|
||||
from unittest.case import _Outcome
|
||||
|
||||
from unittest.test.support import (LoggingResult,
|
||||
from test.test_unittest.support import (LoggingResult,
|
||||
ResultWithNoStartTestRunStopTestRun)
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from unittest.test.support import LoggingResult
|
||||
from test.test_unittest.support import LoggingResult
|
||||
|
||||
|
||||
class Test_TestSkipping(unittest.TestCase):
|
|
@ -3,7 +3,7 @@ import unittest
|
|||
import gc
|
||||
import sys
|
||||
import weakref
|
||||
from unittest.test.support import LoggingResult, TestEquality
|
||||
from test.test_unittest.support import LoggingResult, TestEquality
|
||||
|
||||
|
||||
### Support code for Test_TestSuite
|
|
@ -10,7 +10,7 @@ def load_tests(*args):
|
|||
suite = unittest.TestSuite()
|
||||
for fn in os.listdir(here):
|
||||
if fn.startswith("test") and fn.endswith(".py"):
|
||||
modname = "unittest.test.testmock." + fn[:-3]
|
||||
modname = "test.test_unittest.testmock." + fn[:-3]
|
||||
__import__(modname)
|
||||
module = sys.modules[modname]
|
||||
suite.addTest(loader.loadTestsFromModule(module))
|
|
@ -6,7 +6,7 @@ def load_tests(loader, standard_tests, pattern):
|
|||
# top level directory cached on loader instance
|
||||
this_dir = os.path.dirname(__file__)
|
||||
pattern = pattern or "test*.py"
|
||||
# We are inside unittest.test.testmock, so the top-level is three notches up
|
||||
# We are inside test.test_unittest.testmock, so the top-level is three notches up
|
||||
top_level_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir)))
|
||||
package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
|
||||
top_level_dir=top_level_dir)
|
|
@ -3,7 +3,7 @@
|
|||
# http://www.voidspace.org.uk/python/mock/
|
||||
|
||||
import unittest
|
||||
from unittest.test.testmock.support import is_instance, X, SomeClass
|
||||
from test.test_unittest.testmock.support import is_instance, X, SomeClass
|
||||
|
||||
from unittest.mock import (
|
||||
Mock, MagicMock, NonCallableMagicMock,
|
|
@ -5,7 +5,7 @@ import tempfile
|
|||
|
||||
from test.support import ALWAYS_EQ
|
||||
import unittest
|
||||
from unittest.test.testmock.support import is_instance
|
||||
from test.test_unittest.testmock.support import is_instance
|
||||
from unittest import mock
|
||||
from unittest.mock import (
|
||||
call, DEFAULT, patch, sentinel,
|
|
@ -7,8 +7,8 @@ import sys
|
|||
from collections import OrderedDict
|
||||
|
||||
import unittest
|
||||
from unittest.test.testmock import support
|
||||
from unittest.test.testmock.support import SomeClass, is_instance
|
||||
from test.test_unittest.testmock import support
|
||||
from test.test_unittest.testmock.support import SomeClass, is_instance
|
||||
|
||||
from test.test_importlib.util import uncache
|
||||
from unittest.mock import (
|
||||
|
@ -669,7 +669,7 @@ class PatchTest(unittest.TestCase):
|
|||
# the new dictionary during function call
|
||||
original = support.target.copy()
|
||||
|
||||
@patch.dict('unittest.test.testmock.support.target', {'bar': 'BAR'})
|
||||
@patch.dict('test.test_unittest.testmock.support.target', {'bar': 'BAR'})
|
||||
def test():
|
||||
self.assertEqual(support.target, {'foo': 'BAZ', 'bar': 'BAR'})
|
||||
|
||||
|
@ -1614,7 +1614,7 @@ class PatchTest(unittest.TestCase):
|
|||
|
||||
|
||||
def test_patch_nested_autospec_repr(self):
|
||||
with patch('unittest.test.testmock.support', autospec=True) as m:
|
||||
with patch('test.test_unittest.testmock.support', autospec=True) as m:
|
||||
self.assertIn(" name='support.SomeClass.wibble()'",
|
||||
repr(m.SomeClass.wibble()))
|
||||
self.assertIn(" name='support.SomeClass().wibble()'",
|
||||
|
@ -1882,7 +1882,7 @@ class PatchTest(unittest.TestCase):
|
|||
|
||||
with patch.object(foo, '__module__', "testpatch2"):
|
||||
self.assertEqual(foo.__module__, "testpatch2")
|
||||
self.assertEqual(foo.__module__, 'unittest.test.testmock.testpatch')
|
||||
self.assertEqual(foo.__module__, 'test.test_unittest.testmock.testpatch')
|
||||
|
||||
with patch.object(foo, '__annotations__', dict([('s', 1, )])):
|
||||
self.assertEqual(foo.__annotations__, dict([('s', 1, )]))
|
||||
|
@ -1917,16 +1917,16 @@ class PatchTest(unittest.TestCase):
|
|||
# This exercises the AttributeError branch of _dot_lookup.
|
||||
|
||||
# make sure it's there
|
||||
import unittest.test.testmock.support
|
||||
import test.test_unittest.testmock.support
|
||||
# now make sure it's not:
|
||||
with patch.dict('sys.modules'):
|
||||
del sys.modules['unittest.test.testmock.support']
|
||||
del sys.modules['unittest.test.testmock']
|
||||
del sys.modules['unittest.test']
|
||||
del sys.modules['test.test_unittest.testmock.support']
|
||||
del sys.modules['test.test_unittest.testmock']
|
||||
del sys.modules['test.test_unittest']
|
||||
del sys.modules['unittest']
|
||||
|
||||
# now make sure we can patch based on a dotted path:
|
||||
@patch('unittest.test.testmock.support.X')
|
||||
@patch('test.test_unittest.testmock.support.X')
|
||||
def test(mock):
|
||||
pass
|
||||
test()
|
||||
|
@ -1943,7 +1943,7 @@ class PatchTest(unittest.TestCase):
|
|||
|
||||
|
||||
def test_cant_set_kwargs_when_passing_a_mock(self):
|
||||
@patch('unittest.test.testmock.support.X', new=object(), x=1)
|
||||
@patch('test.test_unittest.testmock.support.X', new=object(), x=1)
|
||||
def test(): pass
|
||||
with self.assertRaises(TypeError):
|
||||
test()
|
|
@ -1,7 +1,7 @@
|
|||
import unittest
|
||||
from warnings import catch_warnings
|
||||
|
||||
from unittest.test.testmock.support import is_instance
|
||||
from test.test_unittest.testmock.support import is_instance
|
||||
from unittest.mock import MagicMock, Mock, patch, sentinel, mock_open, call
|
||||
|
||||
|
|
@ -73,16 +73,6 @@ from .loader import makeSuite, getTestCaseNames, findTestCases
|
|||
_TextTestResult = TextTestResult
|
||||
|
||||
|
||||
# There are no tests here, so don't try to run anything discovered from
|
||||
# introspecting the symbols (e.g. FunctionTestCase). Instead, all our
|
||||
# tests come from within unittest.test.
|
||||
def load_tests(loader, tests, pattern):
|
||||
import os.path
|
||||
# top level directory cached on loader instance
|
||||
this_dir = os.path.dirname(__file__)
|
||||
return loader.discover(start_dir=this_dir, pattern=pattern)
|
||||
|
||||
|
||||
# Lazy import of IsolatedAsyncioTestCase from .async_case
|
||||
# It imports asyncio, which is relatively heavy, but most tests
|
||||
# do not need it.
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
here = os.path.dirname(__file__)
|
||||
loader = unittest.defaultTestLoader
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
for fn in os.listdir(here):
|
||||
if fn.startswith("test") and fn.endswith(".py"):
|
||||
modname = "unittest.test." + fn[:-3]
|
||||
try:
|
||||
__import__(modname)
|
||||
except unittest.SkipTest:
|
||||
continue
|
||||
module = sys.modules[modname]
|
||||
suite.addTest(loader.loadTestsFromModule(module))
|
||||
suite.addTest(loader.loadTestsFromName('unittest.test.testmock'))
|
||||
return suite
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(defaultTest="suite")
|
|
@ -1,18 +0,0 @@
|
|||
import os
|
||||
import unittest
|
||||
|
||||
|
||||
def load_tests(loader, standard_tests, pattern):
|
||||
# top level directory cached on loader instance
|
||||
this_dir = os.path.dirname(__file__)
|
||||
pattern = pattern or "test_*.py"
|
||||
# We are inside unittest.test, so the top-level is two notches up
|
||||
top_level_dir = os.path.dirname(os.path.dirname(this_dir))
|
||||
package_tests = loader.discover(start_dir=this_dir, pattern=pattern,
|
||||
top_level_dir=top_level_dir)
|
||||
standard_tests.addTests(package_tests)
|
||||
return standard_tests
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -1989,12 +1989,12 @@ TESTSUBDIRS= distutils/tests \
|
|||
test/test_tools \
|
||||
test/test_warnings test/test_warnings/data \
|
||||
test/test_zoneinfo test/test_zoneinfo/data \
|
||||
test/test_unittest test/test_unittest/testmock \
|
||||
test/tracedmodules \
|
||||
test/xmltestdata test/xmltestdata/c14n-20 \
|
||||
test/ziptestdata \
|
||||
tkinter/test tkinter/test/test_tkinter \
|
||||
tkinter/test/test_ttk \
|
||||
unittest/test unittest/test/testmock
|
||||
tkinter/test/test_ttk
|
||||
|
||||
TEST_MODULES=@TEST_MODULES@
|
||||
libinstall: all $(srcdir)/Modules/xxmodule.c
|
||||
|
|
|
@ -1491,33 +1491,33 @@
|
|||
<Compile Include="unittest\runner.py" />
|
||||
<Compile Include="unittest\signals.py" />
|
||||
<Compile Include="unittest\suite.py" />
|
||||
<Compile Include="unittest\test\dummy.py" />
|
||||
<Compile Include="unittest\test\support.py" />
|
||||
<Compile Include="unittest\test\testmock\support.py" />
|
||||
<Compile Include="unittest\test\testmock\testcallable.py" />
|
||||
<Compile Include="unittest\test\testmock\testhelpers.py" />
|
||||
<Compile Include="unittest\test\testmock\testmagicmethods.py" />
|
||||
<Compile Include="unittest\test\testmock\testmock.py" />
|
||||
<Compile Include="unittest\test\testmock\testpatch.py" />
|
||||
<Compile Include="unittest\test\testmock\testsentinel.py" />
|
||||
<Compile Include="unittest\test\testmock\testwith.py" />
|
||||
<Compile Include="unittest\test\testmock\__init__.py" />
|
||||
<Compile Include="unittest\test\testmock\__main__.py" />
|
||||
<Compile Include="unittest\test\test_assertions.py" />
|
||||
<Compile Include="unittest\test\test_break.py" />
|
||||
<Compile Include="unittest\test\test_case.py" />
|
||||
<Compile Include="unittest\test\test_discovery.py" />
|
||||
<Compile Include="unittest\test\test_functiontestcase.py" />
|
||||
<Compile Include="unittest\test\test_loader.py" />
|
||||
<Compile Include="unittest\test\test_program.py" />
|
||||
<Compile Include="unittest\test\test_result.py" />
|
||||
<Compile Include="unittest\test\test_runner.py" />
|
||||
<Compile Include="unittest\test\test_setups.py" />
|
||||
<Compile Include="unittest\test\test_skipping.py" />
|
||||
<Compile Include="unittest\test\test_suite.py" />
|
||||
<Compile Include="unittest\test\_test_warnings.py" />
|
||||
<Compile Include="unittest\test\__init__.py" />
|
||||
<Compile Include="unittest\test\__main__.py" />
|
||||
<Compile Include="test\test_unittest\dummy.py" />
|
||||
<Compile Include="test\test_unittest\support.py" />
|
||||
<Compile Include="test\test_unittest\testmock\support.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testcallable.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testhelpers.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testmagicmethods.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testmock.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testpatch.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testsentinel.py" />
|
||||
<Compile Include="test\test_unittest\testmock\testwith.py" />
|
||||
<Compile Include="test\test_unittest\testmock\__init__.py" />
|
||||
<Compile Include="test\test_unittest\testmock\__main__.py" />
|
||||
<Compile Include="test\test_unittest\test_assertions.py" />
|
||||
<Compile Include="test\test_unittest\test_break.py" />
|
||||
<Compile Include="test\test_unittest\test_case.py" />
|
||||
<Compile Include="test\test_unittest\test_discovery.py" />
|
||||
<Compile Include="test\test_unittest\test_functiontestcase.py" />
|
||||
<Compile Include="test\test_unittest\test_loader.py" />
|
||||
<Compile Include="test\test_unittest\test_program.py" />
|
||||
<Compile Include="test\test_unittest\test_result.py" />
|
||||
<Compile Include="test\test_unittest\test_runner.py" />
|
||||
<Compile Include="test\test_unittest\test_setups.py" />
|
||||
<Compile Include="test\test_unittest\test_skipping.py" />
|
||||
<Compile Include="test\test_unittest\test_suite.py" />
|
||||
<Compile Include="test\test_unittest\_test_warnings.py" />
|
||||
<Compile Include="test\test_unittest\__init__.py" />
|
||||
<Compile Include="test\test_unittest\__main__.py" />
|
||||
<Compile Include="unittest\util.py" />
|
||||
<Compile Include="unittest\__init__.py" />
|
||||
<Compile Include="unittest\__main__.py" />
|
||||
|
@ -1804,6 +1804,8 @@
|
|||
<Folder Include="test\test_json" />
|
||||
<Folder Include="test\test_peg_generator" />
|
||||
<Folder Include="test\test_tools" />
|
||||
<Folder Include="test\test_unittest" />
|
||||
<Folder Include="test\test_unittest\testmock" />
|
||||
<Folder Include="test\test_warnings" />
|
||||
<Folder Include="test\test_warnings\data" />
|
||||
<Folder Include="test\tracedmodules" />
|
||||
|
@ -1813,8 +1815,6 @@
|
|||
<Folder Include="tkinter\test\test_ttk" />
|
||||
<Folder Include="turtledemo" />
|
||||
<Folder Include="unittest" />
|
||||
<Folder Include="unittest\test" />
|
||||
<Folder Include="unittest\test\testmock" />
|
||||
<Folder Include="urllib" />
|
||||
<Folder Include="venv" />
|
||||
<Folder Include="wsgiref" />
|
||||
|
|
|
@ -112,7 +112,6 @@ OMIT_MODULE_FILES = {
|
|||
# regression test sub directories
|
||||
OMIT_SUBDIRS = (
|
||||
"tkinter/test/",
|
||||
"unittest/test/",
|
||||
)
|
||||
|
||||
def get_builddir(args: argparse.Namespace) -> pathlib.Path:
|
||||
|
|
Loading…
Reference in New Issue