Files
troupe-standup/wizard-work/beam/test_tree_root.py
T
ledger f864998aba beam: Q128 -- CHECK now grades all 570 cells on stdlib alone (no pytest)
Q105 pointed beam/CHECK at pytest; pytest is not installed on this
interpreter, so the gate exited 2 and ran zero cells. run_lane_tests.py
collects TestCase classes (TestLoader) and bare module-level def test_*()
(FunctionTestCase) itself, treats an unimportable module and a printed
FAIL transcript as faults, and exits 0/1/2. Four test files that imported
pytest now use beam_assert.raises/fail and unittest.mock; no cell dropped.

Measured: unittest discover 353 tests; runner 570 (353 + 217 bare);
bash wizard-work/beam/CHECK rc 0; test_run_lane_tests.py 10 cells OK;
7-mutant battery in scratch copies all as expected (HEAD CHECK rc 2,
broken bare rc 1, pytest import rc 1, failing TestCase rc 1, script FAIL
rc 1, empty lane rc 2, control rc 0).

Record: WORK-QUEUE.md Q128; report wizard-outputs/volt/2026-10-30-q128.md
2026-10-30 16:13:11 +00:00

69 lines
1.9 KiB
Python

import os
import sys
import tempfile
from beam_assert import fail, raises
sys.path.insert(0, os.path.dirname(__file__))
from tree_root import find_tree_root, assert_inside_tree, portable_seed
def test_find_root_walks_up():
d = tempfile.mkdtemp()
root = os.path.join(d, "repo")
os.makedirs(os.path.join(root, "inbox"))
open(os.path.join(root, "WORK-QUEUE.md"), "w").write("x")
deep = os.path.join(root, "a", "b", "c")
os.makedirs(deep)
f = os.path.join(deep, "m.py")
open(f, "w").write("pass")
assert find_tree_root(f) == os.path.realpath(root)
def test_find_root_missing_raises():
d = tempfile.mkdtemp()
with raises(FileNotFoundError):
find_tree_root(d)
def test_assert_inside_ok():
root = tempfile.mkdtemp()
p = os.path.join(root, "inbox", "seed.json")
os.makedirs(os.path.dirname(p), exist_ok=True)
open(p, "w").write("{}")
assert assert_inside_tree(p, root) == os.path.realpath(p)
def test_assert_inside_escape_raises():
root = tempfile.mkdtemp()
with raises(ValueError):
assert_inside_tree("/etc/passwd", root)
def test_portable_seed_inside():
root = tempfile.mkdtemp()
os.makedirs(os.path.join(root, "inbox"))
p = portable_seed(root)
assert p.startswith(os.path.realpath(root) + os.sep)
def test_import_no_io():
src = open(os.path.join(os.path.dirname(__file__), "tree_root.py")).read()
import builtins
orig = builtins.open
calls = []
def guard(*a, **k):
calls.append(a)
raise RuntimeError("import-time I/O detected")
ns = {}
builtins.open = guard
try:
try:
exec(compile(src, "tree_root.py", "exec"), ns)
assert not calls, "import-time open calls: %r" % calls
except RuntimeError as e:
if "import-time I/O" in str(e):
fail("module performed import-time I/O")
raise
finally:
builtins.open = orig