typing - switch around node Definition usage
This commit is contained in:
parent
befa0c5e40
commit
988eb6ac9d
|
@ -420,7 +420,7 @@ class DoctestTextfile(Module):
|
||||||
# todo: this shouldnt be a module
|
# todo: this shouldnt be a module
|
||||||
obj: None = None # type: ignore[assignment]
|
obj: None = None # type: ignore[assignment]
|
||||||
|
|
||||||
def collect(self) -> Iterable[DoctestItem]:
|
def collect(self) -> Iterable[DoctestItem]: # type: ignore[override]
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
# Inspired by doctest.testfile; ideally we would use it directly,
|
# Inspired by doctest.testfile; ideally we would use it directly,
|
||||||
|
@ -498,7 +498,7 @@ def _patch_unwrap_mock_aware() -> Generator[None, None, None]:
|
||||||
|
|
||||||
|
|
||||||
class DoctestModule(Module):
|
class DoctestModule(Module):
|
||||||
def collect(self) -> Iterable[DoctestItem]:
|
def collect(self) -> Iterable[DoctestItem]: # type: ignore[override]
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
class MockAwareDocTestFinder(doctest.DocTestFinder):
|
class MockAwareDocTestFinder(doctest.DocTestFinder):
|
||||||
|
|
|
@ -655,6 +655,11 @@ class Directory(FSCollector, abc.ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Definition(Collector, abc.ABC):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def collect(self) -> Iterable[Item]: ...
|
||||||
|
|
||||||
|
|
||||||
class Item(Node, abc.ABC):
|
class Item(Node, abc.ABC):
|
||||||
"""Base class of all test invocation items.
|
"""Base class of all test invocation items.
|
||||||
|
|
||||||
|
|
|
@ -402,7 +402,7 @@ class PyCollector(PyobjMixin, nodes.Collector, abc.ABC):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def collect(self) -> Iterable[nodes.Item | nodes.Collector]:
|
def collect(self) -> Iterable[nodes.Definition | nodes.Collector]:
|
||||||
if not getattr(self.obj, "__test__", True):
|
if not getattr(self.obj, "__test__", True):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -415,10 +415,10 @@ class PyCollector(PyobjMixin, nodes.Collector, abc.ABC):
|
||||||
# In each class, nodes should be definition ordered.
|
# In each class, nodes should be definition ordered.
|
||||||
# __dict__ is definition ordered.
|
# __dict__ is definition ordered.
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
dict_values: list[list[nodes.Item | nodes.Collector]] = []
|
dict_values: list[list[nodes.Definition | nodes.Collector]] = []
|
||||||
ihook = self.ihook
|
ihook = self.ihook
|
||||||
for dic in dicts:
|
for dic in dicts:
|
||||||
values: list[nodes.Item | nodes.Collector] = []
|
values: list[nodes.Definition | nodes.Collector] = []
|
||||||
# Note: seems like the dict can change during iteration -
|
# Note: seems like the dict can change during iteration -
|
||||||
# be careful not to remove the list() without consideration.
|
# be careful not to remove the list() without consideration.
|
||||||
for name, obj in list(dic.items()):
|
for name, obj in list(dic.items()):
|
||||||
|
@ -564,7 +564,7 @@ class Module(nodes.File, PyCollector):
|
||||||
def _getobj(self) -> types.ModuleType:
|
def _getobj(self) -> types.ModuleType:
|
||||||
return importtestmodule(self.path, self.config)
|
return importtestmodule(self.path, self.config)
|
||||||
|
|
||||||
def collect(self) -> Iterable[nodes.Item | nodes.Collector]:
|
def collect(self) -> Iterable[nodes.Collector]:
|
||||||
self._register_setup_module_fixture()
|
self._register_setup_module_fixture()
|
||||||
self._register_setup_function_fixture()
|
self._register_setup_function_fixture()
|
||||||
self.session._fixturemanager.parsefactories(self)
|
self.session._fixturemanager.parsefactories(self)
|
||||||
|
@ -771,7 +771,7 @@ class Class(PyCollector):
|
||||||
def newinstance(self) -> Any:
|
def newinstance(self) -> Any:
|
||||||
return self.obj()
|
return self.obj()
|
||||||
|
|
||||||
def collect(self) -> Iterable[nodes.Item | nodes.Collector]:
|
def collect(self) -> Iterable[nodes.Collector]:
|
||||||
if not safe_getattr(self.obj, "__test__", True):
|
if not safe_getattr(self.obj, "__test__", True):
|
||||||
return []
|
return []
|
||||||
if hasinit(self.obj):
|
if hasinit(self.obj):
|
||||||
|
@ -1132,6 +1132,8 @@ class Metafunc:
|
||||||
test function is defined.
|
test function is defined.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
definition: FunctionDefinition
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
definition: FunctionDefinition,
|
definition: FunctionDefinition,
|
||||||
|
@ -1708,6 +1710,8 @@ class FunctionDefinition(Function):
|
||||||
"""This class is a stop gap solution until we evolve to have actual function
|
"""This class is a stop gap solution until we evolve to have actual function
|
||||||
definition nodes and manage to get rid of ``metafunc``."""
|
definition nodes and manage to get rid of ``metafunc``."""
|
||||||
|
|
||||||
|
parent: Module | Class
|
||||||
|
|
||||||
def runtest(self) -> None:
|
def runtest(self) -> None:
|
||||||
raise RuntimeError("function definitions are not supposed to be run as tests")
|
raise RuntimeError("function definitions are not supposed to be run as tests")
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class UnitTestCase(Class):
|
||||||
# it.
|
# it.
|
||||||
return self.obj("runTest")
|
return self.obj("runTest")
|
||||||
|
|
||||||
def collect(self) -> Iterable[Item | Collector]:
|
def collect(self) -> Iterable[Item | Collector]: # type: ignore[override]
|
||||||
from unittest import TestLoader
|
from unittest import TestLoader
|
||||||
|
|
||||||
cls = self.obj
|
cls = self.obj
|
||||||
|
|
Loading…
Reference in New Issue