Commit 53cd02b3 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Fix traceback tests for Python ≥ 3.10

Python changed traceback output a bit:

- added '^^^^^^^' and '~~^~~'
- changed lineno of frame corresponding to __exit__ to be at line of `with ...`

-> Adjust to that by introducing a bit more generalized conditionals in
   assertDoc.

Here is, for example, how test_defer_excchain_traceback was failing on py3.11:

E           Failed: not equal:
E           Differences (unified diff with -expected +actual):
E               @@ -1,6 +1,7 @@
E                Traceback (most recent call last):
E               -  File "PYGOLANG/golang/__init__.py", line ..., in _
E               +  File "PYGOLANG/golang/__init__.py", line 103, in _
E                    return f(*argv, **kw)
E               -  File "PYGOLANG/golang/golang_test.py", line ..., in caller
E               +           ^^^^^^^^^^^^^^
E               +  File "PYGOLANG/golang/golang_test.py", line 1550, in caller
E                    raise RuntimeError("ccc")
E                RuntimeError: ccc
E               @@ -9,7 +10,7 @@
E                <BLANKLINE>
E                Traceback (most recent call last):
E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
E               +  File "PYGOLANG/golang/__init__.py", line 180, in __exit__
E                    d()
E               -  File "PYGOLANG/golang/golang_test.py", line ..., in q2
E               +  File "PYGOLANG/golang/golang_test.py", line 1548, in q2
E                    raise RuntimeError("bbb")
E                RuntimeError: bbb
E               @@ -18,14 +19,16 @@
E                <BLANKLINE>
E                Traceback (most recent call last):
E               -  File "PYGOLANG/golang/golang_test.py", line ..., in test_defer_excchain_traceback
E               +  File "PYGOLANG/golang/golang_test.py", line 1553, in test_defer_excchain_traceback
E                    caller()
E               -  ...
E               -  File "PYGOLANG/golang/__init__.py", line ..., in _
E               -    return f(*argv, **kw)
E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
E               +  File "/home/kirr/src/tools/go/py3.venv/lib/python3.11/site-packages/decorator.py", line 232, in fun
E               +    return caller(func, *(extras + args), **kw)
E               +           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E               +  File "PYGOLANG/golang/__init__.py", line 102, in _
E               +    with __goframe__:
E               +  File "PYGOLANG/golang/__init__.py", line 179, in __exit__
E               +    with __goframe__:
E               +  File "PYGOLANG/golang/__init__.py", line 180, in __exit__
E                    d()
E               -  File "PYGOLANG/golang/__init__.py", line ..., in __exit__
E               -    d()
E               -  File "PYGOLANG/golang/golang_test.py", line ..., in q1
E               +  File "PYGOLANG/golang/golang_test.py", line 1545, in q1
E                    raise RuntimeError("aaa")
E                RuntimeError: aaa
parent dfe75e9a
......@@ -1559,6 +1559,7 @@ RuntimeError: gamma
Traceback (most recent call last):
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
^^^^^^^^^^^^^^ +PY311
File "PYGOLANG/golang/golang_test.py", line ..., in caller
raise RuntimeError("ccc")
RuntimeError: ccc
......@@ -1579,9 +1580,11 @@ Traceback (most recent call last):
caller()
...
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
return f(*argv, **kw) -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
d() -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
File "PYGOLANG/golang/golang_test.py", line ..., in q1
......@@ -1596,9 +1599,11 @@ Traceback (most recent call last):
caller()
...
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
return f(*argv, **kw) -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
d() -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
File "PYGOLANG/golang/golang_test.py", line ..., in q1
......@@ -1611,6 +1616,7 @@ RuntimeError: aaa
Traceback (most recent call last):
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
^^^^^^^^^^^^^^ +PY311
File "PYGOLANG/golang/golang_test.py", line ..., in caller
raise RuntimeError("ccc")
RuntimeError: ccc
......@@ -1631,9 +1637,11 @@ Traceback (most recent call last):
caller()
...
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
return f(*argv, **kw) -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
d() -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
d()
File "PYGOLANG/golang/golang_test.py", line ..., in q1
......@@ -1800,9 +1808,25 @@ def assertDoc(want, got):
got = got.replace(udir_pygolang, "PYGOLANG") # ~/.../pygolang -> PYGOLANG
# want: process conditionals
# PY39(...) -> ... if py39 else ø
py39 = sys.version_info >= (3, 9)
want = re.sub(r"PY39\((.*)\)", r"\1" if py39 else "", want)
# PY39(...) -> ... if py ≥ 3.9 else ø (inline)
# `... +PY39` -> ... if py ≥ 3.9 else ø (whole line)
# `... -PY39` -> ... if py < 3.9 else ø (whole line)
have = {} # 'PYxy' -> y/n
for minor in (9,10,11):
have['PY3%d' % minor] = (sys.version_info >= (3, minor))
for x, havex in have.items():
want = re.sub(r"%s\((.*)\)" % x, r"\1" if havex else "", want)
r = re.compile(r'^(?P<main>.*?) +(?P<y>(\+|-))%s$' % x)
v = []
for l in want.splitlines():
m = r.match(l)
if m is not None:
l = m.group('main')
y = {'+':True, '-':False}[m.group('y')]
if (y and not havex) or (havex and not y):
continue
v.append(l)
want = '\n'.join(v)+'\n'
# want: ^$ -> <BLANKLINE>
while "\n\n" in want:
......
Traceback (most recent call last):
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
^^^^^^^^^^^^^^ +PY311
File "PY39(PYGOLANG/golang/testprog/)golang_test_defer_excchain.py", line 42, in main
raise RuntimeError("err")
RuntimeError: err
......@@ -21,6 +22,7 @@ Traceback (most recent call last):
...
File "PY39(PYGOLANG/golang/testprog/)golang_test_defer_excchain.py", line 33, in d2
1/0
~^~ +PY311
ZeroDivisionError: ...
During handling of the above exception, another exception occurred:
......@@ -30,7 +32,8 @@ Traceback (most recent call last):
main()
...
File "PYGOLANG/golang/__init__.py", line ..., in _
return f(*argv, **kw)
return f(*argv, **kw) -PY310
with __goframe__: +PY310
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
...
File "PYGOLANG/golang/__init__.py", line ..., in __exit__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment