Commit c3fdd1c0 authored by Kirill Smelkov's avatar Kirill Smelkov

Add tests for IPython and Pytest integration patches

Add tests for patches to third-party software that were added in
bb9a94c3.

/cc @gabriel, @jerome
/reviewed-on: !2
parents cfcc6db2 09629367
...@@ -25,6 +25,6 @@ include golang/sync_test.cpp ...@@ -25,6 +25,6 @@ include golang/sync_test.cpp
include golang/time.h include golang/time.h
include golang/time.cpp include golang/time.cpp
include golang/_testing.h 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 gpython *.py
recursive-include 3rdparty *.h recursive-include 3rdparty *.h
...@@ -40,6 +40,12 @@ from golang import _golang_test ...@@ -40,6 +40,12 @@ from golang import _golang_test
from golang._golang_test import pywaitBlocked as waitBlocked, pylen_recvq as len_recvq, \ from golang._golang_test import pywaitBlocked as waitBlocked, pylen_recvq as len_recvq, \
pylen_sendq as len_sendq, pypanicWhenBlocked as panicWhenBlocked pylen_sendq as len_sendq, pypanicWhenBlocked as panicWhenBlocked
# directories
dir_golang = dirname(__file__) # .../pygolang/golang
dir_pygolang = dirname(dir_golang) # .../pygolang
dir_testprog = dir_golang + "/testprog" # .../pygolang/golang/testprog
# pyx/c/c++ tests/benchmarks -> {test,bench}_pyx_* in caller's globals. # pyx/c/c++ tests/benchmarks -> {test,bench}_pyx_* in caller's globals.
def import_pyx_tests(modpath): def import_pyx_tests(modpath):
mod = importlib.import_module(modpath) mod = importlib.import_module(modpath)
...@@ -71,7 +77,7 @@ import_pyx_tests("golang._golang_test") ...@@ -71,7 +77,7 @@ import_pyx_tests("golang._golang_test")
# leaked goroutine behaviour check: done in separate process because we need # leaked goroutine behaviour check: done in separate process because we need
# to test process termination exit there. # to test process termination exit there.
def test_go_leaked(): def test_go_leaked():
pyrun([dirname(__file__) + "/testprog/golang_test_goleaked.py"]) pyrun([dir_testprog + "/golang_test_goleaked.py"])
# benchmark go+join a thread/coroutine. # benchmark go+join a thread/coroutine.
# pyx/nogil mirror is in _golang_test.pyx # pyx/nogil mirror is in _golang_test.pyx
...@@ -1641,15 +1647,36 @@ RuntimeError: aaa ...@@ -1641,15 +1647,36 @@ RuntimeError: aaa
# verify that dump of unhandled chained exception traceback works correctly (even on py2). # verify that dump of unhandled chained exception traceback works correctly (even on py2).
def test_defer_excchain_dump(): def test_defer_excchain_dump():
# run golang_test_defer_excchain.py and verify its output via doctest. # run golang_test_defer_excchain.py and verify its output via doctest.
dir_testprog = dirname(__file__) + "/testprog" # pygolang/golang/testprog tbok = readfile(dir_testprog + "/golang_test_defer_excchain.txt")
with open(dir_testprog + "/golang_test_defer_excchain.txt", "r") as f:
tbok = f.read()
retcode, stdout, stderr = _pyrun(["golang_test_defer_excchain.py"], retcode, stdout, stderr = _pyrun(["golang_test_defer_excchain.py"],
cwd=dir_testprog, stdout=PIPE, stderr=PIPE) cwd=dir_testprog, stdout=PIPE, stderr=PIPE)
assert retcode != 0 assert retcode != 0
assert stdout == b"" assert stdout == b""
assertDoc(tbok, stderr) 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. # defer overhead.
def bench_try_finally(b): def bench_try_finally(b):
...@@ -1784,9 +1811,7 @@ def _pyrun(argv, stdin=None, stdout=None, stderr=None, **kw): # -> retcode, st ...@@ -1784,9 +1811,7 @@ def _pyrun(argv, stdin=None, stdout=None, stderr=None, **kw): # -> retcode, st
# adjust $PYTHONPATH to point to pygolang. This makes sure that external # adjust $PYTHONPATH to point to pygolang. This makes sure that external
# script will succeed on `import golang` when running in-tree. # script will succeed on `import golang` when running in-tree.
kw = kw.copy() kw = kw.copy()
dir_golang = dirname(__file__) # .../pygolang/golang pathv = [dir_pygolang]
dir_top = dir_golang + '/..' # ~> .../pygolang
pathv = [dir_top]
env = kw.pop('env', os.environ.copy()) env = kw.pop('env', os.environ.copy())
envpath = env.get('PYTHONPATH') envpath = env.get('PYTHONPATH')
if envpath is not None: if envpath is not None:
...@@ -1857,8 +1882,9 @@ def assertDoc(want, got): ...@@ -1857,8 +1882,9 @@ def assertDoc(want, got):
got = u(got) got = u(got)
# normalize got to PYGOLANG # normalize got to PYGOLANG
dir_pygolang = dirname((dirname(__file__))) # pygolang/golang/golang_test.py -> pygolang udir_pygolang = abbrev_home(dir_pygolang) # /home/x/.../pygolang -> ~/.../pygolang
got = got.replace(dir_pygolang, "PYGOLANG") got = got.replace(dir_pygolang, "PYGOLANG") # /home/x/.../pygolang -> PYGOLANG
got = got.replace(udir_pygolang, "PYGOLANG") # ~/.../pygolang -> PYGOLANG
# ^$ -> <BLANKLINE> # ^$ -> <BLANKLINE>
while "\n\n" in want: while "\n\n" in want:
...@@ -1888,3 +1914,18 @@ def fmtargspec(f): # -> str ...@@ -1888,3 +1914,18 @@ def fmtargspec(f): # -> str
def test_fmtargspec(): def test_fmtargspec():
def f(x, y=3, z=4, *argv, **kw): pass def f(x, y=3, z=4, *argv, **kw): pass
assert fmtargspec(f) == '(x, y=3, z=4, *argv, **kw)' assert fmtargspec(f) == '(x, y=3, z=4, *argv, **kw)'
# readfile returns content of file @path.
def readfile(path):
with open(path, "r") as f:
return f.read()
# abbrev_home returns path with user home prefix abbreviated with ~.
def abbrev_home(path):
home = os.path.expanduser('~')
if path == home:
return '~'
if path.startswith(home+'/'):
return '~'+path[len(home):]
return path
...
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: ...@@ -165,6 +165,9 @@ for pkg in R:
Rall.update(R[pkg]) Rall.update(R[pkg])
R['all'] = Rall 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 <- R
extras_require = {} extras_require = {}
for k in sorted(R.keys()): for k in sorted(R.keys()):
......
...@@ -57,7 +57,7 @@ install_command = ...@@ -57,7 +57,7 @@ install_command =
python -m pip install --no-binary pygolang {opts} {packages} python -m pip install --no-binary pygolang {opts} {packages}
deps = deps =
.[all] .[all_test]
# gpython pre-imports installed golang, will get into conflict with # gpython pre-imports installed golang, will get into conflict with
# golang/ if we run pytest from pygolang worktree. Avoid that. # 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