mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Make tests compatible with venv bundle
This commit is contained in:
parent
b912817240
commit
bf580e6698
2 changed files with 46 additions and 21 deletions
|
@ -10,6 +10,10 @@ import salt.utils.platform
|
|||
from salt.exceptions import CommandExecutionError
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
TARGET = []
|
||||
if os.environ.get('VENV_PIP_TARGET'):
|
||||
TARGET = ["--target", os.environ.get('VENV_PIP_TARGET')]
|
||||
|
||||
|
||||
class FakeFopen:
|
||||
def __init__(self, filename):
|
||||
|
@ -97,6 +101,7 @@ def test_install_frozen_app(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -118,6 +123,7 @@ def test_install_source_app(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -138,6 +144,7 @@ def test_fix4361(python_binary):
|
|||
"install",
|
||||
"--requirement",
|
||||
"requirements.txt",
|
||||
*TARGET,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
expected_cmd,
|
||||
|
@ -164,7 +171,7 @@ def test_install_multiple_editable(python_binary):
|
|||
"git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting",
|
||||
]
|
||||
|
||||
expected = [*python_binary, "install"]
|
||||
expected = [*python_binary, "install", *TARGET]
|
||||
for item in editables:
|
||||
expected.extend(["--editable", item])
|
||||
|
||||
|
@ -200,7 +207,7 @@ def test_install_multiple_pkgs_and_editables(python_binary):
|
|||
"git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting",
|
||||
]
|
||||
|
||||
expected = [*python_binary, "install"]
|
||||
expected = [*python_binary, "install", *TARGET]
|
||||
expected.extend(pkgs)
|
||||
for item in editables:
|
||||
expected.extend(["--editable", item])
|
||||
|
@ -236,6 +243,7 @@ def test_install_multiple_pkgs_and_editables(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
pkgs[0],
|
||||
"--editable",
|
||||
editables[0],
|
||||
|
@ -263,7 +271,7 @@ def test_issue5940_install_multiple_pip_mirrors(python_binary):
|
|||
expected = [*python_binary, "install", "--use-mirrors"]
|
||||
for item in mirrors:
|
||||
expected.extend(["--mirrors", item])
|
||||
expected.append("pep8")
|
||||
expected = [*expected, *TARGET, "pep8"]
|
||||
|
||||
# Passing mirrors as a list
|
||||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
|
@ -295,6 +303,7 @@ def test_issue5940_install_multiple_pip_mirrors(python_binary):
|
|||
"--use-mirrors",
|
||||
"--mirrors",
|
||||
mirrors[0],
|
||||
*TARGET,
|
||||
"pep8",
|
||||
]
|
||||
|
||||
|
@ -322,7 +331,7 @@ def test_install_with_multiple_find_links(python_binary):
|
|||
expected = [*python_binary, "install"]
|
||||
for item in find_links:
|
||||
expected.extend(["--find-links", item])
|
||||
expected.append(pkg)
|
||||
expected = [*expected, *TARGET, pkg]
|
||||
|
||||
# Passing mirrors as a list
|
||||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
|
@ -365,6 +374,7 @@ def test_install_with_multiple_find_links(python_binary):
|
|||
"install",
|
||||
"--find-links",
|
||||
find_links[0],
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
|
||||
|
@ -430,6 +440,7 @@ def test_install_cached_requirements_used(python_binary):
|
|||
"install",
|
||||
"--requirement",
|
||||
"my_cached_reqs",
|
||||
*TARGET,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
|
@ -486,6 +497,7 @@ def test_install_log_argument_in_resulting_command(python_binary, tmp_path):
|
|||
"install",
|
||||
"--log",
|
||||
log_path,
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -516,7 +528,7 @@ def test_install_timeout_argument_in_resulting_command(python_binary):
|
|||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, timeout=10)
|
||||
mock.assert_called_with(
|
||||
expected + [10, pkg],
|
||||
expected + [10, *TARGET, pkg],
|
||||
saltenv="base",
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -528,7 +540,7 @@ def test_install_timeout_argument_in_resulting_command(python_binary):
|
|||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, timeout="10")
|
||||
mock.assert_called_with(
|
||||
expected + ["10", pkg],
|
||||
expected + ["10", *TARGET, pkg],
|
||||
saltenv="base",
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -552,6 +564,7 @@ def test_install_index_url_argument_in_resulting_command(python_binary):
|
|||
"install",
|
||||
"--index-url",
|
||||
index_url,
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -574,6 +587,7 @@ def test_install_extra_index_url_argument_in_resulting_command(python_binary):
|
|||
"install",
|
||||
"--extra-index-url",
|
||||
extra_index_url,
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -590,7 +604,7 @@ def test_install_no_index_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, no_index=True)
|
||||
expected = [*python_binary, "install", "--no-index", pkg]
|
||||
expected = [*python_binary, "install", "--no-index", *TARGET, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -606,7 +620,7 @@ def test_install_build_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, build=build)
|
||||
expected = [*python_binary, "install", "--build", build, pkg]
|
||||
expected = [*python_binary, "install", "--build", build, *TARGET, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -641,6 +655,7 @@ def test_install_download_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--download",
|
||||
download,
|
||||
pkg,
|
||||
|
@ -659,7 +674,7 @@ def test_install_no_download_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, no_download=True)
|
||||
expected = [*python_binary, "install", "--no-download", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, "--no-download", pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -686,6 +701,7 @@ def test_install_download_cache_dir_arguments_in_resulting_command(python_binary
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
cmd_arg,
|
||||
download_cache,
|
||||
pkg,
|
||||
|
@ -715,7 +731,7 @@ def test_install_source_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, source=source)
|
||||
expected = [*python_binary, "install", "--source", source, pkg]
|
||||
expected = [*python_binary, "install", *TARGET, "--source", source, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -734,6 +750,7 @@ def test_install_exists_action_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--exists-action",
|
||||
action,
|
||||
pkg,
|
||||
|
@ -756,7 +773,7 @@ def test_install_install_options_argument_in_resulting_command(python_binary):
|
|||
install_options = ["--exec-prefix=/foo/bar", "--install-scripts=/foo/bar/bin"]
|
||||
pkg = "pep8"
|
||||
|
||||
expected = [*python_binary, "install"]
|
||||
expected = [*python_binary, "install", *TARGET]
|
||||
for item in install_options:
|
||||
expected.extend(["--install-option", item])
|
||||
expected.append(pkg)
|
||||
|
@ -792,6 +809,7 @@ def test_install_install_options_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--install-option",
|
||||
install_options[0],
|
||||
pkg,
|
||||
|
@ -809,7 +827,7 @@ def test_install_global_options_argument_in_resulting_command(python_binary):
|
|||
global_options = ["--quiet", "--no-user-cfg"]
|
||||
pkg = "pep8"
|
||||
|
||||
expected = [*python_binary, "install"]
|
||||
expected = [*python_binary, "install", *TARGET]
|
||||
for item in global_options:
|
||||
expected.extend(["--global-option", item])
|
||||
expected.append(pkg)
|
||||
|
@ -845,6 +863,7 @@ def test_install_global_options_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--global-option",
|
||||
global_options[0],
|
||||
pkg,
|
||||
|
@ -863,7 +882,7 @@ def test_install_upgrade_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, upgrade=True)
|
||||
expected = [*python_binary, "install", "--upgrade", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, "--upgrade", pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -881,6 +900,7 @@ def test_install_force_reinstall_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--force-reinstall",
|
||||
pkg,
|
||||
]
|
||||
|
@ -901,6 +921,7 @@ def test_install_ignore_installed_argument_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
"--ignore-installed",
|
||||
pkg,
|
||||
]
|
||||
|
@ -918,7 +939,7 @@ def test_install_no_deps_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, no_deps=True)
|
||||
expected = [*python_binary, "install", "--no-deps", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, "--no-deps", pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -933,7 +954,7 @@ def test_install_no_install_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, no_install=True)
|
||||
expected = [*python_binary, "install", "--no-install", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, "--no-install", pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -949,7 +970,7 @@ def test_install_proxy_argument_in_resulting_command(python_binary):
|
|||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
pip.install(pkg, proxy=proxy)
|
||||
expected = [*python_binary, "install", "--proxy", proxy, pkg]
|
||||
expected = [*python_binary, "install", "--proxy", proxy, *TARGET, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -976,7 +997,7 @@ def test_install_proxy_false_argument_in_resulting_command(python_binary):
|
|||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
with patch.dict(pip.__opts__, config_mock):
|
||||
pip.install(pkg, proxy=proxy)
|
||||
expected = [*python_binary, "install", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -1007,6 +1028,7 @@ def test_install_global_proxy_in_resulting_command(python_binary):
|
|||
"install",
|
||||
"--proxy",
|
||||
proxy,
|
||||
*TARGET,
|
||||
pkg,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
|
@ -1027,6 +1049,7 @@ def test_install_multiple_requirements_arguments_in_resulting_command(python_bin
|
|||
expected = [*python_binary, "install"]
|
||||
for item in cached_reqs:
|
||||
expected.extend(["--requirement", item])
|
||||
expected.extend(TARGET)
|
||||
|
||||
# Passing option as a list
|
||||
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
|
||||
|
@ -1063,6 +1086,7 @@ def test_install_multiple_requirements_arguments_in_resulting_command(python_bin
|
|||
"install",
|
||||
"--requirement",
|
||||
cached_reqs[0],
|
||||
*TARGET,
|
||||
]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
|
@ -1083,6 +1107,7 @@ def test_install_extra_args_arguments_in_resulting_command(python_binary):
|
|||
expected = [
|
||||
*python_binary,
|
||||
"install",
|
||||
*TARGET,
|
||||
pkg,
|
||||
"--latest-pip-kwarg",
|
||||
"param",
|
||||
|
@ -1599,7 +1624,7 @@ def test_install_pre_argument_in_resulting_command(python_binary):
|
|||
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
|
||||
with patch("salt.modules.pip.version", MagicMock(return_value="1.3")):
|
||||
pip.install(pkg, pre_releases=True)
|
||||
expected = [*python_binary, "install", pkg]
|
||||
expected = [*python_binary, "install", *TARGET, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
@ -1615,7 +1640,7 @@ def test_install_pre_argument_in_resulting_command(python_binary):
|
|||
):
|
||||
with patch("salt.modules.pip._get_pip_bin", MagicMock(return_value=["pip"])):
|
||||
pip.install(pkg, pre_releases=True)
|
||||
expected = ["pip", "install", "--pre", pkg]
|
||||
expected = ["pip", "install", *TARGET, "--pre", pkg]
|
||||
mock_run_all.assert_called_with(
|
||||
expected,
|
||||
saltenv="base",
|
||||
|
|
|
@ -76,7 +76,7 @@ def test_file_server_url_escape(tmp_path):
|
|||
"fileserver_backend": ["roots"],
|
||||
"extension_modules": "",
|
||||
"optimization_order": [
|
||||
0,
|
||||
0, 1
|
||||
],
|
||||
"file_roots": {
|
||||
"base": [fileroot],
|
||||
|
@ -103,7 +103,7 @@ def test_file_server_serve_url_escape(tmp_path):
|
|||
"fileserver_backend": ["roots"],
|
||||
"extension_modules": "",
|
||||
"optimization_order": [
|
||||
0,
|
||||
0, 1
|
||||
],
|
||||
"file_roots": {
|
||||
"base": [fileroot],
|
||||
|
|
Loading…
Add table
Reference in a new issue