Debian Codegraph @

tests/u/parsec/conftest.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
17 import pytest
18
19 from cylc.flow.parsec.config import (
20 ParsecConfig,
21 ConfigNode as Conf
22 )
23 from cylc.flow.parsec.validate import (
24 CylcConfigValidator as VDR
25 )
26
27
28 @pytest.fixture
29 def config(tmp_path):
30 """Returns a function for parsing Parsec configurations."""
31 def _inner(spec, conf):
32 """Parse conf against spec and return the result.
33
34 Arguments:
35 spec (cylc.flow.parsec.config.ConfigNode):
36 The spec to parse the config against.
37 conf (str):
38 Multiline string containing the configuration.
39
40 Returns:
41 cylc.flow.parsec.ParsecConfig
42 """
43 filepath = tmp_path / 'cfg.cylc'
44 with open(filepath, 'w+') as filehandle:
45 filehandle.write(conf)
46 cfg = ParsecConfig(spec)
47 cfg.loadcfg(filepath)
48 return cfg
49 return _inner
50
51
52 @pytest.fixture
53 def sample_spec():
54 """An example cylc.flow.parsec.config.ConfigNode."""
55 with Conf('myconf') as myconf:
56 with Conf('section1'):
57 Conf('value1', VDR.V_STRING, '')
58 Conf('value2', VDR.V_STRING, 'what?')
59 with Conf('section2'):
60 Conf('enabled', VDR.V_BOOLEAN, False)
61 with Conf('section3'):
62 Conf('title', VDR.V_STRING)
63 with Conf('entries'):
64 Conf('key', VDR.V_STRING)
65 Conf('value', VDR.V_INTEGER_LIST)
66 return myconf