Skip to content

Commit

Permalink
Have get_platform_from_task_def to raise an error if platform == None
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Oct 26, 2021
1 parent bc6195c commit 1dfd7d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cylc/rose/platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
17 changes: 17 additions & 0 deletions tests/test_platform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -125,6 +126,8 @@ def fake_flow():
[[qux]]
[[[remote]]]
host = cheese
[[kanga]]
platform = $(echo "myplatform")
[[BAR]]
platform = milk
[[child_of_bar]]
Expand Down Expand Up @@ -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',
[
Expand Down

0 comments on commit 1dfd7d3

Please sign in to comment.