mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
more fixes
This commit is contained in:
parent
c5285a796a
commit
2ad03a8164
6 changed files with 23 additions and 44 deletions
|
@ -12,13 +12,14 @@ from xonsh.events import events
|
||||||
from xonsh.platform import ON_WINDOWS
|
from xonsh.platform import ON_WINDOWS
|
||||||
from xonsh.commands_cache import CommandsCache
|
from xonsh.commands_cache import CommandsCache
|
||||||
|
|
||||||
from tools import DummyShell, sp, DummyCommandsCache, DummyEnv
|
from tools import DummyShell, sp, DummyCommandsCache, DummyEnv, DummyHistory
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def xonsh_execer(monkeypatch):
|
def xonsh_execer(monkeypatch):
|
||||||
"""Initiate the Execer with a mocked nop `load_builtins`"""
|
"""Initiate the Execer with a mocked nop `load_builtins`"""
|
||||||
monkeypatch.setattr(xonsh.built_ins, 'load_builtins', lambda *args, **kwargs: None)
|
monkeypatch.setattr(xonsh.built_ins, 'load_builtins',
|
||||||
|
lambda *args, **kwargs: None)
|
||||||
execer = Execer(login=False, unload=False)
|
execer = Execer(login=False, unload=False)
|
||||||
builtins.__xonsh_execer__ = execer
|
builtins.__xonsh_execer__ = execer
|
||||||
return execer
|
return execer
|
||||||
|
@ -43,6 +44,7 @@ def xonsh_builtins():
|
||||||
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
|
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
|
||||||
builtins.__xonsh_commands_cache__ = DummyCommandsCache()
|
builtins.__xonsh_commands_cache__ = DummyCommandsCache()
|
||||||
builtins.__xonsh_all_jobs__ = {}
|
builtins.__xonsh_all_jobs__ = {}
|
||||||
|
builtins.__xonsh_history__ = DummyHistory()
|
||||||
builtins.XonshBlockError = XonshBlockError
|
builtins.XonshBlockError = XonshBlockError
|
||||||
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
|
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
|
||||||
builtins.evalx = eval
|
builtins.evalx = eval
|
||||||
|
@ -69,6 +71,7 @@ def xonsh_builtins():
|
||||||
del builtins.__xonsh_ensure_list_of_strs__
|
del builtins.__xonsh_ensure_list_of_strs__
|
||||||
del builtins.__xonsh_commands_cache__
|
del builtins.__xonsh_commands_cache__
|
||||||
del builtins.__xonsh_all_jobs__
|
del builtins.__xonsh_all_jobs__
|
||||||
|
del builtins.__xonsh_history__
|
||||||
del builtins.XonshBlockError
|
del builtins.XonshBlockError
|
||||||
del builtins.evalx
|
del builtins.evalx
|
||||||
del builtins.execx
|
del builtins.execx
|
||||||
|
@ -76,7 +79,6 @@ def xonsh_builtins():
|
||||||
del builtins.aliases
|
del builtins.aliases
|
||||||
del builtins.events
|
del builtins.events
|
||||||
|
|
||||||
pytest_plugins = ['xonsh', ]
|
|
||||||
|
|
||||||
if ON_WINDOWS:
|
if ON_WINDOWS:
|
||||||
try:
|
try:
|
||||||
|
|
1
tests/run_pwd.xsh
Normal file
1
tests/run_pwd.xsh
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pwd
|
|
@ -7,8 +7,8 @@ from xonsh.built_ins import run_subproc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture(autouse=True, scope='module')
|
@pytest.yield_fixture(autouse=True)
|
||||||
def chdir_to_test_dir():
|
def chdir_to_test_dir(xonsh_builtins):
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
new_cwd = os.path.dirname(__file__)
|
new_cwd = os.path.dirname(__file__)
|
||||||
os.chdir(new_cwd)
|
os.chdir(new_cwd)
|
||||||
|
@ -20,6 +20,8 @@ def test_runsubproc_simple(xonsh_builtins, xonsh_execer):
|
||||||
new_cwd = os.path.dirname(__file__)
|
new_cwd = os.path.dirname(__file__)
|
||||||
xonsh_builtins.__xonsh_env__['PATH'] = os.path.join(new_cwd, 'bin') + \
|
xonsh_builtins.__xonsh_env__['PATH'] = os.path.join(new_cwd, 'bin') + \
|
||||||
os.pathsep + os.path.dirname(sys.executable)
|
os.pathsep + os.path.dirname(sys.executable)
|
||||||
|
xonsh_builtins.__xonsh_env__['XONSH_ENCODING'] = 'utf8'
|
||||||
|
xonsh_builtins.__xonsh_env__['XONSH_ENCODING_ERRORS'] = 'surrogateescape'
|
||||||
out = run_subproc([['pwd']], captured='stdout')
|
out = run_subproc([['pwd']], captured='stdout')
|
||||||
#run_subproc([['pwd']])
|
#run_subproc([['pwd']])
|
||||||
#out, err = capfd.readouterr()
|
#out, err = capfd.readouterr()
|
||||||
|
|
|
@ -65,11 +65,16 @@ class DummyShell:
|
||||||
return self._shell
|
return self._shell
|
||||||
|
|
||||||
|
|
||||||
class DummyCommandsCache():
|
class DummyCommandsCache:
|
||||||
|
|
||||||
def locate_binary(self, name):
|
def locate_binary(self, name):
|
||||||
return os.path.join(os.path.dirname(__file__), 'bin', name)
|
return os.path.join(os.path.dirname(__file__), 'bin', name)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyHistory:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DummyEnv(MutableMapping):
|
class DummyEnv(MutableMapping):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
@ -770,9 +770,7 @@ def run_subproc(cmds, captured=False):
|
||||||
command = Command(specs, procs, starttime=starttime)
|
command = Command(specs, procs, starttime=starttime)
|
||||||
# now figure out what we should return.
|
# now figure out what we should return.
|
||||||
if captured == 'stdout':
|
if captured == 'stdout':
|
||||||
print(1)
|
|
||||||
command.end()
|
command.end()
|
||||||
print(2)
|
|
||||||
return command.output
|
return command.output
|
||||||
elif captured == 'object' or captured == 'hiddenobject':
|
elif captured == 'object' or captured == 'hiddenobject':
|
||||||
return command
|
return command
|
||||||
|
|
|
@ -622,21 +622,12 @@ class Command:
|
||||||
if ((stdout is None or not stdout.readable()) and
|
if ((stdout is None or not stdout.readable()) and
|
||||||
self.spec.captured_stdout is not None):
|
self.spec.captured_stdout is not None):
|
||||||
stdout = self.spec.captured_stdout
|
stdout = self.spec.captured_stdout
|
||||||
print(stdout)
|
|
||||||
if not stdout or not stdout.readable():
|
if not stdout or not stdout.readable():
|
||||||
print('not readable')
|
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
print('reading lines', proc)
|
|
||||||
#while proc.poll() is None:
|
|
||||||
while proc.returncode is None:
|
while proc.returncode is None:
|
||||||
print('poll', proc.returncode)
|
|
||||||
yield from stdout.readlines(1024)
|
yield from stdout.readlines(1024)
|
||||||
print('poll', proc.returncode)
|
|
||||||
print('ending time')
|
|
||||||
self._endtime()
|
self._endtime()
|
||||||
print('finish reading lines')
|
|
||||||
yield from stdout.readlines()
|
yield from stdout.readlines()
|
||||||
print('read stdout')
|
|
||||||
#self.end()
|
#self.end()
|
||||||
|
|
||||||
def itercheck(self):
|
def itercheck(self):
|
||||||
|
@ -648,27 +639,24 @@ class Command:
|
||||||
self.stdout, self.stderr, self)
|
self.stdout, self.stderr, self)
|
||||||
|
|
||||||
def tee_stdout(self):
|
def tee_stdout(self):
|
||||||
"""Writes the process stdout to sys.stdout, line-by-line, and
|
"""Writes the process stdout to the output variable, line-by-line, and
|
||||||
yields each line.
|
yields each line.
|
||||||
"""
|
"""
|
||||||
self.output = '' if self.spec.universal_newlines else b''
|
self.output = '' if self.spec.universal_newlines else b''
|
||||||
print(self.output)
|
|
||||||
for line in self:
|
for line in self:
|
||||||
print(line)
|
|
||||||
sys.stdout.write(line)
|
|
||||||
print('wrote to stdout')
|
|
||||||
self.output += line
|
self.output += line
|
||||||
print('added line to output')
|
|
||||||
yield line
|
yield line
|
||||||
print('yielded line')
|
|
||||||
|
|
||||||
def _decode_uninew(self, b):
|
def _decode_uninew(self, b):
|
||||||
"""Decode bytes into a str and apply universal newlines as needed."""
|
"""Decode bytes into a str and apply universal newlines as needed."""
|
||||||
if not b:
|
if not b:
|
||||||
return ''
|
return ''
|
||||||
|
if isinstance(b, bytes):
|
||||||
env = builtins.__xonsh_env__
|
env = builtins.__xonsh_env__
|
||||||
s = b.decode(encoding=env.get('XONSH_ENCODING'),
|
s = b.decode(encoding=env.get('XONSH_ENCODING'),
|
||||||
errors=env.get('XONSH_ENCODING_ERRORS'))
|
errors=env.get('XONSH_ENCODING_ERRORS'))
|
||||||
|
else:
|
||||||
|
s = b
|
||||||
if self.spec.universal_newlines:
|
if self.spec.universal_newlines:
|
||||||
s = s.replace('\r\n', '\n')
|
s = s.replace('\r\n', '\n')
|
||||||
return s
|
return s
|
||||||
|
@ -681,30 +669,18 @@ class Command:
|
||||||
"""Waits for the command to complete and then runs any closing and
|
"""Waits for the command to complete and then runs any closing and
|
||||||
cleanup procedures that need to be run.
|
cleanup procedures that need to be run.
|
||||||
"""
|
"""
|
||||||
print(self.ended)
|
|
||||||
if self.ended:
|
if self.ended:
|
||||||
return
|
return
|
||||||
print(10)
|
|
||||||
self.proc.wait()
|
self.proc.wait()
|
||||||
print(20)
|
|
||||||
self._endtime()
|
self._endtime()
|
||||||
print(30)
|
|
||||||
self._close_procs()
|
self._close_procs()
|
||||||
print(40)
|
|
||||||
self._set_input()
|
self._set_input()
|
||||||
print(50)
|
|
||||||
self._set_output()
|
self._set_output()
|
||||||
print(60)
|
|
||||||
self._set_errors()
|
self._set_errors()
|
||||||
print(70)
|
|
||||||
self._check_signal()
|
self._check_signal()
|
||||||
print(80)
|
|
||||||
self._apply_to_history()
|
self._apply_to_history()
|
||||||
print(90)
|
|
||||||
self._raise_subproc_error()
|
self._raise_subproc_error()
|
||||||
print(100)
|
|
||||||
self.ended = True
|
self.ended = True
|
||||||
print(110)
|
|
||||||
|
|
||||||
def _endtime(self):
|
def _endtime(self):
|
||||||
"""Sets the closing timestamp if it hasn't been already."""
|
"""Sets the closing timestamp if it hasn't been already."""
|
||||||
|
@ -730,14 +706,9 @@ class Command:
|
||||||
|
|
||||||
def _set_output(self):
|
def _set_output(self):
|
||||||
"""Sets the output vaiable."""
|
"""Sets the output vaiable."""
|
||||||
#output = b''
|
|
||||||
print('prepping to tee')
|
|
||||||
for line in self.tee_stdout():
|
for line in self.tee_stdout():
|
||||||
pass
|
pass
|
||||||
print('teed')
|
|
||||||
# output += line
|
|
||||||
self.output = self._decode_uninew(self.output)
|
self.output = self._decode_uninew(self.output)
|
||||||
print('converted')
|
|
||||||
|
|
||||||
def _set_errors(self):
|
def _set_errors(self):
|
||||||
"""Sets the errors vaiable."""
|
"""Sets the errors vaiable."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue