Merge pull request #1840 from xonsh/rediralias

Redirect aliases
This commit is contained in:
Gil Forsyth 2016-10-13 08:10:44 -04:00 committed by GitHub
commit 860a027d05
4 changed files with 95 additions and 1 deletions

2
.gitignore vendored
View file

@ -46,4 +46,4 @@ include/
.coverage
feedstock/
*.cred
tests/tttt
tttt

14
news/rediralias.rst Normal file
View file

@ -0,0 +1,14 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* Fixed issue with alais redirections to files throwing an OSError because
the function ProcProxies were not being waited upon.
**Security:** None

View file

@ -0,0 +1,79 @@
import os
import sys
import shutil
import subprocess
import pytest
import xonsh
from xonsh.platform import ON_WINDOWS
XONSH_PREFIX = xonsh.__file__
if 'site-packages' in XONSH_PREFIX:
# must be installed version of xonsh
num_up = 5
else:
# must be in source dir
num_up = 2
for i in range(num_up):
XONSH_PREFIX = os.path.dirname(XONSH_PREFIX)
PATH = os.path.join(os.path.dirname(__file__), 'bin') + os.pathsep + \
os.path.join(XONSH_PREFIX, 'bin') + os.pathsep + \
os.path.join(XONSH_PREFIX, 'Scripts') + os.pathsep + \
os.path.join(XONSH_PREFIX, 'scripts') + os.pathsep + \
os.path.dirname(sys.executable) + os.pathsep + \
os.environ['PATH']
#
# The following list contains a (stdin, stdout, returncode) tuples
#
ALL_PLATFORMS = [
# test calling a function alias
("""
def _f():
print('hello')
aliases['f'] = _f
f
""", "hello\n", 0),
# test redirecting a function alias
("""
def _f():
print('Wow Mom!')
aliases['f'] = _f
f > tttt
with open('tttt') as tttt:
s = tttt.read().strip()
print('REDIRECTED OUTPUT: ' + s)
""", "REDIRECTED OUTPUT: Wow Mom!\n", 0),
]
@pytest.mark.parametrize('case', ALL_PLATFORMS)
def test_script(case):
script, exp_out, exp_rtn = case
env = dict(os.environ)
env['PATH'] = PATH
env['XONSH_DEBUG'] = '1'
env['XONSH_SHOW_TRACEBACK'] = '1'
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=script, timeout=10)
except subprocess.TimeoutExpired:
p.kill()
raise
assert exp_out == out
assert exp_rtn == p.returncode

View file

@ -1450,6 +1450,7 @@ class CommandPipeline:
# we get here if the process is not bacgroundable or the
# class is the real Popen
wait_for_active_job()
proc.wait()
self._endtime()
if self.captured == 'object':
self.end(tee_output=False)