Private
Public Access
0
0
Files
manual_slop/tests/test_check_test_toml_paths.py
T

49 lines
1.9 KiB
Python

"""Tests for scripts/check_test_toml_paths.py (Phase 8, Task 8.1)."""
import subprocess
import sys
from pathlib import Path
def test_audit_runs_without_error() -> None:
"""The audit script runs and exits cleanly."""
result = subprocess.run(
[sys.executable, "scripts/check_test_toml_paths.py"],
capture_output=True, text=True, cwd=str(Path(__file__).resolve().parent.parent)
)
assert result.returncode in (0, 1), f"Unexpected exit code: {result.returncode}"
def test_audit_flags_hardcoded_workspace_path(tmp_path) -> None:
"""A test file with Path('tests/artifacts/...') is flagged."""
bad_file = tmp_path / "test_bad.py"
bad_file.write_text('workspace = Path("tests/artifacts/live_gui_workspace")\n', encoding="utf-8")
# Run a copy of the audit logic on tmp_path
import re
pattern = re.compile(r'Path\(["\']tests/artifacts/')
content = bad_file.read_text(encoding="utf-8")
assert pattern.search(content), "Pattern should match the hardcoded path"
def test_audit_flags_project_root_path(tmp_path) -> None:
"""A test file with Path('C:/projects/...') is flagged."""
bad_file = tmp_path / "test_bad.py"
bad_file.write_text('base_dir = Path("C:/projects/test")\n', encoding="utf-8")
import re
pattern = re.compile(r'Path\(["\']C:[/\\]+projects')
content = bad_file.read_text(encoding="utf-8")
assert pattern.search(content), "Pattern should match the project root path"
def test_audit_passes_clean_file(tmp_path) -> None:
"""A test file with no hardcoded paths passes the audit patterns."""
good_file = tmp_path / "test_good.py"
good_file.write_text("workspace = live_gui_workspace\n", encoding="utf-8")
import re
patterns = [
re.compile(r'Path\(["\']tests/artifacts/'),
re.compile(r'Path\(["\']C:[/\\]+projects'),
]
content = good_file.read_text(encoding="utf-8")
for p in patterns:
assert not p.search(content), f"Pattern {p} should not match clean file"