Skip to content

Commit bea9903

Browse files
committed
Make error message tests more flexible.
Seems like Python 3.11/3.12 changes keep appearing and disappearing.
1 parent cb80c45 commit bea9903

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/PySrc/tests/test_code_tracer_main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,15 @@ def test_driver_fails(self, stdin, stdout):
286286
| File "path/example_driver.py", line 6, in <module> |
287287
| assert 'fail' not in sys.argv, sys.argv[1:] |
288288
| AssertionError: ['fail', 'badly'] |
289-
| ---------------------------------------------------- |
290-
"""
289+
| ---------------------------------------------------- |"""
291290
expected_report_311 = """\
292291
foo = 'Hello, World!' | ---------------------------------------------------- |
293292
| Traceback (most recent call last): |
294293
| File "path/example_driver.py", line 6, in <module> |
295294
| assert 'fail' not in sys.argv, sys.argv[1:] |
296295
| ^^^^^^^^^^^^^^^^^^^^^^ |
297296
| AssertionError: ['fail', 'badly'] |
298-
| ---------------------------------------------------- |
299-
"""
300-
if (3, 11, 0) <= sys.version_info < (3, 12, 0):
301-
expected_report = expected_report_311
297+
| ---------------------------------------------------- |"""
302298

303299
stdin.read.return_value = source
304300

@@ -308,7 +304,10 @@ def test_driver_fails(self, stdin, stdout):
308304
report = stdout.write.call_args_list[0][0][0]
309305
report = self.trim_exception(report)
310306
expected_report = self.trim_exception(expected_report)
311-
self.assertReportEqual(expected_report, report)
307+
expected_report_311 = self.trim_exception(expected_report_311)
308+
# self.assertReportEqual(expected_report, report)
309+
if report != expected_report_311:
310+
assert report == expected_report
312311

313312
# noinspection DuplicatedCode
314313
@patch.multiple('sys', stdin=DEFAULT, stdout=DEFAULT, argv=[
@@ -356,8 +355,6 @@ def bar(): | ----------------------------------------------
356355
def foo(x): | x = 1
357356
# This is shown, as normal. |
358357
return x | return 1"""
359-
if (3, 11, 0) <= sys.version_info < (3, 12, 0):
360-
expected_report = expected_report_311
361358

362359
stdin.read.return_value = source
363360

@@ -367,7 +364,9 @@ def foo(x): | x = 1
367364
report = stdout.write.call_args_list[0][0][0]
368365
report = self.trim_exception(report)
369366
expected_report = self.trim_exception(expected_report)
370-
assert report == expected_report
367+
expected_report_311 = self.trim_exception(expected_report_311)
368+
if report != expected_report:
369+
assert report == expected_report_311
371370

372371
# noinspection DuplicatedCode
373372
@patch.multiple('sys', stdin=DEFAULT, stdout=DEFAULT, argv=[
@@ -701,6 +700,7 @@ def get_foo(x):
701700
def trim_exception(report):
702701
report = re.sub(r"([ -])+\| *$", "", report, flags=re.MULTILINE)
703702
report = re.sub(r"line \d+", "line 9999", report)
703+
report = re.sub(r" +$", "", report)
704704
report = report.replace("IOError", "FileNotFoundError")
705705
report = report.replace('path/example_driver.py', EXAMPLE_DRIVER_PATH)
706706
report = report.replace('path/doctest.py',

0 commit comments

Comments
 (0)