Пример #1
0
    def _mock(pypath, global_config):
        nonlocal tmp_path, monkeypatch
        global_config_path = tmp_path / 'global.cylc'
        global_config_path.write_text(global_config)
        glbl_cfg = ParsecConfig(SPEC)
        glbl_cfg.loadcfg(global_config_path)

        def _inner(cached=False):
            nonlocal glbl_cfg
            return glbl_cfg

        monkeypatch.setattr(pypath, _inner)
Пример #2
0
def files_to_settings(settings, setting_files, cancel_mode=False):
    """Parse setting files, and append to settings."""
    cfg = ParsecConfig(
        SPEC['runtime']['__MANY__'], validator=cylc_config_validate)
    for setting_file in setting_files:
        if setting_file == '-':
            with NamedTemporaryFile() as handle:
                handle.write(sys.stdin.read().encode())
                handle.seek(0, 0)
                cfg.loadcfg(handle.name)
        else:
            cfg.loadcfg(setting_file)
    stack = [([], cfg.get(sparse=True))]
    while stack:
        keys, item = stack.pop()
        if isinstance(item, dict):
            for key, value in item.items():
                stack.append((keys + [key], value))
        else:
            settings.append({})
            cur_setting = settings[-1]
            while keys:
                key = keys.pop(0)
                if keys:
                    cur_setting[key] = {}
                    cur_setting = cur_setting[key]
                elif cancel_mode:
                    cur_setting[key] = None
                else:
                    cur_setting[key] = item
Пример #3
0
    def _inner(spec, conf):
        """Parse conf against spec and return the result.

        Arguments:
            spec (cylc.flow.parsec.config.ConfigNode):
                The spec to parse the config against.
            conf (str):
                Multiline string containing the configuration.

        Returns:
            cylc.flow.parsec.ParsecConfig
        """
        filepath = tmp_path / 'cfg.cylc'
        with open(filepath, 'w+') as filehandle:
            filehandle.write(conf)
        cfg = ParsecConfig(spec)
        cfg.loadcfg(filepath)
        return cfg
Пример #4
0
def test__get_namespace_parents(parse_config):
    """It returns a list of parents and nothing else"""
    def spec_():
        with Conf('myconfig') as myconf:
            with Conf('some_parent'):
                with Conf('manythings'):
                    Conf('<thing>')

        return myconf
    cfg = ParsecConfig(spec_())
    assert cfg.manyparents == [['some_parent', 'manythings']]
Пример #5
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
An empty config file should successfully yield an empty sparse config dict.
"""


import os
import sys

from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.parsec.validate import ParsecValidator as VDR
from cylc.flow.parsec.OrderedDict import OrderedDict

fpath = os.path.dirname(os.path.abspath(__file__))
# parsec
sys.path.append(fpath + '/../../..')

SPEC = {'meta': {'title': [VDR.V_STRING]}}
cfg = ParsecConfig(SPEC)
cfg.loadcfg("empty.rc")

if cfg.get(sparse=True) != OrderedDict():
    sys.exit(1)
Пример #6
0
 def __init__(self, fpath, output_fname, tvars):
     """Return the default instance."""
     ParsecConfig.__init__(self, SPEC, upg, output_fname, tvars,
                           cylc_config_validate)
     self.loadcfg(fpath, "suite definition")
Пример #7
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Check that single-line config print works"""

import os
import sys

fpath = os.path.dirname(os.path.abspath(__file__))
# parsec
sys.path.append(fpath + '/../../..')


from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.parsec.validate import ParsecValidator as VDR

SPEC = {'foo': {'bar': {'__MANY__': [VDR.V_STRING]}}}
cfg = ParsecConfig(SPEC)
cfg.loadcfg("test.rc")

cfg.mdump(
    [['foo', 'bar', 'baz'], ['foo', 'bar', 'qux']], oneline=True, sparse=True)
Пример #8
0
Файл: suite.py Проект: cylc/cylc
 def __init__(self, fpath, output_fname, tvars):
     """Return the default instance."""
     ParsecConfig.__init__(
         self, SPEC, upg, output_fname, tvars, cylc_config_validate)
     self.loadcfg(fpath, "suite definition")
Пример #9
0
    'float_list': {
        '__MANY__': {
            '__MANY__': [VDR.V_FLOAT_LIST]
        }
    },
    'integer_list': {
        '__MANY__': {
            '__MANY__': [VDR.V_INTEGER_LIST]
        }
    },
}

rcname = sys.argv[1]
rcfile = rcname + '.rc'

cfg = ParsecConfig(SPEC)

cfg.loadcfg(rcfile)

res = cfg.get(sparse=True)

for expected in res[rcname]:

    vals = list(cfg.get([rcname, expected], sparse=True).values())
    expected = expected.replace('COMMA', ',').replace('NULL', '')

    if rcname == 'boolean':
        expected = (expected == 'True') or False

    elif rcname == 'integer':
        expected = int(expected)
Пример #10
0
    'boolean': {'__MANY__': {'__MANY__': [VDR.V_BOOLEAN]}},
    'integer': {'__MANY__': {'__MANY__': [VDR.V_INTEGER]}},
    'float': {'__MANY__': {'__MANY__': [VDR.V_FLOAT]}},
    'string': {'__MANY__': {'__MANY__': [VDR.V_STRING]}},
    'string_list': {'__MANY__': {'__MANY__': [VDR.V_STRING_LIST]}},
    'spaceless_string_list': {'__MANY__': {'__MANY__': [
        VDR.V_SPACELESS_STRING_LIST]}},
    'float_list': {'__MANY__': {'__MANY__': [VDR.V_FLOAT_LIST]}},
    'integer_list': {'__MANY__': {'__MANY__': [VDR.V_INTEGER_LIST]}},
}


rcname = sys.argv[1]
rcfile = rcname + '.rc'

cfg = ParsecConfig(SPEC)

cfg.loadcfg(rcfile)

res = cfg.get(sparse=True)

for expected in res[rcname]:

    vals = list(cfg.get([rcname, expected], sparse=True).values())
    expected = expected.replace('COMMA', ',').replace('NULL', '')

    if rcname == 'boolean':
        expected = (expected == 'True') or False

    elif rcname == 'integer':
        expected = int(expected)