Answer architecture round 4: 0 🔴, 0 🟡 (0 misread); loop-claude's suites sit beside their modules, and what tests share across packages lives in each package's doubles.py
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 11:54:34 +01:00
parent 9bc2887ee8
commit 8ca612b7a4
49 changed files with 1415 additions and 1228 deletions
+33
View File
@@ -57,6 +57,21 @@ def upward_imports(bin_folder: pathlib.Path, above: dict[str, tuple[str, ...]])
return sorted(found)
def imports_of_test_modules(bin_folder: pathlib.Path) -> list[str]:
"""Each module under bin_folder that imports a test module of another package, as `<module> imports <test module>`. A module at bin_folder's root, such as test_env.py, belongs to no package."""
found = []
for module in sorted(bin_folder.rglob("*.py")):
package = module.relative_to(bin_folder).parts[0]
for node in ast.walk(ast.parse(module.read_text(encoding="utf-8"))):
names = [alias.name for alias in node.names] if isinstance(node, ast.Import) else [f"{node.module}.{alias.name}" for alias in node.names] if isinstance(node, ast.ImportFrom) and node.level == 0 and node.module else []
for name in names:
top, *below = name.split(".")
tests = [part for part in below if part.startswith("test_")]
if tests and top != package:
found.append(f"{module.relative_to(bin_folder)} imports {name[:name.index(tests[0]) + len(tests[0])]}")
return sorted(set(found))
def cycle(imported: dict[str, set[str]]) -> list[str]:
"""One cycle among the packages, as the packages along it; empty where there is none."""
try:
@@ -92,6 +107,24 @@ class PackageCycles(unittest.TestCase):
(folder / package / name).write_text(source)
self.assertEqual(driver_imports(folder, ("a",)), ["b/mod.py imports a", "b/test_mod.py imports a"])
def test_no_module_imports_a_test_module_of_another_package(self):
self.assertEqual(imports_of_test_modules(ROOT / "bin"), [], "move what the importer needs into the doubles.py of the package that owns it")
def test_a_test_module_imported_from_another_package_is_found_however_it_is_spelled(self):
with tempfile.TemporaryDirectory() as temp:
folder = pathlib.Path(temp)
sources = (
("a", "test_mod.py", "from a.test_other import x\nfrom test_env import y\nfrom a.doubles import z\n"),
("b", "test_mod.py", "from a.test_mod import x\n"),
("b", "mod.py", "def f():\n\timport a.deep.test_far\n"),
("c", "test_mod.py", "from a import test_mod\nfrom a.test_mod import x, y\n"),
)
for package, name, source in sources:
(folder / package).mkdir(exist_ok=True)
(folder / package / name).write_text(source)
(folder / "test_root.py").write_text("from a.test_mod import x\n")
self.assertEqual(imports_of_test_modules(folder), ["b/mod.py imports a.deep.test_far", "b/test_mod.py imports a.test_mod", "c/test_mod.py imports a.test_mod", "test_root.py imports a.test_mod"])
def test_reads_an_import_deferred_into_a_function_and_leaves_out_tests(self):
with tempfile.TemporaryDirectory() as temp:
folder = pathlib.Path(temp)