| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# Tests that configs can be upgraded from earlier versions of Cylc. |
| 18 |
|
| 19 |
import pytest |
| 20 |
from cylc.flow.cfgspec.workflow import upg, upgrade_param_env_templates |
| 21 |
from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults as ord_dict |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.parametrize( |
| 25 |
'cfg, expected', |
| 26 |
[ |
| 27 |
( # No clashes - order is important: |
| 28 |
{ |
| 29 |
'parameter environment templates': ord_dict([ |
| 30 |
('FOO', 'jupiter'), |
| 31 |
('MOO', 'pluto') |
| 32 |
]), |
| 33 |
'environment': ord_dict([ |
| 34 |
('BAR', 'neptune'), |
| 35 |
('BAZ', 'ares') |
| 36 |
]) |
| 37 |
}, |
| 38 |
{ |
| 39 |
'environment': ord_dict([ |
| 40 |
('FOO', 'jupiter'), |
| 41 |
('MOO', 'pluto'), |
| 42 |
('BAR', 'neptune'), |
| 43 |
('BAZ', 'ares') |
| 44 |
]) |
| 45 |
} |
| 46 |
), |
| 47 |
( # Clashes - environment wins: |
| 48 |
{ |
| 49 |
'parameter environment templates': ord_dict([ |
| 50 |
('FOO', 'jupiter'), |
| 51 |
('BAR', 'neptune') |
| 52 |
]), |
| 53 |
'environment': ord_dict([ |
| 54 |
('FOO', 'zeus'), |
| 55 |
('BAR', 'poseidon') |
| 56 |
]) |
| 57 |
}, |
| 58 |
{ |
| 59 |
'environment': ord_dict([ |
| 60 |
('FOO', 'zeus'), |
| 61 |
('BAR', 'poseidon') |
| 62 |
]) |
| 63 |
} |
| 64 |
), |
| 65 |
( # No environment section: |
| 66 |
{ |
| 67 |
'parameter environment templates': ord_dict([ |
| 68 |
('FOO', 'jupiter'), |
| 69 |
('BAR', 'neptune') |
| 70 |
]) |
| 71 |
}, |
| 72 |
{ |
| 73 |
'environment': ord_dict([ |
| 74 |
('FOO', 'jupiter'), |
| 75 |
('BAR', 'neptune') |
| 76 |
]) |
| 77 |
} |
| 78 |
) |
| 79 |
] |
| 80 |
) |
| 81 |
def test_upgrade_param_env_templates(cfg, expected): |
| 82 |
"""Test that the deprecated [runtime][X][parameter environment templates] |
| 83 |
contents are prepended to [runtime][X][environment], in the correct |
| 84 |
order""" |
| 85 |
|
| 86 |
def _cfg(dic): |
| 87 |
"""Return OrderedDictWithDefaults config populated with values from |
| 88 |
dic (dictionary)""" |
| 89 |
result = ord_dict({ |
| 90 |
'runtime': ord_dict({ |
| 91 |
'<foo>': ord_dict({ |
| 92 |
'script': 'echo whatever' |
| 93 |
}) |
| 94 |
}) |
| 95 |
}) |
| 96 |
if 'parameter environment templates' in dic: |
| 97 |
result['runtime']['<foo>']['parameter environment templates'] = ( |
| 98 |
dic['parameter environment templates'] |
| 99 |
) |
| 100 |
if 'environment' in dic: |
| 101 |
result['runtime']['<foo>']['environment'] = dic['environment'] |
| 102 |
return result |
| 103 |
|
| 104 |
config = _cfg(cfg) |
| 105 |
upgrade_param_env_templates(config, 'flow.cylc') |
| 106 |
assert config == _cfg(expected) |
| 107 |
|
| 108 |
|
| 109 |
@pytest.mark.parametrize( |
| 110 |
'macp, rlim', |
| 111 |
[(16, 'P15'), |
| 112 |
('', '')] |
| 113 |
) |
| 114 |
def test_upgrade_max_active_cycle_points(macp, rlim): |
| 115 |
"""Test that `max active cycle points` is correctly upgraded to |
| 116 |
`runahead limit`.""" |
| 117 |
cfg = { |
| 118 |
'scheduling': {'max active cycle points': macp} |
| 119 |
} |
| 120 |
expected = { |
| 121 |
'scheduling': {'runahead limit': rlim} |
| 122 |
} |
| 123 |
upg(cfg, 'flow.cylc') |
| 124 |
assert cfg == expected |