MCPcopy Create free account
hub / github.com/bhowiebkr/PyFlowGraph / analyze_and_generate

Method analyze_and_generate

testing/test_generator.py:674–723  ·  view source on GitHub ↗

Analyze coverage gaps and generate tests.

(self, max_functions: int = 10, 
                           min_complexity: float = 1.0,
                           output_dir: Path = None)

Source from the content-addressed store, hash-verified

672 print(f"Generated: {test_file_path}")
673
674 def analyze_and_generate(self, max_functions: int = 10,
675 min_complexity: float = 1.0,
676 output_dir: Path = None) -> Dict[str, Any]:
677 """Analyze coverage gaps and generate tests."""
678 if output_dir is None:
679 output_dir = self.test_dir / "generated"
680
681 # Analyze coverage gaps
682 functions_needing_tests = self.analyze_coverage_gaps()
683
684 if not functions_needing_tests:
685 return {
686 'status': 'no_gaps',
687 'message': 'No coverage gaps found or coverage.json not available',
688 'functions_analyzed': 0,
689 'tests_generated': 0
690 }
691
692 # Filter by complexity and limit count
693 filtered_functions = [
694 f for f in functions_needing_tests
695 if f.complexity_score >= min_complexity
696 ][:max_functions]
697
698 if not filtered_functions:
699 return {
700 'status': 'filtered_out',
701 'message': f'No functions meet complexity threshold of {min_complexity}',
702 'functions_analyzed': len(functions_needing_tests),
703 'tests_generated': 0
704 }
705
706 # Generate tests
707 self.generate_test_file(filtered_functions, output_dir)
708
709 return {
710 'status': 'success',
711 'message': f'Generated tests for {len(filtered_functions)} functions',
712 'functions_analyzed': len(functions_needing_tests),
713 'tests_generated': len(filtered_functions),
714 'output_directory': str(output_dir),
715 'generated_functions': [
716 {
717 'name': f.name,
718 'file': f.file_path,
719 'complexity': f.complexity_score
720 }
721 for f in filtered_functions
722 ]
723 }
724
725def main():
726 """Main entry point for the test generator."""

Callers 1

mainFunction · 0.95

Calls 2

analyze_coverage_gapsMethod · 0.95
generate_test_fileMethod · 0.95

Tested by

no test coverage detected