Fix unittest for 3.13 (#12307)

This commit is contained in:
Max Muoto
2024-07-10 03:23:58 -05:00
committed by GitHub
parent f698bb67fa
commit 9bf9d1571e
6 changed files with 89 additions and 59 deletions

View File

@@ -137,20 +137,6 @@ tkinter.Text.count
tkinter.Wm.wm_attributes
trace.CoverageResults.write_results
types.MappingProxyType.get
unittest.IsolatedAsyncioTestCase.loop_factory
unittest.TestProgram.usageExit
unittest.__all__
unittest.async_case.IsolatedAsyncioTestCase.loop_factory
unittest.findTestCases
unittest.getTestCaseNames
unittest.loader.findTestCases
unittest.loader.getTestCaseNames
unittest.loader.makeSuite
unittest.main.TestProgram.usageExit
unittest.makeSuite
unittest.mock.NonCallableMock._calls_repr
unittest.mock.ThreadingMock
unittest.mock.__all__
zipfile.CompleteDirs.inject
zipfile.ZipInfo.compress_level
zipfile._path.CompleteDirs.inject

View File

@@ -11,13 +11,7 @@ from .case import (
skipIf as skipIf,
skipUnless as skipUnless,
)
from .loader import (
TestLoader as TestLoader,
defaultTestLoader as defaultTestLoader,
findTestCases as findTestCases,
getTestCaseNames as getTestCaseNames,
makeSuite as makeSuite,
)
from .loader import TestLoader as TestLoader, defaultTestLoader as defaultTestLoader
from .main import TestProgram as TestProgram, main as main
from .result import TestResult as TestResult
from .runner import TextTestResult as TextTestResult, TextTestRunner as TextTestRunner
@@ -52,12 +46,14 @@ __all__ = [
"registerResult",
"removeResult",
"removeHandler",
"getTestCaseNames",
"makeSuite",
"findTestCases",
"addModuleCleanup",
]
if sys.version_info < (3, 13):
from .loader import findTestCases as findTestCases, getTestCaseNames as getTestCaseNames, makeSuite as makeSuite
__all__ += ["getTestCaseNames", "makeSuite", "findTestCases"]
if sys.version_info >= (3, 11):
__all__ += ["enterModuleContext", "doModuleCleanups"]

View File

@@ -1,4 +1,5 @@
import sys
from asyncio.events import AbstractEventLoop
from collections.abc import Awaitable, Callable
from typing import TypeVar
from typing_extensions import ParamSpec
@@ -12,6 +13,9 @@ _T = TypeVar("_T")
_P = ParamSpec("_P")
class IsolatedAsyncioTestCase(TestCase):
if sys.version_info >= (3, 13):
loop_factory: Callable[[], AbstractEventLoop] | None = None
async def asyncSetUp(self) -> None: ...
async def asyncTearDown(self) -> None: ...
def addAsyncCleanup(self, func: Callable[_P, Awaitable[object]], /, *args: _P.args, **kwargs: _P.kwargs) -> None: ...

View File

@@ -5,7 +5,7 @@ from collections.abc import Callable, Sequence
from re import Pattern
from types import ModuleType
from typing import Any
from typing_extensions import TypeAlias
from typing_extensions import TypeAlias, deprecated
_SortComparisonMethod: TypeAlias = Callable[[str, str], int]
_SuiteClass: TypeAlias = Callable[[list[unittest.case.TestCase]], unittest.suite.TestSuite]
@@ -34,18 +34,22 @@ class TestLoader:
defaultTestLoader: TestLoader
def getTestCaseNames(
testCaseClass: type[unittest.case.TestCase],
prefix: str,
sortUsing: _SortComparisonMethod = ...,
testNamePatterns: list[str] | None = None,
) -> Sequence[str]: ...
def makeSuite(
testCaseClass: type[unittest.case.TestCase],
prefix: str = "test",
sortUsing: _SortComparisonMethod = ...,
suiteClass: _SuiteClass = ...,
) -> unittest.suite.TestSuite: ...
def findTestCases(
module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ...
) -> unittest.suite.TestSuite: ...
if sys.version_info < (3, 13):
@deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13")
def getTestCaseNames(
testCaseClass: type[unittest.case.TestCase],
prefix: str,
sortUsing: _SortComparisonMethod = ...,
testNamePatterns: list[str] | None = None,
) -> Sequence[str]: ...
@deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13")
def makeSuite(
testCaseClass: type[unittest.case.TestCase],
prefix: str = "test",
sortUsing: _SortComparisonMethod = ...,
suiteClass: _SuiteClass = ...,
) -> unittest.suite.TestSuite: ...
@deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13")
def findTestCases(
module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ...
) -> unittest.suite.TestSuite: ...

View File

@@ -6,6 +6,7 @@ import unittest.suite
from collections.abc import Iterable
from types import ModuleType
from typing import Any, Protocol
from typing_extensions import deprecated
MAIN_EXAMPLES: str
MODULE_EXAMPLES: str
@@ -61,7 +62,10 @@ class TestProgram:
tb_locals: bool = False,
) -> None: ...
def usageExit(self, msg: Any = None) -> None: ...
if sys.version_info < (3, 13):
@deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13")
def usageExit(self, msg: Any = None) -> None: ...
def parseArgs(self, argv: list[str]) -> None: ...
def createTests(self, from_discovery: bool = False, Loader: unittest.loader.TestLoader | None = None) -> None: ...
def runTests(self) -> None: ... # undocumented

