import json from dataclasses import dataclass from typing import Dict, List @dataclass class GCovLine: line_number: int count: int is_fallthrough: bool = False class GCovFile: def __init__(self, path: str) -> None: self._path = path self._data: dict = {} self.files: Dict[str, List[GCovLine]] = {} def read(self) -> None: with open(self._path, "r") as infile: self._data = json.load(infile) for file in self._data["files"]: name: str = file["file"] lines: List[GCovLine] = [] for line in file["lines"]: if len(line["branches"]): for branch in line["branches"]: lines.append(GCovLine(line["line_number"], branch["count"], branch["fallthrough"])) else: lines.append(GCovLine(line["line_number"], line["count"])) self.files[name] = lines