Пример #1
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)

    last_event = None

    @xonsh_builtins.events.vox_on_create
    def create(name, **_):
        nonlocal last_event
        last_event = "create", name

    @xonsh_builtins.events.vox_on_delete
    def delete(name, **_):
        nonlocal last_event
        last_event = "delete", name

    vox = Vox()
    vox.create("spam")
    assert stat.S_ISDIR(tmpdir.join("spam").stat().mode)
    assert last_event == ("create", "spam")

    ve = vox["spam"]
    assert ve.env == str(tmpdir.join("spam"))
    assert os.path.isdir(ve.bin)

    assert "spam" in vox
    assert "spam" in list(vox)

    del vox["spam"]

    assert not tmpdir.join("spam").check()
    assert last_event == ("delete", "spam")
Пример #2
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)

    last_event = None

    @xonsh_builtins.events.vox_on_create
    def create(name, **_):
        nonlocal last_event
        last_event = 'create', name

    @xonsh_builtins.events.vox_on_delete
    def delete(name, **_):
        nonlocal last_event
        last_event = 'delete', name

    vox = Vox()
    vox.create('spam')
    assert stat.S_ISDIR(tmpdir.join('spam').stat().mode)
    assert last_event == ('create', 'spam')

    ve = vox['spam']
    assert ve.env == str(tmpdir.join('spam'))
    assert os.path.isdir(ve.bin)

    assert 'spam' in vox
    assert 'spam' in list(vox)

    del vox['spam']

    assert not tmpdir.join('spam').check()
    assert last_event == ('delete', 'spam')
Пример #3
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)

    last_event = None

    @xonsh_builtins.events.vox_on_create
    def create(name, **_):
        nonlocal last_event
        last_event = 'create', name

    @xonsh_builtins.events.vox_on_delete
    def delete(name, **_):
        nonlocal last_event
        last_event = 'delete', name

    vox = Vox()
    vox.create('spam')
    assert stat.S_ISDIR(tmpdir.join('spam').stat().mode)
    assert last_event == ('create', 'spam')

    ve = vox['spam']
    assert ve.env == str(tmpdir.join('spam'))
    assert os.path.isdir(ve.bin)

    assert 'spam' in vox
    assert 'spam' in list(vox)

    del vox['spam']

    assert not tmpdir.join('spam').check()
    assert last_event == ('delete', 'spam')
Пример #4
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)

    last_event = None

    @xonsh_builtins.events.vox_on_create
    def create(name):
        nonlocal last_event
        last_event = "create", name

    @xonsh_builtins.events.vox_on_delete
    def delete(name):
        nonlocal last_event
        last_event = "delete", name

    vox = Vox()
    vox.create("spam")
    assert stat.S_ISDIR(tmpdir.join("spam").stat().mode)
    assert last_event == ("create", "spam")

    ve = vox["spam"]
    assert ve.env == str(tmpdir.join("spam"))
    assert os.path.isdir(ve.bin)

    assert "spam" in vox
    assert "spam" in list(vox)

    del vox["spam"]

    assert not tmpdir.join("spam").check()
    assert last_event == ("delete", "spam")
Пример #5
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault('PATH', [])

    last_event = None

    @xonsh_builtins.events.vox_on_activate
    def activate(name, **_):
        nonlocal last_event
        last_event = 'activate', name

    @xonsh_builtins.events.vox_on_deactivate
    def deactivate(name, **_):
        nonlocal last_event
        last_event = 'deactivate', name

    vox = Vox()
    vox.create('spam')
    vox.activate('spam')
    assert xonsh_builtins.__xonsh_env__['VIRTUAL_ENV'] == vox['spam'].env
    assert last_event == ('activate', 'spam')
    vox.deactivate()
    assert 'VIRTUAL_ENV' not in xonsh_builtins.__xonsh_env__
    assert last_event == ('deactivate', 'spam')
