Commit 62bdb806 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_test: Switch test_go to pyrun

test_go was doing the same what pyrun is doing + adjusting PYTHONPATH a
bit. Merge PYTHONPATH adjustment into pyrun and use pyrun uniformly.
parent 88eb8fe0
...@@ -24,7 +24,7 @@ from golang import go, chan, select, default, nilchan, _PanicError, func, panic, ...@@ -24,7 +24,7 @@ from golang import go, chan, select, default, nilchan, _PanicError, func, panic,
from golang import time from golang import time
from pytest import raises from pytest import raises
from os.path import dirname from os.path import dirname
import os, sys, threading, inspect, subprocess import os, sys, threading, inspect
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
...@@ -36,20 +36,7 @@ from golang._pycompat import im_class ...@@ -36,20 +36,7 @@ from golang._pycompat import im_class
def test_go(): def test_go():
# 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.
pyrun([dirname(__file__) + "/testprog/golang_test_goleaked.py"])
# adjust $PYTHONPATH to point to pygolang. This makes sure that external
# script will succeed on `import golang` when running in-tree.
dir_golang = dirname(__file__) # .../pygolang/golang
dir_top = dir_golang + '/..' # ~> .../pygolang
pathv = [dir_top]
env = os.environ.copy()
envpath = env.get('PYTHONPATH')
if envpath is not None:
pathv.append(envpath)
env['PYTHONPATH'] = ':'.join(pathv)
subprocess.check_call([sys.executable, dir_golang + "/testprog/golang_test_goleaked.py"],
env=env)
# benchmark go+join a thread/coroutine. # benchmark go+join a thread/coroutine.
def bench_go(b): def bench_go(b):
...@@ -1020,7 +1007,20 @@ def bench_defer(b): ...@@ -1020,7 +1007,20 @@ def bench_defer(b):
# pyrun runs `sys.executable argv... <stdin`. # pyrun runs `sys.executable argv... <stdin`.
def pyrun(argv, stdin=None, stdout=None, stderr=None, **kw): def pyrun(argv, stdin=None, stdout=None, stderr=None, **kw):
argv = [sys.executable] + argv argv = [sys.executable] + argv
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=stdout, stderr=stderr, **kw)
# adjust $PYTHONPATH to point to pygolang. This makes sure that external
# script will succeed on `import golang` when running in-tree.
kw = kw.copy()
dir_golang = dirname(__file__) # .../pygolang/golang
dir_top = dir_golang + '/..' # ~> .../pygolang
pathv = [dir_top]
env = kw.pop('env', os.environ.copy())
envpath = env.get('PYTHONPATH')
if envpath is not None:
pathv.append(envpath)
env['PYTHONPATH'] = ':'.join(pathv)
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=stdout, stderr=stderr, env=env, **kw)
stdout, stderr = p.communicate(stdin) stdout, stderr = p.communicate(stdin)
if p.returncode: if p.returncode:
raise RuntimeError(' '.join(argv) + '\n' + (stderr and str(stderr) or '(failed)')) raise RuntimeError(' '.join(argv) + '\n' + (stderr and str(stderr) or '(failed)'))
......
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