|
| 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 | +"""What happens to the mode on restart? |
| 17 | +""" |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | +from cylc.flow.exceptions import InputError |
| 22 | + |
| 23 | + |
| 24 | +MODES = [('live'), ('simulation'), ('dummy')] |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.parametrize('mode_before', MODES + [None]) |
| 28 | +@pytest.mark.parametrize('mode_after', MODES) |
| 29 | +async def test_restart_mode( |
| 30 | + flow, run, scheduler, start, one_conf, |
| 31 | + mode_before, mode_after |
| 32 | +): |
| 33 | + """Restarting a workflow in live mode leads to workflow in live mode. |
| 34 | +
|
| 35 | + N.B - we need use run becuase the check in question only happens |
| 36 | + on start. |
| 37 | + """ |
| 38 | + id_ = flow(one_conf) |
| 39 | + schd = scheduler(id_, run_mode=mode_before) |
| 40 | + async with start(schd): |
| 41 | + if not mode_before: |
| 42 | + mode_before = 'live' |
| 43 | + assert schd.config.run_mode() == mode_before |
| 44 | + |
| 45 | + schd = scheduler(id_, run_mode=mode_after) |
| 46 | + |
| 47 | + if ( |
| 48 | + mode_before == mode_after |
| 49 | + or not mode_before and mode_after != 'live' |
| 50 | + ): |
| 51 | + # Restarting in the same mode is fine. |
| 52 | + async with run(schd): |
| 53 | + assert schd.config.run_mode() == mode_before |
| 54 | + else: |
| 55 | + # Restarting in a new mode is not: |
| 56 | + errormsg = f'^This.*{mode_before} mode: Will.*{mode_after} mode.$' |
| 57 | + with pytest.raises(InputError, match=errormsg): |
| 58 | + async with run(schd): |
| 59 | + pass |
0 commit comments