Пример #6
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh__.env.setdefault("PATH", [])

    last_event = None

    @xonsh_builtins.events.vox_on_activate
    def activate(name, **_):
        nonlocal last_event
        last_event = "activate", name

    @xonsh_builtins.events.vox_on_deactivate
    def deactivate(name, **_):
        nonlocal last_event
        last_event = "deactivate", name

    vox = Vox()
    vox.create("spam")
    vox.activate("spam")
    assert xonsh_builtins.__xonsh__.env["VIRTUAL_ENV"] == vox["spam"].env
    assert last_event == ("activate", "spam")
    vox.deactivate()
    assert "VIRTUAL_ENV" not in xonsh_builtins.__xonsh__.env
    assert last_event == ("deactivate", "spam")
Пример #7
0
def test_crud_path(xession, tmpdir, venv_proc):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    tmp = str(tmpdir)

    vox = Vox(force_removals=True)
    vox.create(tmp)
    assert stat.S_ISDIR(tmpdir.join("lib").stat().mode)

    ve = vox[tmp]
    assert ve.env == str(tmp)
    assert os.path.isdir(ve.bin)

    del vox[tmp]

    assert not tmpdir.check()
Пример #8
0
def create_venv(venv_proc):
    vox = Vox(force_removals=True)

    def wrapped(name):
        vox.create(name)
        return local(vox[name].env)

    return wrapped
Пример #9
0
    def test_crud_path(xonsh_builtins, tmpdir):
        """
        Creates a virtual environment, gets it, enumerates it, and then deletes it.
        """
        tmp = pathlib.Path(str(tmpdir))

        vox = Vox()
        vox.create(tmp)
        assert stat.S_ISDIR(tmpdir.join("lib").stat().mode)

        ve = vox[tmp]
        assert ve.env == str(tmp)
        assert os.path.isdir(ve.bin)

        del vox[tmp]

        assert not tmpdir.check()
Пример #10
0
    def test_crud_path(xonsh_builtins, tmpdir):
        """
        Creates a virtual environment, gets it, enumerates it, and then deletes it.
        """
        tmp = pathlib.Path(str(tmpdir))

        vox = Vox()
        vox.create(tmp)
        assert stat.S_ISDIR(tmpdir.join('lib').stat().mode)

        ve = vox[tmp]
        assert ve.env == str(tmp)
        assert os.path.isdir(ve.bin)

        del vox[tmp]

        assert not tmpdir.check()
Пример #11
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__["VIRTUALENV_HOME"] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault("PATH", [])

    last_event = None

    @xonsh_builtins.events.vox_on_activate
    def activate(name):
        nonlocal last_event
        last_event = "activate", name

    @xonsh_builtins.events.vox_on_deactivate
    def deactivate(name):
        nonlocal last_event
        last_event = "deactivate", name

    vox = Vox()
    vox.create("spam")
    vox.activate("spam")
    assert xonsh_builtins.__xonsh_env__["VIRTUAL_ENV"] == vox["spam"].env
    assert last_event == ("activate", "spam")
    vox.deactivate()
    assert "VIRTUAL_ENV" not in xonsh_builtins.__xonsh_env__
    assert last_event == ("deactivate", "spam")
Пример #12
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault('PATH', [])

    last_event = None

    @xonsh_builtins.events.vox_on_activate
    def activate(name, **_):
        nonlocal last_event
        last_event = 'activate', name

    @xonsh_builtins.events.vox_on_deactivate
    def deactivate(name, **_):
        nonlocal last_event
        last_event = 'deactivate', name

    vox = Vox()
    vox.create('spam')
    vox.activate('spam')
    assert xonsh_builtins.__xonsh_env__['VIRTUAL_ENV'] == vox['spam'].env
    assert last_event == ('activate', 'spam')
    vox.deactivate()
    assert 'VIRTUAL_ENV' not in xonsh_builtins.__xonsh_env__
    assert last_event == ('deactivate', 'spam')
