Commit 09629367 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Add tests for IPython and Pytest integration patches

bb9a94c3 (golang: Teach defer to chain exceptions (PEP 3134) even on
Python2) added integration patches for IPython and Pytest to properly
dump tracebacks for chained exceptions even on Python2. However the
functionality of patches was tested only manually.

-> Add corresponding tests to verify how IPython and Pytest behaves
when dumping tracebacks.
parent 42ab98a6
......@@ -25,6 +25,6 @@ include golang/sync_test.cpp
include golang/time.h
include golang/time.cpp
include golang/_testing.h
recursive-include golang *.py *.pxd *.pyx *.toml *.txt
recursive-include golang *.py *.pxd *.pyx *.toml *.txt*
recursive-include gpython *.py
recursive-include 3rdparty *.h
......@@ -1553,6 +1553,29 @@ def test_defer_excchain_dump():
assert stdout == b""
assertDoc(tbok, stderr)
# ----//---- (ipython)
def test_defer_excchain_dump_ipython():
tbok = readfile(dir_testprog + "/golang_test_defer_excchain.txt-ipython")
retcode, stdout, stderr = _pyrun(["-m", "IPython", "--quick", "--colors=NoColor",
"-m", "golang_test_defer_excchain"],
env={"COLUMNS": "80"}, # force ipython5 avoid thinking termwidth=0
cwd=dir_testprog, stdout=PIPE, stderr=PIPE)
assert retcode == 0
# ipython5 uses .pyc for filenames instead of .py
stdout = re.sub(br'\.pyc\b', b'.py', stdout) # normalize .pyc -> .py
assertDoc(tbok, stdout)
assert b"Unknown failure executing module: <golang_test_defer_excchain>" in stderr
# ----//---- (pytest)
def test_defer_excchain_dump_pytest():
tbok = readfile(dir_testprog + "/golang_test_defer_excchain.txt-pytest")
retcode, stdout, stderr = _pyrun(["-m", "pytest", "-o", "python_functions=main",
"--tb=short", "golang_test_defer_excchain.py"],
cwd=dir_testprog, stdout=PIPE, stderr=PIPE)
assert retcode != 0
assert stderr == b""
assertDoc(tbok, stdout)
# defer overhead.
def bench_try_finally(b):
......
...
RuntimeError Traceback (most recent call last)
PYGOLANG/golang/__init__.py in _(f, *argv, **kw)
...
--> ... return f(*argv, **kw)
...
PYGOLANG/golang/testprog/golang_test_defer_excchain.py in main()
41 defer(d1)
---> 42 raise RuntimeError("err")
43
RuntimeError: err
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
PYGOLANG/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
...
PYGOLANG/golang/testprog/golang_test_defer_excchain.py in d1()
30 def d1():
---> 31 raise RuntimeError("d1: aaa")
32 def d2():
RuntimeError: d1: aaa
During handling of the above exception, another exception occurred:
ZeroDivisionError Traceback (most recent call last)
PYGOLANG/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
...
PYGOLANG/golang/testprog/golang_test_defer_excchain.py in d2()
32 def d2():
---> 33 1/0
34 def d3():
ZeroDivisionError: ...
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
...
PYGOLANG/golang/testprog/golang_test_defer_excchain.py in ...
43
44 if __name__ == "__main__":
---> 45 main()
...
PYGOLANG/golang/__init__.py in _(f, *argv, **kw)
...
--> ... return f(*argv, **kw)
...
PYGOLANG/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
...
PYGOLANG/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
...
PYGOLANG/golang/__init__.py in __exit__(__goframe__, exc_type, exc_val, exc_tb)
...
PYGOLANG/golang/testprog/golang_test_defer_excchain.py in d3()
33 1/0
34 def d3():
---> 35 raise RuntimeError("d3: bbb")
36
37 @func
RuntimeError: d3: bbb
...
_____________________________________ main _____________________________________
../__init__.py:...: in _
return f(*argv, **kw)
golang_test_defer_excchain.py:42: in main
raise RuntimeError("err")
E RuntimeError: err
During handling of the above exception, another exception occurred:
../__init__.py:...: in __exit__
...
golang_test_defer_excchain.py:31: in d1
raise RuntimeError("d1: aaa")
E RuntimeError: d1: aaa
During handling of the above exception, another exception occurred:
../__init__.py:...: in __exit__
...
golang_test_defer_excchain.py:33: in d2
1/0
E ZeroDivisionError: ...
During handling of the above exception, another exception occurred:
golang_test_defer_excchain.py:35: in d3
raise RuntimeError("d3: bbb")
E RuntimeError: d3: bbb
=========================== ...
......@@ -165,6 +165,9 @@ for pkg in R:
Rall.update(R[pkg])
R['all'] = Rall
# ipython/pytest are required to test py2 integration patches
R['all_test'] = Rall.union(['ipython', 'pytest']) # pip does not like "+" in all+test
# extras_require <- R
extras_require = {}
for k in sorted(R.keys()):
......
......@@ -57,7 +57,7 @@ install_command =
python -m pip install --no-binary pygolang {opts} {packages}
deps =
.[all]
.[all_test]
# gpython pre-imports installed golang, will get into conflict with
# golang/ if we run pytest from pygolang worktree. Avoid that.
......
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