Skip to content

Commit

Permalink
Use virtualenv 20.0.10 for macosx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch3LL committed Mar 12, 2020
1 parent 19bb6aa commit fdeae1f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion requirements/static/darwin.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rfc3987
salttesting==2017.6.1
strict_rfc3339
supervisor==3.3.5; python_version < '3'
virtualenv
virtualenv==20.0.10
watchdog
yamlordereddictloader
vcert~=0.7.0
Expand Down
55 changes: 32 additions & 23 deletions salt/modules/virtualenv_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ def __virtual__():
return __virtualname__


def virtualenv_ver(venv_bin, user=None, **kwargs):
'''
return virtualenv version if exists
'''
# Virtualenv package
try:
import virtualenv
version = getattr(virtualenv, '__version__', None)
if not version:
version = virtualenv.virtualenv_version
virtualenv_version_info = tuple(
[int(i) for i in version.split('rc')[0].split('.')]
)
except ImportError:
# Unable to import?? Let's parse the version from the console
version_cmd = [venv_bin, '--version']
ret = __salt__['cmd.run_all'](
version_cmd, runas=user, python_shell=False, **kwargs
)
if ret['retcode'] > 0 or not ret['stdout'].strip():
raise CommandExecutionError(
'Unable to get the virtualenv version output using \'{0}\'. '
'Returned data: {1}'.format(version_cmd, ret)
)
virtualenv_version_info = tuple(
[int(i) for i in
ret['stdout'].strip().split('rc')[0].split('.')]
)
return virtualenv_version_info


def create(path,
venv_bin=None,
system_site_packages=False,
Expand Down Expand Up @@ -164,29 +195,7 @@ def create(path,
)
# <---- Stop the user if pyvenv only options are used ----------------

# Virtualenv package
try:
import virtualenv
version = getattr(virtualenv, '__version__',
virtualenv.virtualenv_version)
virtualenv_version_info = tuple(
[int(i) for i in version.split('rc')[0].split('.')]
)
except ImportError:
# Unable to import?? Let's parse the version from the console
version_cmd = [venv_bin, '--version']
ret = __salt__['cmd.run_all'](
version_cmd, runas=user, python_shell=False, **kwargs
)
if ret['retcode'] > 0 or not ret['stdout'].strip():
raise CommandExecutionError(
'Unable to get the virtualenv version output using \'{0}\'. '
'Returned data: {1}'.format(version_cmd, ret)
)
virtualenv_version_info = tuple(
[int(i) for i in
ret['stdout'].strip().split('rc')[0].split('.')]
)
virtualenv_version_info = virtualenv_ver(venv_bin, user=user, **kwargs)

if distribute:
if virtualenv_version_info >= (1, 10):
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/states/test_pip_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,12 @@ def test_issue_6833_pip_upgrade_pip(self):
pprint.pformat(ret)
)
)
import salt.modules.virtualenv_mod
msg = 'New python executable'
if salt.modules.virtualenv_mod.virtualenv_ver(venv_dir) >= (20, 0, 2):
msg = 'created virtual environment'
self.assertIn(
'New python executable',
msg,
ret['stdout'],
msg='Expected STDOUT did not match. Full return dictionary:\n{}'.format(
pprint.pformat(ret)
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/modules/test_virtualenv_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,31 @@ def test_symlinks_argument(self):
runas=None,
python_shell=False
)

def test_virtualenv_ver(self):
'''
test virtualenv_ver when there is no ImportError
'''
ret = virtualenv_mod.virtualenv_ver(venv_bin='pyvenv')
assert ret == (1, 9, 1)

def test_virtualenv_ver_importerror(self):
'''
test virtualenv_ver when there is an ImportError
'''
with ForceImportErrorOn('virtualenv'):
mock_ver = MagicMock(return_value={'retcode': 0, 'stdout': '1.9.1'})
with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock_ver}):
ret = virtualenv_mod.virtualenv_ver(venv_bin='pyenv')
assert ret == (1, 9, 1)

def test_virtualenv_ver_importerror_cmd_error(self):
'''
test virtualenv_ver when there is an ImportError
and virtualenv --version does not return anything
'''
with ForceImportErrorOn('virtualenv'):
mock_ver = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock_ver}):
with self.assertRaises(CommandExecutionError):
virtualenv_mod.virtualenv_ver(venv_bin='pyenv')
7 changes: 7 additions & 0 deletions tests/unit/modules/test_zcbuildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import salt.utils.path
import salt.utils.platform
import salt.modules.zcbuildout as buildout
import salt.modules.virtualenv_mod
import salt.modules.cmdmod as cmd
from salt.ext import six

Expand Down Expand Up @@ -466,6 +467,9 @@ def test_buildout_bootstrap(self):

@requires_network()
def test_run_buildout(self):
if salt.modules.virtualenv_mod.virtualenv_ver(self.ppy_st) >= (20, 0, 0):
self.skipTest("Skiping until upstream resolved https://github.com/pypa/virtualenv/issues/1715")

b_dir = os.path.join(self.tdir, 'b')
ret = buildout.bootstrap(b_dir, buildout_ver=2, python=self.py_st)
self.assertTrue(ret['status'])
Expand All @@ -477,6 +481,9 @@ def test_run_buildout(self):

@requires_network()
def test_buildout(self):
if salt.modules.virtualenv_mod.virtualenv_ver(self.ppy_st) >= (20, 0, 0):
self.skipTest("Skiping until upstream resolved https://github.com/pypa/virtualenv/issues/1715")

b_dir = os.path.join(self.tdir, 'b')
ret = buildout.buildout(b_dir, buildout_ver=2, python=self.py_st)
self.assertTrue(ret['status'])
Expand Down

0 comments on commit fdeae1f

Please sign in to comment.