Exemplo n.º 1
0
def test_autovox(xession, tmpdir, load_vox):
    """
    Tests that autovox works
    """
    import importlib
    import xonsh.dirstack

    # Makes sure that event handlers are registered
    import xontrib.autovox

    importlib.reload(xontrib.autovox)

    @xession.builtins.events.autovox_policy
    def policy(path, **_):
        print("Checking", repr(path), vox.active())
        if str(path) == str(tmpdir):
            return "myenv"

    vox = Vox()

    print(xession.env["PWD"])
    xonsh.dirstack.pushd([str(tmpdir)])
    print(xession.env["PWD"])
    assert vox.active() is None
    xonsh.dirstack.popd([])
    print(xession.env["PWD"])

    vox.create("myenv")
    xonsh.dirstack.pushd([str(tmpdir)])
    print(xession.env["PWD"])
    assert vox.active() == "myenv"
    xonsh.dirstack.popd([])
    print(xession.env["PWD"])
Exemplo n.º 2
0
def test_autovox(xonsh_builtins, tmpdir):
    """
    Tests that autovox works
    """
    import importlib
    import xonsh.dirstack

    # Set up an isolated venv home
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)

    # Makes sure that event handlers are registered
    import xontrib.autovox

    importlib.reload(xontrib.autovox)

    # Set up enough environment for xonsh to function
    xonsh_builtins.__xonsh__.env["PWD"] = os.getcwd()
    xonsh_builtins.__xonsh__.env["DIRSTACK_SIZE"] = 10
    xonsh_builtins.__xonsh__.env["PATH"] = []

    xonsh_builtins.__xonsh__.env["XONSH_SHOW_TRACEBACK"] = True

    @xonsh_builtins.events.autovox_policy
    def policy(path, **_):
        print("Checking", repr(path), vox.active())
        if str(path) == str(tmpdir):
            return "myenv"

    vox = Vox()

    print(xonsh_builtins.__xonsh__.env["PWD"])
    xonsh.dirstack.pushd([str(tmpdir)])
    print(xonsh_builtins.__xonsh__.env["PWD"])
    assert vox.active() is None
    xonsh.dirstack.popd([])
    print(xonsh_builtins.__xonsh__.env["PWD"])

    vox.create("myenv")
    xonsh.dirstack.pushd([str(tmpdir)])
    print(xonsh_builtins.__xonsh__.env["PWD"])
    assert vox.active() == "myenv"
    xonsh.dirstack.popd([])
    print(xonsh_builtins.__xonsh__.env["PWD"])