2016-07-20 14:50:22 -04:00
|
|
|
"""Vox tests"""
|
|
|
|
|
|
|
|
import builtins
|
|
|
|
import stat
|
|
|
|
import os
|
2016-10-02 21:49:38 -04:00
|
|
|
import pytest
|
2016-07-20 16:22:23 -04:00
|
|
|
from xontrib.voxapi import Vox
|
2016-07-20 14:50:22 -04:00
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
from tools import skip_if_on_conda, skip_if_on_msys
|
2016-10-02 21:49:38 -04:00
|
|
|
from xonsh.platform import ON_WINDOWS
|
2016-07-23 11:21:41 -04:00
|
|
|
|
2016-07-23 17:27:27 -04:00
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-07-23 17:27:27 -04:00
|
|
|
@skip_if_on_conda
|
2016-07-20 14:50:22 -04:00
|
|
|
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)
|
2016-08-28 13:37:23 -04:00
|
|
|
|
|
|
|
last_event = None
|
|
|
|
|
|
|
|
@xonsh_builtins.events.vox_on_create
|
2017-01-14 19:06:49 -05:00
|
|
|
def create(name, **_):
|
2016-08-28 13:37:23 -04:00
|
|
|
nonlocal last_event
|
|
|
|
last_event = 'create', name
|
|
|
|
|
|
|
|
@xonsh_builtins.events.vox_on_delete
|
2017-01-14 19:06:49 -05:00
|
|
|
def delete(name, **_):
|
2016-08-28 13:37:23 -04:00
|
|
|
nonlocal last_event
|
|
|
|
last_event = 'delete', name
|
|
|
|
|
2016-07-20 14:50:22 -04:00
|
|
|
vox = Vox()
|
|
|
|
vox.create('spam')
|
|
|
|
assert stat.S_ISDIR(tmpdir.join('spam').stat().mode)
|
2016-08-28 13:37:23 -04:00
|
|
|
assert last_event == ('create', 'spam')
|
2016-07-20 14:50:22 -04:00
|
|
|
|
2016-09-13 20:29:44 -04:00
|
|
|
ve = vox['spam']
|
|
|
|
assert ve.env == str(tmpdir.join('spam'))
|
|
|
|
assert os.path.isdir(ve.bin)
|
2016-07-20 14:50:22 -04:00
|
|
|
|
|
|
|
assert 'spam' in vox
|
2016-09-13 20:49:34 -04:00
|
|
|
assert 'spam' in list(vox)
|
2016-07-20 14:50:22 -04:00
|
|
|
|
|
|
|
del vox['spam']
|
|
|
|
|
|
|
|
assert not tmpdir.join('spam').check()
|
2016-08-28 13:37:23 -04:00
|
|
|
assert last_event == ('delete', 'spam')
|
2016-07-20 14:50:22 -04:00
|
|
|
|
2016-07-23 17:27:27 -04:00
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-07-23 17:27:27 -04:00
|
|
|
@skip_if_on_conda
|
2016-07-20 14:50:22 -04:00
|
|
|
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', [])
|
2016-08-28 13:37:23 -04:00
|
|
|
|
|
|
|
last_event = None
|
|
|
|
|
|
|
|
@xonsh_builtins.events.vox_on_activate
|
2017-01-14 19:06:49 -05:00
|
|
|
def activate(name, **_):
|
2016-08-28 13:37:23 -04:00
|
|
|
nonlocal last_event
|
|
|
|
last_event = 'activate', name
|
|
|
|
|
|
|
|
@xonsh_builtins.events.vox_on_deactivate
|
2017-01-14 19:06:49 -05:00
|
|
|
def deactivate(name, **_):
|
2016-08-28 13:37:23 -04:00
|
|
|
nonlocal last_event
|
|
|
|
last_event = 'deactivate', name
|
|
|
|
|
2016-07-20 14:50:22 -04:00
|
|
|
vox = Vox()
|
|
|
|
vox.create('spam')
|
|
|
|
vox.activate('spam')
|
|
|
|
assert xonsh_builtins.__xonsh_env__['VIRTUAL_ENV'] == vox['spam'].env
|
2016-08-28 13:37:23 -04:00
|
|
|
assert last_event == ('activate', 'spam')
|
2016-07-20 14:50:22 -04:00
|
|
|
vox.deactivate()
|
|
|
|
assert 'VIRTUAL_ENV' not in xonsh_builtins.__xonsh_env__
|
2016-08-28 13:37:23 -04:00
|
|
|
assert last_event == ('deactivate', 'spam')
|
2016-07-30 03:35:39 -04:00
|
|
|
|
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-07-30 03:35:39 -04:00
|
|
|
@skip_if_on_conda
|
|
|
|
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']
|
2016-09-13 20:49:34 -04:00
|
|
|
|
2016-10-02 21:49:38 -04:00
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-09-13 20:49:34 -04:00
|
|
|
@skip_if_on_conda
|
|
|
|
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']
|
2016-09-13 20:52:19 -04:00
|
|
|
assert ve.env == str(tmpdir.join('spam', 'eggs'))
|
2016-09-13 20:49:34 -04:00
|
|
|
assert os.path.isdir(ve.bin)
|
|
|
|
|
|
|
|
assert 'spam/eggs' in vox
|
|
|
|
assert 'spam' not in vox
|
|
|
|
|
2016-09-13 21:01:50 -04:00
|
|
|
#assert 'spam/eggs' in list(vox) # This is NOT true on Windows
|
2016-09-13 20:49:34 -04:00
|
|
|
assert 'spam' not in list(vox)
|
|
|
|
|
|
|
|
del vox['spam/eggs']
|
|
|
|
|
|
|
|
assert not tmpdir.join('spam', 'eggs').check()
|
2016-10-02 21:49:38 -04:00
|
|
|
|
2016-12-09 23:14:41 -05:00
|
|
|
try:
|
|
|
|
import pathlib
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-12-09 23:14:41 -05:00
|
|
|
@skip_if_on_conda
|
|
|
|
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()
|
|
|
|
|
2016-10-02 21:49:38 -04:00
|
|
|
|
2017-12-31 17:36:21 +01:00
|
|
|
@skip_if_on_msys
|
2016-10-02 21:49:38 -04:00
|
|
|
@skip_if_on_conda
|
|
|
|
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')
|