Rewrite coverage paths

Since tox is running tests on the installed package, the coverage paths are no
more relative to the repository root.
This commit is contained in:
Cédric Krier
2026-03-25 19:39:52 +01:00
parent a77f01aff0
commit 94c4f0a9e6
223 changed files with 1599 additions and 891 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
import sys
import xml.etree.ElementTree as ET
def _replace_path(root, tag, attribute, old_prefix, new_prefix):
for element in root.iter(tag):
original_path = element.get(attribute)
if old_prefix and original_path.startswith(old_prefix):
new_path = original_path.replace(old_prefix, new_prefix, 1)
element.set(attribute, new_path)
elif not old_prefix:
new_path = new_prefix + original_path
element.set(attribute, new_path)
def rewrite_coverage_xml(file_path, old_prefix, new_prefix):
tree = ET.parse(file_path)
root = tree.getroot()
if root.tag == 'coverage':
_replace_path(root, 'class', 'filename', old_prefix, new_prefix)
elif root.tag == 'testsuites':
_replace_path(root, 'testcase', 'file', old_prefix, new_prefix)
tree.write(file_path)
if __name__ == "__main__":
old_prefix, new_prefix, *file_paths = sys.argv[1:]
for file_path in file_paths:
rewrite_coverage_xml(file_path, old_prefix, new_prefix)