Debian Codegraph @

tests/integration/test_subprocctx.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 """Tests involving the Cylc Subprocess Context Object
17 """
18
19 from logging import DEBUG
20 from textwrap import dedent
21
22
23 async def test_log_xtrigger_stdout(
24 flow, scheduler, run_dir, start, log_filter
25 ):
26 """Output from xtriggers should appear in the scheduler log:
27
28 (As per the toy example in the Cylc Docs)
29 """
30 # Setup a workflow:
31 id_ = flow({
32 'scheduler': {'allow implicit tasks': True},
33 'scheduling': {
34 'graph': {'R1': '@myxtrigger => foo'},
35 'xtriggers': {'myxtrigger': 'myxtrigger()'}
36 }
37 })
38 # Create an xtrigger:
39 xt_lib = run_dir / id_ / 'lib/python/myxtrigger.py'
40 xt_lib.parent.mkdir(parents=True, exist_ok=True)
41 xt_lib.write_text(dedent(r"""
42 from sys import stderr
43
44 def myxtrigger():
45 print('Hello World')
46 print('Hello Hades', file=stderr)
47 return True, {}
48 """))
49 schd = scheduler(id_)
50 async with start(schd, level=DEBUG):
51 # Set off check for x-trigger:
52 task = schd.pool.get_tasks()[0]
53 schd.xtrigger_mgr.call_xtriggers_async(task)
54
55 # while not schd.xtrigger_mgr._get_xtrigs(task):
56 while schd.proc_pool.is_not_done():
57 schd.proc_pool.process()
58
59 # Assert that both stderr and out from the print statement
60 # in our xtrigger appear in the log.
61 for expected in ['Hello World', 'Hello Hades']:
62 assert log_filter(DEBUG, expected)