more fixes

This commit is contained in:
Anthony Scopatz 2016-09-09 00:58:32 -04:00
parent c5285a796a
commit 2ad03a8164
6 changed files with 23 additions and 44 deletions

View file

@ -12,13 +12,14 @@ from xonsh.events import events
from xonsh.platform import ON_WINDOWS
from xonsh.commands_cache import CommandsCache
from tools import DummyShell, sp, DummyCommandsCache, DummyEnv
from tools import DummyShell, sp, DummyCommandsCache, DummyEnv, DummyHistory
@pytest.fixture
def xonsh_execer(monkeypatch):
"""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)
builtins.__xonsh_execer__ = execer
return execer
@ -43,6 +44,7 @@ def xonsh_builtins():
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
builtins.__xonsh_commands_cache__ = DummyCommandsCache()
builtins.__xonsh_all_jobs__ = {}
builtins.__xonsh_history__ = DummyHistory()
builtins.XonshBlockError = XonshBlockError
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
builtins.evalx = eval
@ -69,6 +71,7 @@ def xonsh_builtins():
del builtins.__xonsh_ensure_list_of_strs__
del builtins.__xonsh_commands_cache__
del builtins.__xonsh_all_jobs__
del builtins.__xonsh_history__
del builtins.XonshBlockError
del builtins.evalx
del builtins.execx
@ -76,7 +79,6 @@ def xonsh_builtins():
del builtins.aliases
del builtins.events
pytest_plugins = ['xonsh', ]
if ON_WINDOWS:
try:

1
tests/run_pwd.xsh Normal file
View file

@ -0,0 +1 @@
pwd

View file

@ -7,8 +7,8 @@ from xonsh.built_ins import run_subproc
@pytest.yield_fixture(autouse=True, scope='module')
def chdir_to_test_dir():
@pytest.yield_fixture(autouse=True)
def chdir_to_test_dir(xonsh_builtins):
old_cwd = os.getcwd()
new_cwd = os.path.dirname(__file__)
os.chdir(new_cwd)
@ -20,6 +20,8 @@ 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'
out = run_subproc([['pwd']], captured='stdout')
#run_subproc([['pwd']])
#out, err = capfd.readouterr()

View file

@ -65,11 +65,16 @@ class DummyShell:
return self._shell
class DummyCommandsCache():
class DummyCommandsCache:
def locate_binary(self, name):
return os.path.join(os.path.dirname(__file__), 'bin', name)
class DummyHistory:
pass
class DummyEnv(MutableMapping):
def __init__(self, *args, **kwargs):

View file

@ -770,9 +770,7 @@ def run_subproc(cmds, captured=False):
command = Command(specs, procs, starttime=starttime)
# now figure out what we should return.
if captured == 'stdout':
print(1)
command.end()
print(2)
return command.output
elif captured == 'object' or captured == 'hiddenobject':
return command

View file

@ -622,21 +622,12 @@ class Command:
if ((stdout is None or not stdout.readable()) and
self.spec.captured_stdout is not None):
stdout = self.spec.captured_stdout
print(stdout)
if not stdout or not stdout.readable():
print('not readable')
raise StopIteration()
print('reading lines', proc)
#while proc.poll() is None:
while proc.returncode is None:
print('poll', proc.returncode)
yield from stdout.readlines(1024)
print('poll', proc.returncode)
print('ending time')
self._endtime()
print('finish reading lines')
yield from stdout.readlines()
print('read stdout')
#self.end()
def itercheck(self):
@ -648,27 +639,24 @@ class Command:
self.stdout, self.stderr, 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.
"""
self.output = '' if self.spec.universal_newlines else b''
print(self.output)
for line in self:
print(line)
sys.stdout.write(line)
print('wrote to stdout')
self.output += line
print('added line to output')
yield line
print('yielded line')
def _decode_uninew(self, b):
"""Decode bytes into a str and apply universal newlines as needed."""
if not b:
return ''
if isinstance(b, bytes):
env = builtins.__xonsh_env__
s = b.decode(encoding=env.get('XONSH_ENCODING'),
errors=env.get('XONSH_ENCODING_ERRORS'))
else:
s = b
if self.spec.universal_newlines:
s = s.replace('\r\n', '\n')
return s
@ -681,30 +669,18 @@ class Command:
"""Waits for the command to complete and then runs any closing and
cleanup procedures that need to be run.
"""
print(self.ended)
if self.ended:
return
print(10)
self.proc.wait()
print(20)
self._endtime()
print(30)
self._close_procs()
print(40)
self._set_input()
print(50)
self._set_output()
print(60)
self._set_errors()
print(70)
self._check_signal()
print(80)
self._apply_to_history()
print(90)
self._raise_subproc_error()
print(100)
self.ended = True
print(110)
def _endtime(self):
"""Sets the closing timestamp if it hasn't been already."""
@ -730,14 +706,9 @@ class Command:
def _set_output(self):
"""Sets the output vaiable."""
#output = b''
print('prepping to tee')
for line in self.tee_stdout():
pass
print('teed')
# output += line
self.output = self._decode_uninew(self.output)
print('converted')
def _set_errors(self):
"""Sets the errors vaiable."""