mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fixes alias redirection
This commit is contained in:
parent
7cbe9e7652
commit
008085ee6b
4 changed files with 75 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -46,4 +46,4 @@ include/
|
||||||
.coverage
|
.coverage
|
||||||
feedstock/
|
feedstock/
|
||||||
*.cred
|
*.cred
|
||||||
tests/tttt
|
tttt
|
||||||
|
|
14
news/rediralias.rst
Normal file
14
news/rediralias.rst
Normal 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
|
55
tests/test_integrations.py
Normal file
55
tests/test_integrations.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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['XONSH_DEBUG'] = '1'
|
||||||
|
env['XONSH_SHOW_TRACEBACK'] = '1'
|
||||||
|
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=1)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
p.kill()
|
||||||
|
raise
|
||||||
|
assert exp_rtn == p.returncode
|
||||||
|
assert exp_out == out
|
||||||
|
|
||||||
|
|
|
@ -1039,7 +1039,10 @@ class ProcProxy(threading.Thread):
|
||||||
self.errwrite = msvcrt.open_osfhandle(self.errwrite.Detach(), 0)
|
self.errwrite = msvcrt.open_osfhandle(self.errwrite.Detach(), 0)
|
||||||
# stdout
|
# stdout
|
||||||
if self.c2pwrite != -1:
|
if self.c2pwrite != -1:
|
||||||
sp_stdout = io.TextIOWrapper(io.open(self.c2pwrite, 'wb', -1),
|
#sp_stdout = io.TextIOWrapper(io.open(self.c2pwrite, 'wb', -1),
|
||||||
|
# encoding=enc, errors=err)
|
||||||
|
sp_stdouth = io.open(self.c2pwrite, 'wb', -1)
|
||||||
|
sp_stdout = io.TextIOWrapper(sp_stdouth,
|
||||||
encoding=enc, errors=err)
|
encoding=enc, errors=err)
|
||||||
else:
|
else:
|
||||||
sp_stdout = sys.stdout
|
sp_stdout = sys.stdout
|
||||||
|
@ -1450,6 +1453,7 @@ class CommandPipeline:
|
||||||
# we get here if the process is not bacgroundable or the
|
# we get here if the process is not bacgroundable or the
|
||||||
# class is the real Popen
|
# class is the real Popen
|
||||||
wait_for_active_job()
|
wait_for_active_job()
|
||||||
|
proc.wait()
|
||||||
self._endtime()
|
self._endtime()
|
||||||
if self.captured == 'object':
|
if self.captured == 'object':
|
||||||
self.end(tee_output=False)
|
self.end(tee_output=False)
|
||||||
|
|
Loading…
Add table
Reference in a new issue