Skip to content

Commit

Permalink
Make tests compatible with venv bundle
Browse files Browse the repository at this point in the history
Co-authored-by: cmcmarrow <[email protected]>
  • Loading branch information
m-czernek and cmcmarrow authored Aug 7, 2024
1 parent 63ff8ce commit 25c3df7
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 60 deletions.
1 change: 1 addition & 0 deletions tests/pytests/functional/modules/test_sdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def minion_config_overrides():
}


@pytest.mark.skip("Great module migration")
@pytest.mark.parametrize(
"expected_value",
(
Expand Down
2 changes: 1 addition & 1 deletion tests/pytests/functional/modules/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import salt.modules.yaml
import salt.utils.yamllint

YAMLLINT_AVAILABLE = True
YAMLLINT_AVAILABLE = salt.utils.yamllint.has_yamllint()
except ImportError:
YAMLLINT_AVAILABLE = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from tests.support import mock
from tests.support.helpers import PatchedEnviron

LD_LIBRARY_PATH = ""
if os.environ.get('VIRTUAL_ENV'):
LD_LIBRARY_PATH = f"{os.environ.get('VIRTUAL_ENV')}/lib"

@pytest.fixture(params=("LD_LIBRARY_PATH", "LIBPATH"))
def envvar(request):
Expand All @@ -17,9 +20,14 @@ def envvar(request):
@pytest.fixture
def meipass(envvar):
with mock.patch("salt.utils.pyinstaller.rthooks._overrides.sys") as patched_sys:
patched_sys._MEIPASS = "{}_VALUE".format(envvar)
assert overrides.sys._MEIPASS == "{}_VALUE".format(envvar)
yield "{}_VALUE".format(envvar)
ld_path_mock_val = f"{envvar}_VALUE"
if envvar == "LD_LIBRARY_PATH" and LD_LIBRARY_PATH:
# venv-minion python wrapper hardcodes LD_LIB_PATH that
# we cannot overwrite from the testsuite
ld_path_mock_val = LD_LIBRARY_PATH
patched_sys._MEIPASS = ld_path_mock_val
assert overrides.sys._MEIPASS == ld_path_mock_val
yield ld_path_mock_val
assert not hasattr(sys, "_MEIPASS")
assert not hasattr(overrides.sys, "_MEIPASS")

Expand Down Expand Up @@ -111,7 +119,8 @@ def test_vt_terminal_environ_cleanup(envvar, meipass):
returned_env = json.loads(buffer_o)
assert returned_env != original_env
assert envvar in returned_env
assert returned_env[envvar] == ""
envvar_value = LD_LIBRARY_PATH if envvar == "LD_LIBRARY_PATH" else ""
assert returned_env[envvar] == envvar_value


def test_vt_terminal_environ_cleanup_passed_directly_not_removed(envvar, meipass):
Expand Down Expand Up @@ -139,4 +148,7 @@ def test_vt_terminal_environ_cleanup_passed_directly_not_removed(envvar, meipass
returned_env = json.loads(buffer_o)
assert returned_env != original_env
assert envvar in returned_env
assert returned_env[envvar] == envvar
envvar_val = envvar
if LD_LIBRARY_PATH and envvar == "LD_LIBRARY_PATH":
envvar_val = LD_LIBRARY_PATH
assert returned_env[envvar] == envvar_val
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from tests.support import mock
from tests.support.helpers import PatchedEnviron

LD_LIBRARY_PATH = ""
if os.environ.get('VIRTUAL_ENV'):
LD_LIBRARY_PATH = f"{os.environ.get('VIRTUAL_ENV')}/lib"

@pytest.fixture(params=("LD_LIBRARY_PATH", "LIBPATH"))
def envvar(request):
Expand All @@ -18,9 +21,14 @@ def envvar(request):
@pytest.fixture
def meipass(envvar):
with mock.patch("salt.utils.pyinstaller.rthooks._overrides.sys") as patched_sys:
patched_sys._MEIPASS = "{}_VALUE".format(envvar)
assert overrides.sys._MEIPASS == "{}_VALUE".format(envvar)
yield "{}_VALUE".format(envvar)
ld_path_mock_val = f"{envvar}_VALUE"
if envvar == "LD_LIBRARY_PATH" and LD_LIBRARY_PATH:
# venv-minion python wrapper hardcodes LD_LIB_PATH that
# we cannot overwrite from the testsuite
ld_path_mock_val = LD_LIBRARY_PATH
patched_sys._MEIPASS = ld_path_mock_val
assert overrides.sys._MEIPASS == ld_path_mock_val
yield ld_path_mock_val
assert not hasattr(sys, "_MEIPASS")
assert not hasattr(overrides.sys, "_MEIPASS")

Expand Down Expand Up @@ -88,7 +96,8 @@ def test_subprocess_popen_environ_cleanup(envvar, meipass):
returned_env = json.loads(stdout)
assert returned_env != original_env
assert envvar in returned_env
assert returned_env[envvar] == ""
envvar_value = LD_LIBRARY_PATH if envvar == "LD_LIBRARY_PATH" else ""
assert returned_env[envvar] == envvar_value


def test_subprocess_popen_environ_cleanup_passed_directly_not_removed(envvar, meipass):
Expand All @@ -108,4 +117,7 @@ def test_subprocess_popen_environ_cleanup_passed_directly_not_removed(envvar, me
returned_env = json.loads(stdout)
assert returned_env != original_env
assert envvar in returned_env
assert returned_env[envvar] == envvar
envvar_val = envvar
if LD_LIBRARY_PATH and envvar == "LD_LIBRARY_PATH":
envvar_val = LD_LIBRARY_PATH
assert returned_env[envvar] == envvar_val
2 changes: 1 addition & 1 deletion tests/pytests/functional/utils/yamllint/test_yamllint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
import salt.utils.yamllint as yamllint

YAMLLINT_AVAILABLE = True
YAMLLINT_AVAILABLE = yamllint.has_yamllint()
except ImportError:
YAMLLINT_AVAILABLE = False

Expand Down
Loading

0 comments on commit 25c3df7

Please sign in to comment.