scripts.gen_tests
Reference › scripts › gen_tests
scripts/gen_tests.py is a small driver that generates test module stubs with EnhancedTestGenerator from orchestrata_tools.test_generator and checks that they are syntactically valid. It uses orchestrata_tools.parser to parse each source file. generate_for_files takes (file path, module path) pairs, parses each and writes the generated stub; main calls it on the fixed SOURCE_FILES list in the module. It takes no arguments and a human runs it. For the broader generator see generate_pytest.
At a glance
| Source | scripts/gen_tests.py |
| Lines of code | 55 |
| Classes | 0 |
| Functions | 2 |
| Imports (internal) | orchestrata_tools.parser, orchestrata_tools.test_generator |
| Imported by | none |
| Tests that import it | none |
Class diagram
No classes; see Functions.
Dependency diagram
API
Functions
| Function | Signature | Summary |
|---|---|---|
generate_for_files |
generate_for_files(source_files: list[tuple[str, str]]) -> None |
Parse each (fpath, modpath) pair, generate a test module stub for its classes, validate the generated source parses, and print a preview. |
main |
main() -> None |
Source
Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/scripts/gen_tests.py
#!/usr/bin/env python3
"""Generate test stubs using EnhancedTestGenerator and validate syntax."""
from __future__ import annotations
import ast
from orchestrata_tools.parser import SourceASTParser
from orchestrata_tools.test_generator import EnhancedTestGenerator
SOURCE_FILES = [
(
"src/orchestrata_ultimate/orchestrator/artifact_store.py",
"orchestrator.artifact_store",
),
(
"src/orchestrata_ultimate/orchestrator/pipeline_router.py",
"orchestrator.pipeline_router",
),
]
def generate_for_files(source_files: list[tuple[str, str]]) -> None:
"""Parse each ``(fpath, modpath)`` pair, generate a test module stub for
its classes, validate the generated source parses, and print a preview.
Any failure (missing file, parse error, generator error) is caught per
file so one bad entry doesn't abort the rest of the batch.
"""
p = SourceASTParser()
g = EnhancedTestGenerator()
for fpath, modpath in source_files:
print(f"\n{'=' * 60}")
print(f"FILE: {fpath}")
print(f"{'=' * 60}")
try:
c = p.parse_file(fpath)
out = g.generate_module(
c.classes, modpath, f"test_{fpath.split('/')[-1].replace('.py', '')}"
)
# Validate syntax
ast.parse(out)
print("SYNTAX: OK")
print(out[:3000])
except Exception as e:
print(f"ERROR: {e}")
def main() -> None:
generate_for_files(SOURCE_FILES)
if __name__ == "__main__":
main()