Ejemplo n.º 1
0
def commands_cache_tmp(xonsh_builtins, tmp_path, monkeypatch):
    xonsh_builtins.__xonsh__.env["XONSH_DATA_DIR"] = tmp_path
    xonsh_builtins.__xonsh__.env["COMMANDS_CACHE_SAVE_INTERMEDIATE"] = True
    xonsh_builtins.__xonsh__.env["PATH"] = [tmp_path]
    exec_mock = MagicMock(return_value=["bin1", "bin2"])
    monkeypatch.setattr(commands_cache, "executables_in", exec_mock)
    return commands_cache.CommandsCache()
Ejemplo n.º 2
0
 def _factory(binaries: tp.List[str]):
     if not xession.env.get("PATH"):
         xession.env["PATH"] = [tmp_path]
     exec_mock = MagicMock(return_value=binaries)
     monkeypatch.setattr(commands_cache, "executables_in", exec_mock)
     cc = commands_cache.CommandsCache()
     xession.commands_cache = cc
     return cc
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def factory(*attrs: str):
        """

        Parameters
        ----------
        attrs
            do not mock the given attributes

        Returns
        -------
        XonshSession
            with most of the attributes mocked out
        """
        if session:
            raise RuntimeError(
                "The factory should be called only once per test")

        for attr, val in [
            ("env", env),
            ("shell", DummyShell()),
            ("help", lambda x: x),
            ("aliases", Aliases()),
            ("exit", False),
            ("history", DummyHistory()),
            (
                "commands_cache",
                commands_cache.CommandsCache(),
            ),  # since env,aliases change , patch cmds-cache
                # ("subproc_captured", sp),
            ("subproc_uncaptured", sp),
            ("subproc_captured_stdout", sp),
            ("subproc_captured_inject", sp),
            ("subproc_captured_object", sp),
            ("subproc_captured_hiddenobject", sp),
        ]:
            if attr in attrs:
                continue
            monkeypatch.setattr(xonsh_session, attr, val)

        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(xonsh_session.builtins, attr, val)

        session.append(xonsh_session)
        return xonsh_session