Analyze coverage data to identify functions needing tests.
(self)
| 221 | } |
| 222 | |
| 223 | def analyze_coverage_gaps(self) -> List[FunctionInfo]: |
| 224 | """Analyze coverage data to identify functions needing tests.""" |
| 225 | coverage_file = self.project_root / "coverage.json" |
| 226 | if not coverage_file.exists(): |
| 227 | print("Warning: coverage.json not found. Run tests with --coverage first.") |
| 228 | return [] |
| 229 | |
| 230 | try: |
| 231 | with open(coverage_file, 'r') as f: |
| 232 | coverage_data = json.load(f) |
| 233 | except json.JSONDecodeError: |
| 234 | print("Warning: Could not parse coverage.json") |
| 235 | return [] |
| 236 | |
| 237 | functions_needing_tests = [] |
| 238 | |
| 239 | for file_path, file_data in coverage_data.get('files', {}).items(): |
| 240 | if not file_path.startswith('src/'): |
| 241 | continue |
| 242 | |
| 243 | missing_lines = set(file_data.get('missing_lines', [])) |
| 244 | if not missing_lines: |
| 245 | continue |
| 246 | |
| 247 | # Analyze the source file |
| 248 | full_path = self.project_root / file_path |
| 249 | if full_path.exists(): |
| 250 | functions = self._extract_functions_from_file(full_path, missing_lines) |
| 251 | functions_needing_tests.extend(functions) |
| 252 | |
| 253 | return sorted(functions_needing_tests, key=lambda x: x.complexity_score, reverse=True) |
| 254 | |
| 255 | def _extract_functions_from_file(self, file_path: Path, missing_lines: Set[int]) -> List[FunctionInfo]: |
| 256 | """Extract function information from a source file.""" |
no test coverage detected