Skip to content

Commit c0fac85

Browse files
ref: extract _group_arcs_by_line helper to deduplicate arc grouping
1 parent 1eb2e39 commit c0fac85

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

drift/core/coverage_server.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ def _is_user_file(filename: str) -> bool:
178178
return not _source_root or resolved.startswith(_source_root + os.sep) or resolved == _source_root
179179

180180

181+
def _group_arcs_by_line(arcs: set) -> dict[int, list[int]]:
182+
"""Group executed arcs by from_line, skipping negative entry arcs."""
183+
by_line: dict[int, list[int]] = {}
184+
for from_line, to_line in arcs:
185+
if from_line < 0:
186+
continue
187+
by_line.setdefault(from_line, []).append(to_line)
188+
return by_line
189+
190+
181191
def _get_branch_data(data, filename: str) -> dict:
182192
"""Extract branch coverage data for a file.
183193
@@ -199,13 +209,7 @@ def _get_branch_data(data, filename: str) -> dict:
199209

200210
missing_arcs = analysis.missing_branch_arcs()
201211
executed_arcs = set(data.arcs(filename) or [])
202-
203-
# Group executed arcs by from_line (skip negative entry arcs)
204-
executed_by_line: dict[int, list[int]] = {}
205-
for from_line, to_line in executed_arcs:
206-
if from_line < 0:
207-
continue
208-
executed_by_line.setdefault(from_line, []).append(to_line)
212+
executed_by_line = _group_arcs_by_line(executed_arcs)
209213

210214
# A line is a branch point if:
211215
# - it appears in missing_arcs (at least one path wasn't taken), OR
@@ -248,13 +252,7 @@ def _get_per_test_branch_data(data, filename: str, cached: dict) -> dict:
248252
return {"totalBranches": 0, "coveredBranches": 0, "branches": {}}
249253

250254
executed_arcs = set(data.arcs(filename) or [])
251-
252-
# Group executed arcs by from_line (skip negative entry arcs)
253-
executed_by_line: dict[int, list[int]] = {}
254-
for from_line, to_line in executed_arcs:
255-
if from_line < 0:
256-
continue
257-
executed_by_line.setdefault(from_line, []).append(to_line)
255+
executed_by_line = _group_arcs_by_line(executed_arcs)
258256

259257
# Use cached branch points — only compute covered from current arcs
260258
cached_branches = cached.get("branches", {})

0 commit comments

Comments
 (0)