Commit 88eb8fe0 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_test: Split pyrun into -> pyrun & pyout

pyrun runs command without piping output.
pyout runs command and returns its output.
parent f812faa2
......@@ -1017,15 +1017,19 @@ def bench_defer(b):
# ---- misc ----
# pyrun runs `sys.executable argv... <stdin` and returns its output.
def pyrun(argv, stdin=None, **kw):
# pyrun runs `sys.executable argv... <stdin`.
def pyrun(argv, stdin=None, stdout=None, stderr=None, **kw):
argv = [sys.executable] + argv
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=PIPE, stderr=PIPE, **kw)
p = Popen(argv, stdin=(PIPE if stdin else None), stdout=stdout, stderr=stderr, **kw)
stdout, stderr = p.communicate(stdin)
if p.returncode:
raise RuntimeError(' '.join(argv) + '\n' + (stderr and str(stderr) or '(failed)'))
return stdout
# pyout runs `sys.executable argv... <stdin` and returns its output.
def pyout(argv, stdin=None, stdout=PIPE, stderr=None, **kw):
return pyrun(argv, stdin=stdin, stdout=stdout, stderr=stderr, **kw)
# panics is similar to pytest.raises and asserts that wrapped code panics with arg.
class panics:
def __init__(self, arg):
......
......@@ -21,7 +21,7 @@
from __future__ import print_function, absolute_import
import sys, os, golang
from golang.golang_test import pyrun
from golang.golang_test import pyout
from six import PY2
from six.moves import builtins
import pytest
......@@ -89,7 +89,7 @@ def test_gevent_activated():
def test_executable():
# sys.executable must point to gpython and we must be able to execute it.
assert 'gpython' in sys.executable
out = pyrun(['-c', 'import sys; print(sys.version)'])
out = pyout(['-c', 'import sys; print(sys.version)'])
assert ('[GPython %s]' % golang.__version__) in str(out)
# b converts s to UTF-8 encoded bytes.
......@@ -108,19 +108,19 @@ def test_pymain():
testdata = join(dirname(__file__), 'testdata')
# interactive
_ = pyrun([], stdin=b'import hello\n', cwd=testdata)
_ = pyout([], stdin=b'import hello\n', cwd=testdata)
assert _ == b"hello\nworld\n['']\n"
# -c
_ = pyrun(['-c', 'import hello', 'abc', 'def'], cwd=testdata)
_ = pyout(['-c', 'import hello', 'abc', 'def'], cwd=testdata)
assert _ == b"hello\nworld\n['-c', 'abc', 'def']\n"
# -m
_ = pyrun(['-m', 'hello', 'abc', 'def'], cwd=testdata)
_ = pyout(['-m', 'hello', 'abc', 'def'], cwd=testdata)
# realpath rewrites e.g. `local/lib -> lib` if local/lib is symlink
hellopy = realpath(join(testdata, 'hello.py'))
assert _ == b"hello\nworld\n['%s', 'abc', 'def']\n" % b(hellopy)
# file
_ = pyrun(['testdata/hello.py', 'abc', 'def'], cwd=here)
_ = pyout(['testdata/hello.py', 'abc', 'def'], cwd=here)
assert _ == b"hello\nworld\n['testdata/hello.py', 'abc', 'def']\n"
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