View File

@@ -12,23 +12,44 @@ _F = TypeVar("_F", bound=Callable[..., Any])
_AF = TypeVar("_AF", bound=Callable[..., Coroutine[Any, Any, Any]])
_P = ParamSpec("_P")
__all__ = (
"Mock",
"MagicMock",
"patch",
"sentinel",
"DEFAULT",
"ANY",
"call",
"create_autospec",
"AsyncMock",
"FILTER_DIR",
"NonCallableMock",
"NonCallableMagicMock",
"mock_open",
"PropertyMock",
"seal",
)
if sys.version_info >= (3, 13):
# ThreadingMock added in 3.13
__all__ = (
"Mock",
"MagicMock",
"patch",
"sentinel",
"DEFAULT",
"ANY",
"call",
"create_autospec",
"ThreadingMock",
"AsyncMock",
"FILTER_DIR",
"NonCallableMock",
"NonCallableMagicMock",
"mock_open",
"PropertyMock",
"seal",
)
else:
__all__ = (
"Mock",
"MagicMock",
"patch",
"sentinel",
"DEFAULT",
"ANY",
"call",
"create_autospec",
"AsyncMock",
"FILTER_DIR",
"NonCallableMock",
"NonCallableMagicMock",
"mock_open",
"PropertyMock",
"seal",
)
if sys.version_info < (3, 9):
__version__: Final[str]
@@ -124,7 +145,6 @@ class NonCallableMock(Base, Any):
def __delattr__(self, name: str) -> None: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __dir__(self) -> list[str]: ...
def _calls_repr(self, prefix: str = "Calls") -> str: ...
def assert_called_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_not_called(self) -> None: ...
def assert_called_once_with(self, *args: Any, **kwargs: Any) -> None: ...
@@ -150,6 +170,10 @@ class NonCallableMock(Base, Any):
def _format_mock_call_signature(self, args: Any, kwargs: Any) -> str: ...
def _call_matcher(self, _call: tuple[_Call, ...]) -> _Call: ...
def _get_child_mock(self, **kw: Any) -> NonCallableMock: ...
if sys.version_info >= (3, 13):
def _calls_repr(self) -> str: ...
else:
def _calls_repr(self, prefix: str = "Calls") -> str: ...
class CallableMixin(Base):
side_effect: Any
@@ -427,4 +451,16 @@ class PropertyMock(Mock):
def __get__(self, obj: _T, obj_type: type[_T] | None = None) -> Self: ...
def __set__(self, obj: Any, val: Any) -> None: ...
if sys.version_info >= (3, 13):
class ThreadingMixin(Base):
DEFAULT_TIMEOUT: Final[float | None] = None
def __init__(self, /, *args: Any, timeout: float | None | _SentinelObject = ..., **kwargs: Any) -> None: ...
# Same as `NonCallableMock.reset_mock.`
def reset_mock(self, visited: Any = None, *, return_value: bool = False, side_effect: bool = False) -> None: ...
def wait_until_called(self, *, timeout: float | None | _SentinelObject = ...) -> None: ...
def wait_until_any_call_with(self, *args: Any, **kwargs: Any) -> None: ...
class ThreadingMock(ThreadingMixin, MagicMixin, Mock): ...
def seal(mock: Any) -> None: ...