-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_comparison.py
More file actions
223 lines (208 loc) · 6.43 KB
/
example_comparison.py
File metadata and controls
223 lines (208 loc) · 6.43 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env python3
import os
import json
import subprocess
# Sample test results for demonstration
sample_result1 = {
"repository": "example_repo",
"status": "failure",
"test_files": [
{
"path": "test_file1.py",
"tested_files": ["file1.py"],
"status": "failure",
"tests": [
{
"name": "test_function1",
"classname": "",
"status": "error",
"message": "collection failure"
}
],
"summary": {"passed_tests": 0, "failed_tests": 1, "skipped_tests": 0}
},
{
"path": "test_file2.py",
"tested_files": ["file2.py"],
"status": "success",
"tests": [
{
"name": "test_function2",
"classname": "",
"status": "success",
"message": ""
}
],
"summary": {"passed_tests": 1, "failed_tests": 0, "skipped_tests": 0}
}
],
"total_summary": {
"total_files": 2,
"passed_files": 1,
"partial_files": 0,
"failed_files": 1,
"passed_tests": 1,
"failed_tests": 1,
"skipped_tests": 0
},
"execution_time": 5.2
}
# Different overall status, different file status, and different test status
sample_result2 = {
"repository": "example_repo",
"status": "success", # Different overall status
"test_files": [
{
"path": "test_file1.py",
"tested_files": ["file1.py"],
"status": "success", # Different file status
"tests": [
{
"name": "test_function1",
"classname": "",
"status": "success", # Different test status
"message": ""
}
],
"summary": {"passed_tests": 1, "failed_tests": 0, "skipped_tests": 0}
},
{
"path": "test_file2.py",
"tested_files": ["file2.py"],
"status": "success",
"tests": [
{
"name": "test_function2",
"classname": "",
"status": "success",
"message": ""
}
],
"summary": {"passed_tests": 1, "failed_tests": 0, "skipped_tests": 0}
},
{
"path": "test_file3.py", # New test file only in result2
"tested_files": ["file3.py"],
"status": "success",
"tests": [
{
"name": "test_function3",
"classname": "",
"status": "success",
"message": ""
}
],
"summary": {"passed_tests": 1, "failed_tests": 0, "skipped_tests": 0}
}
],
"total_summary": {
"total_files": 3,
"passed_files": 3,
"partial_files": 0,
"failed_files": 0,
"passed_tests": 3,
"failed_tests": 0,
"skipped_tests": 0
},
"execution_time": 6.1
}
# Another repository only in first result
sample_result3 = {
"repository": "unique_repo_1",
"status": "success",
"test_files": [
{
"path": "test_unique.py",
"tested_files": ["unique.py"],
"status": "success",
"tests": [
{
"name": "test_unique_function",
"classname": "",
"status": "success",
"message": ""
}
],
"summary": {"passed_tests": 1, "failed_tests": 0, "skipped_tests": 0}
}
],
"total_summary": {
"total_files": 1,
"passed_files": 1,
"partial_files": 0,
"failed_files": 0,
"passed_tests": 1,
"failed_tests": 0,
"skipped_tests": 0
},
"execution_time": 3.4
}
# Another repository only in second result
sample_result4 = {
"repository": "unique_repo_2",
"status": "failure",
"test_files": [
{
"path": "test_unique2.py",
"tested_files": ["unique2.py"],
"status": "failure",
"tests": [
{
"name": "test_unique_function2",
"classname": "",
"status": "failure",
"message": "AssertionError"
}
],
"summary": {"passed_tests": 0, "failed_tests": 1, "skipped_tests": 0}
}
],
"total_summary": {
"total_files": 1,
"passed_files": 0,
"partial_files": 0,
"failed_files": 1,
"passed_tests": 0,
"failed_tests": 1,
"skipped_tests": 0
},
"execution_time": 2.8
}
# Create sample JSONL files
def create_sample_files():
# Create first JSONL file
with open("sample_result1.jsonl", "w") as f:
f.write(json.dumps(sample_result1) + "\n")
f.write(json.dumps(sample_result3) + "\n") # Add unique repo to first file
# Create second JSONL file
with open("sample_result2.jsonl", "w") as f:
f.write(json.dumps(sample_result2) + "\n")
f.write(json.dumps(sample_result4) + "\n") # Add unique repo to second file
print("Created sample JSONL files:")
print(" - sample_result1.jsonl")
print(" - sample_result2.jsonl")
def run_comparison():
cmd = ["python", "compare_test_results.py", "sample_result1.jsonl", "sample_result2.jsonl", "--output", "sample_comparison.json"]
print(f"Running command: {' '.join(cmd)}")
subprocess.run(cmd)
print("\nComparison complete. Results saved to sample_comparison.json")
print("You can examine the detailed results in that file.")
def cleanup():
for file in ["sample_result1.jsonl", "sample_result2.jsonl", "sample_comparison.json"]:
if os.path.exists(file):
os.remove(file)
print("\nCleaned up sample files.")
def main():
print("=== Test Results Comparison Example ===\n")
# Create sample files
create_sample_files()
# Run comparison
run_comparison()
# Ask if user wants to clean up
response = input("\nClean up sample files? (y/n): ")
if response.lower() == 'y':
cleanup()
else:
print("\nSample files retained for your review.")
if __name__ == "__main__":
main()