Switch to the VirtualEnv helper

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-01-24 07:20:23 +00:00 committed by Megan Wilhite
parent 92a845cacf
commit 00b13ff1cd

View file

@ -1,14 +1,7 @@
"""
tests.integration.modules.pip
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
import os
import pprint
import re
import shutil
import sys
import tempfile
import pytest
@ -18,7 +11,7 @@ import salt.utils.path
import salt.utils.platform
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.case import ModuleCase
from tests.support.helpers import patched_environ
from tests.support.helpers import VirtualEnv, patched_environ
from tests.support.runtests import RUNTIME_VARS
@ -39,43 +32,6 @@ class PipModuleTest(ModuleCase):
self.patched_environ.__enter__()
self.addCleanup(self.patched_environ.__exit__)
def _create_virtualenv(self, path):
"""
The reason why the virtualenv creation is proxied by this function is mostly
because under windows, we can't seem to properly create a virtualenv off of
another virtualenv(we can on linux) and also because, we really don't want to
test virtualenv creation off of another virtualenv, we want a virtualenv created
from the original python.
Also, one windows, we must also point to the virtualenv binary outside the existing
virtualenv because it will fail otherwise
"""
try:
if salt.utils.platform.is_windows():
python = os.path.join(sys.real_prefix, os.path.basename(sys.executable))
else:
python_binary_names = [
"python{}.{}".format(*sys.version_info),
"python{}".format(*sys.version_info),
"python",
]
for binary_name in python_binary_names:
python = os.path.join(sys.real_prefix, "bin", binary_name)
if os.path.exists(python):
break
else:
self.fail(
"Couldn't find a python binary name under '{}' matching: {}".format(
os.path.join(sys.real_prefix, "bin"), python_binary_names
)
)
# We're running off a virtualenv, and we don't want to create a virtualenv 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):
"""
Checks to see if a download error looks transitory
@ -112,404 +68,407 @@ class PipModuleTest(ModuleCase):
@pytest.mark.slow_test
def test_issue_2087_missing_pip(self):
# Let's create the testing virtualenv
self._create_virtualenv(self.venv_dir)
with VirtualEnv(self.venv_dir):
# Let's remove the pip binary
pip_bin = os.path.join(self.venv_dir, "bin", "pip")
site_dir = self.run_function(
"virtualenv.get_distribution_path", [self.venv_dir, "pip"]
)
if salt.utils.platform.is_windows():
pip_bin = os.path.join(self.venv_dir, "Scripts", "pip.exe")
site_dir = os.path.join(self.venv_dir, "lib", "site-packages")
if not os.path.isfile(pip_bin):
self.skipTest("Failed to find the pip binary to the test virtualenv")
os.remove(pip_bin)
# Also remove the pip dir from site-packages
# This is needed now that we're using python -m pip instead of the
# pip binary directly. python -m pip will still work even if the
# pip binary is missing
shutil.rmtree(os.path.join(site_dir, "pip"))
# Let's run a pip depending functions
for func in ("pip.freeze", "pip.list"):
ret = self.run_function(func, bin_env=self.venv_dir)
self.assertIn(
"Command required for '{}' not found: "
"Could not find a `pip` binary".format(func),
ret,
# Let's remove the pip binary
pip_bin = os.path.join(self.venv_dir, "bin", "pip")
site_dir = self.run_function(
"virtualenv.get_distribution_path", [self.venv_dir, "pip"]
)
if salt.utils.platform.is_windows():
pip_bin = os.path.join(self.venv_dir, "Scripts", "pip.exe")
site_dir = os.path.join(self.venv_dir, "lib", "site-packages")
if not os.path.isfile(pip_bin):
self.skipTest("Failed to find the pip binary to the test virtualenv")
os.remove(pip_bin)
# Also remove the pip dir from site-packages
# This is needed now that we're using python -m pip instead of the
# pip binary directly. python -m pip will still work even if the
# pip binary is missing
shutil.rmtree(os.path.join(site_dir, "pip"))
# Let's run a pip depending functions
for func in ("pip.freeze", "pip.list"):
ret = self.run_function(func, bin_env=self.venv_dir)
assert (
"Command required for '{}' not found: Could not find a `pip` binary".format(
func
)
in ret
)
@pytest.mark.slow_test
def test_requirements_as_list_of_chains__cwd_set__absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with 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")
req1b_filename = os.path.join(self.venv_dir, "requirements1b.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req2b_filename = os.path.join(self.venv_dir, "requirements2b.txt")
req1_filename = os.path.join(self.venv_dir, "requirements1.txt")
req1b_filename = os.path.join(self.venv_dir, "requirements1b.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req2b_filename = os.path.join(self.venv_dir, "requirements2b.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements1b.txt\n")
with salt.utils.files.fopen(req1b_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("-r requirements2b.txt\n")
with salt.utils.files.fopen(req2b_filename, "w") as f:
f.write("pep8\n")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements1b.txt\n")
with salt.utils.files.fopen(req1b_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("-r requirements2b.txt\n")
with salt.utils.files.fopen(req2b_filename, "w") as f:
f.write("pep8\n")
requirements_list = [req1_filename, req2_filename]
requirements_list = [req1_filename, req2_filename]
ret = self.run_function(
"pip.install",
requirements=requirements_list,
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 dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install",
requirements=requirements_list,
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 dictionary."
" Output:\n{}".format(ret)
)
try:
self.assertEqual(ret["retcode"], 0)
found = self.pip_successful_install(ret["stdout"])
self.assertTrue(found)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
try:
assert ret["retcode"] == 0
found = self.pip_successful_install(ret["stdout"])
assert found
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_requirements_as_list_of_chains__cwd_not_set__absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with 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")
req1b_filename = os.path.join(self.venv_dir, "requirements1b.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req2b_filename = os.path.join(self.venv_dir, "requirements2b.txt")
req1_filename = os.path.join(self.venv_dir, "requirements1.txt")
req1b_filename = os.path.join(self.venv_dir, "requirements1b.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req2b_filename = os.path.join(self.venv_dir, "requirements2b.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements1b.txt\n")
with salt.utils.files.fopen(req1b_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("-r requirements2b.txt\n")
with salt.utils.files.fopen(req2b_filename, "w") as f:
f.write("pep8\n")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements1b.txt\n")
with salt.utils.files.fopen(req1b_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("-r requirements2b.txt\n")
with salt.utils.files.fopen(req2b_filename, "w") as f:
f.write("pep8\n")
requirements_list = [req1_filename, req2_filename]
requirements_list = [req1_filename, req2_filename]
ret = self.run_function(
"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 dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install", requirements=requirements_list, bin_env=self.venv_dir
)
try:
self.assertEqual(ret["retcode"], 0)
found = self.pip_successful_install(ret["stdout"])
self.assertTrue(found)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
assert ret["retcode"] == 0
found = self.pip_successful_install(ret["stdout"])
assert found
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_requirements_as_list__absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with VirtualEnv(self.venv_dir):
req1_filename = os.path.join(self.venv_dir, "requirements.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req1_filename = os.path.join(self.venv_dir, "requirements.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8\n")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8\n")
requirements_list = [req1_filename, req2_filename]
requirements_list = [req1_filename, req2_filename]
ret = self.run_function(
"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 dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install", requirements=requirements_list, bin_env=self.venv_dir
)
try:
self.assertEqual(ret["retcode"], 0)
found = self.pip_successful_install(ret["stdout"])
self.assertTrue(found)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
assert ret["retcode"] == 0
found = self.pip_successful_install(ret["stdout"])
assert found
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_requirements_as_list__non_absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with 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"
req2_filename = "requirements2.txt"
req_cwd = self.venv_dir
req1_filename = "requirements.txt"
req2_filename = "requirements2.txt"
req_cwd = self.venv_dir
req1_filepath = os.path.join(req_cwd, req1_filename)
req2_filepath = os.path.join(req_cwd, req2_filename)
req1_filepath = os.path.join(req_cwd, req1_filename)
req2_filepath = os.path.join(req_cwd, req2_filename)
with salt.utils.files.fopen(req1_filepath, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filepath, "w") as f:
f.write("pep8\n")
with salt.utils.files.fopen(req1_filepath, "w") as f:
f.write("irc3-plugins-test\n")
with salt.utils.files.fopen(req2_filepath, "w") as f:
f.write("pep8\n")
requirements_list = [req1_filename, req2_filename]
requirements_list = [req1_filename, req2_filename]
ret = self.run_function(
"pip.install",
requirements=requirements_list,
bin_env=self.venv_dir,
cwd=req_cwd,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install",
requirements=requirements_list,
bin_env=self.venv_dir,
cwd=req_cwd,
)
try:
self.assertEqual(ret["retcode"], 0)
found = self.pip_successful_install(ret["stdout"])
self.assertTrue(found)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
assert ret["retcode"] == 0
found = self.pip_successful_install(ret["stdout"])
assert found
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_chained_requirements__absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with 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")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
req1_filename = os.path.join(self.venv_dir, "requirements.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8")
ret = self.run_function(
"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 dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"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 dictionary."
" Output:\n{}".format(ret)
)
try:
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))
)
try:
assert ret["retcode"] == 0
assert "installed pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_chained_requirements__non_absolute_file_path(self):
self._create_virtualenv(self.venv_dir)
with VirtualEnv(self.venv_dir):
# Create a requirements file that depends on another one.
req_basepath = self.venv_dir
# Create a requirements file that depends on another one.
req_basepath = self.venv_dir
req1_filename = "requirements.txt"
req2_filename = "requirements2.txt"
req1_filename = "requirements.txt"
req2_filename = "requirements2.txt"
req1_file = os.path.join(self.venv_dir, req1_filename)
req2_file = os.path.join(self.venv_dir, req2_filename)
req1_file = os.path.join(self.venv_dir, req1_filename)
req2_file = os.path.join(self.venv_dir, req2_filename)
with salt.utils.files.fopen(req1_file, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_file, "w") as f:
f.write("pep8")
with salt.utils.files.fopen(req1_file, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_file, "w") as f:
f.write("pep8")
ret = self.run_function(
"pip.install",
requirements=req1_filename,
cwd=req_basepath,
bin_env=self.venv_dir,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install",
requirements=req1_filename,
cwd=req_basepath,
bin_env=self.venv_dir,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
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))
)
try:
assert ret["retcode"] == 0
assert "installed pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_issue_4805_nested_requirements(self):
self._create_virtualenv(self.venv_dir)
with VirtualEnv(self.venv_dir):
# Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, "requirements.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8")
# Create a requirements file that depends on another one.
req1_filename = os.path.join(self.venv_dir, "requirements.txt")
req2_filename = os.path.join(self.venv_dir, "requirements2.txt")
with salt.utils.files.fopen(req1_filename, "w") as f:
f.write("-r requirements2.txt")
with salt.utils.files.fopen(req2_filename, "w") as f:
f.write("pep8")
ret = self.run_function(
"pip.install",
requirements=req1_filename,
bin_env=self.venv_dir,
timeout=300,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
ret = self.run_function(
"pip.install",
requirements=req1_filename,
bin_env=self.venv_dir,
timeout=300,
)
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))
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
assert "installed pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_pip_uninstall(self):
# Let's create the testing virtualenv
self._create_virtualenv(self.venv_dir)
ret = self.run_function("pip.install", ["pep8"], bin_env=self.venv_dir)
with VirtualEnv(self.venv_dir):
ret = self.run_function("pip.install", ["pep8"], bin_env=self.venv_dir)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" 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("pip.uninstall", ["pep8"], bin_env=self.venv_dir)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
assert "installed pep8" in 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("pip.uninstall", ["pep8"], bin_env=self.venv_dir)
if not isinstance(ret, dict):
self.fail(
"The 'pip.uninstall' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.uninstall' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
self.assertEqual(ret["retcode"], 0)
self.assertIn("uninstalled pep8", ret["stdout"])
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
try:
assert ret["retcode"] == 0
assert "uninstalled pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_pip_install_upgrade(self):
# Create the testing virtualenv
self._create_virtualenv(self.venv_dir)
ret = self.run_function("pip.install", ["pep8==1.3.4"], bin_env=self.venv_dir)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
with VirtualEnv(self.venv_dir):
ret = self.run_function(
"pip.install", ["pep8==1.3.4"], bin_env=self.venv_dir
)
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))
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
assert "installed pep8" in 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(
"pip.install", ["pep8"], bin_env=self.venv_dir, upgrade=True
)
ret = self.run_function(
"pip.install", ["pep8"], bin_env=self.venv_dir, upgrade=True
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
assert "installed pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(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("pip.uninstall", ["pep8"], bin_env=self.venv_dir)
ret = self.run_function("pip.uninstall", ["pep8"], bin_env=self.venv_dir)
if not isinstance(ret, dict):
self.fail(
"The 'pip.uninstall' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.uninstall' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
self.assertEqual(ret["retcode"], 0)
self.assertIn("uninstalled pep8", ret["stdout"])
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
try:
assert ret["retcode"] == 0
assert "uninstalled pep8" in ret["stdout"]
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_pip_install_multiple_editables(self):
@ -519,34 +478,37 @@ class PipModuleTest(ModuleCase):
]
# Create the testing virtualenv
self._create_virtualenv(self.venv_dir)
ret = self.run_function(
"pip.install",
[],
editable="{}".format(",".join(editables)),
bin_env=self.venv_dir,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
with VirtualEnv(self.venv_dir):
ret = self.run_function(
"pip.install",
[],
editable="{}".format(",".join(editables)),
bin_env=self.venv_dir,
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
self.assertEqual(ret["retcode"], 0)
for package in ("iStr", "SaltTesting"):
self.assertRegex(
ret["stdout"],
r"(?:.*)(Successfully installed)(?:.*)({})(?:.*)".format(package),
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
for package in ("iStr", "SaltTesting"):
match = re.search(
r"(?:.*)(Successfully installed)(?:.*)({})(?:.*)".format(
package
),
ret["stdout"],
)
assert match is not None
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.slow_test
def test_pip_install_multiple_editables_and_pkgs(self):
@ -556,34 +518,37 @@ class PipModuleTest(ModuleCase):
]
# Create the testing virtualenv
self._create_virtualenv(self.venv_dir)
ret = self.run_function(
"pip.install",
["pep8"],
editable="{}".format(",".join(editables)),
bin_env=self.venv_dir,
)
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
with VirtualEnv(self.venv_dir):
ret = self.run_function(
"pip.install",
["pep8"],
editable="{}".format(",".join(editables)),
bin_env=self.venv_dir,
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
self.assertEqual(ret["retcode"], 0)
for package in ("iStr", "SaltTesting", "pep8"):
self.assertRegex(
ret["stdout"],
r"(?:.*)(Successfully installed)(?:.*)({})(?:.*)".format(package),
if not isinstance(ret, dict):
self.fail(
"The 'pip.install' command did not return the excepted dictionary."
" Output:\n{}".format(ret)
)
try:
if self._check_download_error(ret["stdout"]):
self.skipTest("Test skipped due to pip download error")
assert ret["retcode"] == 0
for package in ("iStr", "SaltTesting", "pep8"):
match = re.search(
r"(?:.*)(Successfully installed)(?:.*)({})(?:.*)".format(
package
),
ret["stdout"],
)
assert match is not None
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
except KeyError as exc:
self.fail(
"The returned dictionary is missing an expected key. Error: '{}'."
" Dictionary: {}".format(exc, pprint.pformat(ret))
)
@pytest.mark.skipif(
shutil.which("/bin/pip3") is None, reason="Could not find /bin/pip3"