Skip to content

Commit

Permalink
Load modules check: Remove symbolic version names from avail output
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-basevi committed Aug 13, 2024
1 parent b69a0db commit bfecc12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions payu/envmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def check_modulefile(modulefile: str) -> None:
modules_avail = [line for line in output.strip().splitlines()
if not (line.startswith('/') and line.endswith(':'))]

# Remove () from end of modulefiles if they exist, e.g. (default)
modules_avail = [mod.rsplit('(', 1)[0] for mod in modules_avail]

# Modules are used for finding model executable paths - so check
# for unique module, or an exact match for the modulefile name
if len(modules_avail) > 1 and modules_avail.count(modulefile) != 1:
Expand Down
35 changes: 35 additions & 0 deletions test/test_envmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def test_check_modulefile_without_version(mock_module_cmd):
mock_module_cmd.return_value.stderr = """/path/to/modulefiles:
test-module/1.0.0
test-module/2.0.0
test-module/3.0.1
"""

# Expect an error raised
with pytest.raises(ValueError) as exc_info:
check_modulefile('test-module')
exc_info.value.startswith(
"There are multiple modules available for test-module"
)

# Mock module avail command use debug in name
mock_module_cmd.return_value.stderr = """/path/to/modulefiles:
test-module/1.0.0
test-module/1.0.0-debug
"""

# Expect an error raised
Expand All @@ -42,6 +56,27 @@ def test_check_modulefile_exact_match(mock_module_cmd):
check_modulefile('test-module/1.0.0')


@patch('payu.envmod.run_module_cmd')
def test_check_modulefile_exact_match_with_symbolic_version(mock_module_cmd):
# Mock module avail command
mock_module_cmd.return_value.stderr = """/path/to/modulefiles:
test-module/1.0.0(default)
test-module/1.0.0-debug
"""

# Test runs without an error
check_modulefile('test-module/1.0.0')

# Rerun test with another symbolic version/alias other than default
mock_module_cmd.return_value.stderr = """/path/to/modulefiles:
test-module/1.0.0(some_symbolic_name_or_alias)
test-module/1.0.0-debug
"""

# Test runs without an error
check_modulefile('test-module/1.0.0')


@patch('payu.envmod.run_module_cmd')
def test_check_modulefile_multiple_modules(mock_module_cmd):
# Mock module avail command
Expand Down

0 comments on commit bfecc12

Please sign in to comment.