Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-93839: Move Lib/unttest/test/ to Lib/test/test_unittest/ #94043

Merged
merged 6 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions Lib/test/test_unittest.py

This file was deleted.

6 changes: 6 additions & 0 deletions Lib/test/test_unittest/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions Lib/test/test_unittest/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import load_tests
import unittest

unittest.main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import unittest

from unittest.test.support import (
from test.test_unittest.support import (
TestEquality, TestHashing, LoggingResult, LegacyLoggingResult,
ResultWithNoStartTestRunStopTestRun
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import unittest
import unittest.mock
import unittest.test
import test.test_unittest


class TestableTestProgram(unittest.TestProgram):
Expand Down Expand Up @@ -789,15 +789,15 @@ def test_discovery_from_dotted_path(self):
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):
self.wasRun = True
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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from unittest.test.support import LoggingResult
from test.test_unittest.support import LoggingResult


class Test_FunctionTestCase(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def test_loadTestsFromName__module_not_loaded(self):
# 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()
Expand Down Expand Up @@ -844,7 +844,7 @@ def test_loadTestsFromNames__unknown_attr_name(self):
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(
Expand Down Expand Up @@ -1141,7 +1141,7 @@ def test_loadTestsFromNames__module_not_loaded(self):
# 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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):
Expand All @@ -15,15 +15,15 @@ def test_discovery_from_dotted_path(self):
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):
self.wasRun = True
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)

Expand Down Expand Up @@ -93,10 +93,10 @@ def run(self, test):
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):
Expand All @@ -109,10 +109,10 @@ def run(self, test):
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):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import unittest
from unittest.case import _Outcome

from unittest.test.support import (LoggingResult,
from test.test_unittest.support import (LoggingResult,
ResultWithNoStartTestRunStopTestRun)


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from unittest.test.support import LoggingResult
from test.test_unittest.support import LoggingResult


class Test_TestSkipping(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
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 (
Expand Down Expand Up @@ -669,7 +669,7 @@ def test_patch_dict_decorator_resolution(self):
# 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'})

Expand Down Expand Up @@ -1614,7 +1614,7 @@ def test_patch_with_spec_mock_repr(self):


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()'",
Expand Down Expand Up @@ -1882,7 +1882,7 @@ def foo(x=0):

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, )]))
Expand Down Expand Up @@ -1917,16 +1917,16 @@ def test_dotted_but_module_not_loaded(self):
# 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()
Expand All @@ -1943,7 +1943,7 @@ class Foo:


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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand Down
10 changes: 0 additions & 10 deletions Lib/unittest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ def testMultiply(self):
_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.
Expand Down
25 changes: 0 additions & 25 deletions Lib/unittest/test/__init__.py

This file was deleted.

18 changes: 0 additions & 18 deletions Lib/unittest/test/__main__.py

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1989,12 +1989,12 @@ TESTSUBDIRS= ctypes/test \
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
Expand Down
Loading