test_the_hook_imports_nothing_from_the_clew_package

Tests › tests/test_hook.py

passed Passed in the packaged run.

What this test is for

Why it exists

THE PROPERTY THE MODULE DOCSTRING ALREADY CLAIMED WAS GATED, AND WHICH NOTHING GATED. It says "it imports nothing from `clew` and must keep importing nothing: the gate asserts it" — no such gate existed until this test. In a file whose own argument is that a component lying about itself teaches a reader to discount everything else it says, that is worth more than the check.

Verifies REQ-DDB-WIKI-054

Given

  1. tree = ast.parse(HOOK_SOURCE.read_text(encoding="utf-8"))
  2. imported: set[str] = set()
4 more
  1. for node in ast.walk(tree): if isinstance(node, ast.Import): imported.update(alias.name for alias in node.names) elif isinstance(node, ast.ImportFrom) and node.module: imported.add(node.module)
  2. offenders = {m for m in imported if m == "clew" or m.startswith("clew.")}
  3. probe = ( "import sys; import clew_hook; " "bad=[m for m in sys.modules if m=='clew' or m.startswith('clew.')]; " "print(','.join(sorted(bad)))" )
  4. result = subprocess.run( [sys.executable, "-c", probe], capture_output=True, text=True, cwd=str(REPO), check=False, )
→

When

  1. —
→

Then

  1. ✓ offenders is false
  2. ✓ result.returncode equals 0
  3. ✓ result.stdout.strip() is false

tests/test_hook.py:1004 · its file's page

What it checks (3)

  1. assert not offenders, f"the hook imports from the clew package: {sorted(offenders)}" not attributed
  2. assert result.returncode == 0, f"the probe failed: {result.stderr[:300]}" not attributed
  3. assert not result.stdout.strip(), ( f"importing clew_hook pulled in clew modules: {result.stdout.strip()} — this is the " f"157 ms the module docstring says was removed by moving out of the package" ) not attributed

What it reaches

Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.

Requirements it verifies (1)

requirementlinked byimplementers exercised
REQ-DDB-WIKI-054catalogunknown