forked from tiiuae/ci-test-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_report.py
37 lines (27 loc) · 1.18 KB
/
edit_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0
import re
import os
# Labels to remove
labels_to_remove = ["lenovo-x1", "nuc", "orin-agx", "orin-nx", "riscv", "test:retry\(1\)"]
# JavaScript pattern to match the labels and their data
pattern = re.compile(r'\{"elapsed":"[^"]+","fail":\d+,"label":"(' + '|'.join(labels_to_remove) + r')","pass":\d+,"skip":\d+\},?')
files = ['report.html', 'log.html']
for file_name in files:
path = os.path.join('Robot-Framework/test-suites', file_name)
print(f'Editing file {os.path.abspath(path)}')
# Read the HTML content
with open(path, 'r') as f:
content = f.read()
# Function to replace the matched text
def replace_func(match):
# If the match is followed by a comma and a newline, remove the comma as well
if match.group(0)[-1] == ',':
return ""
return ""
# Replace the matched patterns with an empty string
modified_content = pattern.sub(replace_func, content)
# Save the modified HTML content back to the file
with open(path, 'w') as f:
f.write(modified_content)
print(f'Modified file saved: {path}')