Skip to content

Commit 1d2d029

Browse files
committed
test_pyp: munge traceback
1 parent 7482467 commit 1d2d029

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tests/test_pyp.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -198,22 +198,21 @@ def effect(*args, **kwargs):
198198

199199
# Check the entire output, end to end
200200
pyp_error = run_cmd("pyp 'def f(): 1/0' 'f()'", check=False)
201-
message = lambda po, pc: ( # noqa
202-
(
203-
"error: Code raised the following exception, "
204-
"consider using --explain to investigate:\n\n"
205-
"Possible reconstructed traceback (most recent call last):\n"
206-
' File "<pyp>", in <module>\n'
207-
" output = f()\n"
208-
)
209-
+ (" ^^^^^^^^^^^\n" if sys.version_info >= (3, 11) else "")
210-
+ (' File "<pyp>", in f\n' f" {po}1 / 0{pc}\n")
211-
+ (" \n" if sys.version_info >= (3, 11) else "")
212-
+ ("ZeroDivisionError: division by zero\n")
201+
pyp_error.replace("(1 / 0)", "1 / 0")
202+
pyp_error = re.sub(r"\n[\s\^]+\n", "\n", pyp_error)
203+
message = (
204+
"error: Code raised the following exception, "
205+
"consider using --explain to investigate:\n\n"
206+
"Possible reconstructed traceback (most recent call last):\n"
207+
' File "<pyp>", in <module>\n'
208+
" output = f()\n"
209+
' File "<pyp>", in f\n'
210+
" 1 / 0\n"
211+
"ZeroDivisionError: division by zero\n"
213212
)
214-
print(repr(pyp_error))
215-
print(repr(message("", "")))
216-
assert pyp_error == message("(", ")") or pyp_error == message("", "")
213+
print("actual", repr(pyp_error))
214+
print("expected", repr(message))
215+
assert pyp_error == message
217216

218217
# Test tracebacks involving statements with nested child statements
219218
pyp_error = run_cmd("""pyp 'if 1 / 0: print("should_not_get_here")'""", check=False)

0 commit comments

Comments
 (0)