| 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 |
"""Test logic in cylc-stop script.""" |
| 18 |
|
| 19 |
import pytest |
| 20 |
from typing import TYPE_CHECKING, Optional, Tuple, Type |
| 21 |
|
| 22 |
from cylc.flow.exceptions import InputError |
| 23 |
from cylc.flow.option_parsers import Options |
| 24 |
from cylc.flow.scripts.stop import get_option_parser, _validate |
| 25 |
|
| 26 |
|
| 27 |
if TYPE_CHECKING: |
| 28 |
from optparse import Values |
| 29 |
|
| 30 |
|
| 31 |
Opts = Options(get_option_parser()) |
| 32 |
|
| 33 |
|
| 34 |
@pytest.mark.parametrize( |
| 35 |
'options, stop_task, stop_cycle, globs, expected_err', |
| 36 |
[ |
| 37 |
( |
| 38 |
Opts(), |
| 39 |
None, |
| 40 |
None, |
| 41 |
None, |
| 42 |
None, |
| 43 |
), |
| 44 |
( |
| 45 |
Opts(kill=True), |
| 46 |
None, |
| 47 |
'10', |
| 48 |
None, |
| 49 |
(InputError, "--kill is not compatible with stop-cycle") |
| 50 |
), |
| 51 |
( |
| 52 |
Opts(), |
| 53 |
'10/foo', |
| 54 |
'10', |
| 55 |
None, |
| 56 |
(InputError, "stop-task is not compatible with stop-cycle") |
| 57 |
), |
| 58 |
( |
| 59 |
Opts(kill=True, now=True), |
| 60 |
None, |
| 61 |
None, |
| 62 |
None, |
| 63 |
(InputError, "--kill is not compatible with --now") |
| 64 |
), |
| 65 |
( |
| 66 |
Opts(flow_num=2, max_polls=2), |
| 67 |
None, |
| 68 |
None, |
| 69 |
None, |
| 70 |
(InputError, "--flow is not compatible with --max-polls") |
| 71 |
), |
| 72 |
( |
| 73 |
Opts(flow_num=2), |
| 74 |
None, |
| 75 |
None, |
| 76 |
'*', |
| 77 |
(InputError, "--flow is not compatible with task IDs") |
| 78 |
), |
| 79 |
] |
| 80 |
) |
| 81 |
def test_validate( |
| 82 |
options: 'Values', |
| 83 |
stop_task: str, |
| 84 |
stop_cycle: str, |
| 85 |
globs: str, |
| 86 |
expected_err: Optional[Tuple[Type[Exception], str]]): |
| 87 |
|
| 88 |
if expected_err: |
| 89 |
err, msg = expected_err |
| 90 |
with pytest.raises(err) as exc: |
| 91 |
_validate(options, stop_task, stop_cycle, globs) |
| 92 |
assert msg in str(exc.value) |
| 93 |
else: |
| 94 |
_validate(options, stop_task, stop_cycle, globs) |