Пример #13
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    vox = Vox()
    vox.create('spam')
    assert stat.S_ISDIR(tmpdir.join('spam').stat().mode)

    env, bin = vox['spam']
    assert env == str(tmpdir.join('spam'))
    assert os.path.isdir(bin)

    assert 'spam' in vox

    del vox['spam']

    assert not tmpdir.join('spam').check()
Пример #14
0
def test_crud_subdir(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)

    vox = Vox()
    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create('Scripts')
        else:
            vox.create('bin')

    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create('spameggs/Scripts')
        else:
            vox.create('spameggs/bin')
Пример #15
0
def test_crud(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    vox = Vox()
    vox.create('spam')
    assert stat.S_ISDIR(tmpdir.join('spam').stat().mode)

    env, bin = vox['spam']
    assert env == str(tmpdir.join('spam'))
    assert os.path.isdir(bin)

    assert 'spam' in vox

    del vox['spam']

    assert not tmpdir.join('spam').check()
Пример #16
0
def test_reserved_names(xonsh_builtins, tmpdir):
    """
    Tests that reserved words are disallowed.
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)

    vox = Vox()
    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create("Scripts")
        else:
            vox.create("bin")

    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create("spameggs/Scripts")
        else:
            vox.create("spameggs/bin")
Пример #17
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault('PATH', [])
    vox = Vox()
    vox.create('spam')
    vox.activate('spam')
    assert xonsh_builtins.__xonsh_env__['VIRTUAL_ENV'] == vox['spam'].env
    vox.deactivate()
    assert 'VIRTUAL_ENV' not in xonsh_builtins.__xonsh_env__
Пример #18
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"])
Пример #19
0
def test_crud_subdir(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)

    vox = Vox()
    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create('Scripts')
        else:
            vox.create('bin')

    with pytest.raises(ValueError):
        if ON_WINDOWS:
            vox.create('spameggs/Scripts')
        else:
            vox.create('spameggs/bin')
Пример #20
0
def test_crud_subdir(xession, venv_home, venv_proc):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """

    vox = Vox(force_removals=True)
    vox.create("spam/eggs")
    assert stat.S_ISDIR(venv_home.join("spam", "eggs").stat().mode)

    ve = vox["spam/eggs"]
    assert ve.env == str(venv_home.join("spam", "eggs"))
    assert os.path.isdir(ve.bin)

    assert "spam/eggs" in vox
    assert "spam" not in vox

    # assert 'spam/eggs' in list(vox)  # This is NOT true on Windows
    assert "spam" not in list(vox)

    del vox["spam/eggs"]

    assert not venv_home.join("spam", "eggs").check()
Пример #21
0
def test_crud_subdir(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)

    vox = Vox()
    vox.create('spam/eggs')
    assert stat.S_ISDIR(tmpdir.join('spam', 'eggs').stat().mode)

    ve = vox['spam/eggs']
    assert ve.env == str(tmpdir.join('spam', 'eggs'))
    assert os.path.isdir(ve.bin)

    assert 'spam/eggs' in vox
    assert 'spam' not in vox

    #assert 'spam/eggs' in list(vox)  # This is NOT true on Windows
    assert 'spam' not in list(vox)

    del vox['spam/eggs']

    assert not tmpdir.join('spam', 'eggs').check()
Пример #22
0
def test_crud_subdir(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)

    vox = Vox()
    vox.create("spam/eggs")
    assert stat.S_ISDIR(tmpdir.join("spam", "eggs").stat().mode)

    ve = vox["spam/eggs"]
    assert ve.env == str(tmpdir.join("spam", "eggs"))
    assert os.path.isdir(ve.bin)

    assert "spam/eggs" in vox
    assert "spam" not in vox

    # assert 'spam/eggs' in list(vox)  # This is NOT true on Windows
    assert "spam" not in list(vox)

    del vox["spam/eggs"]

    assert not tmpdir.join("spam", "eggs").check()
Пример #23
0
def test_reserved_names(xonsh_builtins, tmpdir):
    """
    Tests that reserved words are disallowed.
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)

    vox = Vox()
    vox.create("spam/eggs")
    assert stat.S_ISDIR(tmpdir.join("spam", "eggs").stat().mode)

    ve = vox["spam/eggs"]
    assert ve.env == str(tmpdir.join("spam", "eggs"))
    assert os.path.isdir(ve.bin)

    assert "spam/eggs" in vox
    assert "spam" not in vox

    # assert 'spam/eggs' in list(vox)  # This is NOT true on Windows
    assert "spam" not in list(vox)

    del vox["spam/eggs"]

    assert not tmpdir.join("spam", "eggs").check()
Пример #24
0
def test_activate(xonsh_builtins, tmpdir):
    """
    Creates a virtual environment, gets it, enumerates it, and then deletes it.
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault('PATH', [])
    vox = Vox()
    vox.create('spam')
    vox.activate('spam')
    assert xonsh_builtins.__xonsh_env__['VIRTUAL_ENV'] == vox['spam'].env
    vox.deactivate()
    assert 'VIRTUAL_ENV' not in xonsh_builtins.__xonsh_env__
Пример #25
0
def test_path(xonsh_builtins, tmpdir):
    """
    Test to make sure Vox properly activates and deactivates by examining $PATH
    """
    xonsh_builtins.__xonsh__.env["VIRTUALENV_HOME"] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh__.env.setdefault("PATH", [])

    oldpath = list(xonsh_builtins.__xonsh__.env["PATH"])
    vox = Vox()
    vox.create("eggs")

    vox.activate("eggs")

    assert oldpath != xonsh_builtins.__xonsh__.env["PATH"]

    vox.deactivate()

    assert oldpath == xonsh_builtins.__xonsh__.env["PATH"]
Пример #26
0
def test_path(xonsh_builtins, tmpdir):
    """
    Test to make sure Vox properly activates and deactivates by examining $PATH
    """
    xonsh_builtins.__xonsh_env__['VIRTUALENV_HOME'] = str(tmpdir)
    # I consider the case that the user doesn't have a PATH set to be unreasonable
    xonsh_builtins.__xonsh_env__.setdefault('PATH', [])

    oldpath = list(xonsh_builtins.__xonsh_env__['PATH'])
    vox = Vox()
    vox.create('eggs')

    vox.activate('eggs')
    
    assert oldpath != xonsh_builtins.__xonsh_env__['PATH']
    
    vox.deactivate()
    
    assert oldpath == xonsh_builtins.__xonsh_env__['PATH']
Пример #27
0
def test_activate_non_vox_venv(xession, tmpdir):
    """
    Create a virtual environment using Python's built-in venv module
    (not in VIRTUALENV_HOME) and verify that vox can activate it correctly.
    """
    xession.env.setdefault("PATH", [])

    last_event = None

    @xession.builtins.events.vox_on_activate
    def activate(name, path, **_):
        nonlocal last_event
        last_event = "activate", name, path

    @xession.builtins.events.vox_on_deactivate
    def deactivate(name, path, **_):
        nonlocal last_event
        last_event = "deactivate", name, path

    with tmpdir.as_cwd():
        venv_dirname = "venv"
        sp.run([sys.executable, "-m", "venv", venv_dirname])
        vox = Vox()
        vox.activate(venv_dirname)
        vxv = vox[venv_dirname]

    env = xession.env
    assert os.path.isabs(vxv.bin)
    assert env["PATH"][0] == vxv.bin
    assert os.path.isabs(vxv.env)
    assert env["VIRTUAL_ENV"] == vxv.env
    assert last_event == (
        "activate",
        venv_dirname,
        str(pathlib.Path(str(tmpdir)) / "venv"),
    )

    vox.deactivate()
    assert not env["PATH"]
    assert "VIRTUAL_ENV" not in env
    assert last_event == (
        "deactivate",
        tmpdir.join(venv_dirname),
        str(pathlib.Path(str(tmpdir)) / "venv"),
    )
Пример #28
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"])