Skip to content

Commit 1b84cbb

Browse files
authored
Merge pull request #1813 from rfbgo/fix_utility_base_mock
fix mock util
2 parents 0252411 + 3559a9f commit 1b84cbb

1 file changed

Lines changed: 20 additions & 27 deletions

File tree

‎lib/ramble/ramble/test/test_utility_base.py‎

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# except according to those terms.
88

99
from ramble.repository import ObjectTypes, get
10+
from ramble.toolkit import UtilityBase, env_append, env_prepend, provides_executable, variable
1011

1112

1213
def test_utility_base_validate_exact_version_via_vcs(monkeypatch):
@@ -252,23 +253,24 @@ class MockResult:
252253
assert spack_inst.availability_error is None
253254

254255

255-
class _MockUtility(get("spack", ObjectTypes.utilities).__class__): # type: ignore
256+
class _MockUtility(UtilityBase):
256257
name = "mock_util"
257-
class_variants = {
258-
"dummy_variant": {"name": "dummy_variant", "default": "True", "description": "dummy"}
259-
}
260-
env_prepends = {"default": [{"var": "PATH", "value": "/mock/path"}]}
261-
env_appends = {"default": [{"var": "LD_LIBRARY_PATH", "value": "/mock/lib"}]}
262-
provided_executables = {
263-
"mock_exe_no_ver": [{"executable": "mock_exe_no_ver"}],
264-
"mock_exe_with_ver": [
265-
{
266-
"executable": "mock_exe_with_ver",
267-
"version_cmd": "mock_exe_with_ver --version",
268-
"version_regex": r"Version (.*)",
269-
}
270-
],
271-
}
258+
259+
variable("path", default="system", description="Path to mock_util", scoped=True)
260+
env_prepend("PATH", "/mock/path")
261+
env_append("LD_LIBRARY_PATH", "/mock/lib")
262+
263+
264+
class _MockUtilityNoVersion(_MockUtility):
265+
provides_executable("mock_exe_no_ver")
266+
267+
268+
class _MockUtilityWithVersion(_MockUtility):
269+
provides_executable(
270+
"mock_exe_with_ver",
271+
version_cmd="mock_exe_with_ver --version",
272+
version_regex=r"Version (.*)",
273+
)
272274

273275

274276
def test_utility_base_variants():
@@ -279,7 +281,7 @@ def test_utility_base_variants():
279281

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

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

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

294-
original = inst.provided_executables
295-
inst.provided_executables = {"mock_exe_no_ver": original["mock_exe_no_ver"]}
296-
297296
res = inst.validate_versions(exact_version="1.0.0")
298297
assert res is False
299298
assert "but no version command is defined" in inst.availability_error
300299

301-
inst.provided_executables = original
302-
303300

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

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

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

328-
original = inst.provided_executables
329-
inst.provided_executables = {"mock_exe_with_ver": original["mock_exe_with_ver"]}
330-
331325
res = inst.validate_versions(exact_version="1.0.0")
332326
assert res is True
333-
inst.provided_executables = original
334327

335328

336329
def test_utility_base_get_env_workspace_modifications():

0 commit comments

Comments
 (0)