-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_discover_floors.py
More file actions
84 lines (67 loc) · 2.66 KB
/
Copy pathtest_discover_floors.py
File metadata and controls
84 lines (67 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# FLOOR
"""test_discover_floors.py - deterministic red floor for discover_floors.py.
Proves the discovery's teeth on built-in fixtures, one RED case per decidable
rule (METHOD §2; the "every checker ships its complete red floor" discipline):
- marked file in the head window -> discovered
- unmarked file (a tool) -> not discovered
- marker past the scan window -> not discovered (the bound bites)
- marked file inside an excluded -> not discovered (.venv exclusion bites)
Exit 0 = every behaviour holds; exit 1 = a regression. It carries the ``# FLOOR``
marker itself, so the discoverer finds and runs it like any other floor.
"""
from __future__ import annotations
import sys
import tempfile
from pathlib import Path
import discover_floors as df
MARKED = "#!/usr/bin/env python3\n# FLOOR\nx = 1\n"
UNMARKED = "#!/usr/bin/env python3\n# a tool, not a floor\nx = 1\n"
DEEP = "#\n#\n#\n#\n#\n# FLOOR\nx = 1\n" # marker on line 6, past the window
def _write(base: Path, rel: str, text: str) -> Path:
target = base / rel
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(text, encoding="utf-8")
return target
def main() -> int:
failures: list[str] = []
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
marked = _write(root, "pkg/floor_marked.py", MARKED)
_write(root, "pkg/tool_unmarked.py", UNMARKED)
_write(root, "pkg/floor_deep.py", DEEP)
_write(root, ".venv/lib/floor_hidden.py", MARKED)
found = set(df.discover(root))
checks = [
("marked file discovered", marked in found),
(
"unmarked tool ignored",
(root / "pkg/tool_unmarked.py") not in found,
),
(
"marker past window ignored",
(root / "pkg/floor_deep.py") not in found,
),
(
"excluded .venv ignored",
(root / ".venv/lib/floor_hidden.py") not in found,
),
("exactly one floor found", found == {marked}),
("is_floor true on marked", df.is_floor(marked) is True),
(
"is_floor false on unmarked",
df.is_floor(root / "pkg/tool_unmarked.py") is False,
),
]
for label, ok in checks:
status = "ok " if ok else "FAIL"
print(f"[{status}] {label}")
if not ok:
failures.append(label)
if failures:
print(f"\nFAIL: {len(failures)} check(s) regressed.")
return 1
print(f"\nOK: {len(checks)} checks passed.")
return 0
if __name__ == "__main__":
sys.exit(main())