Skip to content

Commit d36036b

Browse files
olivermeyerclaude
andcommitted
test(utils): port DI plugin discovery tests from Bridge
Add helpers (_mock_package, _make_import_side_effect, context managers for broken/no-match/no-plugin scenarios), module-level di_module import, PLUGIN/MYMODULE constants, and 10 new tests covering shallow plugin scanning, broken plugin handling, and deep main-package scanning for both locate_implementations and locate_subclasses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d58a9e3 commit d36036b

2 files changed

Lines changed: 431 additions & 22 deletions

File tree

src/aignostics/utils/_di.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def load_modules() -> None:
4444

4545
def _scan_packages_deep(package_name: str, predicate: Callable[[object], bool]) -> list[Any]:
4646
"""
47-
Deep-scan a package by walking all submodules via pkgutil.iter_modules.
47+
Deep-scan a package by walking all top-level submodules via pkgutil.iter_modules.
4848
4949
Discovers objects by importing the package, iterating through all submodules,
5050
and checking each module's members against the predicate. Used for the main
@@ -115,9 +115,8 @@ def locate_implementations(_class: type[Any]) -> list[Any]:
115115
"""
116116
Dynamically discover all instances of some class.
117117
118-
Searches plugin packages using a shallow scan (top-level __init__.py exports only)
119-
and the main project package using a deep scan (all submodules via pkgutil). The
120-
shallow scan for plugins prevents over-discovering objects from plugin submodules.
118+
Searches plugin packages using a shallow scan and the main project package using
119+
a deep scan.
121120
122121
Args:
123122
_class (type[Any]): Class to search for.
@@ -144,9 +143,8 @@ def locate_subclasses(_class: type[Any]) -> list[Any]:
144143
"""
145144
Dynamically discover all classes that are subclasses of some type.
146145
147-
Searches plugin packages using a shallow scan (top-level __init__.py exports only)
148-
and the main project package using a deep scan (all submodules via pkgutil). The
149-
shallow scan for plugins prevents over-discovering classes from plugin submodules.
146+
Searches plugin packages using a shallow scan and the main project package using
147+
a deep scan.
150148
151149
Args:
152150
_class (type[Any]): Parent class of subclasses to search for.

0 commit comments

Comments
 (0)