| 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-release script.""" |
| 18 |
|
| 19 |
from optparse import Values |
| 20 |
import pytest |
| 21 |
from typing import Iterable, Optional, Tuple, Type |
| 22 |
|
| 23 |
from cylc.flow.exceptions import InputError |
| 24 |
from cylc.flow.option_parsers import Options |
| 25 |
from cylc.flow.scripts.release import get_option_parser, _validate |
| 26 |
|
| 27 |
|
| 28 |
Opts = Options(get_option_parser()) |
| 29 |
|
| 30 |
|
| 31 |
@pytest.mark.parametrize( |
| 32 |
'opts, task_globs, expected_err', |
| 33 |
[ |
| 34 |
(Opts(), ['*'], None), |
| 35 |
(Opts(release_all=True), [], None), |
| 36 |
( |
| 37 |
Opts(release_all=True), |
| 38 |
['*'], |
| 39 |
(InputError, "Cannot combine --all with Cycle/Task IDs") |
| 40 |
), |
| 41 |
( |
| 42 |
Opts(), |
| 43 |
[], |
| 44 |
(InputError, "Must define Cycles/Tasks") |
| 45 |
), |
| 46 |
] |
| 47 |
) |
| 48 |
def test_validate( |
| 49 |
opts: Values, |
| 50 |
task_globs: Iterable[str], |
| 51 |
expected_err: Optional[Tuple[Type[Exception], str]]): |
| 52 |
|
| 53 |
if expected_err: |
| 54 |
err, msg = expected_err |
| 55 |
with pytest.raises(err) as exc: |
| 56 |
_validate(opts, *task_globs) |
| 57 |
assert msg in str(exc.value) |
| 58 |
else: |
| 59 |
_validate(opts, *task_globs) |