Coverage for packages/workshop/src/livery/workshop/testing/_import_probe.py: 97%
Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop, packages/extensions/ty, packages/extensions/ruff, packages/extensions/python, packages/extensions/pytest, packages/extensions/pyrefly, packages/extensions/nanobind, packages/extensions/mypy, packages/extensions/mkdocstrings, packages/extensions/lfs, packages/extensions/docs, packages/extensions/cpp, packages/extensions/coverage, packages/extensions/conan, packages/extensions/cmake, packages/extensions/claude, packages/extensions/clang-tidy, packages/extensions/clang-format, packages/extensions/changelog, packages/extensions/basedpyright ran.
Keys
- r m x p show or hide the lines of a kind
- j k the next or previous highlighted chunk
- 0 the top of the page
- 1 the first highlighted chunk
- [ ] the previous or next file
- u the index
- ? show or hide this help
1"""Import one module and print what its import registered, as JSON.
3The conformance kit runs ``python -m livery.workshop.testing._import_probe
4<module>`` in a process of its own, so the module is imported for the
5first time. The workshop's own registering modules are imported before
6the recording starts, so a builtin they register is never counted. Then
7each of their registration functions records its calls, and footman's
8task tree is captured, for the one import.
11from __future__ import annotations(empty)
13import importlib(empty)
16from typing import Any(empty)
18#: Each workshop module that registers, with its registration functions.
19REGISTRARS: dict[str, tuple[str, ...]] = {(empty)
20 "livery.workshop._categories": ("register_channels",),
21 "livery.workshop._steps": ("register_step",),
22 "livery.workshop._points": ("contribute_job",),
26def registered_by(module: str) -> list[str]:(empty)
27 """What importing *module* registers, one line per registration."""
28 from livery.footman import capture(empty)
30 found: list[str] = [](empty)
31 for name, functions in REGISTRARS.items():(empty)
32 owner = importlib.import_module(name)(empty)
33 for function in functions:(empty)
34 setattr(owner, function, _recording(getattr(owner, function), found))(empty)
35 with capture() as captured:(empty)
36 importlib.import_module(module)(empty)
37 found += [f"the footman group {name!r}" for name in sorted(captured.groups)](empty)
38 found += [f"the footman task {name!r}" for name in sorted(captured.tasks)](empty)
42def _recording(function: Any, found: list[str]) -> Any:(empty)
43 """*function*, noting each call in *found* by the function's name."""
45 def recorder(*args: Any, **kwargs: Any) -> Any:(empty)
46 found.append(f"a call to {function.__module__}.{function.__name__}")(empty)
47 return function(*args, **kwargs)(empty)
49 return recorder(empty)
52def main() -> None:(empty)
53 """Print what importing the module the first argument names registers."""
54 print(json.dumps(registered_by(sys.argv[1])))(empty)
57if __name__ == "__main__":57 ↛ exitline 57 didn't exit the module because the condition on line 57 was always true(empty)