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

Method analyze_coverage_gaps

testing/test_analyzer.py:234–279  ·  view source on GitHub ↗

Analyze code coverage and identify gaps needing tests.

(self)

Source from the content-addressed store, hash-verified

232 return sorted(patterns, key=lambda x: x.frequency, reverse=True)
233
234 def analyze_coverage_gaps(self) -> List[CoverageGap]:
235 """Analyze code coverage and identify gaps needing tests."""
236 coverage_file = self.project_root / "coverage.json"
237 if not coverage_file.exists():
238 return []
239
240 try:
241 with open(coverage_file, 'r') as f:
242 coverage_data = json.load(f)
243 except json.JSONDecodeError:
244 return []
245
246 gaps = []
247 files_data = coverage_data.get('files', {})
248
249 for file_path, file_data in files_data.items():
250 if not file_path.startswith('src/'):
251 continue
252
253 missing_lines = file_data.get('missing_lines', [])
254 if not missing_lines:
255 continue
256
257 # Analyze missing functions
258 try:
259 full_path = self.project_root / file_path
260 if full_path.exists():
261 functions = self._extract_functions_from_file(full_path)
262
263 for func_name, func_lines in functions.items():
264 missing_in_func = [line for line in missing_lines if line in func_lines]
265 if missing_in_func:
266 complexity = self._calculate_complexity_score(func_lines, missing_in_func)
267 priority = self._determine_priority(complexity, len(missing_in_func))
268
269 gaps.append(CoverageGap(
270 file_path=file_path,
271 function_name=func_name,
272 line_numbers=missing_in_func,
273 complexity_score=complexity,
274 priority=priority
275 ))
276 except Exception as e:
277 print(f"Warning: Could not analyze {file_path}: {e}")
278
279 return sorted(gaps, key=lambda x: (x.priority == 'HIGH', x.complexity_score), reverse=True)
280
281 def _extract_functions_from_file(self, file_path: Path) -> Dict[str, List[int]]:
282 """Extract function definitions and their line ranges from a Python file."""

Callers 2

analyzeMethod · 0.95
mainFunction · 0.95

Calls 5

_determine_priorityMethod · 0.95
CoverageGapClass · 0.85
loadMethod · 0.80

Tested by

no test coverage detected