Debian Codegraph @

tests/i/test_mode_on_restart.py

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