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.

1"""Import one module and print what its import registered, as JSON.
2
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.
9"""
10
11from __future__ import annotations(empty)
12
13import importlib(empty)
14import json(empty)
15import sys(empty)
16from typing import Any(empty)
17
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",),
23}
24
25
26def registered_by(module: str) -> list[str]:(empty)
27 """What importing *module* registers, one line per registration."""
28 from livery.footman import capture(empty)
29
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)
39 return found(empty)
40
41
42def _recording(function: Any, found: list[str]) -> Any:(empty)
43 """*function*, noting each call in *found* by the function's name."""
44
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)
48
49 return recorder(empty)
50
51
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)
55
56
57if __name__ == "__main__":57 ↛ exitline 57 didn't exit the module because the condition on line 57 was always true(empty)
58 main()(empty)