This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
per_file_result_diff.py
executable file
·198 lines (162 loc) · 6.6 KB
/
per_file_result_diff.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python3
# Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
#
# SPDX-License-Identifier: MIT
import json
from argparse import ArgumentParser
from pathlib import Path
from main import TestResult, EMOJIS
class ResultParser:
def __init__(
self, old_path: Path, new_path: Path, regressions: bool, intersection_only: bool
) -> None:
old_results = json.loads(old_path.read_text())
new_results = json.loads(new_path.read_text())
self.duration_delta = float(new_results["duration"]) - float(
old_results["duration"]
)
self.old_results: dict[str, str] = {
k: v for k, v in sorted(old_results["results"].items())
}
self.new_results: dict[str, str] = new_results["results"]
self.regressions = regressions
self.intersection_only = intersection_only
self.new_tests: dict[str, str] = {}
self.removed_tests: dict[str, str] = {}
self.diff_tests: dict[str, dict] = {}
self.summary: dict = {
"new_tests": {},
"removed_tests": {},
"diff_tests": {},
}
self.summary_column_widths: dict[str, int] = {}
self.longest_path_length = 0
self.populate_test_dicts()
self.populate_summary_dicts()
def populate_test_dicts(self) -> None:
for path, result in self.old_results.items():
new_result = self.new_results.get(path, None)
if new_result is None:
if not self.intersection_only:
self.longest_path_length = max(self.longest_path_length, len(path))
self.removed_tests[path] = result
elif result != new_result:
self.longest_path_length = max(self.longest_path_length, len(path))
self.diff_tests[path] = {
"old_result": result,
"new_result": new_result,
}
for path, result in self.new_results.items():
if path not in self.old_results:
self.longest_path_length = max(self.longest_path_length, len(path))
self.new_tests[path] = result
def populate_summary_dicts(self) -> None:
# Initialize all results to zero
for summary in self.summary.values():
for k in TestResult:
summary[k] = 0
for result in self.new_tests.values():
self.summary["new_tests"][result] += 1
for result in self.removed_tests.values():
self.summary["removed_tests"][result] += 1
for result in self.diff_tests.values():
self.summary["diff_tests"][result["old_result"]] -= 1
self.summary["diff_tests"][result["new_result"]] += 1
# Calculate summary column widths to make the summary look better
for v in TestResult:
self.summary_column_widths[v] = max(
len(str(self.summary["new_tests"][v])) + 1,
len(str(self.summary["removed_tests"][v])) + 1,
len(str(self.summary["diff_tests"][v])) + 1,
)
def print_summary_results(self, summary_map: dict) -> None:
for v in TestResult:
if summary_map[v] == 0:
continue
print(
f"{summary_map[v]:+{self.summary_column_widths[v]}d} {EMOJIS[v]} ",
end="",
)
def print_full_results(self) -> None:
has_diff_tests = len(self.diff_tests) > 0
if self.intersection_only and not has_diff_tests:
return
has_new_tests = len(self.new_tests) > 0
has_removed_tests = len(self.removed_tests) > 0
if not self.intersection_only:
print("Duration:")
print(f" {self.duration_delta:+.2f}s")
if not has_new_tests and not has_removed_tests and not has_diff_tests:
return
print()
print("Summary:")
if has_new_tests:
print(" New Tests:\n ", end="")
self.print_summary_results(self.summary["new_tests"])
print()
if has_removed_tests:
print(" Removed Tests:\n ", end="")
self.print_summary_results(self.summary["removed_tests"])
print()
if has_diff_tests:
print(" Diff Tests:\n ", end="")
self.print_summary_results(self.summary["diff_tests"])
print()
print()
if has_new_tests:
print("New Tests:")
for path, result in self.new_tests.items():
print(f" {path:{self.longest_path_length}s} {EMOJIS[result]}")
print()
if has_removed_tests:
print("Removed Tests:")
for path, result in self.removed_tests.items():
print(f" {path:{self.longest_path_length}s} {EMOJIS[result]}")
print()
if has_diff_tests:
print("Diff Tests:")
for path, result in self.diff_tests.items():
old_emoji = EMOJIS[result["old_result"]]
new_emoji = EMOJIS[result["new_result"]]
print(
f" {path:{self.longest_path_length}s} {old_emoji} -> {new_emoji}"
)
def print_regressions(self) -> None:
for path, result in self.diff_tests.items():
if result["old_result"] == "PASSED":
old_emoji = EMOJIS[TestResult.PASSED]
new_emoji = EMOJIS[result["new_result"]]
print(
f" {path:{self.longest_path_length}s} {old_emoji} -> {new_emoji}"
)
def print_results(self) -> None:
if self.regressions:
self.print_regressions()
else:
self.print_full_results()
def main() -> None:
parser = ArgumentParser(description="Compare per-file test262 results")
parser.add_argument(
"-o", "--old", required=True, metavar="PATH", help="the path to the old results"
)
parser.add_argument(
"-n", "--new", required=True, metavar="PATH", help="the path to the new results"
)
parser.add_argument(
"-r",
"--regressions",
action="store_true",
help="only show regressions",
)
parser.add_argument(
"-i",
"--intersection-only",
action="store_true",
help="show only differences in tests which are present in both results",
)
args = parser.parse_args()
ResultParser(
Path(args.old), Path(args.new), args.regressions, args.intersection_only
).print_results()
if __name__ == "__main__":
main()