Commit f812faa2 authored by Kirill Smelkov's avatar Kirill Smelkov

tests: Factor out pyrun from gpython_test into golang_test

We'll need to use this utility in other places; golang_test is the
central place for testing utilities.
parent 75169174
......@@ -25,6 +25,7 @@ from golang import time
from pytest import raises
from os.path import dirname
import os, sys, threading, inspect, subprocess
from subprocess import Popen, PIPE
from six.moves import range as xrange
import gc, weakref
......@@ -1016,6 +1017,15 @@ def bench_defer(b):
# ---- misc ----
# pyrun runs `sys.executable argv... <stdin` and returns its output.
def pyrun(argv, stdin=None, **kw):
argv = [sys.executable] + argv
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=PIPE, stderr=PIPE, **kw)
stdout, stderr = p.communicate(stdin)
if p.returncode:
raise RuntimeError(' '.join(argv) + '\n' + (stderr and str(stderr) or '(failed)'))
return stdout
# panics is similar to pytest.raises and asserts that wrapped code panics with arg.
class panics:
def __init__(self, arg):
......
......@@ -21,6 +21,7 @@
from __future__ import print_function, absolute_import
import sys, os, golang
from golang.golang_test import pyrun
from six import PY2
from six.moves import builtins
import pytest
......@@ -84,16 +85,6 @@ def test_gevent_activated():
assert patched('queue')
# pyrun runs `sys.executable argv... <stdin` and returns its output.
def pyrun(argv, stdin=None, **kw):
from subprocess import Popen, PIPE
argv = [sys.executable] + argv
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=PIPE, stderr=PIPE, **kw)
stdout, stderr = p.communicate(stdin)
if p.returncode:
raise RuntimeError(' '.join(argv) + '\n' + (stderr and str(stderr) or '(failed)'))
return stdout
@gpython_only
def test_executable():
# sys.executable must point to gpython and we must be able to execute it.
......
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