Test Generation Workflow
What It Does
Section titled “What It Does”TestGenerator analyzes Python source files using AST parsing and generates pytest-structured test case skeletons. For each public function it produces a basic unit test, an edge-case test (when parameters exist), and an error-handling test. For public class methods it generates a unit test that instantiates the class.
chimera testgen --source ./chimera --output tests/generatedPython API
Section titled “Python API”from chimera.testgen import TestGenerator, TestCase
generator = TestGenerator()
# Analyze a single filecases = generator.analyze("chimera/core/agent.py")for case in cases: print(f"{case.name} ({case.category}): {case.target_function}") print(case.test_code)Analyze from source string directly:
source = '''def add(a, b): return a + b'''cases = generator.analyze_source(source, filepath="math_utils.py")# Generates: test_add (unit), test_add_edge_empty (edge), test_add_error (error)Access all accumulated test cases:
all_cases = generator.test_casesgenerator.clear() # reset accumulated casesKey Classes
Section titled “Key Classes”TestGenerator
Section titled “TestGenerator”class TestGenerator: def __init__(self) -> None def analyze(self, filepath: str) -> list[TestCase] def analyze_source(self, source: str, filepath: str = "<unknown>") -> list[TestCase] def clear(self) -> NoneProperties: test_cases (list of all accumulated TestCase instances).
TestCase
Section titled “TestCase”Dataclass with fields: name (str), target_function (str), target_file (str), test_code (str), category (str: "unit", "edge", or "error").
CoverageReport
Section titled “CoverageReport”Dataclass with fields: total_statements, total_missing, coverage_percent, file_coverage (dict mapping filepath to percent), uncovered_lines (dict mapping filepath to line numbers).
Properties: covered_statements.
Methods: files_below(threshold) -> list[str].
parse_coverage(output: str) -> CoverageReport
Section titled “parse_coverage(output: str) -> CoverageReport”Parses pytest-cov / coverage.py text output into a CoverageReport.
Import
Section titled “Import”from chimera.testgen import TestGenerator, TestCase, CoverageReport, parse_coverage