Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions lib/ramble/ramble/test/test_utility_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# except according to those terms.

from ramble.repository import ObjectTypes, get
from ramble.toolkit import UtilityBase, env_append, env_prepend, provides_executable, variable


def test_utility_base_validate_exact_version_via_vcs(monkeypatch):
Expand Down Expand Up @@ -252,23 +253,24 @@ class MockResult:
assert spack_inst.availability_error is None


class _MockUtility(get("spack", ObjectTypes.utilities).__class__): # type: ignore
class _MockUtility(UtilityBase):
name = "mock_util"
class_variants = {
"dummy_variant": {"name": "dummy_variant", "default": "True", "description": "dummy"}
}
env_prepends = {"default": [{"var": "PATH", "value": "/mock/path"}]}
env_appends = {"default": [{"var": "LD_LIBRARY_PATH", "value": "/mock/lib"}]}
provided_executables = {
"mock_exe_no_ver": [{"executable": "mock_exe_no_ver"}],
"mock_exe_with_ver": [
{
"executable": "mock_exe_with_ver",
"version_cmd": "mock_exe_with_ver --version",
"version_regex": r"Version (.*)",
}
],
}

variable("path", default="system", description="Path to mock_util", scoped=True)
env_prepend("PATH", "/mock/path")
env_append("LD_LIBRARY_PATH", "/mock/lib")


class _MockUtilityNoVersion(_MockUtility):
provides_executable("mock_exe_no_ver")


class _MockUtilityWithVersion(_MockUtility):
provides_executable(
"mock_exe_with_ver",
version_cmd="mock_exe_with_ver --version",
version_regex=r"Version (.*)",
)


def test_utility_base_variants():
Expand All @@ -279,7 +281,7 @@ def test_utility_base_variants():

def test_utility_base_validate_versions_no_version_cmd(monkeypatch):
"""Test lines 262-263: exact_version requested but no version_cmd."""
inst = _MockUtility("/mock/path")
inst = _MockUtilityNoVersion("/mock/path")

def mock_shutil_which(cmd, *args, **kwargs):
return "/mock/path/mock_exe_no_ver"
Expand All @@ -291,19 +293,14 @@ def mock_check_vcs(self, exec_path, exact_version): # noqa: E501

monkeypatch.setattr(_MockUtility, "_check_exact_match_via_vcs", mock_check_vcs)

original = inst.provided_executables
inst.provided_executables = {"mock_exe_no_ver": original["mock_exe_no_ver"]}

res = inst.validate_versions(exact_version="1.0.0")
assert res is False
assert "but no version command is defined" in inst.availability_error

inst.provided_executables = original


def test_utility_base_validate_versions_regex_fails_but_vcs_true(monkeypatch):
"""Test lines 212-217: regex fails but exact_match_via_vcs is True."""
inst = _MockUtility("/mock/path")
inst = _MockUtilityWithVersion("/mock/path")

def mock_shutil_which(cmd, *args, **kwargs):
return "/mock/path/mock_exe_with_ver"
Expand All @@ -325,12 +322,8 @@ class MockResult:

monkeypatch.setattr("subprocess.run", mock_subprocess_run)

original = inst.provided_executables
inst.provided_executables = {"mock_exe_with_ver": original["mock_exe_with_ver"]}

res = inst.validate_versions(exact_version="1.0.0")
assert res is True
inst.provided_executables = original


def test_utility_base_get_env_workspace_modifications():
Expand Down
Loading