Files
timmy-home/tests/test_codebase_test_generator.py
Alexander Whitestone 840214c8c0
Some checks failed
Agent PR Gate / gate (pull_request) Failing after 17s
Self-Healing Smoke / self-healing-smoke (pull_request) Failing after 8s
Smoke Test / smoke (pull_request) Failing after 6s
Agent PR Gate / report (pull_request) Has been cancelled
fix: harden codebase test generator output (#667)
2026-04-17 02:38:33 -04:00

56 lines
1.7 KiB
Python

import importlib.util
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
SCRIPT = ROOT / "scripts" / "codebase_test_generator.py"
def load_module():
spec = importlib.util.spec_from_file_location("codebase_test_generator", str(SCRIPT))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def test_generate_test_suite_uses_dynamic_loader_for_numbered_paths():
mod = load_module()
func = mod.FunctionInfo(
name="linkify",
module_path="reports/notebooklm/2026-03-27-hermes-openclaw/render_reports.py",
lineno=12,
args=["text"],
has_return=True,
)
gap = mod.CoverageGap(func=func, reason="no test found", test_priority=1)
suite = mod.generate_test_suite([gap], max_tests=1)
assert "import importlib.util" in suite
assert "_load_symbol(" in suite
assert "from reports.notebooklm" not in suite
assert "2026-03-27-hermes-openclaw/render_reports.py" in suite
def test_generate_test_handles_async_and_runtime_args_safely():
mod = load_module()
func = mod.FunctionInfo(
name="keypress",
module_path="angband/mcp_server.py",
lineno=200,
args=["key", "wait_ms", "session_name"],
is_async=True,
has_return=True,
calls=["send_key"],
)
gap = mod.CoverageGap(func=func, reason="no test found", test_priority=1)
test_code = mod.generate_test(gap)
assert "@pytest.mark.asyncio" in test_code
assert "async def" in test_code
assert "await target(" in test_code
assert "key='test'" in test_code
assert "wait_ms=1" in test_code
assert "session_name='test'" in test_code
assert "pytest.raises((RuntimeError, ValueError, TypeError))" in test_code