2016-07-05 09:10:22 +02:00
|
|
|
import glob
|
2016-06-25 01:15:48 +03:00
|
|
|
import builtins
|
2016-07-05 09:10:22 +02:00
|
|
|
|
2016-06-25 01:15:48 +03:00
|
|
|
import pytest
|
2016-08-18 21:49:18 +02:00
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
import xonsh.built_ins
|
2016-08-18 21:49:18 +02:00
|
|
|
|
2016-07-01 13:52:44 +03:00
|
|
|
from xonsh.built_ins import ensure_list_of_strs
|
2016-07-01 15:43:16 +03:00
|
|
|
from xonsh.execer import Execer
|
2016-07-20 22:07:45 +02:00
|
|
|
from xonsh.tools import XonshBlockError
|
2016-08-27 12:21:15 -04:00
|
|
|
from xonsh.events import events
|
2016-09-01 11:54:45 +02:00
|
|
|
from xonsh.platform import ON_WINDOWS
|
2016-08-18 21:49:18 +02:00
|
|
|
from tools import DummyShell, sp
|
2016-06-25 01:15:48 +03:00
|
|
|
|
2016-07-05 09:10:22 +02:00
|
|
|
|
2016-09-01 11:54:45 +02:00
|
|
|
|
|
|
|
|
2016-07-01 15:43:16 +03:00
|
|
|
@pytest.fixture
|
|
|
|
def xonsh_execer(monkeypatch):
|
2016-07-03 12:00:24 +03:00
|
|
|
"""Initiate the Execer with a mocked nop `load_builtins`"""
|
2016-07-01 21:52:37 +03:00
|
|
|
monkeypatch.setattr(xonsh.built_ins, 'load_builtins', lambda *args, **kwargs: None)
|
2016-07-01 15:43:16 +03:00
|
|
|
execer = Execer(login=False, unload=False)
|
|
|
|
builtins.__xonsh_execer__ = execer
|
|
|
|
return execer
|
|
|
|
|
2016-06-25 01:15:48 +03:00
|
|
|
|
|
|
|
@pytest.yield_fixture
|
2016-06-25 21:07:25 +03:00
|
|
|
def xonsh_builtins():
|
2016-07-03 12:00:24 +03:00
|
|
|
"""Mock out most of the builtins xonsh attributes."""
|
2016-06-25 21:07:25 +03:00
|
|
|
builtins.__xonsh_env__ = {}
|
2016-06-25 01:15:48 +03:00
|
|
|
builtins.__xonsh_ctx__ = {}
|
|
|
|
builtins.__xonsh_shell__ = DummyShell()
|
|
|
|
builtins.__xonsh_help__ = lambda x: x
|
|
|
|
builtins.__xonsh_glob__ = glob.glob
|
|
|
|
builtins.__xonsh_exit__ = False
|
|
|
|
builtins.__xonsh_superhelp__ = lambda x: x
|
|
|
|
builtins.__xonsh_regexpath__ = lambda x: []
|
|
|
|
builtins.__xonsh_expand_path__ = lambda x: x
|
|
|
|
builtins.__xonsh_subproc_captured__ = sp
|
|
|
|
builtins.__xonsh_subproc_uncaptured__ = sp
|
|
|
|
builtins.__xonsh_ensure_list_of_strs__ = ensure_list_of_strs
|
|
|
|
builtins.XonshBlockError = XonshBlockError
|
2016-07-01 21:52:37 +03:00
|
|
|
builtins.__xonsh_subproc_captured_hiddenobject__ = sp
|
2016-06-25 01:15:48 +03:00
|
|
|
builtins.evalx = eval
|
|
|
|
builtins.execx = None
|
|
|
|
builtins.compilex = None
|
|
|
|
builtins.aliases = {}
|
2016-08-27 21:24:27 -04:00
|
|
|
# Unlike all the other stuff, this has to refer to the "real" one because all modules that would
|
|
|
|
# be firing events on the global instance.
|
2016-08-27 12:21:15 -04:00
|
|
|
builtins.events = events
|
2016-06-25 21:07:25 +03:00
|
|
|
yield builtins
|
2016-06-25 01:15:48 +03:00
|
|
|
del builtins.__xonsh_env__
|
|
|
|
del builtins.__xonsh_ctx__
|
|
|
|
del builtins.__xonsh_shell__
|
|
|
|
del builtins.__xonsh_help__
|
|
|
|
del builtins.__xonsh_glob__
|
|
|
|
del builtins.__xonsh_exit__
|
|
|
|
del builtins.__xonsh_superhelp__
|
|
|
|
del builtins.__xonsh_regexpath__
|
|
|
|
del builtins.__xonsh_expand_path__
|
|
|
|
del builtins.__xonsh_subproc_captured__
|
|
|
|
del builtins.__xonsh_subproc_uncaptured__
|
|
|
|
del builtins.__xonsh_ensure_list_of_strs__
|
|
|
|
del builtins.XonshBlockError
|
|
|
|
del builtins.evalx
|
|
|
|
del builtins.execx
|
|
|
|
del builtins.compilex
|
|
|
|
del builtins.aliases
|
2016-08-27 12:06:16 -04:00
|
|
|
del builtins.events
|
2016-09-01 11:54:45 +02:00
|
|
|
|
|
|
|
if ON_WINDOWS:
|
|
|
|
try:
|
|
|
|
import win_unicode_console
|
|
|
|
HAVE_WIN_UNICODE_CONSOLE = True
|
|
|
|
except ImportError:
|
|
|
|
HAVE_WIN_UNICODE_CONSOLE = False
|
|
|
|
|
|
|
|
if HAVE_WIN_UNICODE_CONSOLE:
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def disable_win_unicode_console(monkeypatch):
|
|
|
|
""" Disable win_unicode_console if it is present since it collides with
|
|
|
|
pytests ouptput capture"""
|
|
|
|
monkeypatch.setattr(win_unicode_console, 'enable', lambda: None)
|