-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_log_parsers.py
484 lines (360 loc) · 14.4 KB
/
test_log_parsers.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
from testbeds.schema import TestStatus, TraceItem
from testbeds.swebench.log_parsers import parse_log
def test_django_1():
with open("tests/data/django_output_1.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
failed_count = 0
for r in result:
print(f"{r.name} {r.status}")
if r.status == TestStatus.ERROR:
failed_count += 1
assert r.failure_output, f"Failed test {r.name} has no failure output"
assert r.file_path == "tests/model_fields/tests.py"
assert (
"RecursionError: maximum recursion depth exceeded while calling a Python object"
in r.failure_output
)
assert "Ran 30 tests in 0.076s" not in r.failure_output
assert r.file_path
assert r.method
assert len(result) == 30
assert failed_count == 2
def test_django_2():
with open("tests/data/django_output_2.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
for r in result:
print(r)
# Verify that description is used as test name
test_basic_formset = [
r for r in result if r.method == "FormsFormsetTestCase.test_basic_formset"
]
assert len(test_basic_formset) == 1
assert (
test_basic_formset[0].name
== "A FormSet constructor takes the same arguments as Form. Create a"
)
# Find weirdly formatted test
test_absolute_max = [
r for r in result if r.method == "FormsFormsetTestCase.test_absolute_max"
]
assert len(test_absolute_max) == 1
assert test_absolute_max[0].status == TestStatus.PASSED
assert (
test_absolute_max[0].name
== "test_absolute_max (forms_tests.tests.test_formsets.FormsFormsetTestCase)"
)
failures = [r for r in result if r.status == TestStatus.FAILED]
assert len(failures) == 2
for r in result:
if r.status == TestStatus.FAILED:
assert r.failure_output, f"Failed test {r.name} has no failure output"
assert r.file_path == "tests/forms_tests/tests/test_formsets.py"
assert r.file_path
assert r.method
assert len(result) == 157
def test_django_3():
with open("tests/data/django_output_3.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
failures = [r for r in result if r.status == TestStatus.FAILED]
assert len(failures) == 2
assert [r.method for r in failures] == [
"FormsFormsetTestCase.test_more_initial_data",
"Jinja2FormsFormsetTestCase.test_more_initial_data",
]
assert all(
r.file_path == "tests/forms_tests/tests/test_formsets.py" for r in failures
), f"File path is not correct {[r.file_path for r in failures]}"
assert all(r.failure_output for r in failures)
assert len(result) == 157
def test_django_4():
with open("tests/data/django_output_4.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
failures = [r for r in result if r.status in [TestStatus.FAILED, TestStatus.ERROR]]
assert len(failures) == 0
assert len(result) == 344
skipped = [r for r in result if r.status == TestStatus.SKIPPED]
assert len(skipped) == 15
def test_django_5():
with open("tests/data/django_output_5.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
assert len(result) == 1
assert len(result[0].stacktrace) == 24
def test_django_formatting():
output = """test_parsing_rfc1123 (utils_tests.test_http.HttpDateProcessingTests) ... ok
test_parsing_rfc850 (utils_tests.test_http.HttpDateProcessingTests) ... test_parsing_year_less_than_70 (utils_tests.test_http.HttpDateProcessingTests) ... ok
test_bad (utils_tests.test_http.IsSameDomainTests) ... ok"""
result = parse_log(output, "django/django")
assert len(result) == 4
# TODO
def test_django_error():
stacktrace = """Traceback (most recent call last):
File "/testbed/django/forms/widgets.py", line 80, in <genexpr>
return mark_safe('\n'.join(chain.from_iterable(getattr(self, 'render_' + name)() for name in MEDIA_TYPES)))
File "/testbed/django/forms/widgets.py", line 87, in render_js
) for path in self._js
File "/testbed/django/forms/widgets.py", line 76, in _js
js = self.merge(js, obj)
File "/testbed/django/forms/widgets.py", line 144, in merge
all_files = set(list_1 + list_2)
TypeError: can only concatenate list (not "tuple") to list"""
log = (
"""test_can_delete (admin_inlines.tests.TestInline) ... ERROR
======================================================================
ERROR: test_can_delete (admin_inlines.tests.TestInline)
----------------------------------------------------------------------
"""
+ stacktrace
)
result = parse_log(log, "django/django")
assert len(result) == 1
assert result[0].status == TestStatus.ERROR
assert result[0].file_path == "tests/admin_inlines/tests.py"
assert result[0].stacktrace == [
TraceItem(
file_path="django/forms/widgets.py",
method="<genexpr>",
line_number=80,
output=" return mark_safe('\n'.join(chain.from_iterable(getattr(self, 'render_' + name)() for name in MEDIA_TYPES)))",
),
TraceItem(
file_path="django/forms/widgets.py",
method="render_js",
line_number=87,
output=" ) for path in self._js",
),
TraceItem(
file_path="django/forms/widgets.py",
method="_js",
line_number=76,
output=" js = self.merge(js, obj)",
),
TraceItem(
file_path="django/forms/widgets.py",
method="merge",
line_number=144,
output=' all_files = set(list_1 + list_2)\nTypeError: can only concatenate list (not "tuple") to list',
),
]
stacktrace = stacktrace.replace("/testbed/", "")
assert result[0].failure_output == stacktrace
def test_pytest_1():
with open("tests/data/pytest_output_1.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
assert len(result) == 11
failed_count = 0
for r in result:
if r.status == TestStatus.FAILED:
failed_count += 1
assert r.failure_output, f"Failed test {r.name} has no failure output"
assert r.file_path
assert r.method
assert r.method in r.name
assert failed_count == 5
def test_pytest_2():
with open("tests/data/pytest_output_2.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
assert len(result) == 62
failed_count = 0
for r in result:
if r.status == TestStatus.FAILED:
failed_count += 1
assert (
r.failure_output
), f"Failed test {r.name} with method {r.method} has no failure output"
if r.status != TestStatus.SKIPPED:
assert r.file_path
assert r.method
assert failed_count == 3
def test_pytest_3():
with open("tests/data/pytest_output_3.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
failed = [
r
for r in result
if r.status == TestStatus.FAILED and r.file_path == "testing/test_mark.py"
]
assert len(failed) == 1
assert failed[0].failure_output
def test_pytest_4():
with open("tests/data/pytest_output_4.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
assert len(result) == 56
def test_pytest_5():
with open("tests/data/pytest_output_5.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
failures = [r for r in result if r.status == TestStatus.FAILED]
for fai in failures:
print(fai)
assert len(failures) == 1
assert failures[0].failure_output
def test_pytest_6():
with open("tests/data/pytest_output_6.txt") as f:
log = f.read()
result = parse_log(log, "pytest-dev/pytest")
failures = [r for r in result if r.status == TestStatus.FAILED]
assert len(failures) == 0
def test_pytest_option_with_space_swebench_naming():
result = parse_log(
"PASSED testing/test_mark.py::test_marker_expr_eval_failure_handling[NOT internal_err]",
"pytest-dev/pytest",
)
assert 1 == len(result)
assert (
"testing/test_mark.py::test_marker_expr_eval_failure_handling[NOT"
== result[0].name
)
def test_pytest_matplotlib():
with open("tests/data/matplotlib_output_1.txt") as f:
log = f.read()
result = parse_log(log, "matplotlib/matplotlib")
assert len(result) == 48
failed_count = 0
for r in result:
if r.status == TestStatus.FAILED:
failed_count += 1
assert r.failure_output, f"Failed test {r.name} has no failure output"
assert r.file_path
assert r.method
assert r.method in r.name
assert failed_count == 2
def test_pytest_matplotlib_2():
with open("tests/data/matplotlib_output_2.txt") as f:
log = f.read()
result = parse_log(log, "matplotlib/matplotlib")
failed = [r for r in result if r.status == TestStatus.FAILED]
assert len(failed) == 1
assert "def test_double_register_builtin_cmap():" in failed[0].failure_output
assert "> with pytest.warns(UserWarning):" in failed[0].failure_output
assert (
"E matplotlib._api.deprecation.MatplotlibDeprecationWarning: "
in failed[0].failure_output
)
assert (
"lib/matplotlib/tests/test_colors.py:150: MatplotlibDeprecationWarning"
in failed[0].failure_output
)
skipped = [r for r in result if r.status == TestStatus.SKIPPED]
assert len(skipped) == 1
assert skipped[0].file_path == "lib/matplotlib/testing/compare.py"
assert len(result) == 253
def test_pytest_seaborn():
with open("tests/data/seaborn_output_1.txt") as f:
log = f.read()
result = parse_log(log, "mwaskom/seaborn")
assert len(result) == 84
def test_pytest_seaborn_2():
with open("tests/data/seaborn_output_2.txt") as f:
log = f.read()
result = parse_log(log, "mwaskom/seaborn")
for r in result:
assert (
" Attri" not in r.method
), f"Method name contains failure output {r.method}"
failed = [r for r in result if r.status == TestStatus.FAILED]
assert len(failed) == 48
assert len(result) == 85
def test_sphinx_1():
with open("tests/data/sphinx_output_1.txt") as f:
log = f.read()
result = parse_log(log, "sphinx-doc/sphinx")
errored = [r for r in result if r.status == TestStatus.ERROR]
assert len(errored) == 1
assert errored[0].failure_output
assert "ImportError" in errored[0].failure_output
def test_sympy_1():
with open("tests/data/sympy_output_1.txt") as f:
log = f.read()
result = parse_log(log, "sympy/sympy")
failed = [r for r in result if r.status == TestStatus.FAILED]
assert len(failed) == 1
assert failed[0].failure_output
errored = [r for r in result if r.status == TestStatus.ERROR]
assert len(errored) == 3
assert all(r.failure_output for r in errored)
assert len(result) == 116
for r in result:
assert r.file_path
assert r.method
def test_sympy_2():
with open("tests/data/sympy_output_2.txt") as f:
log = f.read()
result = parse_log(log, "sympy/sympy")
failed = [r for r in result if r.status == TestStatus.FAILED]
assert len(failed) == 1
assert (
failed[0].failure_output
== """Traceback (most recent call last):
File "sympy/sets/tests/test_sets.py", line 24, in test_imageset
assert (1, r) not in imageset(x, (x, x), S.Reals)
AssertionError
"""
)
assert len(result) == 855
def test_traceback():
with open("tests/data/syntax_error.txt") as f:
log = f.read()
result = parse_log(log, "django/django")
assert len(result) == 1
result = result[0]
assert result.status == TestStatus.ERROR
assert len(result.stacktrace) == 16
assert result.stacktrace[0].method == "<module>"
assert result.stacktrace[0].file_path == "./tests/runtests.py"
assert result.stacktrace[-1].file_path == "django/db/models/fields/__init__.py"
assert result.stacktrace[-1].line_number == 30
assert result.stacktrace[-1].method == "<module>"
def test_import_error_traceback():
log = """ImportError while loading conftest '/testbed/lib/mpl_toolkits/axes_grid1/tests/conftest.py'.
lib/mpl_toolkits/axes_grid1/__init__.py:3: in <module>
from .axes_grid import AxesGrid, Grid, ImageGrid
lib/mpl_toolkits/axes_grid1/axes_grid.py:29: in <module>
_cbaraxes_class_factory = cbook._make_class_factory(CbarAxesBase, "Cbar{}")
E NameError: name 'CbarAxesBase' is not defined
"""
result = parse_log(log, "matplotlib/matplotlib")
assert result
assert len(result) == 1
assert result[0].status == TestStatus.ERROR
assert len(result[0].stacktrace) == 2
assert (
result[0].stacktrace[0].file_path == "lib/mpl_toolkits/axes_grid1/__init__.py"
)
assert result[0].stacktrace[0].line_number == 3
assert (
result[0].stacktrace[0].output
== "from .axes_grid import AxesGrid, Grid, ImageGrid"
)
assert result[0].stacktrace[0].method == "<module>"
assert (
result[0].stacktrace[1].file_path == "lib/mpl_toolkits/axes_grid1/axes_grid.py"
)
assert result[0].stacktrace[1].line_number == 29
assert result[0].stacktrace[1].method == "<module>"
assert result[0].failure_output == "NameError: name 'CbarAxesBase' is not defined"
def test_sympy_4():
with open("tests/data/sympy_output_4.txt") as f:
log = f.read()
result = parse_log(log, "sympy/sympy")
assert len(result) == 1
assert result[0].status == TestStatus.ERROR
assert result[0].name == "traceback"
assert result[0].file_path == "sympy/combinatorics/permutations.py"
assert result[0].method == "__new__"
assert "TypeError: object of type 'int' has no len()" in result[0].failure_output
assert len(result[0].stacktrace) == 7
assert result[0].stacktrace[0].file_path == "sympy/utilities/runtests.py"
assert result[0].stacktrace[0].line_number == 1079
assert result[0].stacktrace[0].method == "test_file"
assert result[0].stacktrace[-1].file_path == "sympy/combinatorics/permutations.py"
assert result[0].stacktrace[-1].line_number == 900
assert result[0].stacktrace[-1].method == "__new__"