moved test_run_subproc to test_integrations

This commit is contained in:
laerus 2016-10-16 20:30:24 +03:00
parent 1931f478d6
commit 3d1601e3e7
3 changed files with 79 additions and 48 deletions

View file

@ -1,10 +1,14 @@
**Added:** None
**Added:**
* ``test_single_command`` and ``test_redirect_out_to_file`` tests in ``test_integrations``
**Changed:** None
**Deprecated:** None
**Removed:** None
**Removed:**
* ``test_run_subproc.py`` in favor of ``test_integrations.py``
**Fixed:**

View file

@ -8,6 +8,8 @@ import pytest
import xonsh
from xonsh.platform import ON_WINDOWS
from tools import skip_if_on_windows
XONSH_PREFIX = xonsh.__file__
if 'site-packages' in XONSH_PREFIX:
# must be installed version of xonsh
@ -108,3 +110,74 @@ def test_script(case):
assert exp_out == out
assert exp_rtn == p.returncode
@skip_if_on_windows
@pytest.mark.parametrize('cmd, fmt, exp', [
('pwd', None, XONSH_PREFIX + '\n'),
('echo WORKING', None, 'WORKING\n'),
('ls -f', lambda out: out.splitlines().sort(), os.listdir().sort()),
])
def test_single_command(cmd, fmt, exp):
"""The ``fmt`` parameter is a function
that formats the output of cmd, can be None.
"""
env = dict(os.environ)
env['PATH'] = PATH
env['XONSH_DEBUG'] = '1'
env['XONSH_SHOW_TRACEBACK'] = '1'
env['RAISE_SUBPROC_ERROR'] = '1'
env['PROMPT'] = ''
xonsh = 'xonsh.bat' if ON_WINDOWS else 'xon.sh'
xonsh = shutil.which(xonsh, path=PATH)
p = subprocess.Popen([xonsh, '--no-rc'],
env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
try:
out, err = p.communicate(input=cmd, timeout=10)
except subprocess.TimeoutExpired:
p.kill()
raise
if callable(fmt):
out = fmt(out)
assert out == exp
assert p.returncode == 0
@skip_if_on_windows
@pytest.mark.parametrize('cmd, fmt, exp', [
('pwd', None, XONSH_PREFIX + '\n'),
])
def test_redirect_out_to_file(cmd, fmt, exp, tmpdir):
"""The ``fmt`` parameter is a function
that formats the output of cmd, can be None.
"""
env = dict(os.environ)
env['PATH'] = PATH
env['XONSH_DEBUG'] = '1'
env['XONSH_SHOW_TRACEBACK'] = '1'
env['RAISE_SUBPROC_ERROR'] = '1'
env['PROMPT'] = ''
xonsh = 'xonsh.bat' if ON_WINDOWS else 'xon.sh'
xonsh = shutil.which(xonsh, path=PATH)
p = subprocess.Popen([xonsh, '--no-rc'],
env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
outfile = tmpdir.mkdir('xonsh_test_dir').join('xonsh_test_file')
command = '{} > {}'.format(cmd, outfile)
try:
out, err = p.communicate(input=command, timeout=10)
except subprocess.TimeoutExpired:
p.kill()
raise
if callable(fmt):
out = fmt(out)
content = outfile.read()
assert content == exp

View file

@ -1,46 +0,0 @@
import os
import sys
import pytest
from xonsh.platform import ON_WINDOWS
from xonsh.built_ins import run_subproc
from tools import skip_if_on_windows
@pytest.yield_fixture(autouse=True)
def chdir_to_test_dir():
old_cwd = os.getcwd()
new_cwd = os.path.dirname(__file__)
os.chdir(new_cwd)
yield
os.chdir(old_cwd)
@skip_if_on_windows
def test_runsubproc_simple(xonsh_builtins, xonsh_execer):
new_cwd = os.path.dirname(__file__)
xonsh_builtins.__xonsh_env__['PATH'] = os.path.join(new_cwd, 'bin') + \
os.pathsep + os.path.dirname(sys.executable)
xonsh_builtins.__xonsh_env__['XONSH_ENCODING'] = 'utf8'
xonsh_builtins.__xonsh_env__['XONSH_ENCODING_ERRORS'] = 'surrogateescape'
xonsh_builtins.__xonsh_env__['XONSH_PROC_FREQUENCY'] = 1e-4
if ON_WINDOWS:
pathext = xonsh_builtins.__xonsh_env__['PATHEXT']
xonsh_builtins.__xonsh_env__['PATHEXT'] = ';'.join(pathext)
pwd = 'PWD.BAT'
else:
pwd = 'pwd'
out = run_subproc([[pwd]], captured='stdout')
assert out.rstrip() == new_cwd
@skip_if_on_windows
def test_runsubproc_redirect_out_to_file(xonsh_builtins, xonsh_execer):
xonsh_builtins.__xonsh_env__['XONSH_PROC_FREQUENCY'] = 1e-4
run_subproc([['pwd', 'out>', 'tttt']], captured='stdout')
with open('tttt') as f:
assert f.read().rstrip() == os.getcwd()
os.remove('tttt')