| 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 |
import pytest |
| 18 |
from pytest import param |
| 19 |
|
| 20 |
from cylc.flow.option_parsers import Options |
| 21 |
|
| 22 |
from cylc.flow.scripts.validate import ( |
| 23 |
run as validate, |
| 24 |
get_option_parser as validate_gop |
| 25 |
) |
| 26 |
from cylc.flow.scripts.view import ( |
| 27 |
_main as view, |
| 28 |
get_option_parser as view_gop |
| 29 |
) |
| 30 |
from cylc.flow.scripts.graph import ( |
| 31 |
_main as graph, |
| 32 |
get_option_parser as graph_gop |
| 33 |
) |
| 34 |
from cylc.flow.scripts.config import ( |
| 35 |
_main as config, |
| 36 |
get_option_parser as config_gop |
| 37 |
) |
| 38 |
from cylc.flow.scripts.list import ( |
| 39 |
_main as cylclist, |
| 40 |
get_option_parser as list_gop |
| 41 |
) |
| 42 |
|
| 43 |
|
| 44 |
@pytest.fixture(scope='module') |
| 45 |
def _setup(mod_scheduler, mod_flow): |
| 46 |
"""Provide an installed flow with a database to try assorted |
| 47 |
simple Cylc scripts against. |
| 48 |
""" |
| 49 |
conf = { |
| 50 |
'#!jinja2': '', |
| 51 |
'scheduler': { |
| 52 |
'allow implicit tasks': True |
| 53 |
}, |
| 54 |
'scheduling': { |
| 55 |
'graph': { |
| 56 |
'R1': r'{{FOO}}' |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
schd = mod_scheduler(mod_flow(conf), templatevars=['FOO="bar"']) |
| 61 |
yield schd |
| 62 |
|
| 63 |
|
| 64 |
@pytest.mark.parametrize( |
| 65 |
'function, parser, expect', |
| 66 |
( |
| 67 |
param(validate, validate_gop, 'Valid for', id="validate"), |
| 68 |
param(view, view_gop, 'FOO', id="view"), |
| 69 |
param(graph, graph_gop, '1/bar', id='graph'), |
| 70 |
param(config, config_gop, 'R1 = bar', id='config'), |
| 71 |
param(cylclist, list_gop, 'bar', id='list') |
| 72 |
) |
| 73 |
) |
| 74 |
async def test_validate_with_old_tvars( |
| 75 |
_setup, mod_start, capsys, function, parser, expect, |
| 76 |
): |
| 77 |
"""It (A Cylc CLI Command - see parameters) can |
| 78 |
get template vars stored in db. |
| 79 |
|
| 80 |
Else the jinja2 in the config would cause these tasks to fail. |
| 81 |
""" |
| 82 |
parser = parser() |
| 83 |
opts = Options(parser)() |
| 84 |
if function == graph: |
| 85 |
opts.reference = True |
| 86 |
|
| 87 |
async with mod_start(_setup): |
| 88 |
if function in {view, cylclist, graph}: |
| 89 |
await function(opts, _setup.workflow_name) |
| 90 |
else: |
| 91 |
await function(parser, opts, _setup.workflow_name) |
| 92 |
assert expect in capsys.readouterr().out |