diff --git a/cylc/rose/platform_utils.py b/cylc/rose/platform_utils.py index 86eeac98..1994b535 100644 --- a/cylc/rose/platform_utils.py +++ b/cylc/rose/platform_utils.py @@ -22,6 +22,7 @@ from typing import Dict, Any from cylc.flow.config import WorkflowConfig +from cylc.flow.exceptions import PlatformLookupError from cylc.flow.rundb import CylcWorkflowDAO from cylc.flow.workflow_files import parse_reg from cylc.flow.platforms import get_platform @@ -47,6 +48,11 @@ def get_platform_from_task_def( # Get entire task spec to allow Cylc 7 platform from host guessing. task_spec = config.pcfg.get(['runtime', task]) platform = get_platform(task_spec) + if platform is None: + raise PlatformLookupError( + 'Platform lookup failed because the platform definition for' + f' task {task} is {task_spec["platform"]}.' + ) return platform diff --git a/tests/test_platform_utils.py b/tests/test_platform_utils.py index fb6661c1..046c4d44 100644 --- a/tests/test_platform_utils.py +++ b/tests/test_platform_utils.py @@ -25,6 +25,7 @@ from shutil import rmtree from subprocess import run from uuid import uuid4 +from cylc.flow.exceptions import PlatformLookupError from cylc.rose.platform_utils import ( get_platform_from_task_def, @@ -125,6 +126,8 @@ def fake_flow(): [[qux]] [[[remote]]] host = cheese + [[kanga]] + platform = $(echo "myplatform") [[BAR]] platform = milk [[child_of_bar]] @@ -180,6 +183,20 @@ def test_get_platform_from_task_def( assert platform['name'] == expected_platform_n +def test_get_platform_from_task_def_raises( + mock_glbl_cfg, fake_flow +): + """Test getting platform from task definition. + + This is approaching an integration test, because + although it's only testing one unit of Cylc Rose, that unit + is calling lots of Cylc Parts, which aren't mocked. + """ + mock_glbl_cfg(*MOCK_GLBL_CFG) + with pytest.raises(PlatformLookupError, match='Platform lookup failed.*'): + get_platform_from_task_def(fake_flow[0], 'kanga') + + @pytest.mark.parametrize( 'task, cycle, expect', [