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 ...@@ -25,6 +25,7 @@ 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, subprocess
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
...@@ -1016,6 +1017,15 @@ def bench_defer(b): ...@@ -1016,6 +1017,15 @@ def bench_defer(b):
# ---- misc ---- # ---- 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. # panics is similar to pytest.raises and asserts that wrapped code panics with arg.
class panics: class panics:
def __init__(self, arg): def __init__(self, arg):
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
import sys, os, golang import sys, os, golang
from golang.golang_test import pyrun
from six import PY2 from six import PY2
from six.moves import builtins from six.moves import builtins
import pytest import pytest
...@@ -84,16 +85,6 @@ def test_gevent_activated(): ...@@ -84,16 +85,6 @@ def test_gevent_activated():
assert patched('queue') 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 @gpython_only
def test_executable(): def test_executable():
# sys.executable must point to gpython and we must be able to execute it. # 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