diff --git a/payu/envmod.py b/payu/envmod.py index 57128f5f..2b7c98f3 100644 --- a/payu/envmod.py +++ b/payu/envmod.py @@ -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: diff --git a/test/test_envmod.py b/test/test_envmod.py index 36103c9e..b911d6e6 100644 --- a/test/test_envmod.py +++ b/test/test_envmod.py @@ -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 @@ -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