union_summary.py (1716B)
1 # This file is part of GNU Taler 2 # (C) 2026 Taler Systems S.A. 3 # 4 # GNU Taler is free software; you can redistribute it and/or modify it under the 5 # terms of the GNU General Public License as published by the Free Software 6 # Foundation; either version 3, or (at your option) any later version. 7 # 8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License along with 13 # GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 14 """Print the union of the simulator and the unit tests, and what each adds. 15 16 union_summary.py coverage-with-units.xml coverage.xml 17 18 The second figure is the one that changes what to do next: a line the unit 19 tests already reach is a line not worth an emulator and ninety seconds. 20 """ 21 22 import sys 23 import xml.etree.ElementTree as ET 24 25 26 def counters(path: str) -> dict[str, tuple[int, int]]: 27 root = ET.parse(path).getroot() 28 return {c.get("type"): (int(c.get("covered")), int(c.get("missed"))) 29 for c in root.findall("counter")} 30 31 32 def main(argv: list[str]) -> int: 33 both, sim = counters(argv[0]), counters(argv[1]) 34 for kind, (covered, missed) in both.items(): 35 total = covered + missed 36 if not total: 37 continue 38 gained = covered - sim.get(kind, (0, 0))[0] 39 print(f"{kind.lower():12} {covered:7}/{total:<7} " 40 f"{100 * covered / total:5.1f}% (+{gained} from unit tests)") 41 return 0 42 43 44 if __name__ == "__main__": 45 sys.exit(main(sys.argv[1:]))