mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
got some of it
This commit is contained in:
parent
71445888a9
commit
c5285a796a
7 changed files with 68 additions and 22 deletions
|
@ -10,6 +10,8 @@ from xonsh.execer import Execer
|
||||||
from xonsh.tools import XonshBlockError
|
from xonsh.tools import XonshBlockError
|
||||||
from xonsh.events import events
|
from xonsh.events import events
|
||||||
from xonsh.platform import ON_WINDOWS
|
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
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +42,7 @@ def xonsh_builtins():
|
||||||
builtins.__xonsh_stderr_uncaptured__ = None
|
builtins.__xonsh_stderr_uncaptured__ = None
|
||||||
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.XonshBlockError = XonshBlockError
|
builtins.XonshBlockError = XonshBlockError
|
||||||
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
|
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
|
||||||
builtins.evalx = eval
|
builtins.evalx = eval
|
||||||
|
@ -65,6 +68,7 @@ def xonsh_builtins():
|
||||||
del builtins.__xonsh_subproc_uncaptured__
|
del builtins.__xonsh_subproc_uncaptured__
|
||||||
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.XonshBlockError
|
del builtins.XonshBlockError
|
||||||
del builtins.evalx
|
del builtins.evalx
|
||||||
del builtins.execx
|
del builtins.execx
|
||||||
|
@ -72,6 +76,7 @@ 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,22 +1,29 @@
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from xonsh.built_ins import run_subproc
|
from xonsh.built_ins import run_subproc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture(autouse=True, scope='module')
|
@pytest.yield_fixture(autouse=True, scope='module')
|
||||||
def chdir_to_test_dir():
|
def chdir_to_test_dir():
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
os.chdir(os.path.dirname(__file__))
|
new_cwd = os.path.dirname(__file__)
|
||||||
|
os.chdir(new_cwd)
|
||||||
yield
|
yield
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
def test_runsubproc_simple(capfd, xonsh_builtins, xonsh_execer):
|
#def test_runsubproc_simple(capfd, xonsh_builtins, xonsh_execer):
|
||||||
run_subproc([['pwd']])
|
def test_runsubproc_simple(xonsh_builtins, xonsh_execer):
|
||||||
out, err = capfd.readouterr()
|
new_cwd = os.path.dirname(__file__)
|
||||||
assert out.rstrip() == os.getcwd()
|
xonsh_builtins.__xonsh_env__['PATH'] = os.path.join(new_cwd, 'bin') + \
|
||||||
|
os.pathsep + os.path.dirname(sys.executable)
|
||||||
|
out = run_subproc([['pwd']], captured='stdout')
|
||||||
|
#run_subproc([['pwd']])
|
||||||
|
#out, err = capfd.readouterr()
|
||||||
|
assert out.rstrip() == new_cwd
|
||||||
|
|
||||||
def test_runsubproc_pipe(capfd, xonsh_builtins, xonsh_execer):
|
def test_runsubproc_pipe(capfd, xonsh_builtins, xonsh_execer):
|
||||||
run_subproc([['ls'], '|', ['grep', '-i', 'sample']])
|
run_subproc([['ls'], '|', ['grep', '-i', 'sample']])
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
def test_simple():
|
def test_simple():
|
||||||
assert 1 + 1 == 2
|
assert 1 + 1 == 2
|
||||||
|
|
||||||
|
|
||||||
def test_envionment():
|
def test_envionment():
|
||||||
$USER = 'snail'
|
$USER = 'snail'
|
||||||
x = 'USER'
|
x = 'USER'
|
||||||
assert x in ${...}
|
assert x in ${...}
|
||||||
assert ${'U' + 'SER'} == 'snail'
|
assert ${'U' + 'SER'} == 'snail'
|
||||||
|
|
||||||
|
|
||||||
def test_xonsh_party():
|
def test_xonsh_party():
|
||||||
x = 'xonsh'
|
x = 'xonsh'
|
||||||
y = 'party'
|
y = 'party'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Tests the xonsh lexer."""
|
"""Tests the xonsh lexer."""
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import ast
|
import ast
|
||||||
import builtins
|
import builtins
|
||||||
|
@ -66,8 +67,8 @@ class DummyShell:
|
||||||
|
|
||||||
class DummyCommandsCache():
|
class DummyCommandsCache():
|
||||||
|
|
||||||
def locate_binary(self, *args, **kwargs):
|
def locate_binary(self, name):
|
||||||
pass
|
return os.path.join(os.path.dirname(__file__), 'bin', name)
|
||||||
|
|
||||||
class DummyEnv(MutableMapping):
|
class DummyEnv(MutableMapping):
|
||||||
|
|
||||||
|
|
|
@ -660,9 +660,12 @@ def _update_last_spec(last, captured=False):
|
||||||
last.universal_newlines = True
|
last.universal_newlines = True
|
||||||
elif captured in stdout_capture_kinds:
|
elif captured in stdout_capture_kinds:
|
||||||
last.universal_newlines = False
|
last.universal_newlines = False
|
||||||
r, w = os.pipe()
|
if callable(last.alias):
|
||||||
last.stdout = safe_open(w, 'wb')
|
r, w = os.pipe()
|
||||||
last.captured_stdout = safe_open(r, 'rb')
|
last.stdout = safe_open(w, 'wb')
|
||||||
|
last.captured_stdout = safe_open(r, 'rb')
|
||||||
|
else:
|
||||||
|
last.stdout = subprocess.PIPE
|
||||||
elif builtins.__xonsh_stdout_uncaptured__ is not None:
|
elif builtins.__xonsh_stdout_uncaptured__ is not None:
|
||||||
last.universal_newlines = True
|
last.universal_newlines = True
|
||||||
last.stdout = builtins.__xonsh_stdout_uncaptured__
|
last.stdout = builtins.__xonsh_stdout_uncaptured__
|
||||||
|
@ -767,8 +770,9 @@ 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()
|
||||||
#raise Exception
|
print(2)
|
||||||
return command.output
|
return command.output
|
||||||
elif captured == 'object' or captured == 'hiddenobject':
|
elif captured == 'object' or captured == 'hiddenobject':
|
||||||
return command
|
return command
|
||||||
|
|
|
@ -619,14 +619,24 @@ class Command:
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
proc = self.proc
|
proc = self.proc
|
||||||
stdout = proc.stdout
|
stdout = proc.stdout
|
||||||
if not stdout.readable() and self.spec.captured_stdout is not None:
|
if ((stdout is None or not stdout.readable()) and
|
||||||
|
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()
|
||||||
while proc.poll() is None:
|
print('reading lines', proc)
|
||||||
|
#while proc.poll() 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):
|
||||||
|
@ -642,10 +652,15 @@ class Command:
|
||||||
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)
|
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."""
|
||||||
|
@ -666,18 +681,30 @@ 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."""
|
||||||
|
@ -703,10 +730,14 @@ class Command:
|
||||||
|
|
||||||
def _set_output(self):
|
def _set_output(self):
|
||||||
"""Sets the output vaiable."""
|
"""Sets the output vaiable."""
|
||||||
output = b''
|
#output = b''
|
||||||
|
print('prepping to tee')
|
||||||
for line in self.tee_stdout():
|
for line in self.tee_stdout():
|
||||||
output += line
|
pass
|
||||||
self.output = self._decode_uninew(output)
|
print('teed')
|
||||||
|
# output += line
|
||||||
|
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."""
|
||||||
|
|
|
@ -559,7 +559,7 @@ def command_not_found(cmd):
|
||||||
def suggest_commands(cmd, env, aliases):
|
def suggest_commands(cmd, env, aliases):
|
||||||
"""Suggests alternative commands given an environment and aliases."""
|
"""Suggests alternative commands given an environment and aliases."""
|
||||||
if not env.get('SUGGEST_COMMANDS'):
|
if not env.get('SUGGEST_COMMANDS'):
|
||||||
return
|
return ''
|
||||||
thresh = env.get('SUGGEST_THRESHOLD')
|
thresh = env.get('SUGGEST_THRESHOLD')
|
||||||
max_sugg = env.get('SUGGEST_MAX_NUM')
|
max_sugg = env.get('SUGGEST_MAX_NUM')
|
||||||
if max_sugg < 0:
|
if max_sugg < 0:
|
||||||
|
|
Loading…
Add table
Reference in a new issue