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')
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")
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")
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__
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"), )
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']
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"]