Esempio n. 1
0
def load_command_cache(xession):
    gc.collect()
    XSH.unload()
    XSH.load()
    if ON_WINDOWS:
        for key in ("cd", "bash"):
            xession.aliases[key] = lambda *args, **kwargs: None
Esempio n. 2
0
def xsh():
    from xonsh.built_ins import XSH

    XSH.load()
    from xontrib.powerline3 import main

    main()
    yield XSH
    XSH.unload()
Esempio n. 3
0
def xonsh_builtins(monkeypatch, xonsh_events, session_vars):
    """Mock out most of the builtins xonsh attributes."""
    old_builtins = dict(vars(builtins).items())  # type: ignore

    XSH.load(ctx={}, **session_vars)

    def locate_binary(self, name):
        return os.path.join(os.path.dirname(__file__), "bin", name)

    for attr, val in [
        ("env", DummyEnv()),
        ("shell", DummyShell()),
        ("help", lambda x: x),
        ("aliases", Aliases()),
        ("exit", False),
        ("history", DummyHistory()),
            # ("subproc_captured", sp),
        ("subproc_uncaptured", sp),
        ("subproc_captured_stdout", sp),
        ("subproc_captured_inject", sp),
        ("subproc_captured_object", sp),
        ("subproc_captured_hiddenobject", sp),
    ]:
        monkeypatch.setattr(XSH, attr, val)

    if ON_WINDOWS:
        XSH.env["PATHEXT"] = [".EXE", ".BAT", ".CMD"]

    cc = XSH.commands_cache
    monkeypatch.setattr(cc, "locate_binary",
                        types.MethodType(locate_binary, cc))
    monkeypatch.setattr(cc, "_cmds_cache", {})

    for attr, val in [
        ("evalx", eval),
        ("execx", None),
        ("compilex", None),
            # 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.
        ("events", xonsh_events),
    ]:
        # attributes to builtins are dynamicProxy and should pickup the following
        monkeypatch.setattr(XSH.builtins, attr, val)

    # todo: remove using builtins for tests at all
    yield builtins
    XSH.unload()
    for attr in set(dir(builtins)) - set(old_builtins):
        if hasattr(builtins, attr):
            delattr(builtins, attr)
    for attr, old_value in old_builtins.items():
        setattr(builtins, attr, old_value)

    tasks.clear()  # must to this to enable resetting all_jobs
Esempio n. 4
0
def xonsh_session(xonsh_events, session_execer, os_env, monkeypatch):
    """a fixture to use where XonshSession is fully loaded without any mocks"""

    XSH.load(
        ctx={},
        execer=session_execer,
        commands_cache=commands_cache.CommandsCache(),
        env=os_env,
    )
    yield XSH
    XSH.unload()
    tasks.clear()  # must to this to enable resetting all_jobs
Esempio n. 5
0
def postmain(args=None):
    """Teardown for main xonsh entry point, accepts parsed arguments."""
    XSH.unload()
    XSH.shell = None
Esempio n. 6
0
 def __del__(self):
     if self.unload:
         XSH.unload()
Esempio n. 7
0
def imp_env(xession):
    xession.env = Env({"PATH": [], "PATHEXT": []})
    imphooks.install_import_hooks(xession.execer)
    yield
    XSH.unload()
Esempio n. 8
0
def imp_env(xession):
    Execer(unload=False)
    xession.env = Env({"PATH": [], "PATHEXT": []})
    yield
    XSH.unload()