"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/integration/modules/test_pip.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_pip.py  (salt-2019.2.0):test_pip.py  (salt-2019.2.1)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
:codeauthor: Pedro Algarvio (pedro@algarvio.me) tests.integration.modules.pip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests.integration.modules.pip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
''' '''
# Import python libs # Import python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import os import os
import re import re
import sys
import pprint
import shutil import shutil
import tempfile import tempfile
# Import Salt Testing libs # Import Salt Testing libs
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.unit import skipIf from tests.support.unit import skipIf
from tests.support.paths import TMP from tests.support.paths import TMP
from tests.support.helpers import skip_if_not_root
# Import salt libs # Import salt libs
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.platform import salt.utils.platform
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not i nstalled') @skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not i nstalled')
class PipModuleTest(ModuleCase): class PipModuleTest(ModuleCase):
def setUp(self): def setUp(self):
super(PipModuleTest, self).setUp() super(PipModuleTest, self).setUp()
# Restore the environ
def cleanup_environ(environ):
os.environ.clear()
os.environ.update(environ)
self.addCleanup(cleanup_environ, os.environ.copy())
self.venv_test_dir = tempfile.mkdtemp(dir=TMP) self.venv_test_dir = tempfile.mkdtemp(dir=TMP)
# Remove the venv test directory
self.addCleanup(shutil.rmtree, self.venv_test_dir, ignore_errors=True)
self.venv_dir = os.path.join(self.venv_test_dir, 'venv') self.venv_dir = os.path.join(self.venv_test_dir, 'venv')
for key in os.environ.copy(): for key in os.environ.copy():
if key.startswith('PIP_'): if key.startswith('PIP_'):
os.environ.pop(key) os.environ.pop(key)
self.pip_temp = os.path.join(self.venv_test_dir, '.pip-temp') self.pip_temp = os.path.join(self.venv_test_dir, '.pip-temp')
# Remove the pip-temp directory
self.addCleanup(shutil.rmtree, self.pip_temp, ignore_errors=True)
if not os.path.isdir(self.pip_temp): if not os.path.isdir(self.pip_temp):
os.makedirs(self.pip_temp) os.makedirs(self.pip_temp)
os.environ['PIP_SOURCE_DIR'] = os.environ['PIP_BUILD_DIR'] = '' os.environ['PIP_SOURCE_DIR'] = os.environ['PIP_BUILD_DIR'] = ''
for item in ('venv_dir', 'venv_test_dir', 'pip_temp'):
self.addCleanup(delattr, self, item)
def tearDown(self): def _create_virtualenv(self, path):
super(PipModuleTest, self).tearDown() '''
if os.path.isdir(self.venv_test_dir): The reason why the virtualenv creation is proxied by this function is mo
shutil.rmtree(self.venv_test_dir, ignore_errors=True) stly
if os.path.isdir(self.pip_temp): because under windows, we can't seem to properly create a virtualenv off
shutil.rmtree(self.pip_temp, ignore_errors=True) of
del self.venv_dir another virtualenv(we can on linux) and also because, we really don't wa
del self.venv_test_dir nt to
del self.pip_temp test virtualenv creation off of another virtualenv, we want a virtualenv
if 'PIP_SOURCE_DIR' in os.environ: created
os.environ.pop('PIP_SOURCE_DIR') from the original python.
if 'PIP_BUILD_DIR' in os.environ: Also, one windows, we must also point to the virtualenv binary outside t
os.environ.pop('PIP_BUILD_DIR') he existing
virtualenv because it will fail otherwise
'''
try:
if salt.utils.is_windows():
python = os.path.join(sys.real_prefix, os.path.basename(sys.exec
utable))
else:
python = os.path.join(sys.real_prefix, 'bin', os.path.basename(s
ys.executable))
# We're running off a virtualenv, and we don't want to create a virt
ualenv off of
# a virtualenv
kwargs = {'python': python}
except AttributeError:
# We're running off of the system python
kwargs = {}
self.run_function('virtualenv.create', [path], **kwargs)
def _check_download_error(self, ret): def _check_download_error(self, ret):
''' '''
Checks to see if a download error looks transitory Checks to see if a download error looks transitory
''' '''
return any(w in ret for w in ['URLError', 'Download error']) return any(w in ret for w in ['URLError', 'Download error'])
def pip_successful_install(self, target, expect=('irc3-plugins-test', 'pep8' ,)): def pip_successful_install(self, target, expect=('irc3-plugins-test', 'pep8' ,)):
''' '''
isolate regex for extracting `successful install` message from pip isolate regex for extracting `successful install` message from pip
skipping to change at line 86 skipping to change at line 107
success_for = re.findall( success_for = re.findall(
r'({0})(?:-(?:[\d\.-]))?'.format(expect_str), r'({0})(?:-(?:[\d\.-]))?'.format(expect_str),
success.groups()[0] success.groups()[0]
) if success else [] ) if success else []
return expect.issubset(set(success_for)) return expect.issubset(set(success_for))
def test_issue_2087_missing_pip(self): def test_issue_2087_missing_pip(self):
# Let's create the testing virtualenv # Let's create the testing virtualenv
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Let's remove the pip binary # Let's remove the pip binary
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip') pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
site_dir = self.run_function('virtualenv.get_distribution_path', [self.v env_dir, 'pip']) site_dir = self.run_function('virtualenv.get_distribution_path', [self.v env_dir, 'pip'])
if salt.utils.platform.is_windows(): if salt.utils.platform.is_windows():
pip_bin = os.path.join(self.venv_dir, 'Scripts', 'pip.exe') pip_bin = os.path.join(self.venv_dir, 'Scripts', 'pip.exe')
site_dir = os.path.join(self.venv_dir, 'lib', 'site-packages') site_dir = os.path.join(self.venv_dir, 'lib', 'site-packages')
if not os.path.isfile(pip_bin): if not os.path.isfile(pip_bin):
self.skipTest( self.skipTest(
'Failed to find the pip binary to the test virtualenv' 'Failed to find the pip binary to the test virtualenv'
skipping to change at line 115 skipping to change at line 136
# Let's run a pip depending functions # Let's run a pip depending functions
for func in ('pip.freeze', 'pip.list'): for func in ('pip.freeze', 'pip.list'):
ret = self.run_function(func, bin_env=self.venv_dir) ret = self.run_function(func, bin_env=self.venv_dir)
self.assertIn( self.assertIn(
'Command required for \'{0}\' not found: ' 'Command required for \'{0}\' not found: '
'Could not find a `pip` binary'.format(func), 'Could not find a `pip` binary'.format(func),
ret ret
) )
@skip_if_not_root
def test_requirements_as_list_of_chains__cwd_set__absolute_file_path(self): def test_requirements_as_list_of_chains__cwd_set__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, 'requirements1.txt') req1_filename = os.path.join(self.venv_dir, 'requirements1.txt')
req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt') req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt')
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt') req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt') req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt')
with salt.utils.files.fopen(req1_filename, 'w') as f: with salt.utils.files.fopen(req1_filename, 'w') as f:
f.write('-r requirements1b.txt\n') f.write('-r requirements1b.txt\n')
skipping to change at line 141 skipping to change at line 161
f.write('-r requirements2b.txt\n') f.write('-r requirements2b.txt\n')
with salt.utils.files.fopen(req2b_filename, 'w') as f: with salt.utils.files.fopen(req2b_filename, 'w') as f:
f.write('pep8\n') f.write('pep8\n')
requirements_list = [req1_filename, req2_filename] requirements_list = [req1_filename, req2_filename]
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=requirements_list, 'pip.install', requirements=requirements_list,
bin_env=self.venv_dir, cwd=self.venv_dir bin_env=self.venv_dir, cwd=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
found = self.pip_successful_install(ret['stdout']) found = self.pip_successful_install(ret['stdout'])
self.assertTrue(found) self.assertTrue(found)
except (AssertionError, TypeError): except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
@skip_if_not_root
def test_requirements_as_list_of_chains__cwd_not_set__absolute_file_path(sel f): def test_requirements_as_list_of_chains__cwd_not_set__absolute_file_path(sel f):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, 'requirements1.txt') req1_filename = os.path.join(self.venv_dir, 'requirements1.txt')
req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt') req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt')
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt') req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt') req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt')
with salt.utils.files.fopen(req1_filename, 'w') as f: with salt.utils.files.fopen(req1_filename, 'w') as f:
f.write('-r requirements1b.txt\n') f.write('-r requirements1b.txt\n')
skipping to change at line 177 skipping to change at line 202
with salt.utils.files.fopen(req2_filename, 'w') as f: with salt.utils.files.fopen(req2_filename, 'w') as f:
f.write('-r requirements2b.txt\n') f.write('-r requirements2b.txt\n')
with salt.utils.files.fopen(req2b_filename, 'w') as f: with salt.utils.files.fopen(req2b_filename, 'w') as f:
f.write('pep8\n') f.write('pep8\n')
requirements_list = [req1_filename, req2_filename] requirements_list = [req1_filename, req2_filename]
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=requirements_list, bin_env=self.venv_dir 'pip.install', requirements=requirements_list, bin_env=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
found = self.pip_successful_install(ret['stdout']) found = self.pip_successful_install(ret['stdout'])
self.assertTrue(found) self.assertTrue(found)
except KeyError as exc:
self.fail(
'The returned dictionary is missing an expected key. Error: \'{}
\'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
except (AssertionError, TypeError):
import pprint
pprint.pprint(ret)
raise
@skip_if_not_root
def test_requirements_as_list__absolute_file_path(self): def test_requirements_as_list__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
req1_filename = os.path.join(self.venv_dir, 'requirements.txt') req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt') req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
with salt.utils.files.fopen(req1_filename, 'w') as f: with salt.utils.files.fopen(req1_filename, 'w') as f:
f.write('irc3-plugins-test\n') f.write('irc3-plugins-test\n')
with salt.utils.files.fopen(req2_filename, 'w') as f: with salt.utils.files.fopen(req2_filename, 'w') as f:
f.write('pep8\n') f.write('pep8\n')
requirements_list = [req1_filename, req2_filename] requirements_list = [req1_filename, req2_filename]
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=requirements_list, bin_env=self.venv_dir 'pip.install', requirements=requirements_list, bin_env=self.venv_dir
) )
found = self.pip_successful_install(ret['stdout']) if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
found = self.pip_successful_install(ret['stdout'])
self.assertTrue(found) self.assertTrue(found)
except KeyError as exc:
self.fail(
'The returned dictionary is missing an expected key. Error: \'{}
\'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
except (AssertionError, TypeError):
import pprint
pprint.pprint(ret)
raise
@skip_if_not_root
def test_requirements_as_list__non_absolute_file_path(self): def test_requirements_as_list__non_absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req1_filename = 'requirements.txt' req1_filename = 'requirements.txt'
req2_filename = 'requirements2.txt' req2_filename = 'requirements2.txt'
req_cwd = self.venv_dir req_cwd = self.venv_dir
req1_filepath = os.path.join(req_cwd, req1_filename) req1_filepath = os.path.join(req_cwd, req1_filename)
req2_filepath = os.path.join(req_cwd, req2_filename) req2_filepath = os.path.join(req_cwd, req2_filename)
skipping to change at line 242 skipping to change at line 277
f.write('irc3-plugins-test\n') f.write('irc3-plugins-test\n')
with salt.utils.files.fopen(req2_filepath, 'w') as f: with salt.utils.files.fopen(req2_filepath, 'w') as f:
f.write('pep8\n') f.write('pep8\n')
requirements_list = [req1_filename, req2_filename] requirements_list = [req1_filename, req2_filename]
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=requirements_list, 'pip.install', requirements=requirements_list,
bin_env=self.venv_dir, cwd=req_cwd bin_env=self.venv_dir, cwd=req_cwd
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
found = self.pip_successful_install(ret['stdout']) found = self.pip_successful_install(ret['stdout'])
self.assertTrue(found) self.assertTrue(found)
except KeyError as exc:
self.fail(
'The returned dictionary is missing an expected key. Error: \'{}
\'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
except (AssertionError, TypeError):
import pprint
pprint.pprint(ret)
raise
@skip_if_not_root
def test_chained_requirements__absolute_file_path(self): def test_chained_requirements__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, 'requirements.txt') req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt') req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
with salt.utils.files.fopen(req1_filename, 'w') as f: with salt.utils.files.fopen(req1_filename, 'w') as f:
f.write('-r requirements2.txt') f.write('-r requirements2.txt')
with salt.utils.files.fopen(req2_filename, 'w') as f: with salt.utils.files.fopen(req2_filename, 'w') as f:
f.write('pep8') f.write('pep8')
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=req1_filename, bin_env=self.venv_dir 'pip.install', requirements=req1_filename, bin_env=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout']) self.assertIn('installed pep8', ret['stdout'])
except (AssertionError, TypeError): except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
@skip_if_not_root
def test_chained_requirements__non_absolute_file_path(self): def test_chained_requirements__non_absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req_basepath = (self.venv_dir) req_basepath = (self.venv_dir)
req1_filename = 'requirements.txt' req1_filename = 'requirements.txt'
req2_filename = 'requirements2.txt' req2_filename = 'requirements2.txt'
req1_file = os.path.join(self.venv_dir, req1_filename) req1_file = os.path.join(self.venv_dir, req1_filename)
req2_file = os.path.join(self.venv_dir, req2_filename) req2_file = os.path.join(self.venv_dir, req2_filename)
with salt.utils.files.fopen(req1_file, 'w') as f: with salt.utils.files.fopen(req1_file, 'w') as f:
f.write('-r requirements2.txt') f.write('-r requirements2.txt')
with salt.utils.files.fopen(req2_file, 'w') as f: with salt.utils.files.fopen(req2_file, 'w') as f:
f.write('pep8') f.write('pep8')
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=req1_filename, cwd=req_basepath, 'pip.install', requirements=req1_filename, cwd=req_basepath,
bin_env=self.venv_dir bin_env=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout']) self.assertIn('installed pep8', ret['stdout'])
except (AssertionError, TypeError): except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
@skip_if_not_root
def test_issue_4805_nested_requirements(self): def test_issue_4805_nested_requirements(self):
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
# Create a requirements file that depends on another one. # Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, 'requirements.txt') req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt') req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
with salt.utils.files.fopen(req1_filename, 'w') as f: with salt.utils.files.fopen(req1_filename, 'w') as f:
f.write('-r requirements2.txt') f.write('-r requirements2.txt')
with salt.utils.files.fopen(req2_filename, 'w') as f: with salt.utils.files.fopen(req2_filename, 'w') as f:
f.write('pep8') f.write('pep8')
ret = self.run_function( ret = self.run_function(
'pip.install', requirements=req1_filename, bin_env=self.venv_dir, ti meout=300) 'pip.install', requirements=req1_filename, bin_env=self.venv_dir, ti meout=300)
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout']) self.assertIn('installed pep8', ret['stdout'])
except (AssertionError, TypeError): except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
def test_pip_uninstall(self): def test_pip_uninstall(self):
# Let's create the testing virtualenv # Let's create the testing virtualenv
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
ret = self.run_function('pip.install', ['pep8'], bin_env=self.venv_dir) ret = self.run_function('pip.install', ['pep8'], bin_env=self.venv_dir)
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.assertEqual(ret['retcode'], 0) self.fail(
self.assertIn('installed pep8', ret['stdout']) 'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout'])
except KeyError as exc:
self.fail(
'The returned dictionary is missing an expected key. Error: \'{}
\'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
ret = self.run_function( ret = self.run_function(
'pip.uninstall', ['pep8'], bin_env=self.venv_dir 'pip.uninstall', ['pep8'], bin_env=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.uninstall\' command did not return the excepted dicti
onary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('uninstalled pep8', ret['stdout']) self.assertIn('uninstalled pep8', ret['stdout'])
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
def test_pip_install_upgrade(self): def test_pip_install_upgrade(self):
# Create the testing virtualenv # Create the testing virtualenv
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
ret = self.run_function( ret = self.run_function(
'pip.install', ['pep8==1.3.4'], bin_env=self.venv_dir 'pip.install', ['pep8==1.3.4'], bin_env=self.venv_dir
) )
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout']) self.assertIn('installed pep8', ret['stdout'])
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
ret = self.run_function( ret = self.run_function(
'pip.install', 'pip.install',
['pep8'], ['pep8'],
bin_env=self.venv_dir, bin_env=self.venv_dir,
upgrade=True upgrade=True
) )
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('installed pep8', ret['stdout']) self.assertIn('installed pep8', ret['stdout'])
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
ret = self.run_function( ret = self.run_function(
'pip.uninstall', ['pep8'], bin_env=self.venv_dir 'pip.uninstall', ['pep8'], bin_env=self.venv_dir
) )
if not isinstance(ret, dict):
self.fail(
'The \'pip.uninstall\' command did not return the excepted dicti
onary. Output:\n{}'.format(ret)
)
try: try:
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn('uninstalled pep8', ret['stdout']) self.assertIn('uninstalled pep8', ret['stdout'])
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
def test_pip_install_multiple_editables(self): def test_pip_install_multiple_editables(self):
editables = [ editables = [
'git+https://github.com/jek/blinker.git#egg=Blinker', 'git+https://github.com/jek/blinker.git#egg=Blinker',
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting' 'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
] ]
# Create the testing virtualenv # Create the testing virtualenv
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
ret = self.run_function( ret = self.run_function(
'pip.install', [], 'pip.install', [],
editable='{0}'.format(','.join(editables)), editable='{0}'.format(','.join(editables)),
bin_env=self.venv_dir bin_env=self.venv_dir
) )
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
self.assertIn( self.assertIn(
'Successfully installed Blinker SaltTesting', ret['stdout'] 'Successfully installed Blinker SaltTesting', ret['stdout']
) )
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
def test_pip_install_multiple_editables_and_pkgs(self): def test_pip_install_multiple_editables_and_pkgs(self):
editables = [ editables = [
'git+https://github.com/jek/blinker.git#egg=Blinker', 'git+https://github.com/jek/blinker.git#egg=Blinker',
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting' 'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
] ]
# Create the testing virtualenv # Create the testing virtualenv
self.run_function('virtualenv.create', [self.venv_dir]) self._create_virtualenv(self.venv_dir)
ret = self.run_function( ret = self.run_function(
'pip.install', ['pep8'], 'pip.install', ['pep8'],
editable='{0}'.format(','.join(editables)), editable='{0}'.format(','.join(editables)),
bin_env=self.venv_dir bin_env=self.venv_dir
) )
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error') if not isinstance(ret, dict):
self.fail(
'The \'pip.install\' command did not return the excepted diction
ary. Output:\n{}'.format(ret)
)
try: try:
if self._check_download_error(ret['stdout']):
self.skipTest('Test skipped due to pip download error')
self.assertEqual(ret['retcode'], 0) self.assertEqual(ret['retcode'], 0)
for package in ('Blinker', 'SaltTesting', 'pep8'): for package in ('Blinker', 'SaltTesting', 'pep8'):
self.assertRegex( self.assertRegex(
ret['stdout'], ret['stdout'],
r'(?:.*)(Successfully installed)(?:.*)({0})(?:.*)'.format(pa ckage) r'(?:.*)(Successfully installed)(?:.*)({0})(?:.*)'.format(pa ckage)
) )
except AssertionError: except KeyError as exc:
import pprint self.fail(
pprint.pprint(ret) 'The returned dictionary is missing an expected key. Error: \'{}
raise \'. Dictionary: {}'.format(
exc,
pprint.pformat(ret)
)
)
@skipIf(not os.path.isfile('pip3'), 'test where pip3 is installed') @skipIf(not os.path.isfile('pip3'), 'test where pip3 is installed')
@skipIf(salt.utils.platform.is_windows(), 'test specific for linux usage of /bin/python') @skipIf(salt.utils.platform.is_windows(), 'test specific for linux usage of /bin/python')
def test_system_pip3(self): def test_system_pip3(self):
self.run_function('pip.install', pkgs=['lazyimport==0.0.1'], bin_env='/b in/pip3') self.run_function('pip.install', pkgs=['lazyimport==0.0.1'], bin_env='/b in/pip3')
ret1 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport' ) ret1 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport' )
self.run_function('pip.uninstall', pkgs=['lazyimport'], bin_env='/bin/pi p3') self.run_function('pip.uninstall', pkgs=['lazyimport'], bin_env='/bin/pi p3')
ret2 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport' ) ret2 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport' )
assert 'lazyimport==0.0.1' in ret1 assert 'lazyimport==0.0.1' in ret1
assert ret2 == '' assert ret2 == ''
 End of changes. 65 change blocks. 
112 lines changed or deleted 279 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)