#!/usr/bin/env python3 """ Mutation Test Report Generator Generates comprehensive mutation testing reports including: - Mutation scores by module - Surviving mutants analysis - Test coverage gaps - Recommendations for improvement Usage: python generate_mutation_report.py --target priority_p0_financial python generate_mutation_report.py --all """ import argparse import json import subprocess import sys from pathlib import Path from datetime import datetime import configparser def load_targets_config(): """Load mutation testing targets configuration.""" config_path = Path(__file__).parent.parent / "targets" / "TARGETS.ini" config = configparser.ConfigParser() config.read(config_path) return config def get_mutmut_results(): """Get mutation testing results from mutmut.""" try: result = subprocess.run( ["mutmut", "results"], capture_output=True, text=True, timeout=30 ) return result.stdout except Exception as e: print(f"Error getting mutmut results: {e}") return None def parse_mutmut_results(output): """Parse mutmut results into structured data.""" if not output: return None results = { 'score': 0.0, 'killed': 0, 'survived': 0, 'total': 0, 'modules': {} } lines = output.split('\n') for line in lines: if 'Mutation score:' in line: import re match = re.search(r'(\d+\.\d+)%', line) if match: results['score'] = float(match.group(1)) return results def generate_html_report(results, output_path): """Generate HTML mutation testing report.""" html = f"""
Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
| Metric | Value |
|---|---|
| Mutation Score | {results.get('score', 0):.2f}% |
| Killed Mutants | {results.get('killed', 0)} |
| Surviving Mutants | {results.get('survived', 0)} |
| Total Mutants | {results.get('total', 0)} |
| Priority | Target | Status |
|---|---|---|
| P0: Financial & Security | >95% | {'✅ PASS' if results.get('score', 0) >= 95 else '❌ FAIL'} |
| P1: Core Business Logic | >90% | {'✅ PASS' if results.get('score', 0) >= 90 else '❌ FAIL'} |
| P2: API & Tools | >85% | {'✅ PASS' if results.get('score', 0) >= 85 else '❌ FAIL'} |