Skip to content

Commit

Permalink
Update some error-arrow tests for Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Sep 10, 2024
1 parent e866483 commit 56cbe09
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions hy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ def getdoc(object):
result = inspect.getcomments(object)
return result and re.sub('^ *\n', '', result.rstrip()) or ''
pydoc.getdoc = getdoc


def reu(x):
'(R)eplace an (e)rror (u)nderline. This is only used for testing Hy.'
return x.replace('-', '^') if PY3_13 else x
2 changes: 1 addition & 1 deletion tests/native_tests/macros.hy
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@

(setv expected [" File \"<string>\", line 1"
" (defmacro blah [x] `(print ~@z)) (blah y)"
" ^------^"
(hy.compat.reu " ^------^")
"expanding macro blah"
" NameError: global name 'z' is not defined"])

Expand Down
2 changes: 1 addition & 1 deletion tests/native_tests/repl.hy
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
(setv err (rt "(defmacro mabcdefghi [x] x)\n(mabcdefghi)" 'err))
(setv msg-idx (.rindex err " (mabcdefghi)"))
(setv [_ e1 e2 e3 #* _] (.splitlines (cut err msg_idx None)))
(assert (.startswith e1 " ^----------^"))
(assert (.startswith e1 (hy.compat.reu " ^----------^")))
(assert (.startswith e2 "expanding macro mabcdefghi"))
(assert (or
; PyPy can use a function's `__name__` instead of
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ def req_err(x):
# NameError: name 'a' is not defined
output, error = run_cmd('hy -c "(print a)"', expect=1)
# Filter out the underline added by Python 3.11.
error_lines = [x for x in error.splitlines() if set(x) != {" ", "^"}]
error_lines = [x
for x in error.splitlines()
if not (set(x) <= {" ", "^", "~"})]
assert error_lines[3] == ' File "<string>", line 1, in <module>'
# PyPy will add "global" to this error message, so we work around that.
assert error_lines[-1].strip().replace(" global", "") == (
Expand Down

0 comments on commit 56cbe09

Please sign in to comment.