Commit 9c795ca7 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: tests: Factor out code to import test from a pyx module into import_pyx_test

We will soon need this functionality for sync_test.py to import tests
from _sync_test.pyx . In the future many modules will need to import
X_test.pyx from X_test.py as well.
parent d99bb6b7
...@@ -23,7 +23,7 @@ from __future__ import print_function, absolute_import ...@@ -23,7 +23,7 @@ from __future__ import print_function, absolute_import
from golang import go, chan, select, default, nilchan, _PanicError, func, panic, defer, recover from golang import go, chan, select, default, nilchan, _PanicError, func, panic, defer, recover
from pytest import raises from pytest import raises
from os.path import dirname from os.path import dirname
import os, sys, threading, inspect import os, sys, threading, inspect, importlib
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from six.moves import range as xrange from six.moves import range as xrange
import gc, weakref import gc, weakref
...@@ -31,17 +31,22 @@ import gc, weakref ...@@ -31,17 +31,22 @@ import gc, weakref
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
# pyx/c/c++ tests -> test_pyx_* # pyx/c/c++ tests -> test_pyx_* in caller's globals.
from golang import _golang_test def import_pyx_tests(modpath):
for f in dir(_golang_test): mod = importlib.import_module(modpath)
if f.startswith('test_'): callf = inspect.currentframe().f_back # caller's frame
gf = 'test_pyx_' + f[len('test_'):] # test_chan_nogil -> test_pyx_chan_nogil callg = callf.f_globals # caller's globals
# define a python function with gf name (if we use f directly pytest for f in dir(mod):
# will say "cannot collect 'test_pyx_chan_nogil' because it is not a function") if f.startswith('test_'):
def _(func=getattr(_golang_test, f)): gf = 'test_pyx_' + f[len('test_'):] # test_chan_nogil -> test_pyx_chan_nogil
func() # define a python function with gf name (if we use f directly pytest
_.__name__ = gf # will say "cannot collect 'test_pyx_chan_nogil' because it is not a function")
globals()[gf] = _ def _(func=getattr(mod, f)):
func()
_.__name__ = gf
callg[gf] = _
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
......
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