From 897d4dd21611c1b33931ee63c68fa479dad3f6bc Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 20 Jun 2024 12:56:27 +0200 Subject: [PATCH] aa --- tests/auto/test_auto.py | 2983 +++++++------------ tests/test_cache.py | 73 +- tests/test_choice_option.py | 38 +- tests/test_config.py | 24 +- tests/test_config_api.py | 3 +- tests/test_duplicate_config.py | 42 +- tests/test_dyn_optiondescription.py | 3039 ++++++++++---------- tests/test_freeze.py | 108 +- tests/test_leadership.py | 122 +- tests/test_option.py | 60 +- tests/test_option_callback.py | 41 +- tests/test_option_default.py | 22 - tests/test_option_setting.py | 48 +- tests/test_option_type.py | 9 +- tests/test_option_validator.py | 10 +- tests/test_permissive.py | 71 +- tests/test_requires.py | 9 +- tests/test_symlink.py | 34 +- tiramisu/api.py | 705 +++-- tiramisu/autolib.py | 279 +- tiramisu/cacheobj.py | 15 +- tiramisu/config.py | 196 +- tiramisu/error.py | 9 +- tiramisu/locale/fr/LC_MESSAGES/tiramisu.po | 2 +- tiramisu/option/baseoption.py | 137 +- tiramisu/option/choiceoption.py | 19 +- tiramisu/option/dynoptiondescription.py | 65 +- tiramisu/option/leadership.py | 100 +- tiramisu/option/option.py | 79 +- tiramisu/option/optiondescription.py | 163 +- tiramisu/option/symlinkoption.py | 45 +- tiramisu/option/syndynoption.py | 351 --- tiramisu/option/syndynoptiondescription.py | 235 -- tiramisu/setting.py | 145 +- tiramisu/todict.py | 6 +- tiramisu/value.py | 326 ++- 36 files changed, 4299 insertions(+), 5314 deletions(-) delete mode 100644 tiramisu/option/syndynoption.py delete mode 100644 tiramisu/option/syndynoptiondescription.py diff --git a/tests/auto/test_auto.py b/tests/auto/test_auto.py index 3bcefda..74d97ee 100644 --- a/tests/auto/test_auto.py +++ b/tests/auto/test_auto.py @@ -1,1931 +1,1116 @@ """test API """ -import weakref +#import weakref import pytest -import warnings -from copy import copy -from py.test import raises -from collections import OrderedDict -from .autopath import do_autopath -do_autopath() -from tiramisu import Config, MetaConfig, \ - StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \ - submulti, undefined, owners, Params, ParamOption, Calculation -from tiramisu.error import PropertiesOptionError, ConfigError, LeadershipError -ICON = u'\u2937' - -OPTIONS_TYPE = {'str': {'type': str, - 'option': StrOption} - } -PROPERTIES = ['hidden', 'disabled', 'mandatory'] -PROPERTIES_LIST = ['prop1', 'prop2'] - -OWNER = 'user' - -# multi is False -FIRST_VALUE = 'myvalue' -SECOND_VALUE = 'myvalue1' -EMPTY_VALUE = None -# multi is True -LIST_FIRST_VALUE = ['myvalue'] -LIST_SECOND_VALUE = ['myvalue', 'myvalue1'] -LIST_EMPTY_VALUE = [] -# multi is submulti -SUBLIST_FIRST_VALUE = [['myvalue']] -SUBLIST_SECOND_VALUE = [['myvalue'], ['myvalue1', 'myvalue2']] -SUBLIST_EMPTY_VALUE = [] - -DISPLAY = True -DISPLAY = False +#import warnings +#from copy import copy +#from py.test import raises +#from collections import OrderedDict +#from .autopath import do_autopath +#do_autopath() +#from tiramisu import Config, MetaConfig, \ +# StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \ +# submulti, undefined, owners, Params, ParamOption, Calculation +from tiramisu import Config, DynOptionDescription, OptionDescription, Leadership, \ + StrOption, IntOption, ChoiceOption, SymLinkOption, \ + Calculation, Params, ParamValue, ParamOption, ParamSelfOption, ParamInformation, ParamSelfInformation, ParamIndex, ParamSuffix, \ + submulti, calc_value, owners +from tiramisu.i18n import _ +from tiramisu.option.baseoption import BaseOption +from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, LeadershipError +from tiramisu.setting import ALLOWED_LEADER_PROPERTIES -def return_list(val=None, suffix=None): - if val: - return val - else: - return ['val1', 'val2'] - - -def return_str(val, suffix=None): +def return_var(val=None): return val -def display_info(func): - def wrapper(*args, **kwargs): - if DISPLAY: - print(u'\n{} {}'.format(ICON, func.__name__)) - return func(*args, **kwargs) - return wrapper +def return_var_disabled(multi, p=None): + if p is not None: + multi = p + if multi: + return [] + return None -autocheck_registers = [] +def return_val(multi): + if multi: + return ['val'] + return 'val' -def autocheck(func): - autocheck_registers.append(func) - def wrapper(*args, **kwargs): - if DISPLAY and kwargs.get('display', True): - print(u' {} {}'.format(ICON, func.__name__)) - return func(*args, **kwargs) - return wrapper +def return_property(): + return 'prop' -def _autocheck_default_value(cfg, path, conf, **kwargs): - """set and get values - """ - # check if is a multi, a leader or a follower - multi = cfg.unrestraint.option(path).ismulti() - submulti_ = cfg.unrestraint.option(path).issubmulti() - isfollower = cfg.unrestraint.option(path).isfollower() +def return_disabled(var=None): + return 'disabled' - # set default value (different if value is multi or not) - empty_value = kwargs['default'] - # test default value (should be empty) - # cannot test for follower (we cannot get all values for a follower) - if conf is not None: - cfg_ = cfg.config(conf) +def return_validator(self, other): + return self == other + + +def build_variables(*, + mandatory=False, + multi=False, + leadership=False, + dynoptiondescription=False, + parent_variables=[], + dynamic=False, + hidden=False, + ): + base_name = 'str_' + if mandatory: + properties = ['mandatory'] + base_name += 'mandatory_' else: - cfg_ = cfg - with warnings.catch_warnings(record=True) as w: - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(path).value.get() == empty_value - assert cfg_.forcepermissive.option(path).value.get() == empty_value - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(path).value.get() - assert cfg_.forcepermissive.option(path).value.get() == empty_value - else: - with raises(PropertiesOptionError): - cfg_.option(path).value.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(path).value.get() - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(path, 0).value.get() == empty_value - assert cfg_.option(path, 1).value.get() == empty_value - assert cfg_.forcepermissive.option(path, 0).value.get() == empty_value - assert cfg_.forcepermissive.option(path, 1).value.get() == empty_value - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(path, 0).value.get() - assert cfg_.forcepermissive.option(path, 0).value.get() == empty_value - assert cfg_.forcepermissive.option(path, 1).value.get() == empty_value - else: - with raises(PropertiesOptionError): - cfg_.option(path, 0).value.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(path, 0).value.get() - - -def _set_value(cfg, pathwrite, conf, **kwargs): - set_permissive = kwargs.get('set_permissive', True) - multi = cfg.unrestraint.option(pathwrite).ismulti() - submulti_ = cfg.unrestraint.option(pathwrite).issubmulti() - isleader = cfg.unrestraint.option(pathwrite).isleader() - isfollower = cfg.unrestraint.option(pathwrite).isfollower() - if not multi: - first_value = FIRST_VALUE - elif submulti_ is False: - if not isfollower: - first_value = LIST_FIRST_VALUE - else: - second_value = LIST_SECOND_VALUE[1] - - else: - if not isfollower: - first_value = SUBLIST_FIRST_VALUE - else: - second_value = SUBLIST_SECOND_VALUE[1] - - # for follower should have an index and good length - # for leader must append, not set - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - with warnings.catch_warnings(record=True) as w: - if isleader: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - with raises(ConfigError): - cfg_.option(pathwrite, 0).value.set(first_value[0]) - if not set_permissive: - cfg_.option(pathwrite).value.set([first_value[0]]) - else: - cfg_.forcepermissive.option(pathwrite).value.set([first_value[0]]) - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathwrite).value.set([first_value[0]]) - if set_permissive: - cfg_.forcepermissive.option(pathwrite).value.set([first_value[0]]) - else: - with raises(PropertiesOptionError): - cfg_.option(pathwrite).value.set([first_value[0]]) - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathwrite).value.set([first_value[0]]) - if len(first_value) > 1: - with raises(ConfigError): - cfg_.unrestraint.option(pathwrite).value.set(first_value[1]) - elif isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - if not set_permissive: - cfg_.option(pathwrite, 1).value.set(second_value) - else: - cfg_.forcepermissive.option(pathwrite, 1).value.set(second_value) - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathwrite, 1).value.set(second_value) - if set_permissive: - cfg_.forcepermissive.option(pathwrite, 1).value.set(second_value) - else: - with raises(PropertiesOptionError): - cfg_.option(pathwrite, 1).value.set(second_value) - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathwrite, 1).value.set(second_value) - with raises(ConfigError): - cfg_.unrestraint.option(pathwrite).value.set([second_value, second_value]) - - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - if not set_permissive: - cfg_.option(pathwrite).value.set(first_value) - else: - cfg_.forcepermissive.option(pathwrite).value.set(first_value) - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathwrite).value.set(first_value) - if set_permissive: - cfg_.forcepermissive.option(pathwrite).value.set(first_value) - else: - with raises(PropertiesOptionError): - cfg_.option(pathwrite).value.set(first_value) - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathwrite).value.set(first_value) - #FIXME raises(ConfigError, "cfg_.unrestraint.option(pathwrite).value.set(first_value)") - - -def _getproperties(multi, isfollower, kwargs): - # define properties - properties = copy(PROPERTIES_LIST) - if multi and not isfollower: - default_props = ['empty', 'unique'] - properties.append('empty') - properties.append('unique') - else: - default_props = [] - extra_properties = kwargs.get('extra_properties') - if extra_properties: - properties.extend(extra_properties) - default_props.extend(extra_properties) - return default_props, frozenset(properties) - - -def _check_properties(cfg, mcfg, pathread, conf, kwargs, props_permissive, props): - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if not cfg.unrestraint.option(pathread).isfollower(): - if not kwargs.get('permissive_od', False): - assert set(cfg_.option(pathread).property.get()) == set(props_permissive) - assert set(cfg_.option(pathread).property.get()) == set(props) - else: - with raises(PropertiesOptionError): - cfg_.option(pathread).property.get() - with raises(PropertiesOptionError): - cfg_.option(pathread).property.get() - assert set(cfg_.forcepermissive.option(pathread).property.get()) == set(props_permissive) - assert set(cfg_.forcepermissive.option(pathread).property.get()) == set(props) - assert set(cfg_.unrestraint.option(pathread).property.get()) == set(props_permissive) - assert set(cfg_.unrestraint.option(pathread).property.get()) == set(props) - else: - if not kwargs.get('permissive_od', False): - assert set(cfg_.option(pathread, 0).property.get()) == set(props_permissive) - assert set(cfg_.option(pathread, 0).property.get()) == set(props) - # - assert set(cfg_.option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg_.option(pathread, 1).property.get()) == set(props) - else: - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).property.get() - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).property.get() - # - with raises(PropertiesOptionError): - cfg_.option(pathread, 1).property.get() - with raises(PropertiesOptionError): - cfg_.option(pathread, 1).property.get() - assert set(cfg_.forcepermissive.option(pathread, 0).property.get()) == set(props_permissive) - assert set(cfg_.forcepermissive.option(pathread, 0).property.get()) == set(props) - # - assert set(cfg_.forcepermissive.option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg_.forcepermissive.option(pathread, 1).property.get()) == set(props) - assert set(cfg_.unrestraint.option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg_.unrestraint.option(pathread, 1).property.get()) == set(props) - - -def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a multi or a follower - multi = cfg.unrestraint.option(pathread).ismulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - - # define properties - properties = copy(PROPERTIES_LIST) - if multi and not isfollower: - default_props = ['empty', 'unique'] - properties.append('empty') - properties.append('unique') - else: - default_props = [] - extra_properties = kwargs.get('extra_properties') - if extra_properties: - properties.extend(extra_properties) - default_props.extend(extra_properties) - default_props, properties = _getproperties(multi, isfollower, kwargs) - - if confwrite == confread: - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - else: - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - - # set properties with permissive - for prop in properties: - if confread is not None: - cfg_ = cfg.config(confread) - else: - cfg_ = cfg - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg_.option(pathwrite).property.add(prop) - elif not kwargs.get('propertyerror', False): - cfg_.forcepermissive.option(pathwrite).property.add(prop) - else: - cfg_.unrestraint.option(pathwrite).property.add(prop) - if confwrite == confread: - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) - else: - _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) - - -def _autocheck_get_value(cfg, pathread, conf, **kwargs): - set_permissive = kwargs.get('set_permissive', True) - multi = cfg.unrestraint.option(pathread).ismulti() - submulti_ = cfg.unrestraint.option(pathread).issubmulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - empty_value = kwargs['default'] - if not multi: - first_value = FIRST_VALUE - elif submulti_ is False: - if not isfollower: - first_value = LIST_FIRST_VALUE - else: - second_value = LIST_SECOND_VALUE[1] - - else: - if not isfollower: - first_value = SUBLIST_FIRST_VALUE - else: - second_value = SUBLIST_SECOND_VALUE[1] - - # get value after set value without permissive - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - with warnings.catch_warnings(record=True) as w: - if isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread, 0).value.get() == empty_value - assert cfg_.option(pathread, 1).value.get() == second_value - assert cfg_.forcepermissive.option(pathread, 0).value.get() == empty_value - assert cfg_.forcepermissive.option(pathread, 1).value.get() == second_value - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).value.get() - assert cfg_.forcepermissive.option(pathread, 0).value.get() == empty_value - if set_permissive: - assert cfg_.forcepermissive.option(pathread, 1).value.get() == second_value - else: - assert cfg_.forcepermissive.option(pathread, 1).value.get() == empty_value - else: - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).value.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread, 0).value.get() - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread).value.get() == first_value - assert cfg_.forcepermissive.option(pathread).value.get() == first_value - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - cfg_.option(pathread).value.get() - if set_permissive: - assert cfg_.forcepermissive.option(pathread).value.get() == first_value - else: - assert cfg_.forcepermissive.option(pathread).value.get() == empty_value - else: - with raises(PropertiesOptionError): - cfg_.option(pathread).value.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread).value.get() - - -def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner): - isfollower = cfg.unrestraint.option(pathread).isfollower() - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread).owner.get() == owner - assert cfg_.forcepermissive.option(pathread).owner.get() == owner - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.get() - assert cfg_.forcepermissive.option(pathread).owner.get() == permissive_owner - else: - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread).owner.get() - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread, 0).owner.get() == 'default' - assert cfg_.forcepermissive.option(pathread, 0).owner.get() == 'default' - assert cfg_.option(pathread, 1).owner.get() == owner - assert cfg_.forcepermissive.option(pathread, 1).owner.get() == owner - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.get() - with raises(PropertiesOptionError): - cfg_.option(pathread, 1).owner.get() - assert cfg_.forcepermissive.option(pathread, 0).owner.get() == 'default' - assert cfg_.forcepermissive.option(pathread, 1).owner.get() == permissive_owner - else: - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread, 0).owner.get() - - -@autocheck -def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - #FIXME - if pathwrite in ['subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubodval1.firstval1', 'subod.subsubod.third', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2']: - return - if not kwargs.get('permissive_od', False): - cfg.option(pathread).ismulti() - cfg.option(pathread).issubmulti() - cfg.option(pathread).isleader() - cfg.option(pathread).isfollower() - else: - with raises(PropertiesOptionError): - cfg.option(pathread).ismulti() - with raises(PropertiesOptionError): - cfg.option(pathread).issubmulti() - with raises(PropertiesOptionError): - cfg.option(pathread).isleader() - with raises(PropertiesOptionError): - cfg.option(pathread).isfollower() - - cfg.forcepermissive.option(pathread).ismulti() - cfg.forcepermissive.option(pathread).issubmulti() - cfg.forcepermissive.option(pathread).isleader() - cfg.forcepermissive.option(pathread).isfollower() - - - -@autocheck -def autocheck_default_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - """check different value of owner when any value is set to this option - """ - if pathwrite in ['subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2']: - return - isfollower = cfg.unrestraint.option(pathread).isfollower() - # check if owner is a string "default" and 'isdefault' - def do(conf): - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread).owner.get() == 'default' - assert cfg_.forcepermissive.option(pathread).owner.get() == 'default' - # - assert cfg_.option(pathread).owner.isdefault() - assert cfg_.forcepermissive.option(pathread).owner.isdefault() - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.get() - assert cfg_.forcepermissive.option(pathread).owner.get() == 'default' - # - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.isdefault() - assert cfg_.forcepermissive.option(pathread).owner.isdefault() - else: - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread).owner.get() - # - with raises(PropertiesOptionError): - cfg_.option(pathread).owner.isdefault() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread).owner.isdefault() - # - assert cfg_.unrestraint.option(pathread).owner.get() == 'default' - assert cfg_.unrestraint.option(pathread).owner.isdefault() - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread, 0).owner.get() == 'default' - assert cfg_.forcepermissive.option(pathread, 0).owner.get() == 'default' - # - assert cfg_.option(pathread, 0).owner.isdefault() - assert cfg_.forcepermissive.option(pathread, 0).owner.isdefault() - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.get() - assert cfg_.forcepermissive.option(pathread, 0).owner.get() == 'default' - # - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.isdefault() - assert cfg_.forcepermissive.option(pathread, 0).owner.isdefault() - else: - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread, 0).owner.get() - # - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).owner.isdefault() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread, 0).owner.isdefault() - assert cfg_.unrestraint.option(pathread, 0).owner.get() == 'default' - assert cfg_.unrestraint.option(pathread, 0).owner.isdefault() - do(confread) - if confread != confwrite: - do(confwrite) - - -@autocheck -def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - _autocheck_default_value(cfg, pathread, confread, **kwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **kwargs) - - - -@autocheck -def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - _set_value(cfg, pathwrite, confwrite, **kwargs) - - -@autocheck -def autocheck_get_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - multi = cfg.unrestraint.option(pathread).ismulti() - submulti_ = cfg.unrestraint.option(pathread).issubmulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - _set_value(cfg, pathwrite, confwrite, **kwargs) - empty_value = kwargs['default'] - if not multi: - first_value = FIRST_VALUE - elif submulti_ is False: - first_value = LIST_FIRST_VALUE - else: - first_value = SUBLIST_FIRST_VALUE - - def do(conf): - # get value after set value without permissive - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread, 0).value.get() == empty_value - assert cfg_.forcepermissive.option(pathread, 0).value.get() == empty_value - if submulti_: - assert cfg_.option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] - assert cfg_.forcepermissive.option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] - else: - assert cfg_.option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] - assert cfg_.forcepermissive.option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - assert cfg_.option(pathread, 0).value.get() - with raises(PropertiesOptionError): - assert cfg_.option(pathread, 1).value.get() - assert cfg_.forcepermissive.option(pathread, 0).value.get() == empty_value - if submulti_: - assert cfg_.forcepermissive.option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] - else: - assert cfg_.forcepermissive.option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] - else: - with raises(PropertiesOptionError): - assert cfg_.option(pathread, 0).value.get() - with raises(PropertiesOptionError): - assert cfg_.option(pathread, 1).value.get() - with raises(PropertiesOptionError): - assert cfg_.forcepermissive.option(pathread, 0).value.get() - with raises(PropertiesOptionError): - assert cfg_.forcepermissive.option(pathread, 1).value.get() - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - with warnings.catch_warnings(record=True) as w: - assert cfg_.option(pathread).value.get() == first_value - assert cfg_.forcepermissive.option(pathread).value.get() == first_value - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - cfg_.option(pathread).value.get() - assert cfg_.forcepermissive.option(pathread).value.get() == first_value - else: - with raises(PropertiesOptionError): - cfg_.option(pathread).value.get() - with raises(PropertiesOptionError): - cfg_.forcepermissive.option(pathread).value.get() - with warnings.catch_warnings(record=True) as w: - do(confread) - if confread != confwrite: - do(confwrite) - - -@autocheck -def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - _set_value(cfg, pathwrite, confwrite, set_permissive=False, **kwargs) - _autocheck_get_value(cfg, pathread, confread, set_permissive=False, **kwargs) - if pathread.endswith('val1'): - val2_path = pathread.replace('val1', 'val2') - _autocheck_default_value(cfg, val2_path, confread, **kwargs) - if confread != confwrite: - _autocheck_get_value(cfg, pathread, confwrite, set_permissive=False, **kwargs) - if pathread.endswith('val1'): - _autocheck_default_value(cfg, val2_path, confwrite, **kwargs) - - -@autocheck -def autocheck_value_follower(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - #FIXME - if pathwrite in ['odleader.third', 'subodval1.subsubodval1.thirdval1', 'subodval2.subsubodval2.thirdval2']: - return - isfollower = cfg.unrestraint.option(pathread).isfollower() - if not isfollower: - return - if kwargs.get('propertyerror', False): - return - - submulti_ = cfg.forcepermissive.option(pathread).issubmulti() - empty_value = kwargs['default'] - - def do(conf): - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - length = cfg_.option(pathread).value.len() - assert cfg_.forcepermissive.option(pathread).value.len() == length - assert length == 2 - do(confread) - if confread != confwrite: - do(confwrite) - - length = 2 - value = [] - with warnings.catch_warnings(record=True) as w: - for idx in range(length): - value.append(cfg.forcepermissive.option(pathread, idx).value.get()) - - assert value == [empty_value, empty_value] - # cannot access to a follower with index too high - if submulti_ is False: - value = LIST_FIRST_VALUE[0] - else: - value = SUBLIST_FIRST_VALUE[0] - - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.get()") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.set(value)") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).value.reset()") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.get()") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.isdefault()") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).property.get()") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).owner.set('new_user')") - raises(LeadershipError, "cfg.forcepermissive.option(pathread, length).property.add('prop')") - - -@autocheck -def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a multi, a leader or a follower - multi = cfg.unrestraint.option(pathread).ismulti() - submulti_ = cfg.unrestraint.option(pathread).issubmulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - - # set default value (different if value is multi or not) - if not multi: - first_value = FIRST_VALUE - second_value = SECOND_VALUE - elif submulti_ is False: - first_value = LIST_FIRST_VALUE - second_value = LIST_SECOND_VALUE - else: - first_value = SUBLIST_FIRST_VALUE - second_value = SUBLIST_SECOND_VALUE - empty_value = kwargs['default'] - _set_value(cfg, pathwrite, confwrite, **kwargs) - - # reset value without permissive - with warnings.catch_warnings(record=True) as w: - if confwrite is not None: - cfg_ = cfg.config(confwrite) - else: - cfg_ = cfg - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg_.option(pathwrite).value.reset() - #else: - #FIXME with raises(PropertiesOptionError):cfg.config(confwrite).option(pathwrite).value.reset()") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg_.option(pathwrite, 0).value.reset() - #else: - #FIXME with raises(PropertiesOptionError):cfg.config(confwrite).option(pathwrite, 0).value.reset()") - - # get value after reset value without permissive - def do(conf): - if confwrite is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread, 0).value.get() == empty_value - assert cfg_.option(pathread, 1).value.get() == second_value[1] - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - cfg_.option(pathread, 0).value.get() - assert cfg_.forcepermissive.option(pathread, 0).value.get() == empty_value - assert cfg_.forcepermissive.option(pathread, 1).value.get() == second_value[1] - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread).value.get() == empty_value - elif kwargs.get('permissive', False): - with raises(PropertiesOptionError): - cfg_.option(pathread).value.get() - assert cfg_.forcepermissive.option(pathread).value.get() == first_value - with warnings.catch_warnings(record=True) as w: - do(confread) - if confread != confwrite: - do(confwrite) - - -@autocheck -def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - isleader = cfg.unrestraint.option(pathread).isleader() - submulti_ = cfg.unrestraint.option(pathread).issubmulti() - if not isleader: - return - if confread is not None: - cfg_ = cfg.config(confread) - else: - cfg_ = cfg - if confwrite is not None: - cfg2_ = cfg.config(confwrite) - else: - cfg2_ = cfg - - with warnings.catch_warnings(record=True) as w: - if not kwargs.get('propertyerror', False): - leader_value = cfg_.forcepermissive.option(pathread).value.get() - v3 = cfg_.forcepermissive.option(pathread).value.get() - len_value = len(leader_value) - leader_value.append(undefined) - assert len(cfg_.forcepermissive.option(pathread).value.get()) == len_value - with warnings.catch_warnings(record=True) as w: - cfg2_.forcepermissive.option(pathread).value.set(leader_value) - new_leader_value = cfg_.forcepermissive.option(pathread).value.get() - len_new = len(new_leader_value) - assert len_value + 1 == len_new - assert new_leader_value[-1] == kwargs['default_multi'] - follower_path = pathread.rsplit('.', 1)[0] - if follower_path.endswith('val1') or follower_path.endswith('val2'): - follower_path += '.third' + follower_path[-4:] - else: - follower_path += '.third' - for idx in range(len_new): - assert cfg_.forcepermissive.option(follower_path, idx).value.get() == kwargs['default_multi'] - # - if not submulti_: - value = 'value' - else: - value = ['value'] - leader_value.append(value) - assert len(cfg_.forcepermissive.option(pathread).value.get()) == len(new_leader_value) - cfg2_.forcepermissive.option(pathread).value.set(leader_value) - assert cfg_.forcepermissive.option(pathread).value.get()[-1] == value - - -@autocheck -def autocheck_pop_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - isleader = cfg.unrestraint.option(pathread).isleader() - submulti_ = cfg.unrestraint.option(pathread).issubmulti() - if not isleader: - return - - if confwrite is not None: - cfg_ = cfg.config(confwrite) - else: - cfg_ = cfg - if confread is not None: - cfg2_ = cfg.config(confread) - else: - cfg2_ = cfg - if not kwargs.get('propertyerror', False): - if not submulti_: - values = ['value1', 'value2', 'value3', 'value4'] - follower_value = 'follower' - else: - values = [['value1'], ['value2'], ['value3'], ['value4']] - follower_value = ['follower'] - followers = [kwargs['default_multi'], follower_value, kwargs['default_multi'], kwargs['default_multi']] - a_follower = pathwrite.rsplit('.', 1)[0] - if a_follower.endswith('val1') or a_follower.endswith('val2'): - a_follower += '.third' + a_follower[-4:] - else: - a_follower += '.third' - with warnings.catch_warnings(record=True) as w: - cfg_.forcepermissive.option(pathread).value.set(values) - cfg_.forcepermissive.option(a_follower, 1).value.set(follower_value) - cfg2_.forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 0).owner.isdefault() is True - cfg2_.forcepermissive.option(a_follower, 1).value.get() == follower_value - assert cfg2_.forcepermissive.option(a_follower, 1).owner.isdefault() is False - cfg2_.forcepermissive.option(a_follower, 2).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 2).owner.isdefault() is True - cfg2_.forcepermissive.option(a_follower, 3).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 3).owner.isdefault() is True - # - cfg_.forcepermissive.option(pathread).value.pop(3) - cfg2_.forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 0).owner.isdefault() is True - cfg2_.forcepermissive.option(a_follower, 1).value.get() == follower_value - assert cfg2_.forcepermissive.option(a_follower, 1).owner.isdefault() is False - cfg2_.forcepermissive.option(a_follower, 2).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 2).owner.isdefault() is True - # - cfg_.forcepermissive.option(pathread).value.pop(0) - cfg2_.forcepermissive.option(a_follower, 0).value.get() == follower_value - assert cfg2_.forcepermissive.option(a_follower, 0).owner.isdefault() is False - cfg2_.forcepermissive.option(a_follower, 1).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 1).owner.isdefault() is True - # - cfg_.forcepermissive.option(pathread).value.pop(0) - cfg2_.forcepermissive.option(a_follower, 0).value.get() == kwargs['default_multi'] - assert cfg2_.forcepermissive.option(a_follower, 0).owner.isdefault() is True - - -@autocheck -def autocheck_reset_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a multi, a leader or a follower - isfollower = cfg.unrestraint.option(pathread).isfollower() - _set_value(cfg, pathwrite, confwrite, **kwargs) - # reset value with permissive - with warnings.catch_warnings(record=True) as w: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - if not isfollower: - if confwrite is not None: - cfg_ = cfg.forcepermissive.config(confwrite) - else: - cfg_ = cfg.forcepermissive - cfg_.option(pathwrite).value.reset() - else: - cfg.forcepermissive.option(pathwrite, 1).value.reset() - elif kwargs.get('permissive', False): - if not isfollower: - if confwrite is not None: - cfg_ = cfg.forcepermissive.config(confwrite) - else: - cfg_ = cfg.forcepermissive - cfg_.option(pathwrite).value.reset() - else: - cfg.forcepermissive.option(pathwrite, 1).value.reset() - #FIXME else: - # if not isfollower: - # with raises(PropertiesOptionError):cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()") - # else: - # with raises(PropertiesOptionError):cfg.forcepermissive.option(pathwrite, 1).value.reset()") - _autocheck_default_value(cfg, pathread, confread, **kwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathwrite, confwrite, **kwargs) -#FIXME -#FIXME -#FIXME@autocheck -#FIXMEdef autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): -#FIXME """re set value -#FIXME """ -#FIXME if kwargs['callback']: -#FIXME return -#FIXME make_dict = kwargs['make_dict'] -#FIXME make_dict_value = kwargs['make_dict_value'] -#FIXME if confread is not None: -#FIXME cfg_ = cfg.config(confread) -#FIXME else: -#FIXME cfg_ = cfg -#FIXME if confwrite is not None: -#FIXME cfg2_ = cfg.config(confwrite) -#FIXME else: -#FIXME cfg2_ = cfg -#FIXME assert cfg_.value.dict() == make_dict -#FIXME if confread != confwrite: -#FIXME assert(cfg2_.value.dict()) == make_dict -#FIXME _set_value(cfg, pathwrite, confwrite, **kwargs) -#FIXME assert cfg_.value.dict() == make_dict_value -#FIXME if confread != confwrite: -#FIXME assert(cfg2_.value.dict()) == make_dict_value - - -@autocheck -def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - """get property from path - """ - #FIXME - if pathwrite in ['odleader.first', 'subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2', 'subodval1.subsubodval1.firstval1', 'subodval1.subsubodval1.secondval1', 'subodval1.subsubodval1.thirdval1', 'subodval2.subsubodval2.firstval2', 'subodval2.subsubodval2.secondval2', 'subodval2.subsubodval2.thirdval2']: - return - # check if is a multi or a follower - multi = cfg.unrestraint.option(pathread).ismulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - - default_props, properties = _getproperties(multi, isfollower, kwargs) - - if confread == confwrite: - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - else: - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - - # set properties without permissive - for prop in properties: - if confwrite is not None: - cfg_ = cfg.unrestraint.config(confwrite) - else: - cfg_ = cfg.unrestraint - cfg_.option(pathwrite).property.add(prop) - if confread == confwrite: - _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) - else: - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) - - - -@autocheck -def autocheck_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - #FIXME - if pathwrite in ['odleader.first', 'subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2', 'subodval1.subsubodval1.firstval1', 'subodval1.subsubodval1.secondval1', 'subodval1.subsubodval1.thirdval1', 'subodval2.subsubodval2.firstval2', 'subodval2.subsubodval2.secondval2', 'subodval2.subsubodval2.thirdval2']: - return - _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) - - -@autocheck -def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - """check properties after set with permissive - """ - #FIXME - if pathwrite in ['odleader.first', 'subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2', 'subodval1.subsubodval1.firstval1', 'subodval1.subsubodval1.secondval1', 'subodval1.subsubodval1.thirdval1', 'subodval2.subsubodval2.firstval2', 'subodval2.subsubodval2.secondval2', 'subodval2.subsubodval2.thirdval2']: - return - # check if is a multi or a follower - multi = cfg.unrestraint.option(pathread).ismulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - default_props, properties = _getproperties(multi, isfollower, kwargs) - - _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) - - # reset properties without permissive - if confwrite is not None: - cfg_ = cfg.unrestraint.config(confwrite) - else: - cfg_ = cfg.unrestraint - cfg_.option(pathwrite).property.reset() - - if confread == confwrite: - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - else: - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - - -@autocheck -def autocheck_reset_property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a multi or a follower - #FIXME - if pathwrite in ['odleader.first', 'subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2', 'subodval1.subsubodval1.firstval1', 'subodval1.subsubodval1.secondval1', 'subodval1.subsubodval1.thirdval1', 'subodval2.subsubodval2.firstval2', 'subodval2.subsubodval2.secondval2', 'subodval2.subsubodval2.thirdval2']: - return - multi = cfg.unrestraint.option(pathread).ismulti() - isfollower = cfg.unrestraint.option(pathread).isfollower() - default_props, properties = _getproperties(multi, isfollower, kwargs) - - _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs) - - for prop in properties: - cfg.unrestraint.option(pathwrite).property.add(prop) - cfg.unrestraint.option(pathwrite).property.reset() - - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - - -@autocheck -def autocheck_context_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - owner = cfg.owner.get() - assert owner == kwargs['owner'] - - -@autocheck -def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - """value is now changed, check owner in this case - """ - if pathwrite in ['odleader.first', 'subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2']: - return - _set_value(cfg, pathwrite, confwrite, **kwargs) - _check_owner(cfg, pathread, confwrite, kwargs, kwargs['owner'], kwargs['owner']) - if confread != confwrite: - _check_owner(cfg, pathread, confread, kwargs, kwargs['owner'], kwargs['owner']) - - -@autocheck -def autocheck_default_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - isfollower = cfg.unrestraint.option(pathread).isfollower() - _set_value(cfg, pathwrite, confwrite, **kwargs) - - if confwrite is not None: - cfg_ = cfg.config(confread) - cfg2_ = cfg.config(confwrite) - else: - cfg_ = cfg - cfg2_ = cfg - # test if is default owner without permissive - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg_.option(pathread).owner.isdefault() is False - if confwrite != confread: - assert cfg2_.option(pathread).owner.isdefault() is False - #FIXME else: - # with raises(PropertiesOptionError):cfg.config(confwrite).option(pathread).owner.isdefault()") - # with raises(PropertiesOptionError):cfg.config(confread).option(pathread).owner.isdefault()") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg2_.option(pathread, 0).owner.isdefault() is True - assert cfg2_.option(pathread, 1).owner.isdefault() is False - if confwrite != confread: - assert cfg_.option(pathread, 0).owner.isdefault() is True - assert cfg_.option(pathread, 1).owner.isdefault() is False - #FIXME else: - # with raises(PropertiesOptionError):cfg.config(confwrite).option(pathread, 0).owner.isdefault()") - # with raises(PropertiesOptionError):cfg.config(confread).option(pathread, 0).owner.isdefault()") - - -@autocheck -def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a isfollower - isfollower = cfg.unrestraint.option(pathread).isfollower() - - _set_value(cfg, pathwrite, confwrite, **kwargs) - - def do(conf): - # test if is default owner with permissive - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if not kwargs.get('propertyerror', False): - if not isfollower: - assert cfg_.forcepermissive.option(pathread).owner.isdefault() is False - else: - assert cfg_.forcepermissive.option(pathread, 0).owner.isdefault() is True - assert cfg_.forcepermissive.option(pathread, 1).owner.isdefault() is False - do(confwrite) - if confwrite != confread: - do(confread) - - -@autocheck -def autocheck_set_owner_no_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - isfollower = cfg.unrestraint.option(pathread).isfollower() - if confwrite is not None: - cfg_ = cfg.forcepermissive.config(confwrite) - else: - cfg_ = cfg.forcepermissive - if not kwargs.get('propertyerror', False): - if not isfollower: - with raises(ConfigError): - cfg_.option(pathwrite).owner.set('new_user') - else: - with raises(ConfigError): - cfg_.option(pathwrite, 1).owner.set('new_user') - - -@autocheck -def autocheck_set_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # test set owner without permissive - if pathwrite in ['subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2']: - return - isfollower = cfg.unrestraint.option(pathread).isfollower() - - _set_value(cfg, pathwrite, confwrite, **kwargs) - if confwrite is not None: - cfg_ = cfg.config(confwrite) - else: - cfg_ = cfg - - # set owner without permissive - if not isfollower: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg_.option(pathwrite).owner.set('new_user') - with raises(ValueError): - cfg_.option(pathwrite).owner.set('default') - with raises(ValueError): - cfg_.option(pathwrite).owner.set('forced') - #FIXME else: - # with raises(PropertiesOptionError):cfg.config(confwrite).option(pathwrite).owner.set('new_user')") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg.option(pathwrite, 1).owner.set('new_user') - #FIXME else: - # with raises(PropertiesOptionError):cfg.option(pathwrite, 1).owner.set('new_user')") - - _check_owner(cfg, pathread, confwrite, kwargs, owners.new_user, kwargs['owner']) - if confwrite != confread: - _check_owner(cfg, pathread, confread, kwargs, owners.new_user, owners.meta) - - -@autocheck -def autocheck_set_owner_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - if pathwrite in ['subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third', 'subod.subsubodval1.firstval1', 'subod.subsubodval1.secondval1', 'subod.subsubodval1.thirdval1', 'subod.subsubodval2.firstval2', 'subod.subsubodval2.secondval2', 'subod.subsubodval2.thirdval2']: - return - isfollower = cfg.unrestraint.option(pathread).isfollower() - - _set_value(cfg, pathwrite, confwrite, **kwargs) - if confwrite is not None: - cfg_ = cfg.forcepermissive.config(confwrite) - else: - cfg_ = cfg.forcepermissive - - # set owner with permissive - if not kwargs.get('propertyerror', False): - if not isfollower: - cfg_.option(pathwrite).owner.set('new_user1') - else: - cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user1') - #FIXME else: - # if not isfollower: - # with raises(PropertiesOptionError, - # "cfg.forcepermissive.config(confwrite).option(pathwrite).owner.set('new_user1')") - # else: - # with raises(PropertiesOptionError, - # "cfg.forcepermissive.option(pathwrite, 1).owner.set('new_user1')") - - _check_owner(cfg, pathread, confwrite, kwargs, 'new_user1', 'new_user1') - if confwrite != confread: - _check_owner(cfg, pathread, confread, kwargs, 'new_user1', 'new_user1') - - -@autocheck -def autocheck_option(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - #FIXME - if pathwrite.endswith('val1') or pathwrite.endswith('val2') or pathwrite in ['subod.subsubod.first', 'subod.subsubod.second', 'subod.subsubod.third']: - return - expected_name = pathread.split('.')[-1] - if not kwargs.get('permissive_od', False): - current_name = cfg.option(pathread).name() - assert current_name == cfg.forcepermissive.option(pathread).name() - assert current_name == cfg.unrestraint.option(pathread).name() - doc = cfg.option(pathread).doc() - assert doc == cfg.forcepermissive.option(pathread).doc() - assert doc == cfg.unrestraint.option(pathread).doc() - elif not kwargs.get('propertyerror', False): - with raises(PropertiesOptionError): - cfg.option(pathread).name() - current_name = cfg.forcepermissive.option(pathread).name() - assert current_name == cfg.unrestraint.option(pathread).name() - with raises(PropertiesOptionError): - cfg.option(pathread).doc() - doc = cfg.forcepermissive.option(pathread).doc() - assert doc == cfg.unrestraint.option(pathread).doc() - else: - with raises(PropertiesOptionError): - cfg.option(pathread).name() - with raises(PropertiesOptionError): - cfg.forcepermissive.option(pathread).name() - current_name = cfg.unrestraint.option(pathread).name() - with raises(PropertiesOptionError): - cfg.option(pathread).doc() - with raises(PropertiesOptionError): - cfg.forcepermissive.option(pathread).doc() - doc = cfg.unrestraint.option(pathread).doc() - assert current_name == expected_name - if expected_name.endswith('val1') or expected_name.endswith('val2'): - expected_name = expected_name[:-4] - if kwargs['symlink']: - assert doc == "{}'s option link".format(expected_name) - else: - assert doc == "{}'s option".format(expected_name) - - -@autocheck -def autocheck_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - """test permissive for hidden and disabled value - """ - # no permissive before - if confwrite is not None: - cfg_ = cfg.unrestraint.config(confwrite) - else: - cfg_ = cfg.unrestraint - if confread is not None: - cfg2_ = cfg.config(confread).unrestraint - else: - cfg2_ = cfg.unrestraint - - if not cfg_.option(pathread).isfollower(): - assert cfg_.option(pathread).permissive.get() == frozenset() - else: - assert cfg_.option(pathread, 0).permissive.get() == frozenset() - if kwargs.get('permissive_od', False): - assert cfg_.option(pathread.rsplit('.', 1)[0]).permissive.get() == frozenset() - - # cannot access to hidden value without forcepermissive - # and to disabled value (with forcepermissive too) - # - # with meta confread == confwrite - _autocheck_default_value(cfg, pathread, confread, **kwargs) - - # set permissive - cfg_.option(pathwrite).permissive.set(frozenset(['disabled'])) - callback = kwargs['callback'] - if callback: - if pathread.endswith('val1') or pathread.endswith('val2'): - call_path = pathread[:-4] + 'call' + pathread[-4:] - else: - call_path = pathread + 'call' - cfg_.option(call_path).permissive.set(frozenset(['disabled'])) - - # have permissive? - if not cfg_.option(pathread).isfollower(): - assert cfg_.option(pathread).permissive.get() == frozenset(['disabled']) - else: - assert cfg_.option(pathread, 0).permissive.get() == frozenset(['disabled']) - #if confwrite != confread: - # assert cfg.config(confread).unrestraint.option(pathread).permissive.get() == frozenset(['disabled']) - - # can access to disabled value - ckwargs = copy(kwargs) - ckwargs['propertyerror'] = False - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) - - cfg2_.option(pathwrite).permissive.set(frozenset(['disabled', 'hidden'])) - if kwargs['callback']: - cfg2_.option(call_path).permissive.set(frozenset(['disabled', 'hidden'])) - - # can access to all value except when optiondescript have hidden - if not ckwargs.get('permissive_od', False): - ckwargs['permissive'] = False - _autocheck_default_value(cfg, pathread, confread, **ckwargs) - - if ckwargs.get('permissive_od', False): - # set permissive to OptionDescription - cfg2_.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled', - 'hidden'])) - ckwargs['permissive'] = False - _autocheck_default_value(cfg, pathread, confread, **ckwargs) - #if confread != confwrite: - # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) - - # only hidden - cfg2_.option(pathwrite).permissive.set(frozenset(['hidden'])) - if callback: - cfg2_.option(call_path).permissive.set(frozenset(['hidden'])) - if ckwargs.get('permissive_od', False): - _autocheck_default_value(cfg, pathread, confread, **ckwargs) - cfg2_.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden'])) - ckwargs = copy(kwargs) - ckwargs['permissive'] = False - _autocheck_default_value(cfg, pathread, confread, **ckwargs) - - # no permissive - cfg2_.option(pathwrite).permissive.set(frozenset()) - if callback: - cfg2_.option(call_path).permissive.set(frozenset()) - if ckwargs.get('permissive_od', False): - _autocheck_default_value(cfg, pathread, confread, **ckwargs) - cfg2_.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset()) - _autocheck_default_value(cfg, pathread, confread, **kwargs) - - -@autocheck -def autocheck_option_get(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - if '.' in pathread: - name = pathread.rsplit('.', 1)[1] - else: - name = pathread - assert cfg.unrestraint.option(pathread).name() == name - - -@autocheck -def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - def _getoption(opt): - opt = opt.get() - if opt.impl_is_dynsymlinkoption(): - opt = opt.opt - return opt - - def _getoptions(opts): - nopts = [] - for opt in opts: - nopts.append(_getoption(opt)) - return nopts - - if '.' in pathread: - name = pathread.rsplit('.', 1)[1] - else: - name = pathread - option = _getoption(cfg.unrestraint.option(pathread)) - - def do(conf): - if conf is not None: - cfg_ = cfg.config(conf) - else: - cfg_ = cfg - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert option == _getoption(cfg_.option.find(name, first=True)) - assert option == _getoption(cfg_.forcepermissive.option.find(name, first=True)) - elif kwargs.get('permissive', False): - with raises(AttributeError): - cfg_.option.find(name, first=True) - assert option == _getoption(cfg_.forcepermissive.option.find(name, first=True)) - else: - with raises(AttributeError): - cfg_.option.find(name, first=True) - with raises(AttributeError): - cfg_.forcepermissive.option.find(name, first=True) - assert option == _getoption(cfg_.unrestraint.option.find(name, first=True)) - assert [option] == _getoptions(cfg_.unrestraint.option.find(name)) - do(confread) - if confread != confwrite: - do(confwrite) - - -def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, callback, symlink, weakrefs, **kwargs): - def _build_make_dict(): - dico = {} - dico_value = {} - if multi is False: - value = FIRST_VALUE - elif multi is True: - value = LIST_FIRST_VALUE - else: - value = SUBLIST_FIRST_VALUE - if not default or multi is submulti: - if not multi: - default_value = None - else: - default_value = [] - else: - default_value = value - kwargs['default'] = default_value - - is_dyn = False - is_leader = False - dyns = [] - has_value = False - for cpath, options in paths_.items(): - if options is None: - break - if '.' in cpath: - dirname, name = cpath.split('.')[-2:] - for dname in cpath.split('.')[:-1]: - if options.get(dname, {}).get('dyn'): - is_dyn = True - if options.get(dname, {}).get('leader'): - is_leader = True - else: - dirname = '' - name = cpath - if options.get(dirname, {}).get('hidden'): - continue - allow_req = require and req - no_propertieserror = not options.get(name, {}).get('disabled') and not options.get(name, {}).get('hidden') - if is_dyn: - dyns.append(no_propertieserror or allow_req) - if not is_dyn and (no_propertieserror or allow_req): - dico[cpath] = default_value - if symlink: - dico[cpath + 'link'] = default_value - if path == cpath: - dico_value[cpath] = value - if symlink: - dico_value[cpath + 'link'] = value - else: - dico_value[cpath] = default_value - if symlink: - dico_value[cpath + 'link'] = default_value - - has_value = True - isfollower = False - if '.' in path and is_leader and not path.rsplit('.', 1)[1].startswith('first'): - isfollower = True - if not multi is submulti: - kwargs['default'] = None - if is_dyn and dyns: - idx = 0 - for cpath in list(paths_.keys())[len(dyns):]: - if dyns[idx]: - dico[cpath] = default_value - if symlink: - dico[cpath + 'link'] = default_value - if path == cpath: - dico_value[cpath] = value - if symlink: - dico_value[cpath + 'link'] = value - else: - dico_value[cpath] = default_value - if symlink: - dico_value[cpath + 'link'] = default_value - idx += 1 - if idx == len(dyns): - idx = 0 - if require: - if not req: - dico['extraoptrequire'] = None - dico_value['extraoptrequire'] = None - if symlink: - dico['extraoptrequirelink'] = None - dico_value['extraoptrequirelink'] = None - else: - dico['extraoptrequire'] = 'value' - dico_value['extraoptrequire'] = 'value' - if symlink: - dico['extraoptrequirelink'] = 'value' - dico_value['extraoptrequirelink'] = 'value' - if is_leader: - for cpath in list(paths_.keys())[len(dyns):]: - if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'): - second_path = cpath.rsplit('.', 1)[0] + '.second' - third_path = cpath.rsplit('.', 1)[0] + '.third' - cons_path = cpath.rsplit('.', 1)[0] + '.extraoptconsistency' - if is_dyn: - suffix = cpath[-4:] - second_path += suffix - third_path += suffix - cons_path += suffix - # - if default_multi: - if multi is not submulti: - dvalue = SECOND_VALUE - else: - dvalue = LIST_SECOND_VALUE - else: - dvalue = [] - if dvalue == [] and multi is not submulti: - dvalue = None - # - kwargs['default_multi'] = dvalue - if isfollower: - kwargs['default'] = dvalue - len_leader = len(dico[cpath]) - if second_path in dico: - dico[second_path] = [dvalue] * len_leader - if symlink: - dico[second_path + 'link'] = [dvalue] * len_leader - if third_path in dico: - dico[third_path] = [dvalue] * len_leader - if symlink: - dico[third_path + 'link'] = [dvalue] * len_leader - if cons_path in dico: - dico[cons_path] = [dvalue] * len_leader - # - len_leader = len(dico_value[cpath]) - if second_path in dico_value: - dico_value[second_path] = [dvalue] * len_leader - if symlink: - dico_value[second_path + 'link'] = [dvalue] * len_leader - if third_path in dico_value: - dico_value[third_path] = [dvalue] * len_leader - if symlink: - dico_value[third_path + 'link'] = [dvalue] * len_leader - if cons_path in dico_value: - dico_value[cons_path] = [dvalue] * len_leader - return is_dyn, dico, dico_value - if DISPLAY: - text = u' {} launch tests for {}'.format(ICON, path) - if multi is True: - text += u' as a multi' - elif multi is submulti: - text += u' as a submulti' - if default is True: - text += u' with default' - if multi is True: - text += u' with default value' - if default_multi is True: - text += u' with default multi' - if require: - text += u' with requirement' - text += u', kwargs: {}'.format(kwargs) - print(text) - if not require: - requires = [False] - else: - requires = [False, True] - confwrite = confread = None - idx = 0 - for req in requires: - is_dyn, kwargs['make_dict'], kwargs['make_dict_value'] = _build_make_dict() - kwargs['callback'] = callback - kwargs['symlink'] = symlink - for func in autocheck_registers: - cfg_name = 'conftest' + str(idx) - idx += 1 - ncfg = cfg.config.copy(name=cfg_name) - if meta: - confwrite = None - confread = cfg_name - mcfg = MetaConfig([ncfg], name='metatest') - weakrefs.append(weakref.ref(cfg)) - else: - mcfg = ncfg - ckwargs = copy(kwargs) - if meta: - mcfg.owner.set('meta') - ckwargs['owner'] = owners.meta - else: - ckwargs['owner'] = OWNER - - if mcfg.unrestraint.option(path).isfollower(): - dirname = path.rsplit('.', 1)[0] - leader_path = dirname + '.first' - leader_path_2 = None - if dirname.endswith('val1') or dirname.endswith('val2'): - leader_path += 'val1' - leader_path = leader_path.replace('val2', 'val1') - leader_path_2 = leader_path.replace('val1', 'val2') - if multi is submulti: - value = SUBLIST_SECOND_VALUE - else: - value = LIST_SECOND_VALUE - with warnings.catch_warnings(record=True) as w: - mcfg.option(leader_path).value.set(value) - ckwargs['make_dict'][leader_path] = value - ckwargs['make_dict_value'][leader_path] = value - if symlink: - ckwargs['make_dict'][leader_path + 'link'] = value - ckwargs['make_dict_value'][leader_path + 'link'] = value - if leader_path_2: - with warnings.catch_warnings(record=True) as w: - mcfg.option(leader_path_2).value.set(value) - ckwargs['make_dict'][leader_path_2] = value - ckwargs['make_dict_value'][leader_path_2] = value - if symlink: - ckwargs['make_dict'][leader_path_2 + 'link'] = value - ckwargs['make_dict_value'][leader_path_2 + 'link'] = value - if default_multi: - if multi is not submulti: - dvalue = SECOND_VALUE - else: - dvalue = LIST_SECOND_VALUE - elif multi is submulti: - dvalue = [] - else: - dvalue = None - def do(suffix, oldsuffix=None): - if suffix: - ldirname = dirname.replace(oldsuffix, suffix) - else: - ldirname = dirname - npath = ldirname + '.second' + suffix - if npath in ckwargs['make_dict']: - ckwargs['make_dict'][npath] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath] = [dvalue] * len(value) - if symlink: - ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value) - if path == npath: - ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][leader_path][-1] - if symlink: - ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][leader_path][-1] - npath = ldirname + '.third' + suffix - if npath in ckwargs['make_dict']: - ckwargs['make_dict'][npath] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath] = [dvalue] * len(value) - if symlink: - ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value) - if path == npath: - ckwargs['make_dict_value'][npath][-1] = ckwargs['make_dict_value'][leader_path][-1] - if symlink: - ckwargs['make_dict_value'][npath + 'link'][-1] = ckwargs['make_dict_value'][leader_path][-1] - npath = ldirname + '.extraoptconsistency' + suffix - if npath in ckwargs['make_dict']: - ckwargs['make_dict'][npath] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath] = [dvalue] * len(value) - if symlink: - ckwargs['make_dict'][npath + 'link'] = [dvalue] * len(value) - ckwargs['make_dict_value'][npath + 'link'] = [dvalue] * len(value) - if not is_dyn: - do('') - else: - #do(dirname[-4:]) - do('val1', 'val2') - do('val2', 'val1') - - ncfg.property.read_write() - mcfg.property.read_write() - if req: - name = 'extraoptrequire' - if symlink: - name += 'link' - mcfg.option(name).value.set('value') - if 'permissive' in ckwargs and not 'permissive_od' in ckwargs or \ - 'propertyerror' in ckwargs and not 'propertyerror_od' in ckwargs: - for to_del in ['permissive', 'propertyerror', 'extra_properties']: - if to_del in ckwargs: - del ckwargs[to_del] - if DISPLAY: - print(u' {} {}'.format(ICON, func.__name__)) - pathread = path - if symlink: - pathwrite = path + 'link' - else: - pathwrite = path - try: - func(mcfg, ncfg, pathread, pathwrite, confread, confwrite, **ckwargs) - except Exception as err: - msg = u'error in function {} for {}'.format(func.__name__, path) - if multi is True: - msg += u' as a multi' - elif multi is submulti: - msg += u' as a submulti' - if default is True: - msg += u' with default value' - if callback is True: - msg += u' (callback)' - if symlink is True: - msg += u' (symlink)' - print(u'{}: {}'.format(msg, ckwargs)) - raise err - if meta: - del mcfg - del ncfg - - -def check_deref(weakrefs): - """try if all elements are dereferenced - """ - for wrf in weakrefs: - assert wrf() is None - - -def make_conf(options, multi, default, default_multi, require, callback, symlink): - weakrefs = [] - dyn = [] - goptions = [] - def make_option(path, option_infos, in_leader, leader): - option_type = 'str' - option_properties = [] - option_requires = [] - isfollower = False - if in_leader and symlink: - return None, None, None - if option_infos is not None: - if require: - return None, None, None - for prop in PROPERTIES: - if option_infos.get(prop, False) is True: - if not require: - option_properties.append(prop) - else: - option_requires.append({'option': goptions[0], 'expected': None, - 'action': prop}) - isfollower = option_infos.get('follower', False) - args = [path, "{}'s option".format(path)] - kwargs = {} - call_kwargs = {} - if option_properties != []: - kwargs['properties'] = tuple(option_properties) - if callback: - call_kwargs['properties'] = tuple(option_properties) - if option_requires != []: - if callback: - call_kwargs['requires'] = option_requires - else: - kwargs['requires'] = option_requires - if multi and path != 'extraoptrequire': - kwargs['multi'] = multi - if callback: - call_kwargs['multi'] = multi - if ((not in_leader or leader) and default) and path != 'extraoptrequire' and not path.endswith('extraoptconsistency'): - if multi is False: - value = FIRST_VALUE - elif multi is True: - value = LIST_FIRST_VALUE - else: - value = SUBLIST_EMPTY_VALUE - if callback: - kwargs['callback'] = return_str - call_kwargs['default'] = value - else: - kwargs['default'] = value - elif callback: - return None, None, None - if default_multi and path != 'extraoptrequire': - if multi is not submulti: - value = SECOND_VALUE - else: - value = LIST_SECOND_VALUE - kwargs['default_multi'] = value - - tiramisu_option = OPTIONS_TYPE[option_type]['option'] - if callback: - largs = [path + 'call', "{}'s callback option".format(path)] - objcall = tiramisu_option(*largs, **call_kwargs) - kwargs['default'] = Calculation(kwargs['callback'], Params(ParamOption(objcall))) - del kwargs['callback'] - else: - objcall = None - if symlink and not path.endswith('extraoptconsistency'): - sobj = tiramisu_option(args[0] + 'link', args[1] + ' link', **kwargs) - kwargs = {} - args[1] = sobj - tiramisu_option = SymLinkOption - else: - sobj = None - obj = tiramisu_option(*args, **kwargs) - return obj, objcall, sobj - - def make_optiondescriptions(path, collected): - infos = collected.get('properties', {}) properties = [] - kwargs = {} - optiondescription = OptionDescription - - for prop in PROPERTIES: - if infos.get(prop, False) is True: - properties.append(prop) - if infos.get('leader', False) is True: - if not multi: - return - optiondescription = Leadership - if infos.get('dyn', False) is True: - if symlink: - return - optiondescription = DynOptionDescription - kwargs['suffixes'] = Calculation(return_list) - dyn.append(path) - options = [] - if 'options' in collected: - options.extend(collected['options']) - for key, values in collected.items(): - if key in ['options', 'properties']: - continue - option = make_optiondescriptions(key, values) - if option is None: - return - options.append(option) - if properties != []: - kwargs['properties'] = tuple(properties) - obj = optiondescription(path, "{}'s optiondescription".format(path), options, **kwargs) - weakrefs.append(weakref.ref(obj)) - return obj - - collect_options = {} - if require: - noptions = OrderedDict() - if require: - noptions['extraoptrequire'] = {} - noptions.update(options) + if multi is True: + base_name += 'multi_' + elif multi is submulti: + base_name += 'submulti_' + if leadership: + param_multi = multi is submulti else: - noptions = options + param_multi = multi + if not param_multi: + str1_5_informations = {'info': 'value'} + cfg_informations = Calculation(return_var, Params(ParamInformation('cfg_key'))) + else: + str1_5_informations = {'info': ['value']} + cfg_informations = [Calculation(return_var, Params(ParamInformation('cfg_key')))] + if leadership: + base_name += 'deps_follower_0_' + if dynamic or dynoptiondescription: + base_name += 'dynamic_' + if hidden: + base_name += 'hidden_' + str1 = StrOption(base_name + 'information_deps', + '', + multi=multi, + properties=tuple(properties), + informations=str1_5_informations, + ) + str2 = StrOption(base_name + 'disabled_deps', + '', + multi=multi, + properties=tuple(properties + ['disabled']), + ) + str3_name = base_name + 'calc_property_param_disabled' + if not leadership: + str3_name += '_deps' + str3 = StrOption(str3_name, + '', + multi=multi, + properties=tuple(properties + [Calculation(return_disabled, Params(ParamOption(str2, notraisepropertyerror=True)))]), + ) + choice = ChoiceOption(base_name + 'choice_deps', + '', + values=('val1', 'val2'), + multi=multi, + properties=tuple(properties), + ) + variables = [str1, + str2, + StrOption(base_name + 'calc_default', + '', + Calculation(return_val, Params(ParamValue(param_multi))), + multi=multi, + properties=tuple(properties), + ), + StrOption(base_name + 'calc_default_param', + '', + Calculation(return_var, Params(ParamOption(str1))), + multi=multi, + properties=tuple(properties) + ), + StrOption(base_name + 'calc_default_param_disable', + '', + Calculation(return_var_disabled, Params((ParamOption(str2, notraisepropertyerror=True), ParamValue(param_multi)))), + multi=multi, + properties=tuple(properties), + ), + StrOption(base_name + 'calc_property', + '', + multi=multi, + properties=tuple(properties + [Calculation(return_property)]), + ), + StrOption(base_name + 'calc_property_disabled', + '', + multi=multi, + properties=tuple(properties + [Calculation(return_disabled, Params(ParamOption(str1)))]), + ), + StrOption(base_name + 'calc_property_disabled_self', + '', + multi=multi, + properties=tuple(properties + [Calculation(return_disabled, Params(ParamSelfOption()))]), + ), + StrOption(base_name + 'validator', + '', + multi=multi, + properties=tuple(properties), + validators=[Calculation(return_validator, Params((ParamSelfOption(), ParamOption(str1))))], + ), + StrOption(base_name + 'calc_default_information', + '', + Calculation(return_var, Params(ParamInformation('info', option=str1))), + multi=multi, + properties=tuple(properties), + ), + StrOption(base_name + 'calc_default_information_cfg', + '', + cfg_informations, + multi=multi, + properties=tuple(properties), + ), + str3, + StrOption(base_name + 'calc_default_information_self', + '', + Calculation(return_var, Params(ParamSelfInformation('info'))), + multi=multi, + properties=tuple(properties), + informations=str1_5_informations, + ), + choice, + ] + if not leadership: + sym1 = SymLinkOption(base_name + 'symlink_information_deps', str1) + sym2 = SymLinkOption(base_name + 'symlink_disabled_deps', str2) + variables.extend([sym1, + sym2, + SymLinkOption(base_name + 'symlink_calc_property_disabled_deps', str3), + SymLinkOption(base_name + 'symlink_choice_deps', choice), + StrOption(base_name + 'calc_default_param_sym', + '', + Calculation(return_var, Params(ParamOption(sym1))), + multi=multi, + properties=tuple(properties) + ), + StrOption(base_name + 'calc_default_param_disable_sym', + '', + Calculation(return_var_disabled, Params((ParamOption(sym2, notraisepropertyerror=True), ParamValue(param_multi)))), + multi=multi, + properties=tuple(properties), + ), + StrOption(base_name + 'calc_property_param_disabled_sym', + '', + multi=multi, + properties=tuple(properties + [Calculation(return_disabled, Params(ParamOption(sym2, notraisepropertyerror=True)))]), + ) + ]) + else: + default = Calculation(calc_value, Params(ParamIndex())) + if param_multi: + default = [default] + variables.append(IntOption(base_name + 'calc_default_index', + '', + default, + multi=multi, + properties=tuple(properties), + ) + ) + if dynoptiondescription: + default = Calculation(calc_value, Params(ParamSuffix())) + if param_multi: + default = [default] + variables.append(StrOption(base_name + 'calc_default_suffix', + '', + default, + multi=multi, + properties=tuple(properties), + ) + ) + if not leadership: + for idx, parent in enumerate(parent_variables): + if not parent: + continue + base_name_2 = 'parent_' + if dynamic or dynoptiondescription: + base_name_2 += 'dynamic_' + if hidden: + base_name_2 += 'hidden_' + base_name_3 = base_name_2 + if mandatory: + base_name_2 += 'mandatory_' + variables.extend([ + StrOption(f'{base_name_2}calc_default_param_{idx}', + '', + Calculation(return_var, Params(ParamOption(parent[0]))), + properties=tuple(properties), + ), + StrOption(f'{base_name_2}calc_property_disabled_{idx}', + '', + properties=tuple(properties + [Calculation(return_disabled, Params(ParamOption(parent[0])))]), + ), + StrOption(f'{base_name_2}validator_{idx}', + '', + properties=tuple(properties), + validators=[Calculation(return_validator, Params((ParamSelfOption(), ParamOption(parent[0]))))], + ), + StrOption(f'{base_name_2}calc_default_information_{idx}', + '', + Calculation(return_var, Params(ParamInformation('info', option=parent[0]))), + properties=tuple(properties), + ), + SymLinkOption(f'{base_name_3}symlink_information_deps_{idx}', parent[0]), + # + StrOption(f'{base_name_2}calc_property_param_disabled_{idx}', + '', + properties=tuple(properties + [Calculation(return_disabled, Params(ParamOption(parent[1], notraisepropertyerror=True)))]), + ), + StrOption(f'{base_name_2}calc_default_param_disable_{idx}', + '', + Calculation(return_var_disabled, Params((ParamOption(parent[1], notraisepropertyerror=True), ParamValue(False)))), + properties=tuple(properties), + ), + SymLinkOption(f'{base_name_3}symlink_disabled_deps_{idx}', parent[1]), + ]) + return variables - for path, option in noptions.items(): - if option is None: - continue - local_collect_options = collect_options - for optiondescription in path.split('.')[:-1]: - local_collect_options.setdefault(optiondescription, {'properties': {}}) - local_collect_options = local_collect_options[optiondescription] - local_collect_options['properties'].update(option.get(optiondescription, {})) - option_name = path.split('.')[-1] - in_leader = False - if '.' in path: - name_od = path.rsplit('.', 1)[0] - if '.' in name_od: - subod, name_od = name_od.split('.') - oddescr = collect_options.get(subod, {}) - else: - oddescr = collect_options - in_leader = oddescr.get(name_od, {}).get('properties', {}).get('leader') - leader = in_leader and path.endswith('first') - obj, objcall, sobj = make_option(option_name, option.get(option_name), in_leader, leader) - if obj is None: - return None, None, None - weakrefs.append(weakref.ref(obj)) - if callback: - weakrefs.append(weakref.ref(objcall)) - if sobj is not None: - weakrefs.append(weakref.ref(sobj)) - if '.' in path: - if leader: - local_collect_options.setdefault('options', []).insert(0, obj) - else: - local_collect_options.setdefault('options', []).append(obj) + +def build_options_for_parent(dynoptiondescription, + hidden, + ): + base_name = 'parent_' + if dynoptiondescription: + base_name += 'dynamic_' + if hidden: + base_name += 'hidden_' + return (StrOption(base_name + 'information_deps', '', informations={'info': 'parent_value'}), + StrOption(base_name + 'disabled_deps', + '', + properties=('disabled',), + ), + ) + + +def build_root_variables(*, + tree, + **kwargs, + ): + parent_variables = [] + dynamic = False + hidden = False + hidden_idx = 0 + for t in tree: + if hidden: + hidden_idx += 1 + if t.startswith('h'): + t = t[1:] + hidden = True + if t == 'dod': + dynamic=True + parent_variables.append(build_options_for_parent(dynamic, hidden)) + variables = build_variables(**kwargs, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden) + follower_params = kwargs.copy() + follower_params['leadership'] = True + if 'multi' in follower_params and follower_params['multi']: + follower_params['multi'] = submulti + else: + follower_params['multi'] = True + suffix = '' + if dynamic: + suffix += '_dynamic' + lsuffix = suffix + if hidden: + lsuffix += '_hidden' + variables.append(Leadership('leadership' + lsuffix, '', [StrOption('leader_multi_deps' + lsuffix, + '', + default=['l1', 'l2'], + multi=True, + ), + ] + build_variables(**follower_params, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), + )) + suffixes = StrOption('suffixes_multi_deps' + lsuffix, '', ['d1', 'd2'], multi=True) + variables.append(suffixes) + dynamic_name = 'dynamic_' + if hidden: + dynamic_name += 'hidden_' + variables.append(DynOptionDescription(dynamic_name, '', build_variables(**kwargs, dynoptiondescription=True, parent_variables=parent_variables, dynamic=dynamic, hidden=hidden), Calculation(return_var, Params(ParamOption(suffixes))))) + tree.reverse() + for idx, t in enumerate(tree): + lsuffix = suffix + variables.extend(parent_variables.pop(-1)) + if hidden and idx <= hidden_idx: + lsuffix = '_hidden' + suffix + if t.startswith('h'): + t = t[1:] + properties = frozenset(['hidden']) else: - local_collect_options.setdefault('options', []).append(obj) - goptions.append(obj) - if callback: - local_collect_options.setdefault('options', []).append(objcall) - goptions.append(objcall) - if sobj is not None: - local_collect_options.setdefault('options', []).append(sobj) - goptions.append(sobj) - - rootod = make_optiondescriptions('root', collect_options) - if rootod is None: - return None, None, None - cfg = Config(rootod, name='conftest') - weakrefs.append(weakref.ref(cfg)) - del goptions - return cfg, weakrefs, dyn + properties = frozenset() + if t == 'dod': + variables = [DynOptionDescription('tree_dynamic' + lsuffix, '', variables, Calculation(return_var, Params(ParamValue(['var1', 'var2']))), properties=properties)] + else: + variables = [OptionDescription('tree' + lsuffix, '', variables, properties=properties)] + od = OptionDescription('root', 'root', variables, informations={'cfg_key': 'cfg_info'}) + return od -DICT_PATHS = [ - # test a config without optiondescription - OrderedDict([('first', {}), - ('second', {'second': {'disabled': True}}), - ('third', {'third': {'hidden': True}}) - ]), - # test a config with two optiondescription - OrderedDict([('subod.subsubod.first', {}), - ('subod.subsubod.second', {'second': {'disabled': True}}), - ('subod.subsubod.third', {'third': {'hidden': True}})]), - # test a config with leadership - OrderedDict([('odleader.first', {'odleader': {'leader': True}}), - ('odleader.second', {'odleader': {'leader': True}, 'second': {'disabled': True, 'follower': True}}), - ('odleader.third', {'odleader': {'leader': True}, 'third': {'hidden': True, 'follower': True}})]), - # test a config with dynoption - OrderedDict([('subod.first', {'subod': {'dyn': True}}), - ('subod.second', {'second': {'disabled': True}}), - ('subod.third', {'third': {'hidden': True}}), - ('subodval1.firstval1', None), - ('subodval1.secondval1', None), - ('subodval1.thirdval1', None), - ('subodval2.firstval2', None), - ('subodval2.secondval2', None), - ('subodval2.thirdval2', None)]), - # test a config with dynoption subdir - OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True}}), - ('subod.subsubod.second', {'subsubod': {'dyn': True}, 'second': {'disabled': True}}), - ('subod.subsubod.third', {'subsubod': {'dyn': True}, 'third': {'hidden': True}}), - ('subod.subsubodval1.firstval1', None), - ('subod.subsubodval1.secondval1', None), - ('subod.subsubodval1.thirdval1', None), - ('subod.subsubodval2.firstval2', None), - ('subod.subsubodval2.secondval2', None), - ('subod.subsubodval2.thirdval2', None)]), - # test a config with hidden subsubod - OrderedDict([('subod.subsubod.first', {'subsubod': {'hidden': True}}), - ('subod.subsubod.second', {'subsubod': {'hidden': True}}), - ('subod.subsubod.third', {'subsubod': {'hidden': True}})]), - # test a config with hidden dyn subsubod - OrderedDict([('subod.subsubod.first', {'subsubod': {'dyn': True, 'hidden': True}}), - ('subod.subsubod.second', {'subsubod': {'dyn': True, 'hidden': True}}), - ('subod.subsubod.third', {'subsubod': {'dyn': True, 'hidden': True}}), - ('subod.subsubodval1.firstval1', None), - ('subod.subsubodval1.secondval1', None), - ('subod.subsubodval1.thirdval1', None), - ('subod.subsubodval2.firstval2', None), - ('subod.subsubodval2.secondval2', None), - ('subod.subsubodval2.thirdval2', None)]), - # test a config with dyn subsubod with leadership - OrderedDict([('subod.subsubod.first', {'subod': {'dyn': True}, 'subsubod': {'leader': True}}), - ('subod.subsubod.second', {'subod': {'dyn': True}, 'subsubod' : {'leader': True}, 'second': {'disabled': True, 'follower': True}}), - ('subod.subsubod.third', {'subod': {'dyn': True}, 'subsubod': {'leader': True}, 'third': {'hidden': True, 'follower': True}}), - ('subodval1.subsubodval1.firstval1', None), - ('subodval1.subsubodval1.secondval1', None), - ('subodval1.subsubodval1.thirdval1', None), - ('subodval2.subsubodval2.firstval2', None), - ('subodval2.subsubodval2.secondval2', None), - ('subodval2.subsubodval2.thirdval2', None)]), -] +PARAMS = [{}, + {'mandatory': True}, + {'multi': True}, + {'mandatory': True, 'multi': True}, + ] +OD = [ + [], + ['od'], + ['od', 'od'], + ['hod'], + ['hod', 'od'], + ['od', 'hod'], + ['dod'], + ['hdod'], + ['dod', 'dod'], + ['hdod', 'dod'], + ['dod', 'hdod'], + ['dod', 'od'], + ['dod', 'od', 'dod'], + ['dod', 'od', 'dod', 'od'], + ['dod', 'od', 'dod', 'hod'], + ['dod', 'od', 'hdod', 'od'], + ] -@pytest.fixture(scope="function", params=DICT_PATHS) -def paths(request): - if DISPLAY: - print(u'\n{} {}: {}'.format(ICON, request.function.__name__, request.param)) - return request.param +SCENARII = [] +for od in OD: + SCENARII.append({'tree': od}) + for params in PARAMS: + SCENARII[-1].update(params) -def test_options(paths): - def get_kwargs_option(options, kwargs, od=False): - if options.get('mandatory', False): - kwargs['mandatory'] = True - if options.get('hidden', False) is True: - kwargs['permissive'] = True - if not od: - kwargs.setdefault('extra_properties', []).append('hidden') +@pytest.fixture(scope="function", params=SCENARII) +def root_variables(request): + try: + owners.addowner('test') + except ConstError: + pass + ALLOWED_LEADER_PROPERTIES.add('new') + return build_root_variables(**request.param) + +from pprint import pprint as pprint2 +#pprint = pprint2 +def pprint(a): + print() + def p(b): + ret = {} + for i, j in b.items(): + k = i.name() + if isinstance(j, dict): + ret[k] = p(j) else: - kwargs['permissive_od'] = True - if options.get('disabled', False) is True: - kwargs['propertyerror'] = True - if not od: - kwargs.setdefault('extra_properties', []).append('disabled') + ret[k] = j + return ret + c = p(a) + + pprint2(c) + + +def walk(cfg, idx=0): + yield cfg + for opt in cfg.list(): + # print(' ' * idx, opt.path()) + if opt.isoptiondescription(): + yield from walk(opt, idx + 2) + else: + yield(opt) + + +def _test_option(option, without_index=False): + # optiondescription and option + name = option.name() + opt = option.get() + if opt is None: + # it's a 'root' object + assert name is None + assert option.isoptiondescription() + assert not option.isleadership() + assert not option.isdynamic() + assert option.doc() is 'root' + assert option.description() == 'root' + assert option.path() is None + assert not option.has_dependency() + else: + assert isinstance(name, str) + assert isinstance(opt, BaseOption) + assert (isinstance(opt, OptionDescription) and option.isoptiondescription()) or (not isinstance(opt, OptionDescription) and not option.isoptiondescription()) + if option.isoptiondescription(): + assert ('leadership' not in name and not option.isleadership()) or ('leadership' in name and option.isleadership()) + if option.isleadership(): + assert 'leader_' in option.leader().name() else: - kwargs['propertyerror_od'] = True + with pytest.raises(ConfigError): + option.leader() + else: + with pytest.raises(ConfigError): + option.leadership() + assert option.isdynamic() == ('dynamic' in name) + if option.isdynamic(): + suffixes = [] + for path in option.path().split('.'): + if 'dynamicvar1' in path: + suffixes.append('var1') + if 'dynamicvar2' in path: + suffixes.append('var2') + if 'd1' in path: + suffixes.append('d1') + if 'd2' in path: + suffixes.append('d2') + assert option.suffixes() == suffixes + assert isinstance(option.doc(), str) and option.doc() == name + assert isinstance(option.description(), str) and option.description() == '' + assert isinstance(option.path(), str) and (option.path() == name or option.path().endswith(f'.{name}')) + if '_deps' in name: + assert option.has_dependency(False) + assert option.dependencies() + else: + assert not option.has_dependency(False) + assert not option.dependencies() + if option.isoptiondescription(): + assert option.type() == 'optiondescription' + elif 'index' in name: + assert option.type() == _('integer') + elif 'choice' in name: + assert option.type() == _('choice') + else: + assert option.type() == _('string') + # only option + if option.isoptiondescription(): + with pytest.raises(ConfigError): + option.ismulti() + with pytest.raises(ConfigError): + option.issubmulti() + with pytest.raises(ConfigError): + option.isleader() + with pytest.raises(ConfigError): + option.isfollower() + with pytest.raises(ConfigError): + option.issymlinkoption() + with pytest.raises(ConfigError): + option.default() + with pytest.raises(ConfigError): + option.defaultmulti() + with pytest.raises(ConfigError): + option.pattern() + with pytest.raises(ConfigError): + option.index() + else: + assert 'symlink' in name and option.issymlinkoption() or 'symlink' not in name and not option.issymlinkoption() + try: + assert 'multi' in name and option.ismulti() or 'multi' not in name and not option.ismulti() + except Exception as err: + print(err) + print(option.value.get()) + raise Exception('err') + assert 'submulti' in name and option.issubmulti() or 'submulti' not in name and not option.issubmulti() + if option.issymlinkoption(): + assert not option.isleader() + assert not option.isfollower() + with pytest.raises(ConfigError): + option.pattern() + assert option.index() is None + else: + assert 'leader' in name and option.isleader() or 'leader' not in name and not option.isleader() + assert 'follower' in name and option.isfollower() or 'follower' not in name and not option.isfollower() + if option.isfollower() and not without_index: + assert option.index() in [0, 1] + else: + assert option.index() is None + if option.type() == _('integer'): + assert option.pattern() == '^[0-9]+$' + else: + assert not option.pattern() + default = option.default() + if 'calc_default' in name: + assert isinstance(default, Calculation) or (isinstance(default, list) and len(default) == 1 and isinstance(default[0], Calculation)) + elif 'suffixes_multi' in name: + assert default == ['d1', 'd2'] + elif 'leader_multi' in name: + assert default == ['l1', 'l2'] + elif 'multi' in name: + assert default == [] + else: + assert default is None + if option.issubmulti(): + assert option.defaultmulti() == [] + elif option.ismulti(): + assert option.defaultmulti() is None - def get_kwargs(path): - kwargs = {} - spath = path.split('.') - get_kwargs_option(paths[path].get(spath[-1], {}), kwargs) - if len(spath) > 1: - get_kwargs_option(paths[path].get(spath[-2], {}), kwargs, od=True) - return kwargs - lpaths = list(paths.keys()) +def _test_information(cfg, option, without_index=False): + name = option.name() + # list + lst = option.information.list() + if name is None: + assert lst == {'cfg_key', 'doc'} + elif 'information' in name and ('information_self' in name or 'calc_default' not in name): + assert lst == {'doc', 'info'} + else: + assert lst == {'doc'} + # get + assert option.information.get('unknown', 'no_value') == 'no_value' + if name is None: + assert option.information.get('doc') == 'root' + else: + assert option.information.get('doc') == '' + if 'cfg_key' in lst: + assert option.information.get('cfg_key') == 'cfg_info' + if 'info' in lst: + if 'parent' in name: + value = 'parent_value' + else: + value = 'value' + if 'multi' in name: + value = [value] + assert option.information.get('info') == value + # set + if not option.isoptiondescription() and option.issymlinkoption(): + with pytest.raises(ConfigError): + option.information.set('new', 'value') + with pytest.raises(ConfigError): + option.information.reset('new') + return + if not option.isoptiondescription() and option.isfollower() and not without_index: + # index is not allowed + with pytest.raises(ConfigError): + option.information.set('new', 'value') + with pytest.raises(ConfigError): + option.information.reset('new') + option.information.get('doc') + with pytest.raises(ConfigError): + option.information.set('new', 'value') + option.information.list() + with pytest.raises(ConfigError): + option.information.remove('new') + else: + option.information.set('new', 'value') + assert option.information.get('new') == 'value' + assert option.information.list() == lst | {'new'} + option.information.set('new', 'value2') + assert option.information.get('new') == 'value2' + assert option.information.list() == lst | {'new'} + # remove + option.information.remove('new') + assert option.information.list() == lst + with pytest.raises(ValueError): + option.information.remove('doc') -# for meta in (False, True): -# for callback in (False, True): -# for require in (False, True): -# for default_multi in (False, True): -# for symlink in (False, True): -# if callback and default_multi: -# continue -# for default in (False, True): -# for multi in (False, True, submulti): - for meta in (False,): - for callback in (False,): - for require in (False,): - for default_multi in (False,): - for symlink in (False,): - if callback and default_multi: - continue - for default in (False,): - for multi in (True,): - if multi is submulti and default: - continue - if multi is False and default_multi: - continue - cfg, weakrefs, dyn = make_conf(paths, multi, default, default_multi, require, callback, symlink) - if cfg is None: - continue - if dyn: - cnt = 0 - idx = 0 - for index, lpath in enumerate(lpaths): - if paths[lpath]: - cnt += 1 - else: - check_all(cfg, paths, lpaths[index], meta, multi, default, - default_multi, require, callback, symlink, - weakrefs, **get_kwargs(lpaths[idx])) - idx += 1 - if idx == cnt: - idx = 0 - else: - for lpath in lpaths: - check_all(cfg, paths, lpath, meta, multi, default, - default_multi, require, callback, symlink, - weakrefs, **get_kwargs(lpath)) - del cfg - check_deref(weakrefs) +# Value +def _test_value(cfg, option, unrestraint=False, without_index=False): + #owner + name = option.name() + if option.isoptiondescription(): + _test_owner_optiondescription(name, option) + _test_value_optiondescription(name, option, unrestraint) + elif not unrestraint and 'disabled' in name: + if not without_index or 'calc_property' not in name or 'hidden' in name: + _test_owner_disabled(name, option, without_index) + _test_value_disabled(name, option, without_index) + else: + _test_owner_without_index(option) + _test_value_without_index(option) + elif not unrestraint and 'hidden' in name: + _test_owner_disabled(name, option, without_index) + _test_value_disabled(name, option, without_index) + elif without_index: + _test_owner_without_index(option) + _test_value_without_index(option) + else: + _test_owner(option, without_index) + _test_value_normal(name, cfg, option, unrestraint, without_index) + + +def _test_owner_optiondescription(name, option): + with pytest.raises((AttributeError, ConfigError)): + option.owner.isdefault() + if name is None: + assert option.owner.get() == owners.user + option.owner.set(owners.test) + assert option.owner.get() == owners.test + option.owner.set(owners.user) + assert option.owner.get() == owners.user + else: + with pytest.raises(ConfigError): + option.owner.get() + with pytest.raises(ConfigError): + option.owner.set(owners.test) + + +def _test_value_optiondescription(name, option, unrestraint): + if not unrestraint and name and 'hidden' in name: + with pytest.raises(PropertiesOptionError): + option.value.get() + else: + assert isinstance(option.value.get(), dict) + if name != None: + with pytest.raises(ConfigError): + option.value.set('value') + with pytest.raises(ConfigError): + option.value.reset() + with pytest.raises(ConfigError): + option.value.default() + with pytest.raises(ConfigError): + option.value.valid() + with pytest.raises(ConfigError): + option.value.list() + with pytest.raises(ConfigError): + option.value.pop(1) + with pytest.raises(ConfigError): + option.value.len() + + +def _test_owner_disabled(name, option, without_index): + if without_index: + errtype = ConfigError + else: + errtype = PropertiesOptionError + with pytest.raises(errtype): + option.owner.isdefault() + with pytest.raises(errtype): + option.owner.get() + if 'symlink' in name: + with pytest.raises(ConfigError): + option.owner.set(owners.test) + else: + with pytest.raises(errtype): + option.owner.set(owners.test) + + +def _test_owner_without_index(option): + with pytest.raises(ConfigError): + option.owner.isdefault() + with pytest.raises(ConfigError): + option.owner.get() + with pytest.raises(ConfigError): + option.owner.set(owners.test) + + +def _test_owner(option, without_index): + if without_index: + with pytest.raises(ConfigError): + assert option.owner.isdefault() + with pytest.raises(ConfigError): + assert option.owner.get() + else: + assert option.owner.isdefault() + assert option.owner.get() == owners.default + with pytest.raises(ConfigError): + # not availlable for symlink or without index or option has default value + option.owner.set(owners.test) + + +def _test_value_disabled(name, option, without_index): + if without_index: + errtype = ConfigError + else: + errtype = PropertiesOptionError + with pytest.raises(errtype): + option.value.get() + if 'symlink' in name: + with pytest.raises(ConfigError): + option.value.set('val') + with pytest.raises(ConfigError): + option.value.reset() + with pytest.raises(ConfigError): + option.value.valid() + else: + with pytest.raises(errtype): + option.value.set('val') + with pytest.raises(errtype): + option.value.reset() + with pytest.raises(errtype): + option.value.valid() + #if without_index: + # assert option.value.len() == 2 + # if 'choice' in name: + # assert option.value.list() == ('val1', 'val2') + # else: + # with pytest.raises(ConfigError): + # option.value.list() + #else: + if 'leader' in name or 'follower' in name: + with pytest.raises(PropertiesOptionError): + option.value.len() + else: + with pytest.raises(ConfigError): + option.value.len() + if 'choice' in name and 'symlink' not in name: + with pytest.raises(errtype): + option.value.list() + else: + with pytest.raises(ConfigError): + option.value.list() + + +def _test_value_without_index(option): + with pytest.raises(ConfigError): + option.value.get() + with pytest.raises(ConfigError): + option.value.set('val') + with pytest.raises(ConfigError): + option.value.reset() + with pytest.raises(ConfigError): + option.value.valid() + with pytest.raises(ConfigError): + option.value.list() + assert option.value.len() == 2 + + +def _get_value(name, option, unrestraint): + if 'calc_default_information' in name: + if 'calc_default_information_cfg' in name: + value = 'cfg_info' + elif 'parent' in name: + value = 'parent_value' + else: + value = 'value' + if 'multi' in name: + value = [value] + elif 'calc_default_suffix' in name: + value = option.suffixes()[-1] + if 'multi' in name: + value = [value] + elif 'calc_default_index' in name: + value = option.index() + if 'multi' in name: + value = [value] + elif 'calc_default' in name and 'calc_default_param' not in name: + value = 'val' + if 'multi' in name: + value = [value] + elif 'suffixes_multi' in name: + value = ['d1', 'd2'] + elif 'leader_multi_deps' in name: + value = ['l1', 'l2'] + elif 'multi' in name: + value = [] + else: + value = None + return value + + +def _test_value_normal(name, cfg, option, unrestraint, without_index): + #value + value = _get_value(name, option, unrestraint) + if without_index: + with pytest.raises(ConfigError): + option.value.get() + else: + assert option.value.get() == value + #set + if option.issymlinkoption() or without_index: + with pytest.raises(ConfigError): + option.value.set(owners.test) + with pytest.raises(ConfigError): + option.value.reset() + with pytest.raises(ConfigError): + option.value.valid() + if without_index: + assert option.value.len() == 2 + if 'choice' in name: + assert option.value.list() == ('val1', 'val2') + else: + with pytest.raises(ConfigError): + option.value.list() + else: + with pytest.raises(ConfigError): + option.value.len() + with pytest.raises(ConfigError): + option.value.list() + else: + if option.type() == _('string'): + new_value = 'new_value' + new_value2 = 'new_value1' + new_value3 = 'new_value2' + elif option.type() == _('integer'): + new_value = 10 + new_value2 = 11 + new_value3 = 12 + elif 'choice' in name: + new_value = 'val2' + new_value2 = 'val1' + if 'multi' in name: + new_value = [new_value, new_value2] + option.value.set(new_value) + assert option.value.get() == new_value + assert not option.owner.isdefault() + assert option.owner.get() == owners.user + # + option.owner.set(owners.test) + assert option.owner.get() == owners.test + option.value.set(new_value) + assert option.owner.get() == owners.user + cfg.owner.set(owners.test) + option.value.set(new_value) + assert option.owner.get() == owners.test + cfg.owner.set(owners.user) + # + if 'leader' in name: + option.value.set(new_value + [new_value3]) + assert option.value.len() == 3 + with pytest.raises(LeadershipError): + option.value.set(new_value) + assert option.value.len() == 3 + option.value.pop(2) + assert option.value.get() == new_value + # + assert option.value.default() == value + # + option.value.reset() + assert option.value.get() == value + assert option.owner.isdefault() + assert option.owner.get() == owners.default + # valid + assert option.value.valid() is True + # list + if 'choice' in name: + assert option.value.list() == ('val1', 'val2') + else: + with pytest.raises(ConfigError): + option.value.list() + if 'leader' in name or 'follower' in name: + assert option.value.len() == 2 + else: + with pytest.raises(ConfigError): + option.value.len() + + +def _test_property(cfg, option, unrestraint=False, without_index=False): + name = option.name() + properties = [] + properties_only_raises = [] + properties_apply_requires = [] + properties_uncalculated = [] + if not option.isoptiondescription() and option.issymlinkoption(): + name = option.option().name() + if name is None: + if unrestraint: + properties.append('cache') + properties_apply_requires.append('cache') + properties_uncalculated.append('cache') + else: + properties.extend(['disabled', 'frozen', 'validator', 'cache', 'force_store_value', 'hidden']) + properties_apply_requires.extend(['disabled', 'frozen', 'validator', 'cache', 'force_store_value', 'hidden']) + properties_uncalculated.extend(['disabled', 'frozen', 'validator', 'cache', 'force_store_value', 'hidden']) + if name and 'disabled' in name: + properties.append('disabled') + if not unrestraint: + properties_only_raises.append('disabled') + if not 'calc_property' in name: + properties_apply_requires.append('disabled') + properties_uncalculated.append('disabled') + else: + properties_uncalculated.append('calculation') + if name and ('hidden' in name or 'hidden' in option.name()): + properties.append('hidden') + if not unrestraint: + properties_only_raises.append('hidden') + properties_apply_requires.append('hidden') + properties_uncalculated.append('hidden') + if name and 'mandatory' in name: + properties.append('mandatory') + properties_apply_requires.append('mandatory') + properties_uncalculated.append('mandatory') + if name and 'submulti' in name: + # it's a follower + pass + elif name and 'multi' in name and not option.isfollower(): + properties.append('unique') + properties.append('empty') + properties_apply_requires.append('unique') + properties_apply_requires.append('empty') + properties_uncalculated.append('unique') + properties_uncalculated.append('empty') + if name and 'calc_property' in name and not 'calc_property_disabled' in name and not 'property_param_disabled' in name: + properties.append('prop') + properties_uncalculated.append('calculation') + + if not without_index: + assert option.property.get() == set(properties) + assert option.property.get(only_raises=True) == set(properties_only_raises) + assert option.property.get(apply_requires=False) == set(properties_apply_requires) + option_property = option.property.get(uncalculated=True) + if "calculation" in properties_uncalculated: + new_option_property = set() + for p in option_property: + if isinstance(p, Calculation): + properties_uncalculated.remove('calculation') + else: + new_option_property.add(p) + assert new_option_property == set(properties_uncalculated) + else: + assert option_property == set(properties_uncalculated) + # + if (name is not None or not unrestraint) and (option.isoptiondescription() or not option.issymlinkoption()): + assert 'new' not in option.property.get() + option.property.add('new') + assert 'new' in option.property.get() + option.property.remove('new') + assert 'new' not in option.property.get() + if properties: + if option.path() is not None: + for prop in properties: + with pytest.raises(ConfigError): + option.property.remove(prop) + assert option.property.get() == set(properties) + # + option.property.add('new') + option.property.reset() + else: + for prop in properties: + option.property.remove(prop) + assert option.property.get() == set() + for prop in properties: + option.property.add(prop) + assert option.property.get() == set(properties) + # + option.property.reset() + assert option.property.get() == set() + for prop in properties: + option.property.add(prop) + with pytest.raises(ConfigError): + option.property.remove('unknown') + else: + for prop in properties: + with pytest.raises(ConfigError): + option.property.remove(prop) + with pytest.raises(ConfigError): + option.property.add('unknown') + with pytest.raises(ConfigError): + option.property.reset() + assert option.property.get() == set(properties) + else: + with pytest.raises(ConfigError): + option.property.get() + with pytest.raises(ConfigError): + option.property.get(only_raises=True) + with pytest.raises(ConfigError): + option.property.get(apply_requires=False) + with pytest.raises(ConfigError): + option.property.get(uncalculated=True) + #with pytest.raises(ConfigError): + option.property.add('new') + #with pytest.raises(ConfigError): + option.property.remove('new') + #with pytest.raises(ConfigError): + option.property.reset() + # + + +def _test_permissive(cfg, option, unrestraint=False, without_index=False): + name = option.name() + if name is None: + default_permissives = {'hidden'} + else: + default_permissives = set() + assert option.permissive.get() == default_permissives + if (name is not None or not unrestraint) and (option.isoptiondescription() or not option.issymlinkoption()): + option.permissive.add('new') + assert option.permissive.get() == default_permissives | {'new'} + option.permissive.remove('new') + assert option.permissive.get() == default_permissives + # + with pytest.raises(ConfigError): + option.permissive.remove('unknown') + # + option.permissive.add('new') + option.permissive.reset() + assert option.permissive.get() == default_permissives + # + if name and not unrestraint: + props = set() + if 'disabled' in name: + props.add('disabled') + if 'hidden' in name: + props.add('hidden') + if props: + for p in props: + if not without_index: + assert option.property.get(only_raises=True) == props + option.permissive.add(p) + assert option.property.get(only_raises=True) == props - set([p]) + option.permissive.remove(p) + assert option.property.get(only_raises=True) == props + else: + with pytest.raises(ConfigError): + option.property.get(only_raises=True) + # + else: + with pytest.raises(ConfigError): + option.permissive.add('new') + with pytest.raises(ConfigError): + option.permissive.remove('new') + with pytest.raises(ConfigError): + option.permissive.reset() + + +def test_auto_root(root_variables): + cfg = Config(root_variables) + cfg.property.read_write() + for option in walk(cfg.unrestraint): + # we are in unrestraint mode, set option with property + _test_option(option) + _test_information(cfg, option) + _test_value(cfg, option, True) + _test_property(cfg, option, True) + _test_permissive(cfg, option, True) + if not option.isoptiondescription() and option.isfollower(): + follower_without_index_option = cfg.unrestraint.option(option.path()) + _test_option(follower_without_index_option, without_index=True) + _test_information(cfg, follower_without_index_option, without_index=True) + _test_value(cfg, follower_without_index_option, True, without_index=True) + _test_property(cfg, follower_without_index_option, True, without_index=True) + _test_permissive(cfg, follower_without_index_option, True, without_index=True) + if option.path() is None: + continue + elif option.isoptiondescription(): + new_option = cfg.option(option.path()) + else: + new_option = cfg.option(option.path(), option.index()) + _test_option(new_option) + _test_information(cfg, new_option) + _test_value(cfg, new_option) + _test_property(cfg, new_option) + _test_permissive(cfg, new_option) + if not option.isoptiondescription() and option.isfollower(): + follower_without_index_option = cfg.option(option.path()) + _test_option(follower_without_index_option, without_index=True) + _test_information(cfg, follower_without_index_option, without_index=True) + _test_value(cfg, follower_without_index_option, without_index=True) + _test_property(cfg, follower_without_index_option, without_index=True) + _test_permissive(cfg, follower_without_index_option, without_index=True) +## +## +##def test_auto_root_ro(root_variables): +## cfg = Config(root_variables) +## cfg.information.set('cfg_key', 'cfg_info') +## cfg.property.read_only() +## mandatories = cfg.value.mandatory() +## if not mandatories: +## pprint(cfg.value.get()) +# +# +#def test_auto_root_without_cache(root_variables): +# cfg = Config(root_variables) +# cfg.information.set('cfg_key', 'cfg_info') +# cfg.property.read_write() +# cfg.property.remove('cache') +# pprint(cfg.value.get()) +## +## +##def test_auto_root_without_cache_ro(root_variables): +## cfg = Config(root_variables) +## cfg.information.set('cfg_key', 'cfg_info') +## cfg.property.read_only() +## cfg.property.remove('cache') +## mandatories = cfg.value.mandatory() +## if not mandatories: +## pprint(cfg.value.get()) +#FIXME +#class ParamDynOption() +#leadership property, ... +#tester leader ! +#FIXME dependencies doit contenir _dependencies_information + +#Choice +#Choice calculé diff --git a/tests/test_cache.py b/tests/test_cache.py index eb1038d..b8070f0 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -81,10 +81,10 @@ def test_cache_importation_property(): def test_cache_importation_permissive(): od1 = make_description() cfg = Config(od1) - cfg.option('u2').permissive.set(frozenset(['prop'])) + cfg.option('u2').permissive.add('prop') export = cfg.permissive.exportation() assert cfg.option('u2').permissive.get() == {'prop'} - cfg.option('u2').permissive.set(frozenset(['prop', 'prop2'])) + cfg.option('u2').permissive.add('prop2') assert cfg.option('u2').permissive.get() == {'prop', 'prop2'} cfg.permissive.importation(export) assert cfg.option('u2').permissive.get() == {'prop'} @@ -266,7 +266,7 @@ def test_cache_leadership(): #assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None] #assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None cache = settings.get_cached() - assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) + assert set(cache.keys()) == set(['ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(cache['ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == {0} @@ -284,7 +284,7 @@ def test_cache_leadership(): #assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None #assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None cache = settings.get_cached() - assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) + assert set(cache.keys()) == set(['ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(cache['ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1]) @@ -376,26 +376,22 @@ def test_cache_leader_and_followers(): idx_val2 = None values = cfg._config_bag.context._impl_values_cache settings = cfg._config_bag.context.properties_cache - compare(settings.get_cached(), {None: {None: (global_props, None)}, - 'val1': {None: (val1_props, None)}, - 'val1.val1': {None: (val1_val1_props, None)}, - }) + compare(settings.get_cached(), {'val1': {None: (val1_props, None)}, + 'val1.val1': {None: (val1_val1_props, None)}, + }) # len is 0 so don't get any value compare(values.get_cached(), {'val1.val1': {None: ([], None)}}) # cfg.option('val1.val1').value.set([None]) val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)} - compare(settings.get_cached(), {None: {None: (set(global_props), None)}, -# 'val1.val1': {None: (val1_val1_props, None)}, - }) + compare(settings.get_cached(), {'val1.val1': {None: ({'empty', 'unique'}, None, True)}}) compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}}) cfg.value.get() #has value idx_val2 = 0 val_val2 = None val_val2_props = {idx_val2: (val1_val2_props, None)} - compare(settings.get_cached(), {None: {None: (global_props, None)}, - 'val1': {None: (val1_props, None)}, + compare(settings.get_cached(), {'val1': {None: (val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)}, 'val1.val2': val_val2_props}) compare(values.get_cached(), {'val1.val1': {None: ([None], None)}, @@ -404,7 +400,7 @@ def test_cache_leader_and_followers(): cfg.option('val1.val1').value.set([None, None]) cfg.value.get() cfg.option('val1.val2', 1).value.set('oui') - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}}) + compare(settings.get_cached(), {}) compare(values.get_cached(), {'val1.val2': {1: ('oui', None, True)}}) val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)} # assert not list_sessions() @@ -428,15 +424,12 @@ def test_cache_leader_callback(): val1_val2_props = frozenset(val1_val2_props) values = cfg._config_bag.context._impl_values_cache settings = cfg._config_bag.context.properties_cache - compare(settings.get_cached(), {None: {None: (global_props, None)}, - 'val1': {None: (val1_props, None)}, + compare(settings.get_cached(), {'val1': {None: (val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)}, }) compare(values.get_cached(), {'val1.val1': {None: ([], None)}}) cfg.option('val1.val1').value.set([None]) - compare(settings.get_cached(), {None: {None: (set(global_props), None)}, -# 'val1.val1': {None: (val1_val1_props, None)}, - }) + compare(settings.get_cached(), {'val1.val1': {None: ({'unique', 'empty'}, None, True)}}) compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}}) cfg.value.get() @@ -458,39 +451,34 @@ def test_cache_requires(): settings = cfg._config_bag.context.properties_cache assert values.get_cached() == {} assert cfg.option('ip_address_service').value.get() == None - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) compare(values.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) cfg.value.get() - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) compare(values.get_cached(), {'ip_address_service': {None: (None, None)}, - 'activate_service': {None: (True, None)}}) + 'activate_service': {None: (True, None)}}) cfg.option('ip_address_service').value.set('1.1.1.1') - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}}) compare(values.get_cached(), {'activate_service': {None: (True, None)}, 'ip_address_service': {None: ('1.1.1.1', None, True)}}) cfg.value.get() - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) compare(values.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)}, 'activate_service': {None: (True, None)}}) cfg.option('activate_service').value.set(False) - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}}) + compare(settings.get_cached(), {}) compare(values.get_cached(), {'activate_service': {None: (False, None)}}) cfg.value.get() - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set(['disabled']), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set(['disabled']), None)}}) compare(values.get_cached(), {'activate_service': {None: (False, None)}}) # assert not list_sessions() @@ -511,22 +499,19 @@ def test_cache_global_properties(): settings = cfg._config_bag.context.properties_cache assert values.get_cached() == {} assert cfg.option('ip_address_service').value.get() == None - compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) compare(values.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) cfg.property.remove('disabled') assert cfg.option('ip_address_service').value.get() == None - compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) cfg.property.add('test') assert cfg.option('ip_address_service').value.get() == None - compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)}, - 'activate_service': {None: (set([]), None)}, - 'ip_address_service': {None: (set([]), None)}}) + compare(settings.get_cached(), {'activate_service': {None: (set([]), None)}, + 'ip_address_service': {None: (set([]), None)}}) # assert not list_sessions() diff --git a/tests/test_choice_option.py b/tests/test_choice_option.py index 2794513..753b781 100644 --- a/tests/test_choice_option.py +++ b/tests/test_choice_option.py @@ -1,10 +1,9 @@ # coding: utf-8 -from py.test import raises - from .autopath import do_autopath do_autopath() -from .config import config_type, get_config, value_list, global_owner +from .config import config_type, get_config, value_list, global_owner, parse_od_get +from pytest import raises from tiramisu import ChoiceOption, StrOption, OptionDescription, Config, owners, Calculation, \ undefined, Params, ParamValue, ParamOption from tiramisu.error import ConfigError @@ -76,6 +75,29 @@ def test_choiceoption_function(config_type): # assert not list_sessions() +def test_choiceoption_subfunction(config_type): + choice = ChoiceOption('choice', '', values=(Calculation(return_val, Params(ParamValue('val1'))), Calculation(return_val, Params(ParamValue('val2'))))) + od1 = OptionDescription('od', '', [choice]) + cfg = Config(od1) + cfg.property.read_write() + cfg = get_config(cfg, config_type) + owner = global_owner(cfg, config_type) + assert cfg.option('choice').owner.isdefault() + # + cfg.option('choice').value.set('val1') + assert cfg.option('choice').owner.get() == owner + # + cfg.option('choice').value.reset() + assert cfg.option('choice').owner.isdefault() + # + with raises(ValueError): + cfg.option('choice').value.set('no') + assert cfg.option('choice').owner.isdefault() + # + assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2') +# assert not list_sessions() + + def test_choiceoption_function_error(): choice = ChoiceOption('choice', '', values=Calculation(return_error)) od1 = OptionDescription('od', '', [choice]) @@ -262,3 +284,13 @@ def test_choiceoption_calc_not_list(): with raises(ConfigError): cfg.option('choice').value.set(['val1']) # assert not list_sessions() + + +def test_choiceoption_calc_default_value(): + var1 = StrOption("var1", '', default="val1") + var2 = StrOption("var2", '', default="val2") + choice = ChoiceOption("choice", '', values=(Calculation(return_val, Params((ParamOption(var1)))), Calculation(return_val, Params((ParamOption(var2))))), default="val1") + od2 = OptionDescription("rougail", '', children=[var1, var2, choice]) + od1 = OptionDescription("baseoption", "", children=[od2]) + cfg = Config(od1) + assert parse_od_get(cfg.value.get()) == {'rougail.var1': 'val1', 'rougail.var2': 'val2', 'rougail.choice': 'val1'} diff --git a/tests/test_config.py b/tests/test_config.py index d151ea3..5107f15 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -26,8 +26,7 @@ def make_description(): floatoption = FloatOption('float', 'Test float option', default=2.3) stroption = StrOption('str', 'Test string option', default="abc", properties=('mandatory', )) boolop = BoolOption('boolop', 'Test boolean option op', default=True, properties=('hidden',)) - wantref_option = BoolOption('wantref', 'Test requires', default=False) - wantref_option.impl_set_information('info', 'default value') + wantref_option = BoolOption('wantref', 'Test requires', default=False, informations={'info': 'default value'}) wantframework_option = BoolOption('wantframework', 'Test requires', default=False) @@ -143,11 +142,11 @@ def test_information_config(): with pytest.raises(ValueError): cfg.information.get('noinfo') assert cfg.information.get('noinfo', 'default') == 'default' - cfg.information.reset('info') + cfg.information.remove('info') with pytest.raises(ValueError): - cfg.information.get('info') + cfg.information.remove('info') with pytest.raises(ValueError): - cfg.information.reset('noinfo') + cfg.information.remove('noinfo') assert list(cfg.information.list()) == ['doc'] # assert not list_sessions() @@ -194,26 +193,23 @@ def test_information_option(): with pytest.raises(ValueError): cfg.option('gc.name').information.get('noinfo') assert cfg.option('gc.name').information.get('noinfo', 'default') == 'default' - cfg.option('gc.name').information.reset('info') + cfg.option('gc.name').information.remove('info') with pytest.raises(ValueError): cfg.option('gc.name').information.get('info') with pytest.raises(ValueError): - cfg.option('gc.name').information.reset('noinfo') + cfg.option('gc.name').information.remove('noinfo') assert list(cfg.option('gc.name').information.list()) == ['doc'] # assert cfg.option('wantref').information.get('info') == 'default value' cfg.option('wantref').information.set('info', 'default value') assert cfg.option('wantref').information.get('info') == 'default value' - cfg.option('wantref').information.reset('info') + cfg.option('wantref').information.remove('info') assert cfg.option('wantref').information.get('info') == 'default value' # assert not list_sessions() def test_information_option_2(): - i1 = IntOption('test1', '') - i1.impl_set_information('info', 'value') - # it's a dict - assert set(i1.impl_list_information()) == {'info', 'doc'} + i1 = IntOption('test1', '', informations={'info': 'value'}) od1 = OptionDescription('test', '', [i1]) cfg = Config(od1) # it's tuples @@ -234,11 +230,11 @@ def test_information_optiondescription(): with pytest.raises(ValueError): cfg.option('gc').information.get('noinfo') assert cfg.option('gc').information.get('noinfo', 'default') == 'default' - cfg.option('gc').information.reset('info') + cfg.option('gc').information.remove('info') with pytest.raises(ValueError): cfg.option('gc').information.get('info') with pytest.raises(ValueError): - cfg.option('gc').information.reset('noinfo') + cfg.option('gc').information.remove('noinfo') assert list(cfg.option('gc').information.list()) == ['doc'] # assert not list_sessions() diff --git a/tests/test_config_api.py b/tests/test_config_api.py index 577ff04..9ce7ba9 100644 --- a/tests/test_config_api.py +++ b/tests/test_config_api.py @@ -412,7 +412,6 @@ def test_help(): cfg = Config(od2) cfg.help(_display=False) cfg.config.help(_display=False) - cfg.option.help(_display=False) cfg.option('o').help(_display=False) cfg.option('o.s').help(_display=False) # assert not list_sessions() @@ -430,7 +429,7 @@ def test_config_reset(): # cfg.option('gc.gc2.bool').value.set(True) cfg.option('boolop').property.add('test') - cfg.option('float').permissive.set(frozenset(['test'])) + cfg.option('float').permissive.add('test') cfg.option('wantref').information.set('info', 'info') assert cfg.option('gc.gc2.bool').value.get() assert cfg.option('boolop').property.get() diff --git a/tests/test_duplicate_config.py b/tests/test_duplicate_config.py index f4eca78..44d05b6 100644 --- a/tests/test_duplicate_config.py +++ b/tests/test_duplicate_config.py @@ -59,27 +59,27 @@ def test_copy_information(): ncfg = cfg.config.copy() assert ncfg.information.get('key') == 'value' # assert not list_sessions() -# -# -#def test_copy_force_store_value(): -# od1 = make_description() -# conf = Config(od1) -# conf2 = Config(od1) -# assert conf.value.exportation() == {} -# assert conf2.value.exportation() == {} -# # -# conf.property.read_write() -# assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} -# assert conf2.value.exportation() == {} -# # -# conf2.property.read_only() -# assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} -# assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} -# # -# conf.option('creole.general.wantref').value.set(True) -# assert conf.value.exportation() == {'creole.general.wantref': {None: [True, 'user']}} -# assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} -## assert not list_sessions() + + +def test_copy_force_store_value(): + od1 = make_description() + conf = Config(od1) + conf2 = Config(od1) + assert conf.value.exportation() == {} + assert conf2.value.exportation() == {} + # + conf.property.read_write() + assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} + assert conf2.value.exportation() == {} + # + conf2.property.read_only() + assert conf.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} + assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} + # + conf.option('creole.general.wantref').value.set(True) + assert conf.value.exportation() == {'creole.general.wantref': {None: [True, 'user']}} + assert conf2.value.exportation() == {'creole.general.wantref': {None: [False, 'forced']}} +# assert not list_sessions() # # #def test_copy_force_store_value_metaconfig(): diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index 7d0bad5..fdb543d 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -11,17 +11,16 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ OptionDescription, DynOptionDescription, submulti, Leadership, \ Config, \ - Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, \ + Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, ParamSelfInformation, ParamInformation, \ Calculation, calc_value -from tiramisu.option.syndynoption import SynDynOption from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError, ValueOptionError -def display_name(kls) -> str: +def display_name(kls, subconfig) -> str: """Replace the Tiramisu display_name function to display path + description""" - doc = kls.impl_get_information("doc", None) - comment = f" ({doc})" if doc and doc != kls.impl_getname() else "" - return f"{kls.impl_getpath()}{comment}" + doc = kls._get_information(subconfig, "doc", None) + comment = f" ({doc})" if doc and doc != subconfig.path.rsplit('.', 1)[-1] else "" + return f"{subconfig.path}{comment}" class ConvertDynOptionDescription(DynOptionDescription): @@ -256,8 +255,6 @@ def test_prop_dyndescription(): cfg.option('od.dodval2.st').property.add('test2') assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) - cfg.option('od.dodval1.st').property.remove('test') - assert set(cfg.option('od.dodval1.st').property.get()) == set([]) # assert set(cfg.option('od.dodval1').property.get()) == set([]) assert set(cfg.option('od.dodval2').property.get()) == set([]) @@ -268,36 +265,36 @@ def test_prop_dyndescription(): assert set(cfg.option('od.dodval1').property.get()) == set([]) assert set(cfg.option('od.dodval2').property.get()) == set([]) # assert not list_sessions() -# -# -#def test_prop_dyndescription_force_store_value(): -# st = StrOption('st', '', properties=('force_store_value',)) -# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [dod]) -# od2 = OptionDescription('od', '', [od]) -# cfg = Config(od2) -# cfg.property.read_write() -# assert cfg.value.get() == {'od.dodval1.st': None, 'od.dodval2.st': None} -## assert not list_sessions() -# -# -#def test_prop_dyndescription_force_store_value_calculation_prefix(): -# lst = StrOption('lst', '', ['val1', 'val2'], multi=True) -# st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) -# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) -# od = OptionDescription('od', '', [dod, lst]) -# od2 = OptionDescription('od', '', [od]) -# cfg = Config(od2) -# cfg.property.read_write() -# assert cfg.option('od.dodval1.st').owner.isdefault() == False -# assert cfg.option('od.dodval2.st').owner.isdefault() == False -# assert cfg.value.get() == {'od.lst': ['val1', 'val2'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2'} -# # -# cfg.option('od.lst').value.set(['val1', 'val2', 'val3']) -# assert cfg.option('od.dodval3.st').owner.isdefault() == False -# assert cfg.option('od.dodval1.st').owner.isdefault() == False -# assert cfg.option('od.dodval2.st').owner.isdefault() == False -# assert cfg.value.get() == {'od.lst': ['val1', 'val2', 'val3'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.dodval3.st': 'val3'} + + +def test_prop_dyndescription_force_store_value(): + st = StrOption('st', '', properties=('force_store_value',)) + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [dod]) + od2 = OptionDescription('od', '', [od]) + cfg = Config(od2) + cfg.property.read_write() + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st': None, 'od.dodval2.st': None} +# assert not list_sessions() + + +def test_prop_dyndescription_force_store_value_calculation_prefix(): + lst = StrOption('lst', '', ['val1', 'val2'], multi=True) + st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',)) + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) + od = OptionDescription('od', '', [dod, lst]) + od2 = OptionDescription('od', '', [od]) + cfg = Config(od2) + cfg.property.read_write() + assert cfg.option('od.dodval1.st').owner.isdefault() == False + assert cfg.option('od.dodval2.st').owner.isdefault() == False + assert parse_od_get(cfg.value.get()) == {'od.lst': ['val1', 'val2'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2'} + # + cfg.option('od.lst').value.set(['val1', 'val2', 'val3']) + assert cfg.option('od.dodval3.st').owner.isdefault() == False + assert cfg.option('od.dodval1.st').owner.isdefault() == False + assert cfg.option('od.dodval2.st').owner.isdefault() == False + assert parse_od_get(cfg.value.get()) == {'od.lst': ['val1', 'val2', 'val3'], 'od.dodval1.st': 'val1', 'od.dodval2.st': 'val2', 'od.dodval3.st': 'val3'} # assert not list_sessions() @@ -324,26 +321,26 @@ def test_callback_dyndescription(): assert cfg.option('od.dodval1.st').owner.isdefault() assert cfg.option('od.dodval2.st').owner.isdefault() # assert not list_sessions() -# -# -#def test_callback_dyndescription_outside_wrong_param(): -# lst = StrOption('lst', '', ['val1', 'val2'], multi=True) -# st = StrOption('st', '', Calculation(return_dynval)) -# dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) -# out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st)))) -# od = OptionDescription('od', '', [dod, out]) -# od2 = OptionDescription('od', '', [od, lst]) -# cfg = Config(od2) -# with pytest.raises(ValueOptionError): -# cfg.value.get() -## assert not list_sessions() + + +def test_callback_dyndescription_outside_wrong_param(): + lst = StrOption('lst', '', ['val1', 'val2'], multi=True) + st = StrOption('st', '', Calculation(return_dynval)) + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) + out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st)))) + od = OptionDescription('od', '', [dod, out]) + od2 = OptionDescription('od', '', [od, lst]) + cfg = Config(od2) + with pytest.raises(ValueOptionError): + cfg.value.get() +# assert not list_sessions() def test_callback_dyndescription_outside1(): lst = StrOption('lst', '', ['val1', 'val2'], multi=True) st = StrOption('st', '', Calculation(return_dynval)) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst)))) - out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1'], dod)))) + out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, ['val1'])))) od = OptionDescription('od', '', [dod, out]) od2 = OptionDescription('od', '', [od, lst]) cfg = Config(od2) @@ -535,7 +532,7 @@ def test_prop_dyndescription_context(): cfg.option('od.dodval2.st').property.add('test2') assert set(cfg.option('od.dodval1.st').property.get()) == set(['test']) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) - cfg.option('od.dodval1.st').property.remove('test') + cfg.option('od.dodval1.st').permissive.add('test') assert set(cfg.option('od.dodval1.st').property.get()) == set([]) assert set(cfg.option('od.dodval2.st').property.get()) == set(['test', 'test2']) # assert not list_sessions() @@ -849,42 +846,42 @@ def calc_value_not_same(param, condition, expected, default, suffix): return calc_value(param, condition=condition[index], expected=expected, default=default) -#def test_requires_dyndescription_in_dyn_not_same(): -# boolean = BoolOption('boolean', '', True) -# disabled_property = Calculation(calc_value_not_same, -# Params(ParamValue('disabled'), -# kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), -# 'expected': ParamValue(False), -# 'default': ParamValue(None), -# 'suffix': ParamSuffix()})) -# st = StrOption('st', '', properties=(disabled_property,)) -# dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) -# dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [dod1, dod2]) -# od2 = OptionDescription('od', '', [od]) -# cfg = Config(od2) -# cfg.property.read_write() -# -# assert cfg.option('od.dod2val1.st').value.get() is None -# assert cfg.option('od.dod2val2.st').value.get() is None -# # -# cfg.option('od.dod1val1.boolean').value.set(False) -# -# props = [] -# try: -# cfg.option('od.dod2val1.st').value.get() -# except PropertiesOptionError as err: -# props = err.proptype -# assert props == frozenset(['disabled']) -# props = [] -# cfg.option('od.dod2val2.st').value.get() -# # -# cfg.option('od.dod1val1.boolean').value.set(True) -# assert cfg.option('od.dod2val1.st').value.get() is None -# assert cfg.option('od.dod2val2.st').value.get() is None -## assert not list_sessions() -# -# +def test_requires_dyndescription_in_dyn_not_same(): + boolean = BoolOption('boolean', '', True) + disabled_property = Calculation(calc_value_not_same, + Params(ParamValue('disabled'), + kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), + 'expected': ParamValue(False), + 'default': ParamValue(None), + 'suffix': ParamSuffix()})) + st = StrOption('st', '', properties=(disabled_property,)) + dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list)) + dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [dod1, dod2]) + od2 = OptionDescription('od', '', [od]) + cfg = Config(od2) + cfg.property.read_write() + + assert cfg.option('od.dod2val1.st').value.get() is None + assert cfg.option('od.dod2val2.st').value.get() is None + # + cfg.option('od.dod1val1.boolean').value.set(False) + + props = [] + try: + cfg.option('od.dod2val1.st').value.get() + except PropertiesOptionError as err: + props = err.proptype + assert props == frozenset(['disabled']) + props = [] + cfg.option('od.dod2val2.st').value.get() + # + cfg.option('od.dod1val1.boolean').value.set(True) + assert cfg.option('od.dod2val1.st').value.get() is None + assert cfg.option('od.dod2val2.st').value.get() is None +# assert not list_sessions() + + def test_requires_dyndescription2(): boolean = BoolOption('boolean', '', True) st1 = StrOption('st', '') @@ -981,16 +978,14 @@ def test_makedict_dyndescription_context(): # with pytest.raises(AttributeError): # list(cfg.option.find('strnotexists')) ## assert not list_sessions() -# -# + + def test_information_dyndescription_context(): val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) - st = StrOption('st', '') - dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + st = StrOption('st', '', informations={'testst': 'val2'}) + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list), informations={'testod': 'val1'}) od = OptionDescription('od', '', [dod, val1]) od2 = OptionDescription('od', '', [od]) - dod.impl_set_information('testod', 'val1') - st.impl_set_information('testst', 'val2') cfg = Config(od2) cfg.information.set('testcfgod', 'val3') assert cfg.option('od.dodval1').information.get('testod') == 'val1' @@ -1097,535 +1092,535 @@ def test_all_dyndescription(): # assert not list_sessions() -#def test_leadership_dyndescription(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# # -# assert cfg.value.get() == {'od.stval2.st1.st1': [], 'od.stval1.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('no') -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.pop(0) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# cfg.option('od.stval1.st1.st2', 0).value.reset() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# cfg.option('od.stval1.st1.st1').value.reset() -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_dyndescription_force_store_value_leader(): -# st1 = StrOption('st1', "", multi=True, default=Calculation(return_list), properties=('force_store_value',)) -# st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1)))) -# stm = Leadership('st1', '', [st1, st2]) -# val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) -# od = OptionDescription('od', '', [val1, st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# cfg.property.read_write() -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() == False -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() == False -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == True -# assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == True -# assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == True -# assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == True -# assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} -# # -# cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) -# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True -# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True -# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} -# # -# cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) -# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True -# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True -# assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == True -# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} -## assert not list_sessions() -# -# -#def test_leadership_dyndescription_force_store_value(): -# st1 = StrOption('st1', "", multi=True, default=Calculation(return_list)) -# st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1)))) -# stm = Leadership('st1', '', [st1, st2]) -# val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) -# od = OptionDescription('od', '', [val1, st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# cfg.property.read_write() -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() == True -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() == True -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == False -# assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == False -# assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == False -# assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == False -# assert cfg.value.get() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} -# # -# cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) -# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == True -# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False -# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} -# # -# cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) -# assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False -# assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == False -# assert cfg.value.get() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} -## assert not list_sessions() -# -# -#def test_leadership_default_multi_dyndescription1(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True, default_multi='no') -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# # -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_dyndescription_param(): -# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) -# odval = OptionDescription('odval1', '', [val1]) -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) -# od = OptionDescription('od', '', [st, odval]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('no') -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.pop(0) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st2', 0).value.reset() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# cfg.option('od.stval1.st1.st1').value.reset() -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -## assert not list_sessions() -# -# -#def test_leadership_default_multi_dyndescription2(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True, default_multi='no') -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# # -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def _test_leadership(cfg): -# owner = cfg.owner.get() -# cfg.option('od.val1.val1').value.set(['val1', 'val2']) -# cfg.option('od.val1.val2', 0).value.set('val1') -# cfg.option('od.val1.val2', 1).value.set('val2') -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('no') -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.pop(0) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st2', 0).value.reset() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# cfg.option('od.stval1.st1.st1').value.reset() -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default -# assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default -# -# -#def test_leadership_dyndescription_param_leader(): -# val1 = StrOption('val1', "", multi=True) -# val2 = StrOption('val2', "", multi=True) -# odval = Leadership('val1', '', [val1, val2]) -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) -# od = OptionDescription('od', '', [st, odval]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# _test_leadership(cfg) -## assert not list_sessions() -# -# -#def test_leadership_default_multi_dyndescription3(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True, default_multi='no') -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od2 = OptionDescription('od', '', [od]) -# with Config(od2) as cfg: -# owner = cfg.owner.get() -# # -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_dyndescription_param_follower(): -# val1 = StrOption('val1', "", multi=True) -# val2 = StrOption('val2', "", multi=True) -# odval = Leadership('val1', '', [val1, val2]) -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2)))) -# od = OptionDescription('od', '', [st, odval]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# _test_leadership(cfg) -## assert not list_sessions() -# -# -#def test_leadership_default_multi_dyndescription_sub(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True, default_multi='no') -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# # -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_submulti_dyndescription(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=submulti) -# stm = Leadership('st1', '', [st1, st2]) -# std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [std]) -# od2 = OptionDescription('od', '', [od1]) -# cfg = Config(od2) -# owner = cfg.owner.get() -# # -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set(['no']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == ['no'] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_callback_dyndescription(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [st1]) -# od2 = OptionDescription('od', '', [od1]) -# cfg = Config(od2) -# owner = cfg.owner.get() -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() ==[] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes'}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('no') -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.pop(0) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# cfg.option('od.stval1.st1.st2', 0).value.reset() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# cfg.option('od.stval1.st1.st1').value.reset() -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' -## assert not list_sessions() -# -# -#def test_leadership_callback_value_dyndescription(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# cfg.option('od.stval1.st1.st2', 0).value.set('val') -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' -## assert not list_sessions() -# -# -#def test_leadership_callback_nomulti_dyndescription(): -# v11 = StrOption('v1', '', "val") -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [stt]) -# od2 = OptionDescription('od', '', [od1, v11]) -# cfg = Config(od2) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' -## assert not list_sessions() -# -# -#def test_leadership_callback_samegroup_dyndescription(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) -# stm = Leadership('st1', '', [st1, st2, st3]) -# stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [stt]) -# od2 = OptionDescription('od', '', [od1]) -# cfg = Config(od2) -# owner = cfg.owner.get() -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# +def test_leadership_dyndescription(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + # + assert parse_od_get(cfg.value.get()) == {'od.stval2.st1.st1': [], 'od.stval1.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == None + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set('no') + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.pop(0) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + cfg.option('od.stval1.st1.st2', 0).value.reset() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + cfg.option('od.stval1.st1.st1').value.reset() + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_dyndescription_force_store_value_leader(): + st1 = StrOption('st1', "", multi=True, default=Calculation(return_list), properties=('force_store_value',)) + st2 = StrOption('st2', "", multi=True, default=Calculation(return_list, Params(ParamOption(st1)))) + stm = Leadership('st1', '', [st1, st2]) + val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) + od = OptionDescription('od', '', [val1, st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + cfg.property.read_write() + assert cfg.option('od.stval1.st1.st1').owner.isdefault() == False + assert cfg.option('od.stval2.st1.st1').owner.isdefault() == False + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == True + assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == True + assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == True + assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == True + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} + # + cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) + assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True + assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} + # + cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) + assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == True + assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == True + assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == True + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} +# assert not list_sessions() + + +def test_leadership_dyndescription_force_store_value(): + st1 = StrOption('st1', "", multi=True, default=Calculation(return_list)) + st2 = StrOption('st2', "", multi=True, properties=('force_store_value',), default=Calculation(return_list, Params(ParamOption(st1)))) + stm = Leadership('st1', '', [st1, st2]) + val1 = StrOption('val1', '', multi=True, default=['val1', 'val2']) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) + od = OptionDescription('od', '', [val1, st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + cfg.property.read_write() + assert cfg.option('od.stval1.st1.st1').owner.isdefault() == True + assert cfg.option('od.stval2.st1.st1').owner.isdefault() == True + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() == False + assert cfg.option('od.stval1.st1.st2', 1).owner.isdefault() == False + assert cfg.option('od.stval2.st1.st2', 0).owner.isdefault() == False + assert cfg.option('od.stval2.st1.st2', 1).owner.isdefault() == False + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}]} + # + cfg.option('od.val1').value.set(['val1', 'val2', 'val3']) + assert cfg.option('od.stval3.st1.st1').owner.isdefault() == True + assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}]} + # + cfg.option('od.stval3.st1.st1').value.set(['val1', 'val2', 'val3']) + assert cfg.option('od.stval3.st1.st1').owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 0).owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 1).owner.isdefault() == False + assert cfg.option('od.stval3.st1.st2', 2).owner.isdefault() == False + assert parse_od_get(cfg.value.get()) == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'val1', 'od.stval1.st1.st2': 'val1'}, {'od.stval1.st1.st1': 'val2', 'od.stval1.st1.st2': 'val2'}], 'od.stval2.st1.st1': [{'od.stval2.st1.st1': 'val1', 'od.stval2.st1.st2': 'val1'}, {'od.stval2.st1.st1': 'val2', 'od.stval2.st1.st2': 'val2'}], 'od.stval3.st1.st1': [{'od.stval3.st1.st1': 'val1', 'od.stval3.st1.st2': 'val1'}, {'od.stval3.st1.st1': 'val2', 'od.stval3.st1.st2': 'val2'}, {'od.stval3.st1.st1': 'val3', 'od.stval3.st1.st2': 'val3'}]} +# assert not list_sessions() + + +def test_leadership_default_multi_dyndescription1(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True, default_multi='no') + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + # + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_dyndescription_param(): + val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) + odval = OptionDescription('odval1', '', [val1]) + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) + od = OptionDescription('od', '', [st, odval]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.odval1.val1': ['val1', 'val2']} + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == None + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st2', 0).value.set('no') + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.pop(0) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st2', 0).value.reset() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + cfg.option('od.stval1.st1.st1').value.reset() + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default +# assert not list_sessions() + + +def test_leadership_default_multi_dyndescription2(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True, default_multi='no') + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + # + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def _test_leadership(cfg): + owner = cfg.owner.get() + cfg.option('od.val1.val1').value.set(['val1', 'val2']) + cfg.option('od.val1.val2', 0).value.set('val1') + cfg.option('od.val1.val2', 1).value.set('val2') + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]} + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == None + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st2', 0).value.set('no') + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.pop(0) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st2', 0).value.reset() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + cfg.option('od.stval1.st1.st1').value.reset() + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owners.default + assert cfg.option('od.stval2.st1.st1').owner.get() == owners.default + + +def test_leadership_dyndescription_param_leader(): + val1 = StrOption('val1', "", multi=True) + val2 = StrOption('val2', "", multi=True) + odval = Leadership('val1', '', [val1, val2]) + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1)))) + od = OptionDescription('od', '', [st, odval]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + _test_leadership(cfg) +# assert not list_sessions() + + +def test_leadership_default_multi_dyndescription3(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True, default_multi='no') + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od2 = OptionDescription('od', '', [od]) + cfg = Config(od2) + owner = cfg.owner.get() + # + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_dyndescription_param_follower(): + val1 = StrOption('val1', "", multi=True) + val2 = StrOption('val2', "", multi=True) + odval = Leadership('val1', '', [val1, val2]) + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2)))) + od = OptionDescription('od', '', [st, odval]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + _test_leadership(cfg) +# assert not list_sessions() + + +def test_leadership_default_multi_dyndescription_sub(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True, default_multi='no') + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + # + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_submulti_dyndescription(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=submulti) + stm = Leadership('st1', '', [st1, st2]) + std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [std]) + od2 = OptionDescription('od', '', [od1]) + cfg = Config(od2) + owner = cfg.owner.get() + # + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set(['no']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == ['no'] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_callback_dyndescription(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) + stm = Leadership('st1', '', [st1, st2]) + st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [st1]) + od2 = OptionDescription('od', '', [od1]) + cfg = Config(od2) + owner = cfg.owner.get() + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() ==[] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes'}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set('no') + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.pop(0) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + cfg.option('od.stval1.st1.st2', 0).value.reset() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + cfg.option('od.stval1.st1.st1').value.reset() + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'yes' +# assert not list_sessions() + + +def test_leadership_callback_value_dyndescription(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + cfg.option('od.stval1.st1.st2', 0).value.set('val') + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' +# assert not list_sessions() + + +def test_leadership_callback_nomulti_dyndescription(): + v11 = StrOption('v1', '', "val") + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) + stm = Leadership('st1', '', [st1, st2]) + stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [stt]) + od2 = OptionDescription('od', '', [od1, v11]) + cfg = Config(od2) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'val' +# assert not list_sessions() + + +def test_leadership_callback_samegroup_dyndescription(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) + stm = Leadership('st1', '', [st1, st2, st3]) + stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [stt]) + od2 = OptionDescription('od', '', [od1]) + cfg = Config(od2) + owner = cfg.owner.get() + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + def test_invalid_conflict_dyndescription(): st = StrOption('st', '') dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) @@ -1673,7 +1668,7 @@ def test_subdynod_dyndescription_root(): st2 = StrOption('st2', '') dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) od1 = OptionDescription('od', '', [dod, st3]) #, st4]) cfg = Config(od1) @@ -1740,7 +1735,7 @@ def test_subdynod_dyndescription(): dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) od1 = OptionDescription('od', '', [dod]) - st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) od = OptionDescription('od', '', [od1, st3]) #, st4]) cfg = Config(od) assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': None, @@ -1800,96 +1795,141 @@ def test_subdynod_dyndescription(): assert cfg.option('st3').value.get() is None # assert not list_sessions() -#def test_subdynod_dyndescription_2(): -# st2 = StrOption('st2', '') -# st1 = StrOption('st1', '', default=['a', 'b'], multi=True) -# dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) -# dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [dod]) -# st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod)))) -# od = OptionDescription('od', '', [od1, st3]) #, st4]) -# cfg = Config(od) -# assert cfg.value.get() == {'od.dodval1.dod1a.st2': None, -# 'od.dodval1.dod1b.st2': None, -# 'od.dodval1.st1': ['a', 'b'], -# 'od.dodval2.dod1a.st2': None, -# 'od.dodval2.dod1b.st2': None, -# 'od.dodval2.st1': ['a', 'b'], -# 'st3': None, -# } -# cfg.cache.reset() -# assert cfg.option('od.dodval1.dod1a.st2').value.get() is None -# assert cfg.option('od.dodval1.dod1b.st2').value.get() is None -# assert cfg.option('od.dodval1.st1').value.get() == ['a', 'b'] -# assert cfg.option('od.dodval2.dod1a.st2').value.get() is None -# assert cfg.option('od.dodval2.dod1b.st2').value.get() is None -# assert cfg.option('od.dodval2.st1').value.get() == ['a', 'b'] -# assert cfg.option('st3').value.get() is None -# # -# cfg.option('od.dodval1.st1').value.set(['a']) -# cfg.option('od.dodval2.st1').value.set(['b', 'c']) -# assert cfg.value.get() == {'od.dodval1.st1': ['a'], -# 'od.dodval1.dod1a.st2': None, -# 'od.dodval2.st1': ['b', 'c'], -# 'od.dodval2.dod1b.st2': None, -# 'od.dodval2.dod1c.st2': None, -# 'st3': None, -# } -# -# -#def test_subdynod_dyndescription_leadership(): -# st1 = StrOption('st1', '', multi=True) -# st2 = StrOption('st2', '', multi=True) -# stm = Leadership('stm', '', [st1, st2]) -# dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) -# dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) -# od1 = OptionDescription('od', '', [dod]) -# st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, ['val1', 'a'], dod))), multi=True) -# # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) -# st5 = StrOption('st5', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'], dod))), multi=True) -# #cfg = Config(od1) -# #FIXME -# od = OptionDescription('od', '', [od1, st3 , st5]) #, st4]) -# cfg = Config(od) -# assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [], -# 'od.dodval1.dod1b.stm.st1': [], -# 'od.dodval2.dod1a.stm.st1': [], -# 'od.dodval2.dod1b.stm.st1': [], -# 'st3': [], -# 'st5': [], -# } -# assert cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() -# assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == [] -# assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] -# assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] -# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] -# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] -# assert cfg.option('st3').value.get() == [] -# assert cfg.option('st5').value.get() == [] -# # -# cfg.option('od.dodval1.dod1a.stm.st1').value.set(['val']) -# assert cfg.option('st3').value.get() == ['val'] -# assert cfg.value.get() == {'od.dodval1.dod1a.stm.st1': [{'od.dodval1.dod1a.stm.st1': 'val', -# 'od.dodval1.dod1a.stm.st2': None}], -# 'od.dodval1.dod1b.stm.st1': [], -# 'od.dodval2.dod1a.stm.st1': [], -# 'od.dodval2.dod1b.stm.st1': [], -# 'st3': ['val'], -# 'st5': [], -# } -# assert not cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() -# assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == ['val'] -# assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] -# assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] -# assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] -# # -# -# -def test_invalid_symlink_dyndescription(): +def test_subdynod_dyndescription_2(): + st2 = StrOption('st2', '') + st1 = StrOption('st1', '', default=['a', 'b'], multi=True) + dod1 = DynOptionDescription('dod1', '', [st2], suffixes=Calculation(return_list, Params(ParamOption(st1)))) + dod = DynOptionDescription('dod', '', [dod1, st1], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [dod]) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a'])))) + od = OptionDescription('od', '', [od1, st3]) #, st4]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.st2': None, + 'od.dodval1.dod1b.st2': None, + 'od.dodval1.st1': ['a', 'b'], + 'od.dodval2.dod1a.st2': None, + 'od.dodval2.dod1b.st2': None, + 'od.dodval2.st1': ['a', 'b'], + 'st3': None, + } + cfg.cache.reset() + assert cfg.option('od.dodval1.dod1a.st2').value.get() is None + assert cfg.option('od.dodval1.dod1b.st2').value.get() is None + assert cfg.option('od.dodval1.st1').value.get() == ['a', 'b'] + assert cfg.option('od.dodval2.dod1a.st2').value.get() is None + assert cfg.option('od.dodval2.dod1b.st2').value.get() is None + assert cfg.option('od.dodval2.st1').value.get() == ['a', 'b'] + assert cfg.option('st3').value.get() is None + # + cfg.option('od.dodval1.st1').value.set(['a']) + cfg.option('od.dodval2.st1').value.set(['b', 'c']) + assert parse_od_get(cfg.value.get()) == {'od.dodval1.st1': ['a'], + 'od.dodval1.dod1a.st2': None, + 'od.dodval2.st1': ['b', 'c'], + 'od.dodval2.dod1b.st2': None, + 'od.dodval2.dod1c.st2': None, + 'st3': None, + } + + +def test_subdynod_dyndescription_leadership(): + st1 = StrOption('st1', '', multi=True) + st2 = StrOption('st2', '', multi=True) + stm = Leadership('stm', '', [st1, st2]) + dod1 = DynOptionDescription('dod1', '', [stm], suffixes=Calculation(return_list, Params(ParamValue(['a', 'b'])))) + dod = DynOptionDescription('dod', '', [dod1], suffixes=Calculation(return_list)) + od1 = OptionDescription('od', '', [dod]) + st3 = StrOption('st3', '', Calculation(return_dynval, Params(ParamDynOption(st1, ['val1', 'a']))), multi=True) + # FIXME st4 = StrOption('st4', '', Calculation(return_dynval, Params(ParamOption(st2))), multi=True) + st5 = StrOption('st5', '', Calculation(return_dynval, Params(ParamDynOption(st2, ['val1', 'a']))), multi=True) + #cfg = Config(od1) + #FIXME + od = OptionDescription('od', '', [od1, st3 , st5]) #, st4]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.stm.st1': [], + 'od.dodval1.dod1b.stm.st1': [], + 'od.dodval2.dod1a.stm.st1': [], + 'od.dodval2.dod1b.stm.st1': [], + 'st3': [], + 'st5': [], + } + assert cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() + assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == [] + assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] + assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] + assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] + assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] + assert cfg.option('st3').value.get() == [] + assert cfg.option('st5').value.get() == [] + # + cfg.option('od.dodval1.dod1a.stm.st1').value.set(['val']) + assert cfg.option('st3').value.get() == ['val'] + assert parse_od_get(cfg.value.get()) == {'od.dodval1.dod1a.stm.st1': [{'od.dodval1.dod1a.stm.st1': 'val', + 'od.dodval1.dod1a.stm.st2': None}], + 'od.dodval1.dod1b.stm.st1': [], + 'od.dodval2.dod1a.stm.st1': [], + 'od.dodval2.dod1b.stm.st1': [], + 'st3': ['val'], + 'st5': [], + } + assert not cfg.option('od.dodval1.dod1a.stm.st1').owner.isdefault() + assert cfg.option('od.dodval1.dod1a.stm.st1').value.get() == ['val'] + assert cfg.option('od.dodval1.dod1b.stm.st1').value.get() == [] + assert cfg.option('od.dodval2.dod1a.stm.st1').value.get() == [] + assert cfg.option('od.dodval2.dod1b.stm.st1').value.get() == [] + # + + +def test_dyndescription_symlink(): st = StrOption('st', '') st2 = SymLinkOption('st2', st) - with pytest.raises(ConfigError): - DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list)) +# with pytest.raises(ConfigError): + dod = DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [dod]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval1.st2': None, 'dodval2.st': None, 'dodval2.st2': None} + cfg.option('dodval1.st').value.set('j') + assert parse_od_get(cfg.value.get()) == {'dodval1.st': 'j', 'dodval1.st2': 'j', 'dodval2.st': None, 'dodval2.st2': None} +# assert not list_sessions() + + +def test_dyndescription_symlink_not_same(): + st = StrOption('st', '') + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + st2 = SymLinkOption('st2', st) +# with pytest.raises(ConfigError): + dod2 = DynOptionDescription('sdod', '', [st2], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [dod, dod2]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'sdodval1.st2': [None, None], 'sdodval2.st2': [None, None]} + cfg.option('dodval1.st').value.set('j') + assert parse_od_get(cfg.value.get()) == {'dodval1.st': 'j', 'dodval2.st': None, 'sdodval1.st2': ['j', None], 'sdodval2.st2': ['j', None]} +# assert not list_sessions() + + +def test_dyndescription_symlink_outside(): + st = StrOption('st', '') +# with pytest.raises(ConfigError): + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list)) + st2 = SymLinkOption('st2', st) + od = OptionDescription('od', '', [dod, st2]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'st2': [None, None]} + cfg.option('dodval1.st').value.set('j') + assert parse_od_get(cfg.value.get()) == {'dodval1.st': 'j', 'dodval2.st': None, 'st2': ['j', None]} +# assert not list_sessions() + + +def test_dyndescription_symlink_inside(): + st = StrOption('st', '') + st2 = SymLinkOption('st2', st) +# with pytest.raises(ConfigError): + dod = DynOptionDescription('dod', '', [st2], suffixes=Calculation(return_list)) + od = OptionDescription('od', '', [dod, st]) + cfg = Config(od) + assert parse_od_get(cfg.value.get()) == {'dodval1.st2': None, 'dodval2.st2': None, 'st': None} + cfg.option('st').value.set('j') + assert parse_od_get(cfg.value.get()) == {'dodval1.st2': 'j', 'dodval2.st2': 'j', 'st': 'j'} # assert not list_sessions() @@ -1921,751 +1961,826 @@ def test_invalid_name_dyndescription(): # assert not list_sessions() -#def test_leadership_dyndescription_convert(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# stm = Leadership('st1', '', [st1, st2]) -# st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) -# od = OptionDescription('od', '', [st]) -# od1 = OptionDescription('od', '', [od]) -# cfg = Config(od1) -# owner = cfg.owner.get() -# # -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == None -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('no') -# assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] -# assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.pop(0) -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# cfg.option('od.stval1.st1.st2', 0).value.reset() -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# cfg.option('od.stval1.st1.st1').value.reset() -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_leadership_callback_samegroup_dyndescription_convert(): -# st1 = StrOption('st1', "", multi=True) -# st2 = StrOption('st2', "", multi=True) -# st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) -# stm = Leadership('st1', '', [st1, st2, st3]) -# stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) -# od1 = OptionDescription('od', '', [stt]) -# od2 = OptionDescription('od', '', [od1]) -# cfg = Config(od2) -# owner = cfg.owner.get() -# assert cfg.value.get() == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').value.get() == [] -# assert cfg.option('od.stval2.st1.st1').value.get() == [] -# assert cfg.option('od.stval1.st1.st1').owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st1').value.set(['yes']) -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() -# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -# # -# cfg.option('od.stval1.st1.st2', 0).value.set('yes') -# assert cfg.value.get() == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} -# assert cfg.option('od.stval1.st1.st1').owner.get() == owner -# assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner -# assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() -# assert cfg.option('od.stval2.st1.st1').owner.isdefault() -## assert not list_sessions() -# -# -#def test_dyn_with_leader_hidden_in_config(): -# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) -# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) -# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',)) -# dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) -# od1 = OptionDescription('root', '', [dyn]) -# cfg = Config(od1) -# cfg.property.read_write() -# cfg.permissive.add('hidden') -# assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] -# cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) -# assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None -# with pytest.raises(PropertiesOptionError): -# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() -# with pytest.raises(PropertiesOptionError): -# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() -# cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], -# 'leaderval2.ip_admin_eth0.ip_admin_eth0': [{'leaderval2.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]} -## assert not list_sessions() -# -# -#def test_dyn_leadership_requires(): -# ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',)) -# disabled_property = Calculation(calc_value, -# Params(ParamValue('disabled'), -# kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True), -# 'expected': ParamValue('192.168.1.1'), -# 'no_condition_is_invalid': ParamValue(True), -# 'index': ParamIndex()})) -# netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,)) -# interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) -# dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) -# od1 = OptionDescription('toto', '', [dyn]) -# cfg = Config(od1) -# cfg.property.read_write() -# assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] -# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None -# assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] -# # -# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None -# with pytest.raises(PropertiesOptionError): -# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() -# # -# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None -# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' -# ret = cfg.value.get() -# assert ret == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, -# {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}], -# 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} -# -# # -# cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) -# assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None -# with pytest.raises(PropertiesOptionError): -# cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() -# assert cfg.value.get() == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} -# # -## assert not list_sessions() -# -# -#def test_dyn_leadership_mandatory(): -# nsd_zones_all = StrOption(name="nsd_zones_all", doc="nsd_zones_all", multi=True, default=['val1', 'val2']) -# is_auto = BoolOption(name="is_auto_", doc="is auto") -# hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') -# choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") -# leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) -# dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) -# od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) -# cfg = Config(od1) -# assert cfg.value.mandatory() == [] -## assert not list_sessions() -# -# -#def test_dyn_symlink(): -# remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) -# remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) -# dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) -# name = SymLinkOption("name", opt=remote_ip) -# od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) -# cfg = Config(od1) -# assert cfg.option('name').value.get() == ['a', 'b', 'c'] -# assert cfg.option('name').ismulti() == True -# assert cfg.option('name').issubmulti() == False -# assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'name': ['a', 'b', 'c']} -## assert not list_sessions() -# -# -#def test_dyn_callback_with_not_dyn(): -# remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) -# remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) -# dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) -# names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True) -# od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) -# cfg = Config(od1) -# assert cfg.option('names').value.get() == ['a', 'b', 'c'] -# assert cfg.option('names').ismulti() == True -# assert cfg.option('names').issubmulti() == False -# assert cfg.value.get() == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'names': ['a', 'b', 'c']} -## assert not list_sessions() -# -# -#def test_dyn_link_subdyn(): -# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) -# password = StrOption(name="password", doc="password", properties=('mandatory',)) -# name = StrOption(name="name", doc="name", properties=('mandatory',)) -# password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) -# user = OptionDescription(name="user", doc="user", children=[name, password2]) -# sub = OptionDescription(name="sub", doc="sub", children=[user]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) -# socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] -# assert cfg.option('socle.user_database_srep.password').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', -# 'socle.user_database_srep.sub.user.name', -# 'socle.user_database_srep.sub.user.password', -# 'socle.user_database_snom.password', -# 'socle.user_database_snom.sub.user.name', -# 'socle.user_database_snom.sub.user.password', -# 'socle.user_database_srem.password', -# 'socle.user_database_srem.sub.user.name', -# 'socle.user_database_srem.sub.user.password', -# ] -# # -# cfg.option('socle.user_database_srep.password').value.set('pass') -# cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') -# assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' -# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is 'pass' -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', -# 'socle.user_database_snom.password', -# 'socle.user_database_snom.sub.user.name', -# 'socle.user_database_srem.password', -# 'socle.user_database_srem.sub.user.name', -# 'socle.user_database_srem.sub.user.password', -# ] -# # -# cfg.option('socle.user_database_snom.password').value.set('pass2') -# cfg.option('socle.user_database_srem.password').value.set('pass3') -# cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') -# cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') -# cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# assert cfg.value.get() == {'socle.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.user_database_snom.password': 'pass2', -# 'socle.user_database_snom.sub.user.name': 'name2', -# 'socle.user_database_snom.sub.user.password': 'pass', -# 'socle.user_database_srem.password': 'pass3', -# 'socle.user_database_srem.sub.user.name': 'name3', -# 'socle.user_database_srem.sub.user.password': 'pass3', -# 'socle.user_database_srep.password': 'pass', -# 'socle.user_database_srep.sub.user.name': 'name1', -# 'socle.user_database_srep.sub.user.password': 'pass', -# } -# # -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# -# -#def test_dyn_link_subdyn_2(): -# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) -# password2 = StrOption(name="password", doc="password", properties=('mandatory',)) -# password = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password2)))), properties=('mandatory',)) -# name = StrOption(name="name", doc="name", properties=('mandatory',)) -# user = OptionDescription(name="user", doc="user", children=[name, password2]) -# sub = OptionDescription(name="sub", doc="sub", children=[user]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) -# socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] -# assert cfg.option('socle.user_database_srep.password').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', -# 'socle.user_database_srep.sub.user.name', -# 'socle.user_database_srep.sub.user.password', -# 'socle.user_database_snom.password', -# 'socle.user_database_snom.sub.user.name', -# 'socle.user_database_snom.sub.user.password', -# 'socle.user_database_srem.password', -# 'socle.user_database_srem.sub.user.name', -# 'socle.user_database_srem.sub.user.password', -# ] -# # -# cfg.option('socle.user_database_srep.password').value.set('pass') -# cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') -# assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' -# assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None -# assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', -# 'socle.user_database_srep.sub.user.password', -# 'socle.user_database_snom.sub.user.name', -# 'socle.user_database_srem.password', -# 'socle.user_database_srem.sub.user.name', -# 'socle.user_database_srem.sub.user.password', -# ] -# # -# cfg.option('socle.user_database_srep.sub.user.password').value.set('pass2') -# cfg.option('socle.user_database_srem.sub.user.password').value.set('pass3') -# cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') -# cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') -# cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# assert cfg.value.get() == {'socle.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.user_database_snom.password': 'pass', -# 'socle.user_database_snom.sub.user.name': 'name2', -# 'socle.user_database_snom.sub.user.password': 'pass', -# 'socle.user_database_srem.password': 'pass3', -# 'socle.user_database_srem.sub.user.name': 'name3', -# 'socle.user_database_srem.sub.user.password': 'pass3', -# 'socle.user_database_srep.password': 'pass', -# 'socle.user_database_srep.sub.user.name': 'name1', -# 'socle.user_database_srep.sub.user.password': 'pass2', -# } -# # -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# -# -#def test_dyn_link_subdyn_twice(): -# password = StrOption(name="password", doc="password", properties=('mandatory',)) -# name = StrOption(name="name", doc="name", properties=('mandatory',)) -# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) -# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) -# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2]) -# databases = OptionDescription(name="databases", doc="database", children=[password, user_database]) -# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"]) -# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) -# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1', -# 'schema2', -# 'schema3'], -# 'socle.schema_schema1.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema1.databases.password': None, -# 'socle.schema_schema1.databases.user_database_snom.name': None, -# 'socle.schema_schema1.databases.user_database_snom.login': None, -# 'socle.schema_schema1.databases.user_database_snom.password2': None, -# 'socle.schema_schema1.databases.user_database_srem.name': None, -# 'socle.schema_schema1.databases.user_database_srem.login': None, -# 'socle.schema_schema1.databases.user_database_srem.password2': None, -# 'socle.schema_schema1.databases.user_database_srep.name': None, -# 'socle.schema_schema1.databases.user_database_srep.login': None, -# 'socle.schema_schema1.databases.user_database_srep.password2': None, -# 'socle.schema_schema2.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema2.databases.password': None, -# 'socle.schema_schema2.databases.user_database_snom.name': None, -# 'socle.schema_schema2.databases.user_database_snom.login': None, -# 'socle.schema_schema2.databases.user_database_snom.password2': None, -# 'socle.schema_schema2.databases.user_database_srem.name': None, -# 'socle.schema_schema2.databases.user_database_srem.login': None, -# 'socle.schema_schema2.databases.user_database_srem.password2': None, -# 'socle.schema_schema2.databases.user_database_srep.name': None, -# 'socle.schema_schema2.databases.user_database_srep.login': None, -# 'socle.schema_schema2.databases.user_database_srep.password2': None, -# 'socle.schema_schema3.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema3.databases.password': None, -# 'socle.schema_schema3.databases.user_database_snom.name': None, -# 'socle.schema_schema3.databases.user_database_snom.login': None, -# 'socle.schema_schema3.databases.user_database_snom.password2': None, -# 'socle.schema_schema3.databases.user_database_srem.name': None, -# 'socle.schema_schema3.databases.user_database_srem.login': None, -# 'socle.schema_schema3.databases.user_database_srem.password2': None, -# 'socle.schema_schema3.databases.user_database_srep.name': None, -# 'socle.schema_schema3.databases.user_database_srep.login': None, -# 'socle.schema_schema3.databases.user_database_srep.password2': None, -# } -# # -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.databases.password', -# 'socle.schema_schema1.databases.user_database_srep.name', -# 'socle.schema_schema1.databases.user_database_srep.login', -# 'socle.schema_schema1.databases.user_database_srep.password2', -# 'socle.schema_schema1.databases.user_database_snom.name', -# 'socle.schema_schema1.databases.user_database_snom.login', -# 'socle.schema_schema1.databases.user_database_snom.password2', -# 'socle.schema_schema1.databases.user_database_srem.name', -# 'socle.schema_schema1.databases.user_database_srem.login', -# 'socle.schema_schema1.databases.user_database_srem.password2', -# 'socle.schema_schema2.databases.password', -# 'socle.schema_schema2.databases.user_database_srep.name', -# 'socle.schema_schema2.databases.user_database_srep.login', -# 'socle.schema_schema2.databases.user_database_srep.password2', -# 'socle.schema_schema2.databases.user_database_snom.name', -# 'socle.schema_schema2.databases.user_database_snom.login', -# 'socle.schema_schema2.databases.user_database_snom.password2', -# 'socle.schema_schema2.databases.user_database_srem.name', -# 'socle.schema_schema2.databases.user_database_srem.login', -# 'socle.schema_schema2.databases.user_database_srem.password2', -# 'socle.schema_schema3.databases.password', -# 'socle.schema_schema3.databases.user_database_srep.name', -# 'socle.schema_schema3.databases.user_database_srep.login', -# 'socle.schema_schema3.databases.user_database_srep.password2', -# 'socle.schema_schema3.databases.user_database_snom.name', -# 'socle.schema_schema3.databases.user_database_snom.login', -# 'socle.schema_schema3.databases.user_database_snom.password2', -# 'socle.schema_schema3.databases.user_database_srem.name', -# 'socle.schema_schema3.databases.user_database_srem.login', -# 'socle.schema_schema3.databases.user_database_srem.password2', -# ] -# # -# cfg.option('socle.schema_schema2.database_names').value.set(['another']) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1', -# 'schema2', -# 'schema3'], -# 'socle.schema_schema1.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema1.databases.password': None, -# 'socle.schema_schema1.databases.user_database_snom.name': None, -# 'socle.schema_schema1.databases.user_database_snom.login': None, -# 'socle.schema_schema1.databases.user_database_snom.password2': None, -# 'socle.schema_schema1.databases.user_database_srem.name': None, -# 'socle.schema_schema1.databases.user_database_srem.login': None, -# 'socle.schema_schema1.databases.user_database_srem.password2': None, -# 'socle.schema_schema1.databases.user_database_srep.name': None, -# 'socle.schema_schema1.databases.user_database_srep.login': None, -# 'socle.schema_schema1.databases.user_database_srep.password2': None, -# 'socle.schema_schema2.database_names': ['another'], -# 'socle.schema_schema2.databases.password': None, -# 'socle.schema_schema2.databases.user_database_another.name': None, -# 'socle.schema_schema2.databases.user_database_another.login': None, -# 'socle.schema_schema2.databases.user_database_another.password2': None, -# 'socle.schema_schema3.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema3.databases.password': None, -# 'socle.schema_schema3.databases.user_database_snom.name': None, -# 'socle.schema_schema3.databases.user_database_snom.login': None, -# 'socle.schema_schema3.databases.user_database_snom.password2': None, -# 'socle.schema_schema3.databases.user_database_srem.name': None, -# 'socle.schema_schema3.databases.user_database_srem.login': None, -# 'socle.schema_schema3.databases.user_database_srem.password2': None, -# 'socle.schema_schema3.databases.user_database_srep.name': None, -# 'socle.schema_schema3.databases.user_database_srep.login': None, -# 'socle.schema_schema3.databases.user_database_srep.password2': None, -# } -# # -# cfg.option('socle.database_schemas').value.set(['schema1']) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema1.databases.password': None, -# 'socle.schema_schema1.databases.user_database_snom.name': None, -# 'socle.schema_schema1.databases.user_database_snom.login': None, -# 'socle.schema_schema1.databases.user_database_snom.password2': None, -# 'socle.schema_schema1.databases.user_database_srem.name': None, -# 'socle.schema_schema1.databases.user_database_srem.login': None, -# 'socle.schema_schema1.databases.user_database_srem.password2': None, -# 'socle.schema_schema1.databases.user_database_srep.name': None, -# 'socle.schema_schema1.databases.user_database_srep.login': None, -# 'socle.schema_schema1.databases.user_database_srep.password2': None, -# } -# # -# cfg.option('socle.schema_schema1.databases.password').value.set('password') -# cfg.option('socle.schema_schema1.databases.user_database_snom.name').value.set('name1') -# cfg.option('socle.schema_schema1.databases.user_database_srem.name').value.set('name2') -# cfg.option('socle.schema_schema1.databases.user_database_srep.name').value.set('name3') -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep', -# 'snom', -# 'srem'], -# 'socle.schema_schema1.databases.password': 'password', -# 'socle.schema_schema1.databases.user_database_snom.login': 'name1', -# 'socle.schema_schema1.databases.user_database_snom.name': 'name1', -# 'socle.schema_schema1.databases.user_database_snom.password2': 'password', -# 'socle.schema_schema1.databases.user_database_srem.login': 'name2', -# 'socle.schema_schema1.databases.user_database_srem.name': 'name2', -# 'socle.schema_schema1.databases.user_database_srem.password2': 'password', -# 'socle.schema_schema1.databases.user_database_srep.login': 'name3', -# 'socle.schema_schema1.databases.user_database_srep.name': 'name3', -# 'socle.schema_schema1.databases.user_database_srep.password2': 'password', -# } -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# # -# cfg.option('socle.schema_schema1.database_names').value.set(['snom']) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['snom'], -# 'socle.schema_schema1.databases.password': 'password', -# 'socle.schema_schema1.databases.user_database_snom.login': 'name1', -# 'socle.schema_schema1.databases.user_database_snom.name': 'name1', -# 'socle.schema_schema1.databases.user_database_snom.password2': 'password', -# } -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# -# -#def test_dyn_link_subdyn_tree(): -# password = StrOption(name="password", doc="password", properties=('mandatory',)) -# name = StrOption(name="name", doc="name", properties=('mandatory',)) -# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) -# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) -# user_names = StrOption(name="users", doc="users", multi=True, default=["user1"]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2]) -# database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"]) -# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database]) -# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) -# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) -# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', -# 'socle.schema_schema1.db_srep.user_database_user1.name', -# 'socle.schema_schema1.db_srep.user_database_user1.login', -# 'socle.schema_schema1.db_srep.user_database_user1.password2', -# ] -# # -# cfg.option('socle.schema_schema1.db_srep.user_database_user1.name').value.set('name') -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', -# 'socle.schema_schema1.db_srep.user_database_user1.password2', -# ] -# # -# cfg.option('socle.schema_schema1.db_srep.password').value.set('password') -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep'], -# 'socle.schema_schema1.db_srep.password': 'password', -# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', -# 'socle.schema_schema1.db_srep.users': ['user1'], -# } -# # -# cfg.option('socle.schema_schema1.db_srep.users').value.set(['user1', 'user2']) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep'], -# 'socle.schema_schema1.db_srep.password': 'password', -# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', -# 'socle.schema_schema1.db_srep.user_database_user2.login': None, -# 'socle.schema_schema1.db_srep.user_database_user2.name': None, -# 'socle.schema_schema1.db_srep.user_database_user2.password2': 'password', -# 'socle.schema_schema1.db_srep.users': ['user1', 'user2'], -# } -# # -# cfg.option('socle.schema_schema1.db_srep.users').value.set([]) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep'], -# 'socle.schema_schema1.db_srep.password': 'password', -# 'socle.schema_schema1.db_srep.users': [], -# } -# # -# cfg.option('socle.schema_schema1.database_names').value.set([]) -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': [], -# } -# # -# cfg.option('socle.database_schemas').value.set([]) -# assert cfg.value.get() == {'socle.database_schemas': [], -# } -# # -# cfg.option('socle.database_schemas').value.reset() -# cfg.option('socle.schema_schema1.database_names').value.reset() -# cfg.option('socle.schema_schema1.db_srep.users').value.reset() -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.database_names': ['srep'], -# 'socle.schema_schema1.db_srep.password': 'password', -# 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', -# 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', -# 'socle.schema_schema1.db_srep.users': ['user1'], -# } -# -# -#def test_dyn_link_subdyn_same_variable(): -# password = StrOption(name="password", doc="password", properties=('mandatory',)) -# name = StrOption(name="name", doc="name", properties=('mandatory',)) -# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) -# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) -# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) -# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) -# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) -# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.login', -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2', -# ] -# # -# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2', -# ] -# # -# cfg.option('socle.schema_schema1.db_schema1.password').value.set('password') -# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.db_schema1.password': 'password', -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', -# } -# # -# cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) -# assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.user_database_schema2.name', -# 'socle.schema_schema1.db_schema1.user_database_schema2.login', -# 'socle.schema_schema1.db_schema2.password', -# 'socle.schema_schema1.db_schema2.user_database_schema1.name', -# 'socle.schema_schema1.db_schema2.user_database_schema1.login', -# 'socle.schema_schema1.db_schema2.user_database_schema1.password2', -# 'socle.schema_schema1.db_schema2.user_database_schema2.name', -# 'socle.schema_schema1.db_schema2.user_database_schema2.login', -# 'socle.schema_schema1.db_schema2.user_database_schema2.password2', -# 'socle.schema_schema2.db_schema1.password', -# 'socle.schema_schema2.db_schema1.user_database_schema1.name', -# 'socle.schema_schema2.db_schema1.user_database_schema1.login', -# 'socle.schema_schema2.db_schema1.user_database_schema1.password2', -# 'socle.schema_schema2.db_schema1.user_database_schema2.name', -# 'socle.schema_schema2.db_schema1.user_database_schema2.login', -# 'socle.schema_schema2.db_schema1.user_database_schema2.password2', -# 'socle.schema_schema2.db_schema2.password', -# 'socle.schema_schema2.db_schema2.user_database_schema1.name', -# 'socle.schema_schema2.db_schema2.user_database_schema1.login', -# 'socle.schema_schema2.db_schema2.user_database_schema1.password2', -# -# 'socle.schema_schema2.db_schema2.user_database_schema2.name', -# 'socle.schema_schema2.db_schema2.user_database_schema2.login', -# 'socle.schema_schema2.db_schema2.user_database_schema2.password2', -# ] -# assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], -# 'socle.schema_schema1.db_schema1.password': 'password', -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', -# 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, -# 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, -# 'socle.schema_schema1.db_schema1.user_database_schema2.password2': 'password', -# 'socle.schema_schema1.db_schema2.password': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, -# 'socle.schema_schema2.db_schema1.password': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, -# 'socle.schema_schema2.db_schema2.password': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, -# 'socle.schema_schema2.db_schema2.user_database_schema2.login': None, -# 'socle.schema_schema2.db_schema2.user_database_schema2.name': None, -# 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, -# } -# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1').value.get() == { -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', -# } -# -# -#def test_dyn_link_subdyn_disabled(): -# password = StrOption(name="password", doc="password") -# name = StrOption(name="name", doc="name") -# login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name))))) -# disabled_property = Calculation(calc_value, -# Params(ParamValue('disabled'), -# kwargs={'condition': ParamOption(login), -# 'expected': ParamValue('name'), -# 'default': ParamValue(None)})) -# password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,)) -# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) -# user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) -# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) -# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) -# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root) -# cfg.property.read_write() -# assert [opt.path() for opt in cfg.value.mandatory()] == [] -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.db_schema1.password': None, -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': None, -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': None, -# 'socle.schema_schema1.db_schema1.user_database_schema1.password2': None, -# } -# # -# cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') -# assert cfg.value.get() == {'socle.database_schemas': ['schema1'], -# 'socle.schema_schema1.db_schema1.password': None, -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', -# } -# # -# cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) -# cfg.option('socle.schema_schema2.db_schema2.user_database_schema2.name').value.set('name2') -# assert cfg.value.get() == {'socle.database_schemas': ['schema1', 'schema2'], -# 'socle.schema_schema1.db_schema1.password': None, -# 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', -# 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, -# 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, -# 'socle.schema_schema1.db_schema1.user_database_schema2.password2': None, -# 'socle.schema_schema1.db_schema2.password': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, -# 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, -# 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, -# 'socle.schema_schema2.db_schema1.password': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, -# 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, -# 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, -# 'socle.schema_schema2.db_schema2.password': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, -# 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, -# 'socle.schema_schema2.db_schema2.user_database_schema2.login': 'name2', -# 'socle.schema_schema2.db_schema2.user_database_schema2.name': 'name2', -# 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, -# } -# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').owner.get() == owners.user -# assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').information.get('doc') == 'name' -# -# -#def test_option_dynoption_display_name(): -# password = StrOption(name="password", doc="password") -# schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) -# user_database = OptionDescription(name="user_database", doc="user database", children=[password]) -# databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[user_database]) -# schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) -# socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) -# root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) -# cfg = Config(root, display_name=display_name) -# assert cfg.option('socle.schema_schema1.db_schema1.user_database').doc() == 'socle.schema_schema1.db_schema1.user_database (user database)' +def test_leadership_dyndescription_convert(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + stm = Leadership('st1', '', [st1, st2]) + st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) + od = OptionDescription('od', '', [st]) + od1 = OptionDescription('od', '', [od]) + cfg = Config(od1) + owner = cfg.owner.get() + # + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == None + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set('no') + assert cfg.option('od.stval1.st1.st1').value.get() == ['yes'] + assert cfg.option('od.stval1.st1.st2', 0).value.get() == 'no' + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.pop(0) + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + cfg.option('od.stval1.st1.st2', 0).value.reset() + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + cfg.option('od.stval1.st1.st1').value.reset() + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_leadership_callback_samegroup_dyndescription_convert(): + st1 = StrOption('st1', "", multi=True) + st2 = StrOption('st2', "", multi=True) + st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) + stm = Leadership('st1', '', [st1, st2, st3]) + stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot)) + od1 = OptionDescription('od', '', [stt]) + od2 = OptionDescription('od', '', [od1]) + cfg = Config(od2) + owner = cfg.owner.get() + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').value.get() == [] + assert cfg.option('od.stval2.st1.st1').value.get() == [] + assert cfg.option('od.stval1.st1.st1').owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st1').value.set(['yes']) + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': None, 'od.stval1.st1.st3': None}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.isdefault() + assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() + # + cfg.option('od.stval1.st1.st2', 0).value.set('yes') + assert parse_od_get(cfg.value.get()) == {'od.stval1.st1.st1': [{'od.stval1.st1.st1': 'yes', 'od.stval1.st1.st2': 'yes', 'od.stval1.st1.st3': 'yes'}], 'od.stval2.st1.st1': []} + assert cfg.option('od.stval1.st1.st1').owner.get() == owner + assert cfg.option('od.stval1.st1.st2', 0).owner.get() == owner + assert cfg.option('od.stval1.st1.st3', 0).owner.isdefault() + assert cfg.option('od.stval2.st1.st1').owner.isdefault() +# assert not list_sessions() + + +def test_dyn_with_leader_hidden_in_config(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',)) + dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + od1 = OptionDescription('root', '', [dyn]) + cfg = Config(od1) + cfg.property.read_write() + cfg.permissive.add('hidden') + assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] + cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) + assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + with pytest.raises(PropertiesOptionError): + cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() + with pytest.raises(PropertiesOptionError): + cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() + assert parse_od_get(cfg.value.get()) == {} + assert parse_od_get(cfg.forcepermissive.value.get()) == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}], + 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} +# assert not list_sessions() + + +def test_dyn_with_leader_hidden_in_config2(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + od1 = OptionDescription('root', '', [dyn]) + cfg = Config(od1) + cfg.property.read_write() + cfg.permissive.add('hidden') + assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] + cfg.forcepermissive.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) + assert cfg.forcepermissive.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + with pytest.raises(PropertiesOptionError): + cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() + assert parse_od_get(cfg.value.get()) == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], + 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} +# assert not list_sessions() + + +def test_dyn_leadership_requires(): + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',)) + disabled_property = Calculation(calc_value, + Params(ParamValue('disabled'), + kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True), + 'expected': ParamValue('192.168.1.1'), + 'no_condition_is_invalid': ParamValue(True), + 'index': ParamIndex()})) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,)) + interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) + dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list)) + od1 = OptionDescription('toto', '', [dyn]) + cfg = Config(od1) + cfg.property.read_write() + assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == [] + cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + assert cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] + # + cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + with pytest.raises(PropertiesOptionError): + cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() + # + cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None + cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' + ret = parse_od_get(cfg.value.get()) + assert ret == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, + {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}], + 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} + + # + cfg.option('leaderval1.ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) + assert cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None + with pytest.raises(PropertiesOptionError): + cfg.option('leaderval1.ip_admin_eth0.netmask_admin_eth0', 1).value.get() + assert parse_od_get(cfg.value.get()) == {'leaderval1.ip_admin_eth0.ip_admin_eth0': [{'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'leaderval1.ip_admin_eth0.netmask_admin_eth0': None}, {'leaderval1.ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}], 'leaderval2.ip_admin_eth0.ip_admin_eth0': []} + # +# assert not list_sessions() + + +def test_dyn_leadership_mandatory(): + nsd_zones_all = StrOption(name="nsd_zones_all", doc="nsd_zones_all", multi=True, default=['val1', 'val2']) + is_auto = BoolOption(name="is_auto_", doc="is auto") + hostname = DomainnameOption(name="hostname_", doc="hostname_", multi=True, type='hostname') + choice = ChoiceOption(name="type_", doc="type_", values=('A', 'CNAME'), multi=True, default_multi="A") + leadership = Leadership(name="hostname_", doc="hostname_", children=[hostname, choice], properties=frozenset({Calculation(calc_value, Params(ParamValue('hidden'), kwargs={'condition': ParamOption(is_auto, notraisepropertyerror=True), 'expected': ParamValue(True)}))})) + dyn = DynOptionDescription(name="nsd_zone_", doc="Zone ", suffixes=Calculation(calc_value, Params((ParamOption(nsd_zones_all, notraisepropertyerror=True)))), children=[is_auto, leadership], properties=frozenset({"normal"})) + od1 = OptionDescription(name="nsd", doc="nsd", children=[nsd_zones_all, dyn]) + cfg = Config(od1) + assert cfg.value.mandatory() == [] +# assert not list_sessions() + + +def test_dyn_symlink(): + remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) + remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) + dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) + name = SymLinkOption("name", opt=remote_ip) + od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, name]) + cfg = Config(od1) + assert cfg.option('name').value.get() == ['a', 'b', 'c'] + assert cfg.option('name').ismulti() == True + assert cfg.option('name').issubmulti() == False + assert parse_od_get(cfg.value.get()) == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'name': ['a', 'b', 'c']} +# assert not list_sessions() + + +def test_dyn_callback_with_not_dyn(): + remotes = StrOption("remotes", "Remotes", ['a', 'b', 'c'], multi=True) + remote_ip = StrOption("remote_ip_", "Remote IP", Calculation(calc_value, Params(ParamSuffix()))) + dyn_remote = DynOptionDescription("remote_", "Account for ", suffixes=Calculation(calc_value, Params((ParamOption(remotes)))), children=[remote_ip]) + names = StrOption('names', '', Calculation(calc_value, Params(ParamOption(remote_ip))), multi=True) + od1 = OptionDescription(name="accounts", doc="accounts.remote_.remote_ip_", children=[remotes, dyn_remote, names]) + cfg = Config(od1) + assert cfg.option('names').value.get() == ['a', 'b', 'c'] + assert cfg.option('names').ismulti() == True + assert cfg.option('names').issubmulti() == False + assert parse_od_get(cfg.value.get()) == {'remotes': ['a', 'b', 'c'], 'remote_a.remote_ip_': 'a', 'remote_b.remote_ip_': 'b', 'remote_c.remote_ip_': 'c', 'names': ['a', 'b', 'c']} +# assert not list_sessions() + + +def test_dyn_link_subdyn(): + database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) + password = StrOption(name="password", doc="password", properties=('mandatory',)) + name = StrOption(name="name", doc="name", properties=('mandatory',)) + password2 = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) + user = OptionDescription(name="user", doc="user", children=[name, password2]) + sub = OptionDescription(name="sub", doc="sub", children=[user]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) + socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] + assert cfg.option('socle.user_database_srep.password').value.get() is None + assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None + assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', + 'socle.user_database_srep.sub.user.name', + 'socle.user_database_srep.sub.user.password', + 'socle.user_database_snom.password', + 'socle.user_database_snom.sub.user.name', + 'socle.user_database_snom.sub.user.password', + 'socle.user_database_srem.password', + 'socle.user_database_srem.sub.user.name', + 'socle.user_database_srem.sub.user.password', + ] + # + cfg.option('socle.user_database_srep.password').value.set('pass') + cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') + assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' + assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None + assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is 'pass' + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', + 'socle.user_database_snom.password', + 'socle.user_database_snom.sub.user.name', + 'socle.user_database_srem.password', + 'socle.user_database_srem.sub.user.name', + 'socle.user_database_srem.sub.user.password', + ] + # + cfg.option('socle.user_database_snom.password').value.set('pass2') + cfg.option('socle.user_database_srem.password').value.set('pass3') + cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') + cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') + cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') + assert [opt.path() for opt in cfg.value.mandatory()] == [] + assert parse_od_get(cfg.value.get()) == {'socle.database_names': ['srep', + 'snom', + 'srem'], + 'socle.user_database_snom.password': 'pass2', + 'socle.user_database_snom.sub.user.name': 'name2', + 'socle.user_database_snom.sub.user.password': 'pass', + 'socle.user_database_srem.password': 'pass3', + 'socle.user_database_srem.sub.user.name': 'name3', + 'socle.user_database_srem.sub.user.password': 'pass3', + 'socle.user_database_srep.password': 'pass', + 'socle.user_database_srep.sub.user.name': 'name1', + 'socle.user_database_srep.sub.user.password': 'pass', + } + # + assert [opt.path() for opt in cfg.value.mandatory()] == [] + + +def test_dyn_link_subdyn_2(): + database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) + password2 = StrOption(name="password", doc="password", properties=('mandatory',)) + password = StrOption(name="password", doc="password", default=Calculation(calc_value, Params((ParamOption(password2)))), properties=('mandatory',)) + name = StrOption(name="name", doc="name", properties=('mandatory',)) + user = OptionDescription(name="user", doc="user", children=[name, password2]) + sub = OptionDescription(name="sub", doc="sub", children=[user]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[password, sub]) + socle = OptionDescription(name="socle", doc="socle", children=[user_database, database_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + assert cfg.option('socle.database_names').value.get() == ["srep", "snom", "srem"] + assert cfg.option('socle.user_database_srep.password').value.get() is None + assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None + + assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.password', + 'socle.user_database_srep.sub.user.name', + 'socle.user_database_srep.sub.user.password', + 'socle.user_database_snom.password', + 'socle.user_database_snom.sub.user.name', + 'socle.user_database_snom.sub.user.password', + 'socle.user_database_srem.password', + 'socle.user_database_srem.sub.user.name', + 'socle.user_database_srem.sub.user.password', + ] + # + cfg.option('socle.user_database_srep.password').value.set('pass') + cfg.option('socle.user_database_snom.sub.user.password').value.set('pass') + assert cfg.option('socle.user_database_srep.password').value.get() is 'pass' + assert cfg.option('socle.user_database_srep.sub.user.name').value.get() is None + assert cfg.option('socle.user_database_srep.sub.user.password').value.get() is None + assert cfg.option('socle.user_database_snom.password').value.get() is 'pass' + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.user_database_srep.sub.user.name', + 'socle.user_database_srep.sub.user.password', + 'socle.user_database_snom.sub.user.name', + 'socle.user_database_srem.password', + 'socle.user_database_srem.sub.user.name', + 'socle.user_database_srem.sub.user.password', + ] + # + cfg.option('socle.user_database_srep.sub.user.password').value.set('pass2') + cfg.option('socle.user_database_srem.sub.user.password').value.set('pass3') + cfg.option('socle.user_database_srep.sub.user.name').value.set('name1') + cfg.option('socle.user_database_snom.sub.user.name').value.set('name2') + cfg.option('socle.user_database_srem.sub.user.name').value.set('name3') + assert [opt.path() for opt in cfg.value.mandatory()] == [] + assert parse_od_get(cfg.value.get()) == {'socle.database_names': ['srep', + 'snom', + 'srem'], + 'socle.user_database_snom.password': 'pass', + 'socle.user_database_snom.sub.user.name': 'name2', + 'socle.user_database_snom.sub.user.password': 'pass', + 'socle.user_database_srem.password': 'pass3', + 'socle.user_database_srem.sub.user.name': 'name3', + 'socle.user_database_srem.sub.user.password': 'pass3', + 'socle.user_database_srep.password': 'pass', + 'socle.user_database_srep.sub.user.name': 'name1', + 'socle.user_database_srep.sub.user.password': 'pass2', + } + # + assert [opt.path() for opt in cfg.value.mandatory()] == [] + + +def test_dyn_link_subdyn_twice(): + password = StrOption(name="password", doc="password", properties=('mandatory',)) + name = StrOption(name="name", doc="name", properties=('mandatory',)) + login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) + password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) + database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep", "snom", "srem"]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[name, login, password2]) + databases = OptionDescription(name="databases", doc="database", children=[password, user_database]) + schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1", "schema2", "schema3"]) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) + socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1', + 'schema2', + 'schema3'], + 'socle.schema_schema1.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema1.databases.password': None, + 'socle.schema_schema1.databases.user_database_snom.name': None, + 'socle.schema_schema1.databases.user_database_snom.login': None, + 'socle.schema_schema1.databases.user_database_snom.password2': None, + 'socle.schema_schema1.databases.user_database_srem.name': None, + 'socle.schema_schema1.databases.user_database_srem.login': None, + 'socle.schema_schema1.databases.user_database_srem.password2': None, + 'socle.schema_schema1.databases.user_database_srep.name': None, + 'socle.schema_schema1.databases.user_database_srep.login': None, + 'socle.schema_schema1.databases.user_database_srep.password2': None, + 'socle.schema_schema2.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema2.databases.password': None, + 'socle.schema_schema2.databases.user_database_snom.name': None, + 'socle.schema_schema2.databases.user_database_snom.login': None, + 'socle.schema_schema2.databases.user_database_snom.password2': None, + 'socle.schema_schema2.databases.user_database_srem.name': None, + 'socle.schema_schema2.databases.user_database_srem.login': None, + 'socle.schema_schema2.databases.user_database_srem.password2': None, + 'socle.schema_schema2.databases.user_database_srep.name': None, + 'socle.schema_schema2.databases.user_database_srep.login': None, + 'socle.schema_schema2.databases.user_database_srep.password2': None, + 'socle.schema_schema3.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema3.databases.password': None, + 'socle.schema_schema3.databases.user_database_snom.name': None, + 'socle.schema_schema3.databases.user_database_snom.login': None, + 'socle.schema_schema3.databases.user_database_snom.password2': None, + 'socle.schema_schema3.databases.user_database_srem.name': None, + 'socle.schema_schema3.databases.user_database_srem.login': None, + 'socle.schema_schema3.databases.user_database_srem.password2': None, + 'socle.schema_schema3.databases.user_database_srep.name': None, + 'socle.schema_schema3.databases.user_database_srep.login': None, + 'socle.schema_schema3.databases.user_database_srep.password2': None, + } + # + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.databases.password', + 'socle.schema_schema1.databases.user_database_srep.name', + 'socle.schema_schema1.databases.user_database_srep.login', + 'socle.schema_schema1.databases.user_database_srep.password2', + 'socle.schema_schema1.databases.user_database_snom.name', + 'socle.schema_schema1.databases.user_database_snom.login', + 'socle.schema_schema1.databases.user_database_snom.password2', + 'socle.schema_schema1.databases.user_database_srem.name', + 'socle.schema_schema1.databases.user_database_srem.login', + 'socle.schema_schema1.databases.user_database_srem.password2', + 'socle.schema_schema2.databases.password', + 'socle.schema_schema2.databases.user_database_srep.name', + 'socle.schema_schema2.databases.user_database_srep.login', + 'socle.schema_schema2.databases.user_database_srep.password2', + 'socle.schema_schema2.databases.user_database_snom.name', + 'socle.schema_schema2.databases.user_database_snom.login', + 'socle.schema_schema2.databases.user_database_snom.password2', + 'socle.schema_schema2.databases.user_database_srem.name', + 'socle.schema_schema2.databases.user_database_srem.login', + 'socle.schema_schema2.databases.user_database_srem.password2', + 'socle.schema_schema3.databases.password', + 'socle.schema_schema3.databases.user_database_srep.name', + 'socle.schema_schema3.databases.user_database_srep.login', + 'socle.schema_schema3.databases.user_database_srep.password2', + 'socle.schema_schema3.databases.user_database_snom.name', + 'socle.schema_schema3.databases.user_database_snom.login', + 'socle.schema_schema3.databases.user_database_snom.password2', + 'socle.schema_schema3.databases.user_database_srem.name', + 'socle.schema_schema3.databases.user_database_srem.login', + 'socle.schema_schema3.databases.user_database_srem.password2', + ] + # + cfg.option('socle.schema_schema2.database_names').value.set(['another']) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1', + 'schema2', + 'schema3'], + 'socle.schema_schema1.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema1.databases.password': None, + 'socle.schema_schema1.databases.user_database_snom.name': None, + 'socle.schema_schema1.databases.user_database_snom.login': None, + 'socle.schema_schema1.databases.user_database_snom.password2': None, + 'socle.schema_schema1.databases.user_database_srem.name': None, + 'socle.schema_schema1.databases.user_database_srem.login': None, + 'socle.schema_schema1.databases.user_database_srem.password2': None, + 'socle.schema_schema1.databases.user_database_srep.name': None, + 'socle.schema_schema1.databases.user_database_srep.login': None, + 'socle.schema_schema1.databases.user_database_srep.password2': None, + 'socle.schema_schema2.database_names': ['another'], + 'socle.schema_schema2.databases.password': None, + 'socle.schema_schema2.databases.user_database_another.name': None, + 'socle.schema_schema2.databases.user_database_another.login': None, + 'socle.schema_schema2.databases.user_database_another.password2': None, + 'socle.schema_schema3.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema3.databases.password': None, + 'socle.schema_schema3.databases.user_database_snom.name': None, + 'socle.schema_schema3.databases.user_database_snom.login': None, + 'socle.schema_schema3.databases.user_database_snom.password2': None, + 'socle.schema_schema3.databases.user_database_srem.name': None, + 'socle.schema_schema3.databases.user_database_srem.login': None, + 'socle.schema_schema3.databases.user_database_srem.password2': None, + 'socle.schema_schema3.databases.user_database_srep.name': None, + 'socle.schema_schema3.databases.user_database_srep.login': None, + 'socle.schema_schema3.databases.user_database_srep.password2': None, + } + # + cfg.option('socle.database_schemas').value.set(['schema1']) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema1.databases.password': None, + 'socle.schema_schema1.databases.user_database_snom.name': None, + 'socle.schema_schema1.databases.user_database_snom.login': None, + 'socle.schema_schema1.databases.user_database_snom.password2': None, + 'socle.schema_schema1.databases.user_database_srem.name': None, + 'socle.schema_schema1.databases.user_database_srem.login': None, + 'socle.schema_schema1.databases.user_database_srem.password2': None, + 'socle.schema_schema1.databases.user_database_srep.name': None, + 'socle.schema_schema1.databases.user_database_srep.login': None, + 'socle.schema_schema1.databases.user_database_srep.password2': None, + } + # + cfg.option('socle.schema_schema1.databases.password').value.set('password') + cfg.option('socle.schema_schema1.databases.user_database_snom.name').value.set('name1') + cfg.option('socle.schema_schema1.databases.user_database_srem.name').value.set('name2') + cfg.option('socle.schema_schema1.databases.user_database_srep.name').value.set('name3') + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep', + 'snom', + 'srem'], + 'socle.schema_schema1.databases.password': 'password', + 'socle.schema_schema1.databases.user_database_snom.login': 'name1', + 'socle.schema_schema1.databases.user_database_snom.name': 'name1', + 'socle.schema_schema1.databases.user_database_snom.password2': 'password', + 'socle.schema_schema1.databases.user_database_srem.login': 'name2', + 'socle.schema_schema1.databases.user_database_srem.name': 'name2', + 'socle.schema_schema1.databases.user_database_srem.password2': 'password', + 'socle.schema_schema1.databases.user_database_srep.login': 'name3', + 'socle.schema_schema1.databases.user_database_srep.name': 'name3', + 'socle.schema_schema1.databases.user_database_srep.password2': 'password', + } + assert [opt.path() for opt in cfg.value.mandatory()] == [] + # + cfg.option('socle.schema_schema1.database_names').value.set(['snom']) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['snom'], + 'socle.schema_schema1.databases.password': 'password', + 'socle.schema_schema1.databases.user_database_snom.login': 'name1', + 'socle.schema_schema1.databases.user_database_snom.name': 'name1', + 'socle.schema_schema1.databases.user_database_snom.password2': 'password', + } + assert [opt.path() for opt in cfg.value.mandatory()] == [] + + +def test_dyn_link_subdyn_tree(): + password = StrOption(name="password", doc="password", properties=('mandatory',)) + name = StrOption(name="name", doc="name", properties=('mandatory',)) + login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) + password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) + user_names = StrOption(name="users", doc="users", multi=True, default=["user1"]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(user_names, notraisepropertyerror=True)))), children=[name, login, password2]) + database_names = StrOption(name="database_names", doc="database_names", multi=True, default=["srep"]) + databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(database_names, notraisepropertyerror=True)))), children=[user_names, password, user_database]) + schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[database_names, databases]) + socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', + 'socle.schema_schema1.db_srep.user_database_user1.name', + 'socle.schema_schema1.db_srep.user_database_user1.login', + 'socle.schema_schema1.db_srep.user_database_user1.password2', + ] + # + cfg.option('socle.schema_schema1.db_srep.user_database_user1.name').value.set('name') + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_srep.password', + 'socle.schema_schema1.db_srep.user_database_user1.password2', + ] + # + cfg.option('socle.schema_schema1.db_srep.password').value.set('password') + assert [opt.path() for opt in cfg.value.mandatory()] == [] + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep'], + 'socle.schema_schema1.db_srep.password': 'password', + 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', + 'socle.schema_schema1.db_srep.users': ['user1'], + } + # + cfg.option('socle.schema_schema1.db_srep.users').value.set(['user1', 'user2']) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep'], + 'socle.schema_schema1.db_srep.password': 'password', + 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', + 'socle.schema_schema1.db_srep.user_database_user2.login': None, + 'socle.schema_schema1.db_srep.user_database_user2.name': None, + 'socle.schema_schema1.db_srep.user_database_user2.password2': 'password', + 'socle.schema_schema1.db_srep.users': ['user1', 'user2'], + } + # + cfg.option('socle.schema_schema1.db_srep.users').value.set([]) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep'], + 'socle.schema_schema1.db_srep.password': 'password', + 'socle.schema_schema1.db_srep.users': [], + } + # + cfg.option('socle.schema_schema1.database_names').value.set([]) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': [], + } + # + cfg.option('socle.database_schemas').value.set([]) + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': [], + } + # + cfg.option('socle.database_schemas').value.reset() + cfg.option('socle.schema_schema1.database_names').value.reset() + cfg.option('socle.schema_schema1.db_srep.users').value.reset() + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.database_names': ['srep'], + 'socle.schema_schema1.db_srep.password': 'password', + 'socle.schema_schema1.db_srep.user_database_user1.login': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.name': 'name', + 'socle.schema_schema1.db_srep.user_database_user1.password2': 'password', + 'socle.schema_schema1.db_srep.users': ['user1'], + } + + +def test_dyn_link_subdyn_same_variable(): + password = StrOption(name="password", doc="password", properties=('mandatory',)) + name = StrOption(name="name", doc="name", properties=('mandatory',)) + login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name)))), properties=('mandatory',)) + password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=('mandatory',)) + schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) + databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', + 'socle.schema_schema1.db_schema1.user_database_schema1.name', + 'socle.schema_schema1.db_schema1.user_database_schema1.login', + 'socle.schema_schema1.db_schema1.user_database_schema1.password2', + ] + # + cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.password', + 'socle.schema_schema1.db_schema1.user_database_schema1.password2', + ] + # + cfg.option('socle.schema_schema1.db_schema1.password').value.set('password') + cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') + assert [opt.path() for opt in cfg.value.mandatory()] == [] + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.db_schema1.password': 'password', + 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', + } + # + cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) + assert [opt.path() for opt in cfg.value.mandatory()] == ['socle.schema_schema1.db_schema1.user_database_schema2.name', + 'socle.schema_schema1.db_schema1.user_database_schema2.login', + 'socle.schema_schema1.db_schema2.password', + 'socle.schema_schema1.db_schema2.user_database_schema1.name', + 'socle.schema_schema1.db_schema2.user_database_schema1.login', + 'socle.schema_schema1.db_schema2.user_database_schema1.password2', + 'socle.schema_schema1.db_schema2.user_database_schema2.name', + 'socle.schema_schema1.db_schema2.user_database_schema2.login', + 'socle.schema_schema1.db_schema2.user_database_schema2.password2', + 'socle.schema_schema2.db_schema1.password', + 'socle.schema_schema2.db_schema1.user_database_schema1.name', + 'socle.schema_schema2.db_schema1.user_database_schema1.login', + 'socle.schema_schema2.db_schema1.user_database_schema1.password2', + 'socle.schema_schema2.db_schema1.user_database_schema2.name', + 'socle.schema_schema2.db_schema1.user_database_schema2.login', + 'socle.schema_schema2.db_schema1.user_database_schema2.password2', + 'socle.schema_schema2.db_schema2.password', + 'socle.schema_schema2.db_schema2.user_database_schema1.name', + 'socle.schema_schema2.db_schema2.user_database_schema1.login', + 'socle.schema_schema2.db_schema2.user_database_schema1.password2', + + 'socle.schema_schema2.db_schema2.user_database_schema2.name', + 'socle.schema_schema2.db_schema2.user_database_schema2.login', + 'socle.schema_schema2.db_schema2.user_database_schema2.password2', + ] + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1', 'schema2'], + 'socle.schema_schema1.db_schema1.password': 'password', + 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', + 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, + 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, + 'socle.schema_schema1.db_schema1.user_database_schema2.password2': 'password', + 'socle.schema_schema1.db_schema2.password': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, + 'socle.schema_schema2.db_schema1.password': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, + 'socle.schema_schema2.db_schema2.password': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, + 'socle.schema_schema2.db_schema2.user_database_schema2.login': None, + 'socle.schema_schema2.db_schema2.user_database_schema2.name': None, + 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, + } + assert parse_od_get(cfg.option('socle.schema_schema1.db_schema1.user_database_schema1').value.get()) == { + 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.password2': 'password', + } + + +def test_dyn_link_subdyn_disabled(): + password = StrOption(name="password", doc="password") + name = StrOption(name="name", doc="name") + login = StrOption(name="login", doc="login", default=Calculation(calc_value, Params((ParamOption(name))))) + disabled_property = Calculation(calc_value, + Params(ParamValue('disabled'), + kwargs={'condition': ParamOption(login), + 'expected': ParamValue('name'), + 'default': ParamValue(None)})) + password2 = StrOption(name="password2", doc="password2", default=Calculation(calc_value, Params((ParamOption(password)))), properties=(disabled_property,)) + schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) + user_database = DynOptionDescription(name="user_database_", doc="user database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[name, login, password2]) + databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[password, user_database]) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root) + cfg.property.read_write() + assert [opt.path() for opt in cfg.value.mandatory()] == [] + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.db_schema1.password': None, + 'socle.schema_schema1.db_schema1.user_database_schema1.login': None, + 'socle.schema_schema1.db_schema1.user_database_schema1.name': None, + 'socle.schema_schema1.db_schema1.user_database_schema1.password2': None, + } + # + cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').value.set('name') + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1'], + 'socle.schema_schema1.db_schema1.password': None, + 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', + } + # + cfg.option('socle.database_schemas').value.set(['schema1', 'schema2']) + cfg.option('socle.schema_schema2.db_schema2.user_database_schema2.name').value.set('name2') + assert parse_od_get(cfg.value.get()) == {'socle.database_schemas': ['schema1', 'schema2'], + 'socle.schema_schema1.db_schema1.password': None, + 'socle.schema_schema1.db_schema1.user_database_schema1.login': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema1.name': 'name', + 'socle.schema_schema1.db_schema1.user_database_schema2.login': None, + 'socle.schema_schema1.db_schema1.user_database_schema2.name': None, + 'socle.schema_schema1.db_schema1.user_database_schema2.password2': None, + 'socle.schema_schema1.db_schema2.password': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.login': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.name': None, + 'socle.schema_schema1.db_schema2.user_database_schema1.password2': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.login': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.name': None, + 'socle.schema_schema1.db_schema2.user_database_schema2.password2': None, + 'socle.schema_schema2.db_schema1.password': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.login': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.name': None, + 'socle.schema_schema2.db_schema1.user_database_schema1.password2': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.login': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.name': None, + 'socle.schema_schema2.db_schema1.user_database_schema2.password2': None, + 'socle.schema_schema2.db_schema2.password': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.login': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.name': None, + 'socle.schema_schema2.db_schema2.user_database_schema1.password2': None, + 'socle.schema_schema2.db_schema2.user_database_schema2.login': 'name2', + 'socle.schema_schema2.db_schema2.user_database_schema2.name': 'name2', + 'socle.schema_schema2.db_schema2.user_database_schema2.password2': None, + } + assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').owner.get() == owners.user + assert cfg.option('socle.schema_schema1.db_schema1.user_database_schema1.name').information.get('doc') == 'name' + + +def test_option_dynoption_display_name(): + password = StrOption(name="password", doc="password") + schema_names = StrOption(name="database_schemas", doc="database_schemas", multi=True, default=["schema1"]) + user_database = OptionDescription(name="user_database", doc="user database", children=[password]) + databases = DynOptionDescription(name="db_", doc="database", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[user_database]) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params((ParamOption(schema_names, notraisepropertyerror=True)))), children=[databases]) + socle = OptionDescription(name="socle", doc="socle", children=[schema, schema_names]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[socle]) + cfg = Config(root, display_name=display_name) + assert cfg.option('socle.schema_schema1.db_schema1.user_database').doc() == 'socle.schema_schema1.db_schema1.user_database (user database)' + + +def test_option_dynoption_param_information(): + info1 = StrOption("info1", '', Calculation(calc_value, Params(ParamSelfInformation('key'))), informations={'key': 'value'}) + info2 = StrOption("info2", '', Calculation(calc_value, Params(ParamInformation('key', option=info1)))) + schema = DynOptionDescription(name="schema_", doc="schema_", suffixes=Calculation(calc_value, Params(ParamValue(['1', '2']))), children=[info1, info2]) + root = OptionDescription(name="baseoption", doc="baseoption", children=[schema]) + cfg = Config(root, display_name=display_name) + assert parse_od_get(cfg.value.get()) == {'schema_1.info1': 'value', 'schema_1.info2': 'value', 'schema_2.info1': 'value', 'schema_2.info2': 'value'} + cfg.option('schema_1.info1').information.set('key', 'value1') + assert parse_od_get(cfg.value.get()) == {'schema_1.info1': 'value1', 'schema_1.info2': 'value1', 'schema_2.info1': 'value', 'schema_2.info2': 'value'} + + +def test_callback_list_dyndescription_information(): + st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) + dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamInformation('suffix')))) + od = OptionDescription('od', '', [dod]) + od2 = OptionDescription('od', '', [od], informations={'suffix': ['ival1', 'ival2']}) + cfg = Config(od2) + owner = cfg.owner.get() + assert cfg.option('od.dodival1.st').value.get() == ['ival1', 'val2'] + assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] + assert cfg.option('od.dodival1.st').owner.isdefault() + assert cfg.option('od.dodival2.st').owner.isdefault() + cfg.option('od.dodival1.st').value.set(['val3', 'val2']) + assert cfg.option('od.dodival1.st').value.get() == ['val3', 'val2'] + assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] + assert cfg.option('od.dodival1.st').owner.get() == owner + assert cfg.option('od.dodival2.st').owner.isdefault() + cfg.information.set('suffix', ['ival3']) + assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2'] +# assert not list_sessions() + + +def test_callback_list_dyndescription_information_not_list(): + st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',)) + dod = DynOptionDescription('dod', '', [st], suffixes=["sval1", Calculation(return_dynval, Params(ParamInformation('suffix')))]) + od = OptionDescription('od', '', [dod]) + od2 = OptionDescription('od', '', [od], informations={'suffix': 'ival2'}) + cfg = Config(od2) + owner = cfg.owner.get() + assert cfg.option('od.dodsval1.st').value.get() == ['sval1', 'val2'] + assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] + assert cfg.option('od.dodsval1.st').owner.isdefault() + assert cfg.option('od.dodival2.st').owner.isdefault() + cfg.option('od.dodsval1.st').value.set(['val3', 'val2']) + assert cfg.option('od.dodsval1.st').value.get() == ['val3', 'val2'] + assert cfg.option('od.dodival2.st').value.get() == ['ival2', 'val2'] + assert cfg.option('od.dodsval1.st').owner.get() == owner + assert cfg.option('od.dodival2.st').owner.isdefault() + cfg.information.set('suffix', 'ival3') + assert cfg.option('od.dodival3.st').value.get() == ['ival3', 'val2'] +# assert not list_sessions() diff --git a/tests/test_freeze.py b/tests/test_freeze.py index 105bd18..0622709 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -160,57 +160,57 @@ def test_freeze_multi(): # assert not list_sessions() -#def test_force_store_value(): -# od1 = make_description_freeze() -# cfg = Config(od1) -# compare(cfg.value.exportation(), {}) -# cfg.property.read_write() -# compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) -# cfg.option('bool').value.set(False) -# cfg.option('wantref').value.set(True) -# cfg.option('bool').value.reset() -# compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) -# cfg.option('bool').value.set(False) -# cfg.option('wantref').value.reset() -# cfg.option('bool').value.reset() -# compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) -## assert not list_sessions() -# -# -#def test_force_store_value_leadership_sub(): -# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',)) -# c = StrOption('str', 'Test string option', multi=True) -# descr = Leadership("int", "", [b, c]) -# od1 = OptionDescription('odr', '', [descr]) -# cfg = Config(od1) -# cfg.property.read_only() -# compare(cfg.value.exportation(), {'int.int': {None: [[], 'forced']}}) -## assert not list_sessions() -# -# -#def test_force_store_value_callback(): -# b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',)) -# od1 = OptionDescription("int", "", [b]) -# cfg = Config(od1) -# cfg.property.read_only() -# compare(cfg.value.exportation(), {'int': {None: [1, 'forced']}}) -## assert not list_sessions() -# -# -#def test_force_store_value_callback_params(): -# b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',)) -# od1 = OptionDescription("int", "", [b]) -# cfg = Config(od1) -# cfg.property.read_only() -# compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) -## assert not list_sessions() -# -# -#def test_force_store_value_callback_params_with_opt(): -# a = IntOption('val1', "", 2) -# b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',)) -# od1 = OptionDescription("int", "", [a, b]) -# cfg = Config(od1) -# cfg.property.read_only() -# compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) -## assert not list_sessions() +def test_force_store_value(): + od1 = make_description_freeze() + cfg = Config(od1) + compare(cfg.value.exportation(), {}) + cfg.property.read_write() + compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) + cfg.option('bool').value.set(False) + cfg.option('wantref').value.set(True) + cfg.option('bool').value.reset() + compare(cfg.value.exportation(), {'wantref': {None: [True, 'user']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) + cfg.option('bool').value.set(False) + cfg.option('wantref').value.reset() + cfg.option('bool').value.reset() + compare(cfg.value.exportation(), {'wantref': {None: [False, 'forced']}, 'wantref2': {None: [False, 'forced']}, 'wantref3': {None: [[False], 'forced']}}) +# assert not list_sessions() + + +def test_force_store_value_leadership_sub(): + b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',)) + c = StrOption('str', 'Test string option', multi=True) + descr = Leadership("int", "", [b, c]) + od1 = OptionDescription('odr', '', [descr]) + cfg = Config(od1) + cfg.property.read_only() + compare(cfg.value.exportation(), {'int.int': {None: [[], 'forced']}}) +# assert not list_sessions() + + +def test_force_store_value_callback(): + b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',)) + od1 = OptionDescription("int", "", [b]) + cfg = Config(od1) + cfg.property.read_only() + compare(cfg.value.exportation(), {'int': {None: [1, 'forced']}}) +# assert not list_sessions() + + +def test_force_store_value_callback_params(): + b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',)) + od1 = OptionDescription("int", "", [b]) + cfg = Config(od1) + cfg.property.read_only() + compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) +# assert not list_sessions() + + +def test_force_store_value_callback_params_with_opt(): + a = IntOption('val1', "", 2) + b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',)) + od1 = OptionDescription("int", "", [a, b]) + cfg = Config(od1) + cfg.property.read_only() + compare(cfg.value.exportation(), {'int': {None: [2, 'forced']}}) +# assert not list_sessions() diff --git a/tests/test_leadership.py b/tests/test_leadership.py index d71b901..0e2c12d 100644 --- a/tests/test_leadership.py +++ b/tests/test_leadership.py @@ -159,7 +159,7 @@ def test_iter_on_empty_group(): od1 = OptionDescription("name", "descr", []) cfg = Config(od1) cfg.property.read_write() - result = list(cfg.option.list()) + result = list(cfg.list()) assert result == [] # assert not list_sessions() @@ -207,7 +207,7 @@ def test_leader_list(config_type): od1 = OptionDescription('od', '', [interface1]) cfg = Config(od1) cfg = get_config(cfg, config_type) - ret = cfg.option.list() + ret = cfg.list() assert len(ret) == 1 assert ret[0].name() == 'leadership' # @@ -983,65 +983,65 @@ def test_follower_not_multi(): # assert not list_sessions() -#def test_follower_force_store_value_none(): -# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) -# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',)) -# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) -# od1 = OptionDescription('od', '', [interface0]) -# od2 = OptionDescription('toto', '', [od1]) -# cfg = Config(od2) -# cfg.property.read_write() -# assert cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -## assert not list_sessions() -# -# -#def test_follower_force_store_value(): -# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) -# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) -# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) -# od1 = OptionDescription('od', '', [interface0]) -# od2 = OptionDescription('toto', '', [od1]) -# cfg = Config(od2) -# cfg.property.read_write() -# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -## assert not list_sessions() -# -# -#def test_follower_force_store_value_read_only(): -# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) -# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) -# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) -# od1 = OptionDescription('od', '', [interface0]) -# od2 = OptionDescription('toto', '', [od1]) -# cfg = Config(od2) -# cfg.property.read_only() -# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -## assert not list_sessions() -# -# -#def test_follower_force_store_value_reset(): -# ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) -# netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) -# interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) -# od1 = OptionDescription('od', '', [interface0]) -# od2 = OptionDescription('toto', '', [od1]) -# cfg = Config(od2) -# cfg.property.read_write() -# cfg.option('od.interface0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0']) -# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -# assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() -# # -# cfg.option('od.interface0.netmask_admin_eth0', 1).value.reset() -# assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() -# # -# cfg.option('od.interface0.ip_admin_eth0').value.pop(0) -# cfg.option('od.interface0.ip_admin_eth0').value.pop(0) -# assert cfg.option('od.interface0.ip_admin_eth0').value.get() == [] -# cfg.option('od.interface0.ip_admin_eth0').value.reset() -# assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() -## assert not list_sessions() -# -# +def test_follower_force_store_value_none(): + ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) + netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',)) + interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) + od1 = OptionDescription('od', '', [interface0]) + od2 = OptionDescription('toto', '', [od1]) + cfg = Config(od2) + cfg.property.read_write() + assert cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +# assert not list_sessions() + + +def test_follower_force_store_value(): + ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) + netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) + interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) + od1 = OptionDescription('od', '', [interface0]) + od2 = OptionDescription('toto', '', [od1]) + cfg = Config(od2) + cfg.property.read_write() + assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +# assert not list_sessions() + + +def test_follower_force_store_value_read_only(): + ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) + netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) + interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) + od1 = OptionDescription('od', '', [interface0]) + od2 = OptionDescription('toto', '', [od1]) + cfg = Config(od2) + cfg.property.read_only() + assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +# assert not list_sessions() + + +def test_follower_force_store_value_reset(): + ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1']) + netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',)) + interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0]) + od1 = OptionDescription('od', '', [interface0]) + od2 = OptionDescription('toto', '', [od1]) + cfg = Config(od2) + cfg.property.read_write() + cfg.option('od.interface0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0']) + assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() + assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() + # + cfg.option('od.interface0.netmask_admin_eth0', 1).value.reset() + assert not cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault() + # + cfg.option('od.interface0.ip_admin_eth0').value.pop(0) + cfg.option('od.interface0.ip_admin_eth0').value.pop(0) + assert cfg.option('od.interface0.ip_admin_eth0').value.get() == [] + cfg.option('od.interface0.ip_admin_eth0').value.reset() + assert not cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault() +# assert not list_sessions() + + #def test_follower_properties(): ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('aproperty',)) diff --git a/tests/test_option.py b/tests/test_option.py index 4542db7..768a6d5 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -34,20 +34,6 @@ def test_option_valid_name(): i = SymLinkOption("test1", i) -def test_option_get_information(): - description = "it's ok" - string = 'some informations' - i = IntOption('test', description) - with pytest.raises(ValueError): - i.impl_get_information('noinfo') - i.impl_set_information('info', string) - assert i.impl_get_information('info') == string - with pytest.raises(ValueError): - i.impl_get_information('noinfo') - assert i.impl_get_information('noinfo', 'default') == 'default' - assert i.impl_get_information('doc') == description - - def test_option_get_information_config(): description = "it's ok" string = 'some informations' @@ -55,21 +41,16 @@ def test_option_get_information_config(): od = OptionDescription('od', '', [i]) cfg = Config(od) with pytest.raises(ValueError): - i.impl_get_information('noinfo') - with pytest.raises(AttributeError): - i.impl_set_information('info', string) - with pytest.raises(ValueError): - i.impl_get_information('noinfo') - assert i.impl_get_information('noinfo', 'default') == 'default' - assert i.impl_get_information('doc') == description + cfg.option('test').information.get('noinfo') + assert cfg.option('test').information.get('noinfo', 'default') == 'default' + assert cfg.option('test').information.get('doc') == description # assert not list_sessions() def test_option_unknown(): description = "it's ok" string = 'some informations' - i = IntOption('test', description) - i.impl_set_information('noinfo', 'optdefault') + i = IntOption('test', description, informations={'noinfo': 'optdefault'}) od = OptionDescription('od', '', [i]) cfg = Config(od) # @@ -93,8 +74,7 @@ def test_option_description(): def test_option_get_information_default(): description = "it's ok" string = 'some informations' - i = IntOption('test', description) - i.impl_set_information('noinfo', 'optdefault') + i = IntOption('test', description, informations={'noinfo': 'optdefault'}) od = OptionDescription('od', '', [i]) cfg = Config(od) # @@ -108,32 +88,30 @@ def test_option_get_information_default(): def test_option_get_information_config2(): description = "it's ok" string = 'some informations' - i = IntOption('test', description) - i.impl_set_information('info', string) + i = IntOption('test', description, informations={'info': string}) od = OptionDescription('od', '', [i]) cfg = Config(od) with pytest.raises(ValueError): - i.impl_get_information('noinfo') - with pytest.raises(AttributeError): - i.impl_set_information('info', 'hello') - assert i.impl_get_information('info') == string + cfg.option('test').information.get('noinfo') + assert cfg.option('test').information.get('info') == string with pytest.raises(ValueError): - i.impl_get_information('noinfo') - assert i.impl_get_information('noinfo', 'default') == 'default' - assert i.impl_get_information('doc') == description + cfg.option('test').information.get('noinfo') + assert cfg.option('test').information.get('noinfo', 'default') == 'default' + assert cfg.option('test').information.get('doc') == description # assert not list_sessions() def test_optiondescription_get_information(): description = "it's ok" string = 'some informations' - o = OptionDescription('test', description, []) - o.impl_set_information('info', string) - assert o.impl_get_information('info') == string + o = OptionDescription('test', description, [], informations={'info': string}) + od = OptionDescription('od', '', [o]) + cfg = Config(od) + assert cfg.option('test').information.get('info') == string with pytest.raises(ValueError): - o.impl_get_information('noinfo') - assert o.impl_get_information('noinfo', 'default') == 'default' - assert o.impl_get_information('doc') == description + cfg.option('test').information.get('noinfo') + assert cfg.option('test').information.get('noinfo', 'default') == 'default' + assert cfg.option('test').information.get('doc') == description # assert not list_sessions() @@ -218,7 +196,7 @@ def test_optiondescription_group(): od3.impl_set_group_type(groups.notfamily) od2 = OptionDescription('od', '', [od1, od3]) cfg = Config(od2) - assert len(list(cfg.option.list())) == 2 + assert len(list(cfg.list())) == 2 # assert not list_sessions() diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index 1550cdd..36f9392 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -415,8 +415,7 @@ def test_callback_information(config_type): def test_callback_information2(config_type): val1 = StrOption('val1', "", Calculation(return_value, Params(ParamSelfInformation('information', 'no_value')))) - val2 = StrOption('val2', "", Calculation(return_value, Params(ParamSelfInformation('information')))) - val2.impl_set_information('information', 'new_value') + val2 = StrOption('val2', "", Calculation(return_value, Params(ParamSelfInformation('information'))), informations={'information': 'new_value'}) val3 = StrOption('val3', "", Calculation(return_value, Params(ParamSelfInformation('information')))) od1 = OptionDescription('rootconfig', '', [val1, val2, val3]) cfg = Config(od1) @@ -432,9 +431,8 @@ def test_callback_information2(config_type): def test_callback_information3(config_type): - val1 = StrOption('val1', "") + val1 = StrOption('val1', "", informations={'information': 'new_value'}) val2 = StrOption('val2', "", Calculation(return_value, Params(ParamInformation('information', option=val1)))) - val1.impl_set_information('information', 'new_value') od1 = OptionDescription('rootconfig', '', [val1, val2]) cfg = Config(od1) cfg.property.read_write() @@ -1691,3 +1689,38 @@ def test_calc_dependencies(config_type): def test_callback__kwargs_wrong(config_type): with pytest.raises(ValueError): Params(kwargs='string') + + +def test_callback_information_parent(config_type): + information = ParamInformation('information') + val1 = StrOption('val1', "", Calculation(return_value, Params(information))) + od2 = OptionDescription('od', '', [val1], informations={'information': 'new_value'}) + information.set_option(od2) + od1 = OptionDescription('rootconfig', '', [od2]) + cfg = Config(od1) + cfg.property.read_write() + cfg = get_config(cfg, config_type) + assert cfg.option('od.val1').value.get() == 'new_value' + cfg.option('od').information.set('information', 'new_value2') + assert cfg.option('od.val1').value.get() == 'new_value2' + + +def test_callback_information_redefined(config_type): + val1 = StrOption('val1', "") + information = ParamInformation('information', option=val1) + val2 = StrOption('val2', "", Calculation(return_value, Params(information))) + od2 = OptionDescription('od', '', [val1, val2], informations={'information': 'new_value'}) + with pytest.raises(ConfigError): + information.set_option(od2) + + +def test_callback_information_redefined_after(config_type): + information = ParamInformation('information') + val1 = StrOption('val1', "", Calculation(return_value, Params(information))) + od2 = OptionDescription('od', '', [val1], informations={'information': 'new_value'}) + od1 = OptionDescription('rootconfig', '', [od2]) + cfg = Config(od1) + cfg.property.read_write() + cfg = get_config(cfg, config_type) + with pytest.raises(ConfigError): + information.set_option(od2) diff --git a/tests/test_option_default.py b/tests/test_option_default.py index 5c2bee6..f8feaad 100644 --- a/tests/test_option_default.py +++ b/tests/test_option_default.py @@ -166,28 +166,6 @@ def test_force_default_on_freeze_multi(): # assert not list_sessions() -def test_force_default_on_freeze_leader_frozen(): - dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen')) - dummy2 = BoolOption('dummy2', 'Test string option', multi=True) - descr = Leadership("dummy1", "", [dummy1, dummy2]) - od1 = OptionDescription("root", "", [descr]) - cfg = Config(od1) - with pytest.raises(LeadershipError): - cfg.option('dummy1.dummy1').property.remove('frozen') -# assert not list_sessions() - - -def test_force_metaconfig_on_freeze_leader_frozen(): - dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_metaconfig_on_freeze', 'frozen')) - dummy2 = BoolOption('dummy2', 'Test string option', multi=True) - descr = Leadership("dummy1", "", [dummy1, dummy2]) - od1 = OptionDescription("root", "", [descr]) - cfg = Config(od1) - with pytest.raises(LeadershipError): - cfg.option('dummy1.dummy1').property.remove('frozen') -# assert not list_sessions() - - def test_force_default_on_freeze_follower(config_type): dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('notunique',)) dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',)) diff --git a/tests/test_option_setting.py b/tests/test_option_setting.py index 54027fe..4701e9e 100644 --- a/tests/test_option_setting.py +++ b/tests/test_option_setting.py @@ -82,7 +82,7 @@ def test_mod_read_only_write(): 'empty', } # - config.property.setdefault(frozenset(['cache'])) +# config.property.setdefault(frozenset(['cache'])) config.property.setdefault(type='read_only', when='append', properties=frozenset(['disabled'])) config.property.setdefault(type='read_only', when='remove', properties=frozenset(['hidden'])) config.property.setdefault(type='read_write', when='append', properties=frozenset(['disabled', 'hidden'])) @@ -94,7 +94,7 @@ def test_mod_read_only_write(): with pytest.raises(TypeError): config.property.setdefault(type='read_only', when='append', properties=['disabled']) - assert config.property.default() == {'cache'} + assert config.property.default() == {'warnings', 'validator', 'cache'} assert config.property.default('read_only', 'append') == {'disabled'} assert config.property.default('read_only', 'remove') == {'hidden'} assert config.property.default('read_write', 'append') == {'disabled', @@ -102,11 +102,11 @@ def test_mod_read_only_write(): assert config.property.default('read_write', 'remove') == set([]) # config.property.read_only() - assert config.property.get() == {'cache', 'disabled'} + assert config.property.get() == {'warnings', 'validator', 'cache', 'disabled'} config.property.read_write() - assert config.property.get() == {'cache', 'disabled', 'hidden'} + assert config.property.get() == {'warnings', 'validator', 'cache', 'disabled', 'hidden'} config.property.read_only() - assert config.property.get() == {'cache', 'disabled'} + assert config.property.get() == {'warnings', 'validator', 'cache', 'disabled'} # assert config2.property.default() == {'cache', 'validator', 'warnings'} assert config2.property.default('read_only', 'append') == {'frozen', @@ -138,6 +138,19 @@ def test_mod_read_only_write(): # assert not list_sessions() +def test_setting_tree(config_type): + s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True) + od4 = OptionDescription("option4", "", [s]) + od3 = OptionDescription("option3", "", [od4]) + od2 = OptionDescription("option2", "", [od3], properties=('hidden',)) + od1 = OptionDescription("root", "", [od2]) + cfg = Config(od1) + cfg = get_config(cfg, config_type) + cfg.property.read_write() + with pytest.raises(PropertiesOptionError): + cfg.option('option2.option3.option4.string').value.get() + + def test_setitem(config_type): s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True) od1 = OptionDescription("options", "", [s]) @@ -365,8 +378,7 @@ def test_apply_requires_from_config(): with pytest.raises(PropertiesOptionError): cfg.option('opt.str').value.get() assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get() - assert 'hidden' not in cfg.forcepermissive.option('opt.str').properties() - assert 'hidden' not in cfg.forcepermissive.option('opt.str').properties(only_raises=True) + assert 'hidden' not in cfg.forcepermissive.option('opt.str').property.get(only_raises=True) # assert not list_sessions() @@ -386,8 +398,7 @@ def test_apply_requires_with_disabled(): cfg.option('int').value.set(1) with pytest.raises(PropertiesOptionError): cfg.option('opt.str').value.get() - assert 'disabled' not in cfg.unrestraint.option('opt.str').properties() - assert 'disabled' not in cfg.unrestraint.option('opt.str').properties(only_raises=True) + assert 'disabled' not in cfg.unrestraint.option('opt.str').property.get(only_raises=True, apply_requires=False) assert 'disabled' in cfg.unrestraint.option('opt.str').property.get() # assert not list_sessions() @@ -607,7 +618,7 @@ def test_properties_get_add_reset(): cfg.property.add('frozen') assert cfg.property.get() == {'validator', 'warnings', 'cache', 'frozen'} cfg.property.reset() - assert cfg.property.get() == {'validator', 'warnings', 'cache'} + assert cfg.property.get() == frozenset() def test_reset_properties_force_store_value(): @@ -615,28 +626,25 @@ def test_reset_properties_force_store_value(): gcgroup = OptionDescription('gc', '', [gcdummy]) od1 = OptionDescription('tiramisu', '', [gcgroup]) cfg = Config(od1) - assert cfg.property.exportation() == {} + assert cfg.property.exportation() == {None: {None: frozenset({'validator', 'warnings', 'cache'})}} cfg.property.add('frozen') assert cfg.property.exportation() == \ {None: {None: set(('frozen', 'cache', 'validator', 'warnings'))}} cfg.property.reset() assert cfg.property.exportation() == {None: {}} cfg.option('gc.dummy').property.add('test') - assert cfg.property.exportation() == {None: {}, 'gc.dummy': {None: set(('test', 'force_store_value'))}} + assert cfg.property.exportation() == {None: {}, 'gc.dummy': {None: frozenset({'test'})}} cfg.property.reset() - assert cfg.property.exportation() == {None: {}, 'gc.dummy': {None: set(('test', 'force_store_value'))}} + assert cfg.property.exportation() == {None: {}, 'gc.dummy': {None: frozenset({'test'})}} cfg.property.add('frozen') assert cfg.property.exportation() == \ - {None: {None: set(('frozen', 'validator', 'cache', 'warnings'))}, - 'gc.dummy': {None: set(('test', 'force_store_value'))}} + {None: {None: frozenset({'frozen'})}, 'gc.dummy': {None: frozenset({'test'})}} cfg.property.add('frozen') assert cfg.property.exportation() == \ - {None: {None: set(('frozen', 'validator', 'cache', 'warnings'))}, - 'gc.dummy': {None: set(('test', 'force_store_value'))}} + {None: {None: frozenset({'frozen'})}, 'gc.dummy': {None: frozenset({'test'})}} cfg.option('gc.dummy').property.add('test') assert cfg.property.exportation() == \ - {None: {None: set(('frozen', 'validator', 'cache', 'warnings'))}, - 'gc.dummy': {None: set(('test', 'force_store_value'))}} + {None: {None: frozenset({'frozen'})}, 'gc.dummy': {None: frozenset({'test'})}} # assert not list_sessions() @@ -666,7 +674,7 @@ def test_set_modified_value(): gcgroup = OptionDescription('gc', '', [gcdummy]) od1 = OptionDescription('tiramisu', '', [gcgroup]) cfg = Config(od1) - assert cfg.property.exportation() == {} + assert cfg.property.exportation() == {None: {None: frozenset({'warnings', 'validator', 'cache'})}} cfg.property.importation({None: {None: set(('frozen', 'cache', 'validator', 'warnings'))}}) assert cfg.property.exportation() == \ {None: {None: set(('frozen', 'cache', 'validator', 'warnings'))}} diff --git a/tests/test_option_type.py b/tests/test_option_type.py index a964c08..70645bd 100644 --- a/tests/test_option_type.py +++ b/tests/test_option_type.py @@ -64,7 +64,10 @@ def test_is_hidden(config_type): def test_group_is_hidden(config_type): - od1 = make_description() + gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),)) + floatoption = FloatOption('float', 'Test float option', default=2.3) + gcgroup = OptionDescription('gc', '', [gcdummy, floatoption]) + od1 = OptionDescription('trs', '', [gcgroup]) cfg_ori = Config(od1) cfg_ori.property.read_write() cfg_ori.option('gc').property.add('hidden') @@ -73,14 +76,14 @@ def test_group_is_hidden(config_type): cfg.option('gc.dummy').value.get() if config_type == 'tiramisu-api': cfg.send() - assert 'hidden' in cfg_ori.forcepermissive.option('gc').property.get() + assert 'hidden' in cfg_ori.option('gc').property.get() cfg = get_config(cfg_ori, config_type) with pytest.raises(PropertiesOptionError): cfg.option('gc.float').value.get() # manually set the subconfigs to "show" if config_type == 'tiramisu-api': cfg.send() - cfg_ori.forcepermissive.option('gc').property.remove('hidden') + cfg_ori.option('gc').property.remove('hidden') cfg = get_config(cfg_ori, config_type) assert not 'hidden' in cfg.option('gc').property.get() assert cfg.option('gc.float').value.get() == 2.3 diff --git a/tests/test_option_validator.py b/tests/test_option_validator.py index f904cae..5aaa83d 100644 --- a/tests/test_option_validator.py +++ b/tests/test_option_validator.py @@ -1260,18 +1260,24 @@ def test_consistency_not_equal_has_dependency(): def test_validator_information(config_type): opt1 = StrOption('opt1', '', validators=[Calculation(return_true, Params((ParamSelfInformation('key'), ParamValue('yes'))))], default='val') opt2 = StrOption('opt2', '', validators=[Calculation(return_true, Params((ParamInformation('key'), ParamValue('yes'))))], default='val') - od1 = OptionDescription('root', '', [opt1, opt2]) + opt3 = StrOption('opt3', '', validators=[Calculation(return_true, Params((ParamInformation('key', option=opt1), ParamValue('yes'))))], default='val') + od1 = OptionDescription('root', '', [opt1, opt2, opt3]) cfg = Config(od1) with pytest.raises(ConfigError): cfg.option('opt1').value.get() + with pytest.raises(ConfigError): + cfg.option('opt3').value.get() cfg.option('opt1').information.set('key', 'val') assert cfg.option('opt1').value.get() == 'val' + assert cfg.option('opt3').value.get() == 'val' cfg.option('opt1').information.set('key', 'val1') with pytest.raises(ValueError): cfg.option('opt1').value.get() + with pytest.raises(ValueError): + cfg.option('opt3').value.get() # with pytest.raises(ConfigError): - assert cfg.option('opt2').value.get() + cfg.option('opt2').value.get() cfg.information.set('key', 'val') assert cfg.option('opt2').value.get() == 'val' cfg.information.set('key', 'val1') diff --git a/tests/test_permissive.py b/tests/test_permissive.py index b5e24e9..f382fed 100644 --- a/tests/test_permissive.py +++ b/tests/test_permissive.py @@ -22,7 +22,7 @@ def test_forcepermissive_and_unrestraint(config_type): cfg_ori.property.read_write() cfg = get_config(cfg_ori, config_type) with pytest.raises(ConfigError): - cfg_ori.unrestraint.forcepermissive.add('disabled') + cfg_ori.forcepermissive.add('disabled') def test_permissive(config_type): @@ -39,9 +39,9 @@ def test_permissive(config_type): assert set(props) == {'disabled'} if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.permissive.add('disabled') - cfg_ori.unrestraint.permissive.remove('hidden') - assert cfg_ori.unrestraint.permissive.get() == frozenset(['disabled']) + cfg_ori.permissive.add('disabled') + cfg_ori.permissive.remove('hidden') + assert cfg_ori.permissive.get() == frozenset(['disabled']) cfg = get_config(cfg_ori, config_type) props = frozenset() try: @@ -81,8 +81,8 @@ def test_permissive_add(config_type): assert set(props) == {'disabled'} if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.permissive.add('disabled') - assert cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) + cfg_ori.permissive.add('disabled') + assert cfg_ori.permissive.get() == frozenset(['hidden', 'disabled']) cfg = get_config(cfg_ori, config_type) props = frozenset() try: @@ -119,10 +119,10 @@ def test_permissive_pop(): except PropertiesOptionError as err: props = err.proptype assert set(props) == {'disabled'} - cfg.unrestraint.permissive.add('disabled') - assert cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) + cfg.permissive.add('disabled') + assert cfg.permissive.get() == frozenset(['hidden', 'disabled']) cfg.forcepermissive.option('u1').value.get() - cfg.unrestraint.permissive.remove('disabled') + cfg.permissive.remove('disabled') props = frozenset() try: cfg.forcepermissive.option('u1').value.get() @@ -136,14 +136,14 @@ def test_permissive_reset(): od1 = make_description() cfg = Config(od1) cfg.property.read_write() - assert cfg.unrestraint.permissive.get() == frozenset(['hidden']) + assert cfg.permissive.get() == frozenset(['hidden']) # - cfg.unrestraint.permissive.add('disabled') - cfg.unrestraint.permissive.remove('hidden') - assert cfg.unrestraint.permissive.get() == frozenset(['disabled']) + cfg.permissive.add('disabled') + cfg.permissive.remove('hidden') + assert cfg.permissive.get() == frozenset(['disabled']) # - cfg.unrestraint.permissive.reset() - assert cfg.unrestraint.permissive.get() == frozenset() + cfg.permissive.reset() + assert cfg.permissive.get() == frozenset(['hidden']) # assert not list_sessions() @@ -157,9 +157,9 @@ def test_permissive_mandatory(): except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) - cfg.unrestraint.permissive.add('mandatory') - cfg.unrestraint.permissive.add('disabled') - assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled']) + cfg.permissive.add('mandatory') + cfg.permissive.add('disabled') + assert cfg.permissive.get() == frozenset(['hidden', 'mandatory', 'disabled']) cfg.property.add('permissive') cfg.option('u1').value.get() cfg.property.remove('permissive') @@ -175,10 +175,10 @@ def test_permissive_frozen(): od1 = make_description() cfg = Config(od1) cfg.property.read_write() - cfg.unrestraint.permissive.remove('hidden') - cfg.unrestraint.permissive.add('frozen') - cfg.unrestraint.permissive.add('disabled') - assert cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled']) + cfg.permissive.remove('hidden') + cfg.permissive.add('frozen') + cfg.permissive.add('disabled') + assert cfg.permissive.get() == frozenset(['frozen', 'disabled']) assert cfg.permissive.get() == frozenset(['frozen', 'disabled']) try: cfg.option('u1').value.set(1) @@ -229,7 +229,7 @@ def test_permissive_option(config_type): if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) + cfg_ori.option('u1').permissive.add('disabled') cfg = get_config(cfg_ori, config_type) props = frozenset() try: @@ -293,7 +293,7 @@ def test_permissive_option_cache(): props = err.proptype assert set(props) == {'disabled'} - cfg.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) + cfg.option('u1').permissive.add('disabled') props = frozenset() try: cfg.option('u1').value.get() @@ -342,8 +342,9 @@ def test_permissive_option_mandatory(): except PropertiesOptionError as err: props = err.proptype assert frozenset(props) == frozenset(['disabled']) - cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled'])) - assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled']) + cfg.option('u1').permissive.add('mandatory') + cfg.option('u1').permissive.add('disabled') + assert cfg.option('u1').permissive.get() == frozenset(['mandatory', 'disabled']) cfg.property.add('permissive') cfg.option('u1').value.get() cfg.property.remove('permissive') @@ -359,7 +360,8 @@ def test_permissive_option_frozen(): od1 = make_description() cfg = Config(od1) cfg.property.read_write() - cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled'])) + cfg.option('u1').permissive.add('disabled') + cfg.option('u1').permissive.add('frozen') cfg.option('u1').value.set(1) assert cfg.option('u1').value.get() == 1 cfg.property.add('permissive') @@ -369,15 +371,6 @@ def test_permissive_option_frozen(): # assert not list_sessions() -def test_invalid_option_permissive(): - od1 = make_description() - cfg = Config(od1) - cfg.property.read_write() - with pytest.raises(TypeError): - cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled']) -# assert not list_sessions() - - def test_remove_option_permissive(config_type): var1 = StrOption('var1', '', u'value', properties=('hidden',)) od1 = OptionDescription('od1', '', [var1]) @@ -389,13 +382,13 @@ def test_remove_option_permissive(config_type): cfg.option('od1.var1').value.get() if config_type == 'tiramisu-api': cfg.send() - cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) + cfg_ori.forcepermissive.option('od1.var1').permissive.add('hidden') assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) cfg = get_config(cfg_ori, config_type) assert cfg.option('od1.var1').value.get() == 'value' if config_type == 'tiramisu-api': cfg.send() - cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset()) + cfg_ori.forcepermissive.option('od1.var1').permissive.reset() assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset() cfg = get_config(cfg_ori, config_type) with pytest.raises(PropertiesOptionError): @@ -414,7 +407,7 @@ def test_reset_option_permissive(config_type): cfg.option('od1.var1').value.get() if config_type == 'tiramisu-api': cfg.send() - cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) + cfg_ori.forcepermissive.option('od1.var1').permissive.add('hidden') assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) cfg = get_config(cfg_ori, config_type) assert cfg.option('od1.var1').value.get() == 'value' diff --git a/tests/test_requires.py b/tests/test_requires.py index 68a7f2e..724e32a 100644 --- a/tests/test_requires.py +++ b/tests/test_requires.py @@ -31,12 +31,12 @@ def test_properties(config_type): assert frozenset(props) == frozenset(['disabled']) if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.option('ip_address_service').property.remove('disabled') + cfg_ori.unrestraint.option('ip_address_service').permissive.add('disabled') cfg = get_config(cfg_ori, config_type) cfg.option('ip_address_service').value.get() if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.option('ip_address_service').property.add('disabled') + cfg_ori.unrestraint.option('ip_address_service').permissive.remove('disabled') cfg = get_config(cfg_ori, config_type) props = [] try: @@ -47,8 +47,8 @@ def test_properties(config_type): # pop twice if config_type == 'tiramisu-api': cfg.send() - cfg_ori.unrestraint.option('ip_address_service').property.remove('disabled') - cfg_ori.unrestraint.option('ip_address_service').property.remove('disabled') + cfg_ori.unrestraint.option('ip_address_service').permissive.add('disabled') + cfg_ori.unrestraint.option('ip_address_service').permissive.remove('disabled') # assert not list_sessions() @@ -613,6 +613,7 @@ def test_requires_transitive_hidden_disabled_multiple(config_type): del req # cfg_ori.permissive.reset() + cfg_ori.permissive.remove('hidden') if config_type == 'tiramisu-api': try: cfg = get_config(cfg_ori, config_type) diff --git a/tests/test_symlink.py b/tests/test_symlink.py index 78bd3c0..1165cbe 100644 --- a/tests/test_symlink.py +++ b/tests/test_symlink.py @@ -141,7 +141,7 @@ def test_symlink_getpermissive(): od1 = OptionDescription('opt', '', [boolopt, linkopt]) cfg = Config(od1) cfg.property.read_write() - cfg.option('b').permissive.set(frozenset(['perm'])) + cfg.option('b').permissive.add('perm') cfg.option('c').permissive.get() == frozenset(['perm']) # assert not list_sessions() @@ -266,14 +266,26 @@ def test_symlink_owner(config_type): def test_symlink_get_information(): - boolopt = BoolOption("b", "", default=False) + boolopt = BoolOption("b", "", default=False, informations={'test': 'test'}) linkopt = SymLinkOption("c", boolopt) - boolopt.impl_set_information('test', 'test') - assert boolopt.impl_get_information('test') == 'test' - assert linkopt.impl_get_information('test') == 'test' - boolopt.impl_set_information('test', 'test2') - assert boolopt.impl_get_information('test') == 'test2' - assert linkopt.impl_get_information('test') == 'test2' + od1 = OptionDescription('opt', '', [linkopt, boolopt]) + cfg = Config(od1) + assert cfg.option('b').information.get('test') == 'test' + assert cfg.option('c').information.get('test') == 'test' + cfg.option('b').information.set('test', 'test2') + assert cfg.option('b').information.get('test') == 'test2' + assert cfg.option('c').information.get('test') == 'test2' + + +def test_symlink_informations(): + boolopt = BoolOption("b", "", default=False) + with pytest.raises(TypeError): + linkopt = SymLinkOption("c", boolopt, informations={'test': 'test'}) + linkopt = SymLinkOption("c", boolopt) + od1 = OptionDescription('opt', '', [linkopt, boolopt]) + cfg = Config(od1) + with pytest.raises(ConfigError): + cfg.option('c').information.set('test', 'test2') def test_symlink_leader(): @@ -359,9 +371,9 @@ def test_symlink_dependency(): [linkopt, OptionDescription("s1", "", [boolopt])]) cfg = Config(od1) assert cfg.option('s1.b').has_dependency() is False - assert cfg.option('c').has_dependency() is True + assert cfg.option('c').has_dependency() is False assert cfg.option('s1.b').has_dependency(False) is True - assert cfg.option('c').has_dependency(False) is False + assert cfg.option('c').has_dependency(False) is True # assert not list_sessions() @@ -385,7 +397,7 @@ def test_symlink_list(config_type): [linkopt, OptionDescription("s1", "", [boolopt])]) cfg = Config(od1) cfg = get_config(cfg, config_type) - assert [opt.path() for opt in cfg.option.list()] == ['c', 's1'] + assert [opt.path() for opt in cfg.list()] == ['c', 's1'] # assert [opt.path() for opt in cfg.option('s1').list()] == ['s1.b'] # assert not list_sessions() diff --git a/tiramisu/api.py b/tiramisu/api.py index 56e87ec..377eeda 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -24,14 +24,15 @@ from copy import deepcopy from .error import ConfigError, LeadershipError, ValueErrorWarning from .i18n import _ from .setting import ConfigBag, owners, groups, undefined, \ - FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES + FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, \ + DEFAULT_PROPERTIES from .config import KernelConfig, KernelGroupConfig, KernelMetaConfig, KernelMixConfig, SubConfig from .option import RegexpOption, OptionDescription, ChoiceOption, Leadership from .todict import TiramisuDict from .autolib import Calculation -TIRAMISU_VERSION = 4 +TIRAMISU_VERSION = 5 class TiramisuHelp: @@ -70,10 +71,6 @@ class TiramisuHelp: _('Do not warnings during validation') ).expandtabs(max_len + 10)) display() - if isinstance(self, TiramisuDispatcherOption): - doc = _(getdoc(self.__call__)) - display(_('Call: {}').format(doc)) - display() display(_('Commands:')) for module_name in modules: module = getattr(self, module_name) @@ -90,21 +87,6 @@ class TiramisuHelp: class CommonTiramisu(TiramisuHelp): _validate_properties = True - def _get_subconfig(self, - follower_not_apply_requires: bool, - ) -> "OptionBag": - try: - return self._config_bag.context.get_sub_config(self._config_bag, - self._path, - self._index, - validate_properties=self._validate_properties, - follower_not_apply_requires=follower_not_apply_requires, - ) - except AssertionError as err: - raise ConfigError(str(err)) - except Exception as err: - raise err - def option_type(typ): if not isinstance(typ, list): @@ -126,17 +108,39 @@ def option_type(typ): kwargs['is_group'] = True return func(self, options_bag, *args[1:], **kwargs) if not self._subconfig: - self._subconfig = self._get_subconfig('with_index' not in types) + self._subconfig = self._config_bag.context.get_sub_config(self._config_bag, + self._path, + self._index, + validate_properties=False, + ) option = self._subconfig.option - if option.impl_is_optiondescription() and 'optiondescription' in types or \ - option.impl_is_optiondescription() and option.impl_is_leadership() and 'leadership' in types or \ - not option.impl_is_optiondescription() and ( - option.impl_is_symlinkoption() and 'symlink' in types or \ - not option.impl_is_symlinkoption() and ( - 'option' in types or \ - option.impl_is_leader() and 'leader' in types or \ - option.impl_is_follower() and 'follower' in types or \ - isinstance(option, ChoiceOption) and 'choice' in types)): + error_type = None + if 'dynamic' in types: + if not self._subconfig.is_dynamic: + error_type = 'only available for dynamic option' + elif option.impl_is_optiondescription(): + if 'optiondescription' not in types: + if option.impl_is_leadership(): + if 'leadership' not in types: + error_type = 'not available for a Leadership' + else: + error_type = 'not available for an OptionDescription' + elif option.impl_is_symlinkoption(): + if 'symlink' not in types: + error_type = 'this function is not available for a SymLinkOption' + elif 'option' not in types: + if 'choice' in types: + if not isinstance(option, ChoiceOption): + error_type = 'only available for ChoiceOption' + elif option.impl_is_leader(): + if 'leader' not in types: + error_type = 'not available for a Leader' + elif option.impl_is_follower(): + if 'follower' not in types: + error_type = 'not available for a Follower' + else: + error_type = 'not available for an Option' + if not error_type: if not option.impl_is_optiondescription() and \ not option.impl_is_symlinkoption() and \ option.impl_is_follower(): @@ -150,9 +154,23 @@ def option_type(typ): msg = _('please specify index with a follower option ' f'({self.__class__.__name__}.{func.__name__})') raise ConfigError(msg) + if self._validate_properties: + settings = self._config_bag.context.get_settings() + parent = self._subconfig.parent + if parent and parent.raises_properties: + while parent: + if not parent.parent.raises_properties: + settings.validate_properties(parent, + need_help=True, + ) + break + parent = parent.parent + settings.validate_properties(self._subconfig, + need_help=True, + ) return func(self, *args[1:], **kwargs) msg = _('please specify a valid sub function ' - f'({self.__class__.__name__}.{func.__name__})') + f'({self.__class__.__name__}.{func.__name__}): {error_type}') raise ConfigError(msg) wrapped.func = func return wrapped @@ -201,20 +219,28 @@ class _TiramisuOptionOptionDescription: """Get Tiramisu option""" return self._subconfig.option + @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) + def isoptiondescription(self): + """Test if option is an optiondescription""" + return self._subconfig.option.impl_is_optiondescription() + @option_type(['optiondescription']) def isleadership(self): """Test if option is a leader or a follower""" return self._subconfig.option.impl_is_leadership() - @option_type(['optiondescription', 'option', 'with_or_without_index']) + @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) def doc(self): """Get option document""" - return self._subconfig.option.impl_get_display_name() + return self._subconfig.option.impl_get_display_name(self._subconfig) - @option_type(['optiondescription', 'option', 'with_or_without_index']) + @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) def description(self): """Get option description""" - return self._subconfig.option.impl_get_information('doc', None) + return self._subconfig.option._get_information(self._subconfig, + 'doc', + None, + ) @option_type(['optiondescription', 'option', 'symlink', 'with_or_without_index']) def name(self) -> str: @@ -235,7 +261,7 @@ class _TiramisuOptionOptionDescription: """Test if option has dependency""" return self._subconfig.option.impl_has_dependency(self_is_dep) - @option_type(['optiondescription', 'option']) + @option_type(['optiondescription', 'option', 'symlink', 'with_or_without_index']) def dependencies(self): """Get dependencies from this option""" options = [] @@ -246,30 +272,41 @@ class _TiramisuOptionOptionDescription: )) return options - @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) - def isoptiondescription(self): - """Test if option is an optiondescription""" - return self._subconfig.option.impl_is_optiondescription() + @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) + def type(self): + """Get de option type""" + option = self._subconfig.option + if option.impl_is_optiondescription(): + return 'optiondescription' + return option.get_type() - @option_type(['optiondescription', 'option', 'with_or_without_index', 'symlink']) - def properties(self, - only_raises=False, - uncalculated=False, - ): - """Get properties for an option""" - settings = self._config_bag.context.get_settings() - if uncalculated: - return settings.getproperties(self._subconfig, - uncalculated=True, - ) - if not only_raises: - return settings.getproperties(self._subconfig, - apply_requires=False, - ) - return settings.calc_raises_properties(self._subconfig, - apply_requires=False, - uncalculated=uncalculated, - ) + @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) + def isdynamic(self): + """Test if option is a dynamic optiondescription""" + return self._subconfig.is_dynamic + + @option_type(['option', 'leadership']) + def leader(self): + """Get the leader option for a follower option""" + option = self._subconfig.option + if isinstance(option, Leadership): + leadership = self._subconfig + else: + leadership = self._subconfig.parent + leader_subconfig = leadership.get_child(leadership.option.get_leader(), + None, + False, + ) + return TiramisuOption(leader_subconfig.path, + None, + self._config_bag, + subconfig=leader_subconfig, + ) + + @option_type(['dynamic', 'with_or_without_index']) + def suffixes(self): + """Get suffixes for dynamic option""" + return self._subconfig.suffixes class _TiramisuOptionOption(_TiramisuOptionOptionDescription): @@ -284,7 +321,7 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription): """Test if option could have submulti value""" return self._subconfig.option.impl_is_submulti() - @option_type(['option', 'with_or_without_index']) + @option_type(['option', 'with_or_without_index', 'symlink']) def isleader(self): """Test if option is a leader""" return self._subconfig.option.impl_is_leader() @@ -294,11 +331,6 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription): """Test if option is a follower""" return self._subconfig.option.impl_is_follower() - @option_type(['option', 'optiondescription', 'with_or_without_index']) - def isdynamic(self): - """Test if option is a dynamic optiondescription""" - return self._subconfig.is_dynamic - @option_type(['option', 'symlink', 'with_or_without_index']) def issymlinkoption(self) -> bool: """Test if option is a symlink option""" @@ -316,14 +348,6 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription): raise ConfigError(_('only multi value has defaultmulti')) return self._subconfig.option.impl_getdefault_multi() - @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) - def type(self): - """Get de option type""" - option = self._subconfig.option - if option.impl_is_optiondescription(): - return 'optiondescription' - return option.get_type() - @option_type(['option', 'with_or_without_index']) def pattern(self) -> str: """Get the option pattern""" @@ -340,46 +364,57 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription): #FIXME only from 0.0.0.0 to 255.255.255.255 return r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' - @option_type(['option', 'leadership']) - def leader(self): - """Get the leader option for a follower option""" - option = self._subconfig.option - if isinstance(option, Leadership): - leadership = self._subconfig - else: - leadership = self._subconfig.parent - leader_subconfig = leadership.get_child(leadership.option.get_leader(), - None, - True, - ) - return TiramisuOption(leader_subconfig.path, - None, - self._config_bag, - subconfig=leader_subconfig, - ) - - @option_type(['option', 'with_or_without_index']) + @option_type(['option', 'with_or_without_index', 'symlink']) def index(self): - """Get then index of option""" + """Get index of option""" return self._subconfig.index + @option_type(['symlink', 'optiondescription']) + def option(self, *args, **kwargs): + """For OptionDescription get sub option, for symlinkoption get the linked option""" + if self._subconfig.option.impl_is_optiondescription(): + return self._option_description(*args, **kwargs) + return self._option_symlink(*args, **kwargs) -class TiramisuOptionOption(CommonTiramisuOption): - """Manage option""" - def __call__(self, - name: str, - index: Optional[int]=None, - ) -> 'TiramisuOption': - """Select an option by path""" - return TiramisuOption(self._path + '.' + name, + def _option_description(self, + path, + index=None, + ): + sub_path = self._path + '.' + path + return TiramisuOption(sub_path, index, self._config_bag, ) + def _option_symlink(self): + subconfig = self._subconfig.config_bag.context._get(self._subconfig, + need_help=True, + validate_properties=self._validate_properties, + ) + return TiramisuOption(subconfig.path, + subconfig.index, + self._config_bag, + subconfig=subconfig, + ) +# +# +#class TiramisuOptionOption(CommonTiramisuOption): +# """Manage option""" +# _validate_properties = False +# def __call__(self, +# name: str, +# index: Optional[int]=None, +# ) -> 'TiramisuOption': +# """Select an option by path""" +# return TiramisuOption(self._path + '.' + name, +# index, +# self._config_bag, +# ) + class TiramisuOptionOwner(CommonTiramisuOption): - #FIXME optiondescription must not have Owner! """Manage option's owner""" + _validate_properties=True @option_type(['symlink', 'option', 'with_index']) def get(self): @@ -410,17 +445,22 @@ class TiramisuOptionProperty(CommonTiramisuOption): """Manage option's property""" _validate_properties = False - @option_type(['option', 'optiondescription', 'with_or_without_index']) + @option_type(['option', 'optiondescription', 'with_index', 'symlink']) def get(self, - only_raises=False, - uncalculated=False, + only_raises: bool=False, + apply_requires: bool=True, + uncalculated: bool=False, ): """Get properties for an option""" settings = self._config_bag.context.get_settings() if not only_raises: - return settings.getproperties(self._subconfig) + return settings.getproperties(self._subconfig, + uncalculated=uncalculated, + apply_requires=apply_requires, + ) return settings.calc_raises_properties(self._subconfig, uncalculated=uncalculated, + apply_requires=apply_requires, ) @option_type(['option', 'optiondescription', 'with_or_without_index']) @@ -430,10 +470,9 @@ class TiramisuOptionProperty(CommonTiramisuOption): raise ConfigError(_('cannot add this property: "{0}"').format( ' '.join(prop))) settings = self._config_bag.context.get_settings() - props = settings.get_stored_properties(self._path, - self._index, - self._subconfig.option.impl_getproperties(), - ) + props = settings.get_personalize_properties(self._path, + self._index, + ) settings.setproperties(self._subconfig, props | {prop}, ) @@ -444,7 +483,19 @@ class TiramisuOptionProperty(CommonTiramisuOption): ): """Remove new property for an option""" settings = self._config_bag.context.get_settings() - props = settings.getproperties(self._subconfig) + props = settings.get_personalize_properties(self._path, + self._index, + ) + + if prop not in props: + if prop in settings.getproperties(self._subconfig): + msg = f'cannot remove option\'s property "{prop}", use permissive instead' + else: + msg = f'cannot find "{prop}"' + msg += f' in option "{self._path}"' + if self._index is not None: + msg += f' at index "{self._index}"' + raise ConfigError(msg) settings.setproperties(self._subconfig, props - {prop}, ) @@ -457,6 +508,7 @@ class TiramisuOptionProperty(CommonTiramisuOption): class TiramisuOptionPermissive(CommonTiramisuOption): """Manage option's permissive""" + _validate_properties = False @option_type(['option', 'optiondescription', 'symlink', 'with_or_without_index']) def get(self): @@ -464,15 +516,27 @@ class TiramisuOptionPermissive(CommonTiramisuOption): return self._config_bag.context.get_settings().getpermissives(self._subconfig) @option_type(['option', 'optiondescription', 'with_or_without_index']) - def set(self, - permissives, + def add(self, + permissive, ): """Set permissives value""" + permissives = self._config_bag.context.get_settings().getpermissives(self._subconfig) self._config_bag.context.get_settings().setpermissives(self._subconfig, - permissives=permissives, + frozenset(permissives | {permissive}), ) - @option_type(['option', 'optiondescription', 'with_index']) + @option_type(['option', 'optiondescription', 'with_or_without_index']) + def remove(self, permissive): + """Remove a config property""" + permissives = set(self.get()) + if permissive not in permissives: + msg = f'cannot find "{permissive}"' + raise ConfigError(msg) + self._config_bag.context.get_settings().setpermissives(self._subconfig, + frozenset(permissives - {permissive}), + ) + + @option_type(['option', 'optiondescription', 'with_or_without_index']) def reset(self): """Reset all personalised permissive""" self._config_bag.context.get_settings().reset_permissives(self._subconfig) @@ -480,6 +544,7 @@ class TiramisuOptionPermissive(CommonTiramisuOption): class TiramisuOptionInformation(CommonTiramisuOption): """Manage option's informations""" + _validate_properties = False @option_type(['option', 'optiondescription', 'with_or_without_index', 'symlink']) def get(self, @@ -487,13 +552,10 @@ class TiramisuOptionInformation(CommonTiramisuOption): default=undefined, ) -> Any: """Get information""" - try: - return self._config_bag.context.get_values().get_information(self._subconfig, - name, - undefined, - ) - except ValueError: - return self._subconfig.option.impl_get_information(name, default) + return self._config_bag.context.get_values().get_information(self._subconfig, + name, + default, + ) @option_type(['option', 'optiondescription']) def set(self, @@ -506,9 +568,9 @@ class TiramisuOptionInformation(CommonTiramisuOption): ) @option_type(['option', 'optiondescription']) - def reset(self, - key: str, - ) -> None: + def remove(self, + key: str, + ) -> None: """Remove information""" self._config_bag.context.get_values().del_information(key, path=self._path, @@ -517,7 +579,7 @@ class TiramisuOptionInformation(CommonTiramisuOption): @option_type(['option', 'optiondescription', 'with_or_without_index', 'symlink']) def list(self) -> list: """List information's keys""" - lst1 = set(self._subconfig.option.impl_list_information()) + lst1 = set(self._subconfig.option._list_information()) lst2 = set(self._config_bag.context.get_values().list_information(self._path)) return lst1 | lst2 @@ -584,10 +646,11 @@ class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet): if not isinstance(value, Calculation) and option.impl_is_leader() and \ len(value) < self._subconfig.parent.get_length_leadership(): raise LeadershipError(_('cannot reduce length of the leader "{}"' - '').format(option.impl_get_display_name())) - return self._subconfig.config_bag.context.set_value(self._subconfig, - value, - ) + '').format(option.impl_get_display_name(self._subconfig))) + values = self._config_bag.context.get_values() + return values.set_value(self._subconfig, + value + ) @option_type(['group', 'option', 'with_index']) def reset(self, @@ -624,7 +687,7 @@ class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet): return False return True - @option_type(['choice', 'with_or_without_index']) + @option_type(['choice', 'with_index']) def list(self): """All values available for a ChoiceOption""" return self._subconfig.option.impl_get_values(self._subconfig) @@ -640,7 +703,7 @@ class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet): @option_type(['leader', 'follower', 'with_or_without_index']) def len(self): - """Length for a follower option""" + """Length for a leadership""" return self._subconfig.parent.get_length_leadership() @@ -674,18 +737,6 @@ class TiramisuConfig(TiramisuHelp, _TiramisuOptionWalk): if isinstance(config, KernelGroupConfig): return GroupConfig(config) - def _reset_config_properties(self): - config = self._config_bag.context - settings = config.get_settings() - properties = settings.get_context_properties(config.properties_cache) - permissives = settings.get_context_permissives() - self._config_bag.properties = properties - self._config_bag.permissives = permissives - if self._orig_config_bags: - for config_bag in self._orig_config_bags: - config_bag.properties = properties - config_bag.permissives = permissives - def name(self): """get the name""" return self._config_bag.context.impl_getname() @@ -714,7 +765,7 @@ class TiramisuOption(CommonTiramisu, _registers(self._registers, 'TiramisuOption') def __repr__(self): - msg = f' Set: """Get all config properties""" + if only_raises: + return set() return self._config_bag.properties def _set(self, props, ): """Personalise config properties""" -# if 'force_store_value' in props: -# force_store_value = 'force_store_value' not in self._config_bag.properties -# else: -# force_store_value = False - context = self._config_bag.context - context.get_settings().set_context_properties(props, - self._config_bag.context, - ) - self._reset_config_properties() -# if force_store_value: -# self._force_store_value() + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context property in unrestraint mode') + if 'force_store_value' in props: + force_store_value = 'force_store_value' not in self._config_bag.properties + else: + force_store_value = False + settings = self._config_bag.context.get_settings() + settings.set_context_properties(props, + self._config_bag.context, + ) + self._reset_config_properties(settings) + if force_store_value: + self._force_store_value() def reset(self): """Remove config properties""" - context = self._config_bag.context - context.get_settings().reset(self._config_bag) - self._reset_config_properties() + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context property in unrestraint mode') + settings = self._config_bag.context.get_settings() + settings.reset(self._config_bag) + self._reset_config_properties(settings) def exportation(self): """Export config properties""" @@ -1017,44 +1103,45 @@ class TiramisuContextProperty(TiramisuConfig): def importation(self, properties): """Import config properties""" -# if 'force_store_value' in properties.get(None, {}).get(None, []): -# force_store_value = 'force_store_value' not in self._config_bag.properties -# else: -# force_store_value = False - self._config_bag.context.get_settings()._properties = deepcopy(properties) - self._config_bag.context.reset_cache(None, None) - self._reset_config_properties() -# if force_store_value: -# self._force_store_value() -# -# def _force_store_value(self): -# descr = self._config_bag.context.get_description() -# descr.impl_build_force_store_values(self._config_bag) + if 'force_store_value' in properties.get(None, {}).get(None, []): + force_store_value = 'force_store_value' not in self._config_bag.properties + else: + force_store_value = False + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context property in unrestraint mode') + context = self._config_bag.context + settings = context.get_settings() + settings._properties = deepcopy(properties) + context.reset_cache(None, None) + self._reset_config_properties(settings) + if force_store_value: + self._force_store_value() + + def _force_store_value(self): + descr = self._config_bag.context.get_description() + descr.impl_build_force_store_values(self._config_bag) def setdefault(self, properties: Set[str], - type: Optional[str]=None, + type: Optional[str], when: Optional[str]=None) -> None: if not isinstance(properties, frozenset): raise TypeError(_('properties must be a frozenset')) setting = self._config_bag.context.get_settings() - if type is None and when is None: - setting.default_properties = properties - else: - if when not in ['append', 'remove']: - raise ValueError(_('unknown when {} (must be in append or remove)').format(when)) - if type == 'read_only': - if when == 'append': - setting.ro_append = properties - else: - setting.ro_remove = properties - elif type == 'read_write': - if when == 'append': - setting.rw_append = properties - else: - setting.rw_remove = properties + if when not in ['append', 'remove']: + raise ValueError(_('unknown when {} (must be in append or remove)').format(when)) + if type == 'read_only': + if when == 'append': + setting.ro_append = properties else: - raise ValueError(_('unknown type {}').format(type)) + setting.ro_remove = properties + elif type == 'read_write': + if when == 'append': + setting.rw_append = properties + else: + setting.rw_remove = properties + else: + raise ValueError(_('unknown type {}').format(type)) def default(self, type: Optional[str]=None, @@ -1062,7 +1149,7 @@ class TiramisuContextProperty(TiramisuConfig): ) -> Set[str]: setting = self._config_bag.context.get_settings() if type is None and when is None: - return setting.default_properties + return DEFAULT_PROPERTIES if type == 'current': return setting.get_context_properties(self._config_bag.context.properties_cache) if when not in ['append', 'remove']: @@ -1078,7 +1165,7 @@ class TiramisuContextProperty(TiramisuConfig): raise ValueError(_('unknown type {}').format(type)) -class TiramisuContextPermissive(TiramisuConfig): +class TiramisuContextPermissive(TiramisuConfig, PropertyPermissive): """Manage config permissives""" def get(self): """Get config permissives""" @@ -1091,8 +1178,11 @@ class TiramisuContextPermissive(TiramisuConfig): permissives, ): """Set config permissives""" - self._config_bag.context.get_settings().set_context_permissives(permissives) - self._reset_config_properties() + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context permissive in unrestraint mode') + settings = self._config_bag.context.get_settings() + settings.set_context_permissives(permissives) + self._reset_config_properties(settings) def exportation(self): """Export config permissives""" @@ -1100,32 +1190,39 @@ class TiramisuContextPermissive(TiramisuConfig): def importation(self, permissives): """Import config permissives""" - settings = self._config_bag.context.get_settings() - self._config_bag.context.get_settings()._permissives = deepcopy(permissives) - self._config_bag.context.reset_cache(None, - None, - ) - self._reset_config_properties() + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context permissive in unrestraint mode') + context = self._config_bag.context + settings = context.get_settings() + settings._permissives = deepcopy(permissives) + context.reset_cache(None, + None, + ) + self._reset_config_properties(settings) def reset(self): """Remove config permissives""" - context = self._config_bag.context - settings = context.get_settings() + if self._config_bag.is_unrestraint: + raise ConfigError('cannot change context permissive in unrestraint mode') + settings = self._config_bag.context.get_settings() settings.reset_permissives(self._config_bag) - self._reset_config_properties() + self._set_default_permissive(settings) + self._reset_config_properties(settings) - def add(self, prop): + def add(self, permissive): """Add a config permissive""" - props = set(self._get()) - props.add(prop) - self._set(frozenset(props)) + permissives = set(self._get()) + permissives.add(permissive) + self._set(frozenset(permissives)) - def remove(self, prop): + def remove(self, permissive): """Remove a config permissive""" - props = set(self._get()) - if prop in props: - props.remove(prop) - self._set(frozenset(props)) + permissives = set(self._get()) + if permissive not in permissives: + msg = f'cannot find "{permissive}"' + raise ConfigError(msg) + permissives.remove(permissive) + self._set(frozenset(permissives)) class TiramisuContextOption(TiramisuConfig, _TiramisuOptionWalk): @@ -1134,31 +1231,49 @@ class TiramisuContextOption(TiramisuConfig, _TiramisuOptionWalk): **kwargs) -> None: self._tiramisu_dict = None super().__init__(*args, **kwargs) -# -# def find(self, -# name, -# value=undefined, -# type=None, -# first=False): -# """Find an or a list of options""" -# options = [] -# option_bag = OptionBag(self._config_bag.context.get_description(), -# None, -# self._config_bag, -# ) -# for path in self._config_bag.context.find(option_bag, -# byname=name, -# byvalue=value, -# bytype=type, -# ): -# option = TiramisuOption(path, -# None, -# self._config_bag, -# ) -# if first: -# return option -# options.append(option) -# return options + + def get(self): + """Get Tiramisu option""" + return None + + def isleadership(self): + """Test if option is a leader or a follower""" + return False + + def doc(self): + """Get option document""" + return self._config_bag.context.get_description().impl_get_display_name(None) + + def description(self): + """Get option description""" + return self._config_bag.context.get_description()._get_information(None, 'doc', None) + + def name(self): + """Get option name""" + return None + + def path(self, + ): + """Get option path""" + return None + + def has_dependency(self, + self_is_dep=True, + ) -> bool: + """Test if option has dependency""" + return False + + def isoptiondescription(self): + """Test if option is an optiondescription""" + return True + + def isdynamic(self): + """Test if option is a dynamic optiondescription""" + return False + + def type(self): + """Get de option type""" + return 'optiondescription' def list(self, validate_properties: bool=True, @@ -1362,12 +1477,17 @@ class TiramisuAPI(TiramisuHelp): if not self._registers: _registers(self._registers, 'TiramisuContext') + def option(self, + path: str, + index: Optional[int]=None, + ) -> TiramisuOption: + """Select an option by path""" + return TiramisuOption(path, + index, + self._config_bag, + ) + def __getattr__(self, subfunc: str) -> Any: - if subfunc == 'option': - config_bag = self._config_bag - return TiramisuDispatcherOption(config_bag, - self._orig_config_bags, - ) if subfunc in ['forcepermissive', 'unrestraint', 'nowarnings']: if self._orig_config_bags: msg = _('do not use unrestraint, nowarnings or forcepermissive together') @@ -1379,7 +1499,7 @@ class TiramisuAPI(TiramisuHelp): config_bag.nowarnings() else: config_bag.set_permissive() - return TiramisuAPI(config_bag, [self._config_bag]) + return ConfigProp(config_bag, [self._config_bag]) if subfunc == 'config': config_type = self._config_bag.context.impl_type if config_type == 'group': @@ -1404,20 +1524,12 @@ class TiramisuAPI(TiramisuHelp): ['unrestraint', 'forcepermissive', 'nowarnings', 'config'] -class TiramisuDispatcherOption(TiramisuContextOption): - """Select an option""" - def __call__(self, - path: str, - index: Optional[int]=None, - ) -> TiramisuOption: - """Select an option by path""" - return TiramisuOption(path, - index, - self._config_bag, - ) +class ConfigProp(TiramisuAPI, TiramisuContextOption): + def __repr__(self): + return f'' -class Config(TiramisuAPI): +class Config(TiramisuAPI, TiramisuContextOption): """Root config object that enables us to handle the configuration options""" def __init__(self, descr: OptionDescription, @@ -1432,7 +1544,7 @@ class Config(TiramisuAPI): display_name=display_name, ) settings = config.get_settings() - properties = settings.get_context_properties(config.properties_cache) + properties = settings.get_context_properties() permissives = settings.get_context_permissives() config_bag = ConfigBag(config, properties=properties, @@ -1448,6 +1560,9 @@ class Config(TiramisuAPI): except ConfigError: pass + def __repr__(self): + return f'' + class MetaConfig(TiramisuAPI): """MetaConfig object that enables us to handle the sub configuration's options @@ -1478,7 +1593,7 @@ class MetaConfig(TiramisuAPI): display_name=display_name, ) settings = config.get_settings() - properties = settings.get_context_properties(config.properties_cache) + properties = settings.get_context_properties() permissives = settings.get_context_permissives() config_bag = ConfigBag(config, properties=properties, diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index c10b5ea..f7e8d65 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -19,16 +19,47 @@ # ____________________________________________________________ "enables us to carry out a calculation and return an option's value" from typing import Any, Optional, Union, Callable, Dict, List -from os.path import commonprefix from itertools import chain +import weakref from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning from .i18n import _ -from .setting import undefined, ConfigBag, Undefined +from .setting import undefined, ConfigBag from .function import FUNCTION_WAITING_FOR_DICT # ____________________________________________________________ +def get_calculated_value(subconfig: "SubConfig", + value: Any, + *, + reset_cache: bool=True, + validate_properties: bool=True, + ) -> Any: + """value could be a calculation, in this case do calculation + """ + has_calculation = False + if isinstance(value, Calculation): + if subconfig is None: + return undefined, False + value = value.execute(subconfig, + validate_properties=validate_properties, + ) + has_calculation = True + elif isinstance(value, list): + # if value is a list, do subcalculation + for idx, val in enumerate(value): + value[idx], _has_calculation = get_calculated_value(subconfig, + val, + reset_cache=False, + validate_properties=validate_properties, + ) + if value[idx] is undefined: + return undefined, False + if _has_calculation: + has_calculation = True + return value, has_calculation + + class Params: __slots__ = ('args', 'kwargs') def __init__(self, args=None, kwargs=None, **kwgs): @@ -85,13 +116,11 @@ class ParamOption(Param): class ParamDynOption(ParamOption): __slots__ = ('suffixes', - 'dynoptiondescription', 'optional', ) def __init__(self, option: 'Option', suffixes: list[str], - dynoptiondescription: 'DynOptionDescription'=None, notraisepropertyerror: bool=False, raisepropertyerror: bool=False, optional: bool=False, @@ -101,7 +130,6 @@ class ParamDynOption(ParamOption): raisepropertyerror, ) self.suffixes = suffixes - self.dynoptiondescription = dynoptiondescription self.optional = optional @@ -125,6 +153,7 @@ class ParamInformation(Param): __slots__ = ('information_name', 'default_value', 'option', + 'self_option', ) def __init__(self, information_name: str, @@ -133,7 +162,22 @@ class ParamInformation(Param): ) -> None: self.information_name = information_name self.default_value = default_value + self.self_option = None + self.option = None if option: + self.set_option(option) + + def set_self_option(self, option): + self.self_option = option + + def set_option(self, + option: 'Option'=None + ) -> None: + if not hasattr(self, 'self_option'): + raise ConfigError('cannot add option in information after creating config') + if self.option: + raise ConfigError('cannot redefine option in information') + if not option.impl_is_optiondescription(): if option.impl_is_symlinkoption(): raise ValueError(_('option in ParamInformation cannot be a symlinkoption')) if option.impl_is_follower(): @@ -141,10 +185,27 @@ class ParamInformation(Param): if option.impl_is_dynsymlinkoption(): raise ValueError(_('option in ParamInformation cannot be a dynamic option')) self.option = option + if self.self_option: + informations = self.self_option._dependencies_information + if set(informations) == {None, self.information_name}: + del self.self_option._dependencies_information + else: + informations.remove(None) + if not getattr(option, '_dependencies_information', {}): + option._dependencies_information = {None: []} + option._dependencies_information[None].append(self) + option._dependencies_information.setdefault(self.information_name, []).append(weakref.ref(self.self_option)) class ParamSelfInformation(ParamInformation): __slots__ = tuple() + def __init__(self, + information_name: str, + default_value: Any=undefined, + ) -> None: + return super().__init__(information_name, + default_value, + ) class ParamIndex(Param): @@ -152,7 +213,11 @@ class ParamIndex(Param): class ParamSuffix(Param): - __slots__ = tuple() + __slots__ = ('suffix_index',) + def __init__(self, + suffix_index: int=-1, + ) -> None: + self.suffix_index = suffix_index class Calculation: @@ -190,6 +255,7 @@ class Calculation: allow_value_error: bool=False, force_value_warning: bool=False, for_settings: bool=False, + validate_properties: bool=True, ) -> Any: return carry_out_calculation(subconfig, callback=self.function, @@ -200,6 +266,7 @@ class Calculation: allow_value_error=allow_value_error, force_value_warning=force_value_warning, for_settings=for_settings, + validate_properties=validate_properties, ) def help(self, @@ -229,6 +296,7 @@ def manager_callback(callback: Callable, orig_value, config_bag: ConfigBag, for_settings: bool, + validate_properties: bool, ) -> Any: """replace Param by true value""" option = subconfig.option @@ -297,18 +365,18 @@ def manager_callback(callback: Callable, return value def _get_value(param: Params, - subconfig: SubConfig, + subconfig: 'SubConfig', ) -> Any: try: # get value value = config_bag.context.get_value(subconfig) except PropertiesOptionError as err: # raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation - if param.notraisepropertyerror or param.raisepropertyerror: + if isinstance(param, ParamSelfOption) or param.notraisepropertyerror or param.raisepropertyerror: raise err from err raise ConfigError(_('unable to carry out a calculation for "{}", {}').format(display_name, err)) from err except ValueError as err: - display_name = subconfig.option.impl_get_display_name() + display_name = subconfig.option.impl_get_display_name(subconfig) raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(display_name, err)) from err except AttributeError as err: if isinstance(param, ParamDynOption) and param.optional: @@ -317,7 +385,7 @@ def manager_callback(callback: Callable, ['configerror'], config_bag.context.get_settings(), ) - display_name = subconfig.option.impl_get_display_name() + display_name = subconfig.option.impl_get_display_name(subconfig) raise ConfigError(_(f'unable to get value for calculating "{display_name}", {err}')) from err return value @@ -341,20 +409,20 @@ def manager_callback(callback: Callable, config_bag.remove_validation() # root = config_bag.context.get_root(config_bag) try: - subconfig = config_bag.context.get_sub_config(config_bag, - opt.impl_getpath(), - index_, - validate_properties=not self_calc, - properties=properties, - ) + subsubconfig = config_bag.context.get_sub_config(config_bag, + opt.impl_getpath(), + index_, + validate_properties=not self_calc, + properties=properties, + ) except PropertiesOptionError as err: # raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation if param.notraisepropertyerror or param.raisepropertyerror: raise err from err - display_name = option.impl_get_display_name() + display_name = option.impl_get_display_name(subconfig) raise ConfigError(_('unable to carry out a calculation for "{}", {}').format(display_name, err)) from err except ValueError as err: - raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option.impl_get_display_name(), err)) from err + raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option.impl_get_display_name(subconfig), err)) from err except AttributeError as err: if isinstance(param, ParamDynOption) and param.optional: # cannot acces, simulate a propertyerror @@ -362,19 +430,9 @@ def manager_callback(callback: Callable, ['configerror'], config_bag.context.get_settings(), ) - display_name = option.impl_get_display_name() + display_name = option.impl_get_display_name(subconfig) raise ConfigError(_(f'unable to get value for calculating "{display_name}", {err}')) from err - return subconfig - - def get_common_path(path1, path2): - common_path = commonprefix([path1, path2]) - if common_path in [path1, path2]: - return common_path - if common_path.endswith('.'): - return common_path[:-1] - if '.' in common_path: - return common_path.rsplit('.', 1)[0] - return None + return subsubconfig if isinstance(param, ParamValue): return param.value @@ -383,22 +441,30 @@ def manager_callback(callback: Callable, if isinstance(param, ParamSelfInformation): isubconfig = subconfig elif param.option: - isubconfig = get_option_bag(config_bag, - param.option, - param, - None, - False, - #properties=properties, - ) + if param.option.issubdyn(): + search_option = param.option + isubconfig = subconfig.get_common_child(search_option, + true_path=subconfig.path, + ) + if isinstance(isubconfig, list): + raise ConfigError(f'cannot find information for "{option.impl_get_display_name(subconfig)}", "{search_option.impl_get_display_name(None)}" is a dynamic option') + else: + isubconfig = get_option_bag(config_bag, + param.option, + param, + None, + False, + #properties=properties, + ) else: - isubconfig = None + isubconfig = config_bag.context.get_root(config_bag) try: return config_bag.context.get_values().get_information(isubconfig, param.information_name, param.default_value, ) except ValueError as err: - display_name = option.impl_get_display_name() + display_name = option.impl_get_display_name(subconfig) raise ConfigError(_(f'unable to get value for calculating "{display_name}", {err}')) from err if isinstance(param, ParamIndex): @@ -406,9 +472,9 @@ def manager_callback(callback: Callable, if isinstance(param, ParamSuffix): if not option.issubdyn(): - display_name = subconfig.option.impl_get_display_name() + display_name = subconfig.option.impl_get_display_name(subconfig) raise ConfigError(_('option "{display_name}" is not in a dynoptiondescription')) - return subconfig.suffixes[-1] + return subconfig.suffixes[param.suffix_index] if isinstance(param, ParamSelfOption): value = calc_self(param, @@ -418,45 +484,13 @@ def manager_callback(callback: Callable, ) if callback.__name__ not in FUNCTION_WAITING_FOR_DICT: return value - return {'name': option.impl_get_display_name(), + return {'name': option.impl_get_display_name(subconfig), 'value': value, } if isinstance(param, ParamOption): callbk_option = param.option - callbk_options = None - subconfigs = None - if callbk_option.issubdyn(): - found = False - - if isinstance(param, ParamDynOption): - # SUBDYN INSIDE CURRENT != SUBDYN OUTSIDE ? - callbk_option = callbk_option.to_sub_dyoption(param.suffixes) - found = True - else: - search_option = param.option - current_option_path = option.impl_getpath() - search_option_path = search_option.impl_getpath() - common_path = get_common_path(current_option_path, search_option_path) - if common_path: - parent_number = current_option_path[len(common_path) + 2:].count('.') - if parent_number: - raise Exception('pfff') - subconfig = subconfig.parent.get_child(search_option, - None, - True, - ) - else: - raise Exception('pfff') - subconfigs = [subconfig] - found = True - if not found: - callbk_options = [] - for doption_bag in callbk_option.getsubdyn().get_sub_children(callbk_option, - config_bag, - index=None, - ): - callbk_options.append(doption_bag.option) + config_bag = subconfig.config_bag if index is not None and callbk_option.impl_get_leadership() and \ callbk_option.impl_get_leadership().in_same_leadership(option): if not callbk_option.impl_is_follower(): @@ -470,7 +504,69 @@ def manager_callback(callback: Callable, else: index_ = None with_index = False - if subconfigs is None: + if callbk_option.issubdyn(): + if isinstance(param, ParamDynOption): + #callbk_option = callbk_option.to_sub_dyoption(param.suffixes) + suffixes = param.suffixes.copy() + paths = callbk_option.impl_getpath().split('.') + parents = [config_bag.context.get_root(config_bag)] + subconfigs_is_a_list = False + for name in paths: + new_parents = [] + for parent in parents: + doption = parent.option.get_child(name, + config_bag, + parent, + allow_dynoption=True, + ) + if doption.impl_is_dynoptiondescription(): + if suffixes: + suffix = suffixes.pop(0) + name = doption.impl_getname(suffix) + try: + doption = parent.option.get_child(name, + config_bag, + parent, + ) + except AttributeError as err: + raise ConfigError(err) from err + new_parents.append(parent.get_child(doption, + None, + True, + name=name, + suffix=suffix, + )) + else: + subconfigs_is_a_list = True + new_parents.extend(parent.dyn_to_subconfig(doption, + True, + ) + ) + else: + new_parents.append(parent.get_child(doption, + None, + True, + name=name, + )) + parents = new_parents + + if subconfigs_is_a_list: + subconfigs = parents + else: + subconfigs = parents[0] + + else: + search_option = param.option + subconfigs = subconfig.get_common_child(search_option, + true_path=subconfig.path, + validate_properties=validate_properties, + ) + if isinstance(subconfigs, list): + values = [] + else: + values = None + subconfigs = [subconfigs] + else: subconfigs = [get_option_bag(config_bag, callbk_option, param, @@ -479,13 +575,7 @@ def manager_callback(callback: Callable, #properties=properties, ) ] -# callbk_options = [callbk_option] values = None - else: - values = [] - #FIXME - values = None -# for callbk_option in callbk_options: for subconfig in subconfigs: callbk_option = subconfig.option value = get_value(config_bag, @@ -501,7 +591,7 @@ def manager_callback(callback: Callable, value = values if callback.__name__ not in FUNCTION_WAITING_FOR_DICT: return value - return {'name': callbk_option.impl_get_display_name(), + return {'name': callbk_option.impl_get_display_name(subconfig), 'value': value} @@ -514,6 +604,8 @@ def carry_out_calculation(subconfig: 'SubConfig', allow_value_error: bool=False, force_value_warning: bool=False, for_settings: bool=False, + *, + validate_properties: bool=True, ): """a function that carries out a calculation for an option's value @@ -533,7 +625,7 @@ def carry_out_calculation(subconfig: 'SubConfig', Values could have multiple values only when key is ''.""" option = subconfig.option if not option.impl_is_optiondescription() and option.impl_is_follower() and index is None: - raise Exception('follower must have index in carry_out_calculation!') + raise ConfigError(f'the follower "{option.impl_get_display_name(subconfig)}" must have index in carry_out_calculation!') def fake_items(iterator): return ((None, i) for i in iterator) args = [] @@ -548,20 +640,21 @@ def carry_out_calculation(subconfig: 'SubConfig', orig_value, config_bag, for_settings, + validate_properties, ) if key is None: args.append(value) else: kwargs[key] = value except PropertiesOptionError as err: - if param.raisepropertyerror: + if isinstance(param, ParamSelfOption) or param.raisepropertyerror: raise err if callback.__name__ in FUNCTION_WAITING_FOR_DICT: if key is None: - args.append({'propertyerror': str(err), 'name': option.impl_get_display_name()}) + args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}) else: - kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name()} - ret = calculate(option, + kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)} + ret = calculate(subconfig, callback, allow_value_error, force_value_warning, @@ -579,17 +672,17 @@ def carry_out_calculation(subconfig: 'SubConfig', args, kwargs, ret, - option.impl_get_display_name())) + option.impl_get_display_name(subconfig))) else: raise LeadershipError(_('the "{}" function must not return a list ("{}") ' 'for the follower option "{}"' '').format(callback.__name__, ret, - option.impl_get_display_name())) + option.impl_get_display_name(subconfig))) return ret -def calculate(option, +def calculate(subconfig, callback: Callable, allow_value_error: bool, force_value_warning: bool, @@ -617,12 +710,12 @@ def calculate(option, msg = _('unexpected error "{0}" in function "{1}" with arguments "{3}" and "{4}" ' 'for option "{2}"').format(str(error), callback.__name__, - option.impl_get_display_name(), + subconfig.option.impl_get_display_name(subconfig), args, kwargs) else: msg = _('unexpected error "{0}" in function "{1}" for option "{2}"' '').format(str(error), callback.__name__, - option.impl_get_display_name()) + subconfig.option.impl_get_display_name(subconfig)) raise ConfigError(msg) from error diff --git a/tiramisu/cacheobj.py b/tiramisu/cacheobj.py index 165c292..beae9d0 100644 --- a/tiramisu/cacheobj.py +++ b/tiramisu/cacheobj.py @@ -47,17 +47,12 @@ class Cache: if path not in self._cache or index not in self._cache[path]: return no_cache value, timestamp, validated = self._cache[path][index] - if type_ == 'context_props': - # cached value is settings properties so value is props - props = value - self_props = {} + props = subconfig.config_bag.properties + if type_ == 'self_props': + # cached value is self_props + self_props = value else: - props = subconfig.config_bag.properties - if type_ == 'self_props': - # cached value is self_props - self_props = value - else: - self_props = subconfig.properties + self_props = subconfig.properties if 'cache' in props or \ 'cache' in self_props: if expiration and timestamp and \ diff --git a/tiramisu/config.py b/tiramisu/config.py index 9c060b8..11ce32d 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -23,6 +23,7 @@ import weakref from copy import copy, deepcopy from typing import Optional, List, Any, Union +from os.path import commonprefix from .error import PropertiesOptionError, ConfigError, ConflictError, \ LeadershipError @@ -35,6 +36,17 @@ from .autolib import Calculation from . import autolib +def get_common_path(path1, path2): + common_path = commonprefix([path1, path2]) + if common_path in [path1, path2]: + return common_path + if common_path.endswith('.'): + return common_path[:-1] + if '.' in common_path: + return common_path.rsplit('.', 1)[0] + return None + + class CCache: __slots__ = tuple() # ============================================================================= @@ -171,6 +183,7 @@ class SubConfig: 'path', 'true_path', 'properties', + 'raises_properties', 'is_dynamic', 'suffixes', '_length', @@ -187,8 +200,6 @@ class SubConfig: properties: Union[list[str], undefined]=undefined, validate_properties: bool=True, ) -> None: - if path and '.' in path and not parent: - raise Exception('pff connard') self.index = index self.suffixes = suffixes self.option = option @@ -198,12 +209,14 @@ class SubConfig: self.path = path if true_path is None: true_path = path + is_follower = not option.impl_is_optiondescription() and option.impl_is_follower() + apply_requires = not is_follower or index is not None self.true_path = true_path + settings = config_bag.context.get_settings() if properties is undefined: if path is None: self.properties = frozenset() else: - settings = config_bag.context.get_settings() self.properties = frozenset() if validate_properties: self.properties = settings.getproperties(self, @@ -211,7 +224,7 @@ class SubConfig: ) self.config_bag.context.get_settings().validate_properties(self) self.properties = settings.getproperties(self, - apply_requires=True, + apply_requires=apply_requires, ) else: self.properties = properties @@ -221,6 +234,15 @@ class SubConfig: self.is_dynamic = False if validate_properties: self.config_bag.context.get_settings().validate_properties(self) + if self.option.impl_is_optiondescription(): + if self.properties is not None: + self.raises_properties = settings.calc_raises_properties(self, + apply_requires=apply_requires, + not_unrestraint=True, + ) + else: + self.raises_properties = frozenset() + def __repr__(self): return f'' @@ -228,7 +250,8 @@ class SubConfig: def dyn_to_subconfig(self, child: Option, validate_properties: bool, - follower_not_apply_requires: bool=False, + *, + true_path: Optional[str]=None, ) -> List['SubConfig']: config_bag = self.config_bag for suffix in child.get_suffixes(self): @@ -241,10 +264,10 @@ class SubConfig: yield self.get_child(child, None, validate_properties, - follower_not_apply_requires=follower_not_apply_requires, suffix=suffix, name=name, properties=properties, + true_path=true_path, ) except PropertiesOptionError as err: if err.proptype in (['mandatory'], ['empty']): @@ -298,7 +321,6 @@ class SubConfig: validate_properties: bool, *, properties=undefined, - follower_not_apply_requires: bool=False, allow_dynoption: bool=False, suffix: Optional[str]=None, name: Optional[str]=None, @@ -312,24 +334,6 @@ class SubConfig: if not self.option.impl_is_optiondescription(): raise TypeError(f'"{self.path}" is not an optiondescription') - - if check_index and index is not None: - if option.impl_is_optiondescription() or \ - option.impl_is_symlinkoption() or \ - not option.impl_is_follower(): - raise ConfigError('index must be set only with a follower option') - length = self.get_length_leadership() - if index >= length: - raise LeadershipError(_(f'index "{index}" is greater than the leadership ' - f'length "{length}" for option ' - f'"{option.impl_get_display_name()}"')) - if properties is undefined and not validate_properties: - # not transitive property error - apply_requires = False - else: - apply_requires = not follower_not_apply_requires or \ - option.impl_is_optiondescription() or \ - not option.impl_is_follower() path = self.get_path(name, option, ) @@ -340,16 +344,27 @@ class SubConfig: suffixes = self.suffixes + [suffix] else: suffixes = [suffix] - return SubConfig(option, - index, - path, - self.config_bag, - self, - suffixes, - properties=properties, - validate_properties=validate_properties, - true_path=true_path, - ) + subsubconfig = SubConfig(option, + index, + path, + self.config_bag, + self, + suffixes, + properties=properties, + validate_properties=validate_properties, + true_path=true_path, + ) + if check_index and index is not None: + if option.impl_is_optiondescription() or \ + option.impl_is_symlinkoption() or \ + not option.impl_is_follower(): + raise ConfigError('index must be set only with a follower option') + length = self.get_length_leadership() + if index >= length: + raise LeadershipError(_(f'index "{index}" is greater than the leadership ' + f'length "{length}" for option ' + f'"{option.impl_get_display_name(subsubconfig)}"')) + return subsubconfig def get_path(self, name: str, @@ -379,10 +394,77 @@ class SubConfig: cconfig_bag, self, self.suffixes, + validate_properties=False, ) self._length = len(cconfig_bag.context.get_value(subconfig)) return self._length -autolib.SubConfig = SubConfig + + def get_common_child(self, + search_option: 'BaseOption', + true_path: Optional[str]=None, + validate_properties: bool=True, + ): + current_option_path = self.option.impl_getpath() + search_option_path = search_option.impl_getpath() + common_path = get_common_path(current_option_path, search_option_path) + config_bag = self.config_bag + index = None + if not self.option.impl_is_optiondescription() and \ + self.option.impl_is_follower() and search_option.impl_is_follower() and \ + self.parent.option == search_option.impl_get_leadership(): + index = self.index + search_child_number = 0 + parents = [self.parent] + else: + if common_path: + parent = self.parent + common_parent_number = common_path.count('.') + 1 + for idx in range(current_option_path.count('.') - common_parent_number): + parent = parent.parent + parents = [parent] + else: + common_parent_number = 0 + parents = [config_bag.context.get_root(config_bag)] + search_child_number = search_option_path.count('.') - common_parent_number + subconfigs_is_a_list = False + if search_child_number: + if common_parent_number: + parent_paths = search_option_path.rsplit('.', search_child_number + 1)[1:-1] + else: + parent_paths = search_option_path.split('.')[:-1] + for parent_path in parent_paths: + new_parents = [] + for parent in parents: + sub_option = parent.option.get_child(parent_path, + config_bag, + parent, + allow_dynoption=True, + ) + if sub_option.impl_is_dynoptiondescription(): + new_parents.extend(parent.dyn_to_subconfig(sub_option, + True, + true_path=true_path, + ) + ) + subconfigs_is_a_list = True + else: + new_parents.append(parent.get_child(sub_option, + None, + validate_properties, + true_path=true_path, + ) + ) + parents = new_parents + subconfigs = [] + for parent in parents: + subconfigs.append(parent.get_child(search_option, + index, + validate_properties, + ) + ) + if subconfigs_is_a_list: + return subconfigs + return subconfigs[0] class _Config(CCache): @@ -486,7 +568,6 @@ class _Config(CCache): path, None, validate_properties=True, - follower_not_apply_requires=False, ) except PropertiesOptionError: continue @@ -541,7 +622,6 @@ class _Config(CCache): index, *, validate_properties: bool=True, - follower_not_apply_requires: bool=False, properties=undefined, true_path: Optional[str]=None, ): @@ -577,7 +657,6 @@ class _Config(CCache): subconfig = subconfig.get_child(option, index_, validate_properties, - follower_not_apply_requires=follower_not_apply_requires, properties=properties, name=name, suffix=suffix, @@ -647,17 +726,6 @@ class _Config(CCache): # ============================================================================= # Manage value - def set_value(self, - subconfig: SubConfig, - value: Any, - ) -> Any: - """set value - """ - self.get_settings().validate_properties(subconfig) - return self.get_values().set_value(subconfig, - value - ) - def get_value(self, subconfig, need_help=True, @@ -672,8 +740,9 @@ class _Config(CCache): if isinstance(subconfig, list): value = [] follower_subconfig = None + is_follower = not subconfig or subconfig[0].option.impl_is_follower() for sconfig in subconfig: - if follower_subconfig is None: + if not is_follower or follower_subconfig is None: follower_subconfig = self.get_sub_config(sconfig.config_bag, sconfig.path, sconfig.index, @@ -692,7 +761,7 @@ class _Config(CCache): length = subconfig.parent.get_length_leadership() follower_len = self.get_values().get_max_length(subconfig.path) if follower_len > length: - option_name = subconfig.option.impl_get_display_name() + option_name = subconfig.option.impl_get_display_name(subconfig) raise LeadershipError(_(f'the follower option "{option_name}" ' f'has greater length ({follower_len}) than the leader ' f'length ({length})')) @@ -704,6 +773,7 @@ class _Config(CCache): def _get(self, subconfig: "SubConfig", need_help: bool, + validate_properties: bool=True, ) -> "OptionBag": # pylint: disable=too-many-locals option = subconfig.option @@ -712,17 +782,15 @@ class _Config(CCache): suboption = option.impl_getopt() if suboption.issubdyn(): dynopt = suboption.getsubdyn() - return list(dynopt.get_sub_children(suboption, - suboption.config_bag, - index=suboption.index, - true_path=subconfig.path, - )) + return subconfig.get_common_child(suboption, + true_path=subconfig.path, + validate_properties=validate_properties, + ) if suboption.impl_is_follower(): subconfig = self.get_sub_config(subconfig.config_bag, # pylint: disable=no-member suboption.impl_getpath(), None, - validate_properties=True, - follower_not_apply_requires=False, + validate_properties=validate_properties, true_path=subconfig.path, ) leadership_length = subconfig.parent.get_length_leadership() @@ -739,8 +807,7 @@ class _Config(CCache): s_subconfig = self.get_sub_config(subconfig.config_bag, # pylint: disable=no-member suboption.impl_getpath(), None, - validate_properties=True, - follower_not_apply_requires=False, + validate_properties=validate_properties, true_path=subconfig.path, ) return self._get(s_subconfig, @@ -818,6 +885,7 @@ class _CommonConfig(_Config): self.reset_cache(option_bag) def impl_get_information(self, + subconfig, key, default, ): @@ -893,7 +961,7 @@ class _CommonConfig(_Config): duplicated_settings.rw_append = self.get_settings().rw_append duplicated_settings.ro_remove = self.get_settings().ro_remove duplicated_settings.rw_remove = self.get_settings().rw_remove - duplicated_settings.default_properties = self.get_settings().default_properties +# duplicated_settings.default_properties = self.get_settings().default_properties duplicated_config.reset_cache(None, None) if child is not None: duplicated_config._impl_children.append(child) # pylint: disable=protected-access @@ -1412,7 +1480,7 @@ class KernelMixConfig(KernelGroupConfig): ) # Copy context properties/permissives settings = config.get_settings() - properties = settings.get_context_properties(config.properties_cache) + properties = settings.get_context_properties() settings.set_context_properties(properties, config, ) @@ -1421,7 +1489,7 @@ class KernelMixConfig(KernelGroupConfig): settings.rw_append = settings.rw_append settings.ro_remove = settings.ro_remove settings.rw_remove = settings.rw_remove - settings.default_properties = settings.default_properties +# settings.default_properties = settings.default_properties config.parents.append(weakref.ref(self)) self._impl_children.append(config) diff --git a/tiramisu/error.py b/tiramisu/error.py index f559daa..649d131 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -70,8 +70,9 @@ class PropertiesOptionError(AttributeError): self._opt_type = 'optiondescription' else: self._opt_type = 'option' - self._name = subconfig.option.impl_get_display_name() + self._name = subconfig.option.impl_get_display_name(subconfig) self._orig_opt = None + self._subconfig = subconfig self.proptype = proptype self.help_properties = help_properties self._settings = settings @@ -108,8 +109,9 @@ class PropertiesOptionError(AttributeError): else: msg = 'cannot access to {0} "{1}" because has {2} {3}' if self._orig_opt: + # FIXME _orig_opt ? self.msg = _(msg).format(self._opt_type, - self._orig_opt.impl_get_display_name(), + self._orig_opt.impl_get_display_name(subconfig), self._name, prop_msg, properties_msg) @@ -156,6 +158,7 @@ class ConstError(TypeError): class _CommonError: def __init__(self, + subconfig, val, display_type, opt, @@ -164,7 +167,7 @@ class _CommonError: self.val = val self.display_type = display_type self.opt = weakref.ref(opt) - self.name = opt.impl_get_display_name() + self.name = opt.impl_get_display_name(subconfig) self.err_msg = err_msg self.index = index super().__init__(self.err_msg) diff --git a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po index 3c8a926..2bd837f 100644 --- a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po +++ b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po @@ -944,7 +944,7 @@ msgstr "option \"{0}\" inconnue dans l'optiondescription \"{1}\"" #: tiramisu/option/optiondescription.py:279 msgid "children in optiondescription \"{}\" must be a list" -msgstr "les enfants d'une optiondescription \"{}\" doit être une liste" +msgstr "les enfants d'une optiondescription \"{}\" doivent être une liste" #: tiramisu/option/optiondescription.py:303 msgid "duplicate option name: \"{0}\"" diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index e45dd6a..c5bcf5c 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -20,14 +20,14 @@ # ____________________________________________________________ """base option """ -from typing import FrozenSet, Set, Any, List +from typing import FrozenSet, Set, Any, List, Optional, Dict import weakref from itertools import chain from ..i18n import _ from ..setting import undefined -from ..autolib import Calculation, ParamOption +from ..autolib import Calculation, ParamOption, ParamInformation, ParamSelfInformation STATIC_TUPLE = frozenset() @@ -57,6 +57,7 @@ class Base: '_properties', '_has_dependency', '_dependencies', + '_dependencies_information', '_suffixes_dependencies', '__weakref__' ) @@ -64,8 +65,11 @@ class Base: def __init__(self, name: str, doc: str, + informations: Optional[Dict], + *, properties=None, - is_multi: bool=False) -> None: + is_multi: bool=False, + ) -> None: if not valid_name(name): raise ValueError(_('"{0}" is an invalid name for an option').format(name)) if properties is None: @@ -83,6 +87,9 @@ class Base: assert isinstance(properties, frozenset), _('invalid properties type {0} for {1},' ' must be a frozenset').format(type(properties), name) + _setattr = object.__setattr__ + _setattr(self, '_name', name) + _setattr(self, '_informations', {'doc': doc}) for prop in properties: if not isinstance(prop, str): if not isinstance(prop, Calculation): @@ -91,11 +98,19 @@ class Base: for param in chain(prop.params.args, prop.params.kwargs.values()): if isinstance(param, ParamOption): param.option._add_dependency(self) - _setattr = object.__setattr__ - _setattr(self, '_name', name) - _setattr(self, '_informations', {'doc': doc}) if properties: _setattr(self, '_properties', properties) + self.set_informations(informations) + + def set_informations(self, + informations: Optional[Dict], + ) -> None: + if not informations: + return + for key, value in informations.items(): + self._set_information(key, + value, + ) def impl_has_dependency(self, self_is_dep: bool=True, @@ -196,10 +211,11 @@ class Base: # ____________________________________________________________ # information - def impl_get_information(self, - key: str, - default: Any=undefined, - ) -> Any: + def _get_information(self, + subconfig: "SubConfig", + key: str, + default: Any=undefined, + ) -> Any: """retrieves one information's item :param key: the item string (ex: "help") @@ -217,13 +233,13 @@ class Base: if default is not undefined: return default # pylint: disable=no-member - raise ValueError(_(f'information\'s item for "{self.impl_get_display_name()}" ' + raise ValueError(_(f'information\'s item for "{self.impl_get_display_name(subconfig)}" ' f'not found: "{key}"')) - def impl_set_information(self, - key: str, - value: Any, - ) -> None: + def _set_information(self, + key: str, + value: Any, + ) -> None: """updates the information's attribute (which is a dictionary) @@ -237,13 +253,13 @@ class Base: key)) self._informations[key] = value # pylint: disable=no-member - def impl_list_information(self) -> Any: + def _list_information(self) -> Any: """get the list of information keys """ dico = self._informations # pylint: disable=no-member if isinstance(dico, tuple): return list(dico[0]) - if isinstance(dico, str): + if not isinstance(dico, dict): return ['doc'] # it's a dict return list(dico.keys()) @@ -272,7 +288,7 @@ class BaseOption(Base): if self.impl_is_readonly(): raise AttributeError(_('"{}" ({}) object attribute "{}" is' ' read-only').format(self.__class__.__name__, - self.impl_get_display_name(), + self.impl_get_display_name(None), name)) super().__setattr__(name, value) @@ -282,21 +298,22 @@ class BaseOption(Base): try: return self._path except AttributeError as err: - raise AttributeError(_(f'"{self.impl_get_display_name()}" not part of any Config')) \ + raise AttributeError(_(f'"{self.impl_get_display_name(None)}" not part of any Config')) \ from err def impl_get_display_name(self, - dynopt=None, + subconfig: "SubConfig", ) -> str: """get display name """ - if dynopt is None: - dynopt = self if hasattr(self, '_display_name_function'): - return self._display_name_function(dynopt) - name = self.impl_get_information('doc', None) + return self._display_name_function(self, subconfig) + name = self._get_information(subconfig, 'doc', None) if name is None or name == '': - name = dynopt.impl_getname() + if subconfig and subconfig.path: + name = subconfig.path.rsplit('.', 1)[-1] + else: + name = self._name return name def reset_cache(self, @@ -322,33 +339,43 @@ class BaseOption(Base): """ return getattr(self, '_dependencies_information', {}) - def to_sub_dyoption(self, - suffixes: list[str], - ): - sub_dyn = self - # retrieve all subdyn options - sub_dyns = [] - while True: - sub_dyn = sub_dyn.getsubdyn() - sub_dyns.append(sub_dyn) - if not sub_dyn.issubdyn(): - break - paths = [] - parent_path = self.impl_getpath().rsplit('.', 1)[0] - suffix_idx = len(sub_dyns) - 1 - for sub_dyn in sub_dyns: - dyn_path = sub_dyn.impl_getpath() - if dyn_path.count('.') == parent_path.count('.'): - *root_paths, dyn_path_ = parent_path.split('.', dyn_path.count('.') + 1) - else: - *root_paths, dyn_path_, child_path = parent_path.split('.', dyn_path.count('.') + 1) - paths.insert(0, child_path) - paths.insert(0, sub_dyn.impl_getname(suffixes[suffix_idx])) - suffix_idx -= 1 - parent_path = '.'.join(root_paths) - if parent_path: - paths.insert(0, parent_path) - full_parent_path = '.'.join(paths) - return self.to_dynoption(full_parent_path, - suffixes, - ) + def value_dependencies(self, + value: Any, + is_suffix: bool=False, + ) -> Any: + """parse dependancies to add dependencies + """ + if isinstance(value, list): + for val in value: + if isinstance(value, list): + self.value_dependencies(val, is_suffix) + elif isinstance(value, Calculation): + self.value_dependency(val, is_suffix) + elif isinstance(value, Calculation): + self.value_dependency(value, is_suffix) + + def value_dependency(self, + value: Any, + is_suffix: bool=False, + ) -> Any: + """parse dependancy to add dependencies + """ + for param in chain(value.params.args, value.params.kwargs.values()): + if isinstance(param, ParamOption): + # pylint: disable=protected-access + param.option._add_dependency(self, is_suffix=is_suffix) + self._has_dependency = True + elif isinstance(param, ParamInformation): + dest = self + if isinstance(param, ParamSelfInformation): + opt = weakref.ref(self) + elif param.option: + dest = param.option + opt = weakref.ref(self) + else: + param.set_self_option(self) + opt = None + if not getattr(dest, '_dependencies_information', {}): + dest._dependencies_information = {None: []} + dest._dependencies_information[None].append(param) + dest._dependencies_information.setdefault(param.information_name, []).append(opt) diff --git a/tiramisu/option/choiceoption.py b/tiramisu/option/choiceoption.py index 86bb43d..96d1f36 100644 --- a/tiramisu/option/choiceoption.py +++ b/tiramisu/option/choiceoption.py @@ -25,7 +25,7 @@ from typing import Any from ..setting import undefined from ..i18n import _ from .option import Option -from ..autolib import Calculation +from ..autolib import Calculation, get_calculated_value from ..error import ConfigError, display_list @@ -61,13 +61,16 @@ class ChoiceOption(Option): ): """get values allowed by option """ - if isinstance(self._choice_values, Calculation): - values = self._choice_values.execute(subconfig) - if values is not undefined and not isinstance(values, list): - raise ConfigError(_('the calculated values "{0}" for "{1}" is not a list' - '').format(values, self.impl_getname())) - else: - values = self._choice_values + choices = self._choice_values + if isinstance(choices, tuple): + choices = list(choices) + values = get_calculated_value(subconfig, + choices, + )[0] + + if values != undefined and not isinstance(values, (list, tuple)): + raise ConfigError(_('the calculated values "{0}" for "{1}" is not a list' + '').format(values, self.impl_getname())) return values def validate(self, diff --git a/tiramisu/option/dynoptiondescription.py b/tiramisu/option/dynoptiondescription.py index 8a57d35..15ab91d 100644 --- a/tiramisu/option/dynoptiondescription.py +++ b/tiramisu/option/dynoptiondescription.py @@ -20,22 +20,23 @@ # ____________________________________________________________ """DynOptionDescription """ +import re import weakref -from typing import List, Any, Optional +from typing import List, Any, Optional, Dict from itertools import chain from ..autolib import ParamOption from ..i18n import _ from .optiondescription import OptionDescription -from .syndynoption import CommonDyn #, SynDynLeadership from .baseoption import BaseOption from ..setting import ConfigBag, undefined from ..error import ConfigError -from ..autolib import Calculation +from ..autolib import Calculation, get_calculated_value -class DynOptionDescription(OptionDescription, CommonDyn): +NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') +class DynOptionDescription(OptionDescription): """dyn option description """ __slots__ = ('_suffixes', @@ -48,25 +49,28 @@ class DynOptionDescription(OptionDescription, CommonDyn): children: List[BaseOption], suffixes: Calculation, properties=None, + informations: Optional[Dict]=None, ) -> None: # pylint: disable=too-many-arguments super().__init__(name, doc, children, properties, + informations=informations, ) # check children + set relation to this dynoptiondescription wself = weakref.ref(self) for child in children: child._setsubdyn(wself) # add suffixes - if __debug__ and not isinstance(suffixes, Calculation): - raise ConfigError(_('suffixes in dynoptiondescription has to be a calculation')) - for param in chain(suffixes.params.args, suffixes.params.kwargs.values()): - if isinstance(param, ParamOption): - param.option._add_dependency(self, - is_suffix=True, - ) + self.value_dependencies(suffixes, is_suffix=True) +# if __debug__ and not isinstance(suffixes, Calculation): +# raise ConfigError(_('suffixes in dynoptiondescription has to be a calculation')) +# for param in chain(suffixes.params.args, suffixes.params.kwargs.values()): +# if isinstance(param, ParamOption): +# param.option._add_dependency(self, +# is_suffix=True, +# ) self._suffixes = suffixes def convert_suffix_to_path(self, @@ -98,3 +102,42 @@ class DynOptionDescription(OptionDescription, CommonDyn): return name path_suffix = self.convert_suffix_to_path(suffix) return name + path_suffix + + def get_suffixes(self, + parent: 'SubConfig', + ) -> List[str]: + """get dynamic suffixes + """ + subconfig = parent.get_child(self, + None, + False, + properties=None, + ) + suffixes = self._suffixes + if isinstance(suffixes, list): + suffixes = suffixes.copy() + values = get_calculated_value(subconfig, + suffixes, + validate_properties=False, + )[0] + if values is None: + values = [] + values_ = [] + if __debug__: + if not isinstance(values, list): + raise ValueError(_('DynOptionDescription suffixes for ' + f'option "{self.impl_get_display_name(subconfig)}", is not ' + f'a list ({values})')) + for val in values: + cval = self.convert_suffix_to_path(val) + if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: + if __debug__ and cval is not None: + raise ValueError(_('invalid suffix "{}" for option "{}"' + '').format(cval, + self.impl_get_display_name(subconfig))) + else: + values_.append(val) + if __debug__ and len(values_) > len(set(values_)): + raise ValueError(_(f'DynOptionDescription "{self._name}" suffixes return a list with ' + f'same values "{values_}"''')) + return values_ diff --git a/tiramisu/option/leadership.py b/tiramisu/option/leadership.py index a7765a5..dd20a7d 100644 --- a/tiramisu/option/leadership.py +++ b/tiramisu/option/leadership.py @@ -75,15 +75,15 @@ class Leadership(OptionDescription): def _check_child_is_valid(self, child: BaseOption): if child.impl_is_symlinkoption(): raise ValueError(_('leadership "{0}" shall not have ' - "a symlinkoption").format(self.impl_get_display_name())) + "a symlinkoption").format(self.impl_get_display_name(None))) if not isinstance(child, Option): raise ValueError(_('leadership "{0}" shall not have ' - 'a subgroup').format(self.impl_get_display_name())) + 'a subgroup').format(self.impl_get_display_name(None))) if not child.impl_is_multi(): raise ValueError(_('only multi option allowed in leadership "{0}" but option ' '"{1}" is not a multi' - '').format(self.impl_get_display_name(), - child.impl_get_display_name())) + '').format(self.impl_get_display_name(None), + child.impl_get_display_name(None))) def _check_default_value(self, child: BaseOption): default = child.impl_getdefault() @@ -100,8 +100,8 @@ class Leadership(OptionDescription): calculation = isinstance(default, Calculation) if not calculation: raise ValueError(_('not allowed default value for follower option ' - f'"{child.impl_get_display_name()}" in leadership ' - f'"{self.impl_get_display_name()}"')) + f'"{child.impl_get_display_name(None)}" in leadership ' + f'"{self.impl_get_display_name(None)}"')) def _setsubdyn(self, subdyn, @@ -143,58 +143,54 @@ class Leadership(OptionDescription): def reset(self, parent: "SubConfig") -> None: """reset follower value """ - #config_bag = parent.option_bag.config_bag values = parent.config_bag.context.get_values() - #config_bag = config_bag.copy() - #config_bag.remove_validation() for follower in self.get_followers(): subconfig_follower = parent.get_child(follower, None, False, ) -# OptionBag(follower, -# None, -# config_bag, -# ) - values.reset(subconfig_follower) -# -# def follower_force_store_value(self, -# value, -# config_bag: 'ConfigBag', -# owner, -# dyn=None, -# ) -> None: -# """apply force_store_value to follower -# """ -# if value: -# if dyn is None: -# dyn = self -# values = config_bag.context.get_values() -# for idx, follower in enumerate(dyn.get_children(config_bag)): -# if not idx: -# # it's a master -# apply_requires = True -# indexes = [None] -# else: -# apply_requires = False -# indexes = range(len(value)) -# foption_bag = OptionBag(follower, -# None, -# config_bag, -# apply_requires=apply_requires, -# ) -# if 'force_store_value' not in foption_bag.properties: -# continue -# for index in indexes: -# foption_bag_index = OptionBag(follower, -# index, -# config_bag, -# ) -# values.set_storage_value(foption_bag_index.path, -# index, -# values.get_value(foption_bag_index)[0], -# owner, -# ) + values.reset(subconfig_follower, + validate=False, + ) + + def follower_force_store_value(self, + value, + subconfig: 'SubConfig', + owner, + ) -> None: + """apply force_store_value to follower + """ + if not value: + return + config_bag = subconfig.config_bag + values = config_bag.context.get_values() + for idx, follower in enumerate(self.get_children()): + sub_subconfig = subconfig.get_child(follower, + None, + False, + config_bag=config_bag, + ) + if 'force_store_value' not in sub_subconfig.properties: + continue + self_path = sub_subconfig.path + if not idx: + # it's a master + apply_requires = True + indexes = [None] + else: + apply_requires = False + indexes = range(len(value)) + for index in indexes: + i_sub_subconfig = subconfig.get_child(follower, + index, + False, + config_bag=config_bag, + ) + values.set_storage_value(self_path, + index, + values.get_value(i_sub_subconfig)[0], + owner, + ) def pop(self, subconfig: 'SubConfig', diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 3276e86..232edc8 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -26,9 +26,8 @@ from itertools import chain from .baseoption import BaseOption, submulti from ..i18n import _ from ..setting import undefined -from ..autolib import Calculation, ParamOption, ParamInformation, ParamSelfInformation +from ..autolib import Calculation from ..error import ValueWarning, ValueErrorWarning, ValueOptionError -from .syndynoption import SynDynOption class Option(BaseOption): @@ -48,7 +47,6 @@ class Option(BaseOption): # '_validators', # - '_dependencies_information', '_leadership', '_choice_values', '_choice_values_params', @@ -63,7 +61,9 @@ class Option(BaseOption): validators: Optional[List[Calculation]]=None, properties: Optional[List[str]]=None, warnings_only: bool=False, - extra: Optional[Dict]=None): + extra: Optional[Dict]=None, + informations: Optional[Dict]=None, + ): _setattr = object.__setattr__ if not multi and default_multi is not None: raise ValueError(_("default_multi is set whereas multi is False" @@ -92,8 +92,10 @@ class Option(BaseOption): default = [] super().__init__(name, doc, + informations, properties=properties, - is_multi=is_multi) + is_multi=is_multi, + ) if validators is not None: if __debug__ and not isinstance(validators, list): raise ValueError(_(f'validators must be a list of Calculation for "{name}"')) @@ -126,10 +128,10 @@ class Option(BaseOption): if not str_err: raise ValueError(_('invalid default_multi value "{0}" ' 'for option "{1}"').format(str(value), - self.impl_get_display_name()) + self.impl_get_display_name(None)) ) from err raise ValueError(_(f'invalid default_multi value "{value}" for option ' - f'"{self.impl_get_display_name()}", {str_err}') + f'"{self.impl_get_display_name(None)}", {str_err}') ) from err if _multi is submulti: if not isinstance(default_multi, Calculation): @@ -137,7 +139,7 @@ class Option(BaseOption): raise ValueError(_('invalid default_multi value "{0}" ' 'for option "{1}", must be a list for a submulti' '').format(str(default_multi), - self.impl_get_display_name())) + self.impl_get_display_name(None))) for value in default_multi: test_multi_value(value) else: @@ -164,43 +166,6 @@ class Option(BaseOption): default = tuple(default) _setattr(self, '_default', default) - def value_dependencies(self, - value: Any, - ) -> Any: - """parse dependancies to add dependencies - """ - if isinstance(value, list): - for val in value: - if isinstance(value, list): - self.value_dependencies(val) - elif isinstance(value, Calculation): - self.value_dependency(val) - elif isinstance(value, Calculation): - self.value_dependency(value) - - def value_dependency(self, - value: Any, - ) -> Any: - """parse dependancy to add dependencies - """ - for param in chain(value.params.args, value.params.kwargs.values()): - if isinstance(param, ParamOption): - # pylint: disable=protected-access - param.option._add_dependency(self) - self._has_dependency = True - elif isinstance(param, ParamInformation): - dest = self - if isinstance(param, ParamSelfInformation): - opt = self - elif param.option: - dest = param.option - opt = self - else: - opt = None - if not getattr(dest, '_dependencies_information', {}): - dest._dependencies_information = {} - dest._dependencies_information.setdefault(param.information_name, []).append(opt) - #__________________________________________________________________________ # option's information @@ -326,7 +291,8 @@ class Option(BaseOption): **kwargs, ) except ValueWarning as warn: - warnings.warn_explicit(ValueWarning(val, + warnings.warn_explicit(ValueWarning(subconfig, + val, self.get_type(), self, str(warn), @@ -343,7 +309,7 @@ class Option(BaseOption): return if isinstance(_value, list): raise ValueError(_('which must not be a list').format(_value, - self.impl_get_display_name()), + self.impl_get_display_name(subconfig)), ) if isinstance(_value, Calculation) and not subconfig: return @@ -361,7 +327,8 @@ class Option(BaseOption): is_warnings_only) except ValueError as err: if is_warnings_only: - warnings.warn_explicit(ValueWarning(_value, + warnings.warn_explicit(ValueWarning(subconfig, + _value, self.get_type(), self, str(err), @@ -420,12 +387,14 @@ class Option(BaseOption): except ValueError as err: if not subconfig or \ 'demoting_error_warning' not in subconfig.config_bag.properties: - raise ValueOptionError(val, + raise ValueOptionError(subconfig, + val, self.get_type(), self, str(err), err_index) from err - warnings.warn_explicit(ValueErrorWarning(val, + warnings.warn_explicit(ValueErrorWarning(subconfig, + val, self.get_type(), self, str(err), @@ -476,16 +445,6 @@ class Option(BaseOption): #pylint: disable=not-callable return leadership() - def to_dynoption(self, - rootpath: str, - suffixes: list[str], - ) -> SynDynOption: - """tranforme a dynoption to a syndynoption - """ - return SynDynOption(self, - rootpath, - suffixes, - ) def validate(self, value: Any): """option needs a validate function """ diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 5e9bdc5..85b1942 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -21,7 +21,7 @@ """OptionDescription """ import weakref -from typing import Optional, Iterator, Union, List +from typing import Optional, Iterator, Union, List, Dict from ..i18n import _ @@ -87,6 +87,10 @@ class CacheOptionDescription(BaseOption): dependencies_information, ) else: + informations = option.get_dependencies_information() + if informations: + for param in informations.pop(None): + del param.self_option for information, options in option.get_dependencies_information().items(): if None in options: dependencies_information.setdefault(information, []).append(option) @@ -105,71 +109,86 @@ class CacheOptionDescription(BaseOption): self._cache_dependencies_information = dependencies_information # pylint: disable=attribute-defined-outside-init self._path = None # pylint: disable=attribute-defined-outside-init,no-member self._set_readonly() -# -# def impl_build_force_store_values(self, -# config_bag: ConfigBag, -# ) -> None: -# """set value to force_store_values option -# """ -# # pylint: disable=too-many-branches -# def do_option_bags(option): -# if option.issubdyn(): -# dynopt = option.getsubdyn() -# yield from dynopt.get_sub_children(option, -# config_bag, -# index=None, -# ) -# else: -# yield OptionBag(option, -# None, -# config_bag, -# properties=None, -# ) -# if 'force_store_value' not in config_bag.properties: -# return -# values = config_bag.context.get_values() -# for option in self._cache_force_store_values: -# if option.impl_is_follower(): -# leader = option.impl_get_leadership().get_leader() -# for leader_option_bag in do_option_bags(leader): -# leader_option_bag.properties = frozenset() -# follower_len = len(values.get_value(leader_option_bag)[0]) -# if option.issubdyn(): -# doption = option.to_dynoption(leader_option_bag.option.rootpath, -# leader_option_bag.option.get_current_suffixes(), -# ) -# else: -# doption = option -# subpath = doption.impl_getpath() -# for index in range(follower_len): -# option_bag = OptionBag(doption, -# index, -# config_bag, -# properties=frozenset(), -# ) -# if values.hasvalue(subpath, index=index): -# continue -# value = values.get_value(option_bag)[0] -# if value is None: -# continue -# values.set_storage_value(subpath, -# index, -# value, -# owners.forced, -# ) -# else: -# for option_bag in do_option_bags(option): -# option_bag.properties = frozenset() -# value = values.get_value(option_bag)[0] -# if value is None: -# continue -# if values.hasvalue(option_bag.path): -# continue -# values.set_storage_value(option_bag.path, -# None, -# value, -# owners.forced, -# ) + + def impl_build_force_store_values(self, + config_bag: ConfigBag, + ) -> None: + """set value to force_store_values option + """ + # pylint: disable=too-many-branches + context = config_bag.context + if 'force_store_value' not in config_bag.properties: + return + + values = config_bag.context.get_values() + for option in self._cache_force_store_values: + if option.issubdyn(): + paths = option.impl_getpath().split('.') + parents = [config_bag.context.get_root(config_bag)] + for name in paths: + new_parents = [] + for parent in parents: + doption = parent.option.get_child(name, + config_bag, + parent, + allow_dynoption=True, + ) + if doption.impl_is_dynoptiondescription(): + new_parents.extend(parent.dyn_to_subconfig(doption, + True, + ) + ) + else: + new_parents.append(parent.get_child(doption, + None, + True, + name=name, + )) + parents = new_parents + subconfigs = new_parents + else: + subconfigs = [context.get_sub_config(config_bag, + option.impl_getpath(), + None, + properties=None, + validate_properties=False, + )] + + if option.impl_is_follower(): + for follower_subconfig in subconfigs: + parent = follower_subconfig.parent + follower_len = parent.get_length_leadership() + for index in range(follower_len): + if values.hasvalue(follower_subconfig.path, + index=index, + ): + continue + idx_follower_subconfig = parent.get_child(follower_subconfig.option, + index, + validate_properties=False, + ) + + value = values.get_value(idx_follower_subconfig)[0] + if value is None: + continue + values.set_storage_value(follower_subconfig.path, + index, + value, + owners.forced, + ) + else: + for subconfig in subconfigs: + subconfig.properties = frozenset() + value = values.get_value(subconfig)[0] + if value is None: + continue + if values.hasvalue(subconfig.path): + continue + values.set_storage_value(subconfig.path, + None, + value, + owners.forced, + ) class OptionDescriptionWalk(CacheOptionDescription): @@ -228,7 +247,7 @@ class OptionDescriptionWalk(CacheOptionDescription): 'in root optiondescription' )) raise AttributeError(_(f'unknown option "{name}" ' - f'in optiondescription "{self.impl_get_display_name()}"' + f'in optiondescription "{self.impl_get_display_name(parent)}"' )) def get_children(self) -> List[BaseOption]: @@ -278,7 +297,9 @@ class OptionDescription(OptionDescriptionWalk): name: str, doc: str, children: List[BaseOption], - properties=None) -> None: + properties=None, + informations: Optional[Dict]=None, + ) -> None: """ :param children: a list of options (including optiondescriptions) @@ -286,8 +307,10 @@ class OptionDescription(OptionDescriptionWalk): assert isinstance(children, list), _('children in optiondescription "{}" ' 'must be a list').format(name) super().__init__(name, - doc=doc, - properties=properties) + doc, + informations, + properties=properties, + ) child_names = [] if __debug__: dynopt_names = [] diff --git a/tiramisu/option/symlinkoption.py b/tiramisu/option/symlinkoption.py index acfdc04..b02e447 100644 --- a/tiramisu/option/symlinkoption.py +++ b/tiramisu/option/symlinkoption.py @@ -20,7 +20,7 @@ # ____________________________________________________________ """SymLinkOption link to an other option """ -from typing import Any +from typing import Any, Optional, Dict from .baseoption import BaseOption, valid_name from ..error import ConfigError from ..i18n import _ @@ -41,55 +41,46 @@ class SymLinkOption(BaseOption): if not isinstance(opt, BaseOption) or \ opt.impl_is_optiondescription() or \ opt.impl_is_symlinkoption(): - raise ValueError(_('malformed symlinkoption must be an option for symlink {0}' - '').format(name)) - _setattr = object.__setattr__ - _setattr(self, '_name', name) - _setattr(self, '_opt', opt) + raise ValueError(_(f'malformed symlink second parameters must be an option for "{name}", not {opt}')) + self._name = name + self._opt = opt opt._add_dependency(self) def __getattr__(self, name: str, ) -> Any: + if name == '_subdyns': + return None if name == '_path': raise AttributeError() return getattr(self._opt, name) - def _setsubdyn(self, - subdyn, - ) -> None: - raise ConfigError(_('cannot set symlinkoption in a ' - 'dynoptiondescription')) - - def impl_has_dependency(self, - self_is_dep: bool=True, - ) -> bool: - """If self_is_dep is True, it has dependency (self._opt), so return True - if self_is_dep is False, cannot has validation or callback, so return False - """ - return self_is_dep - def impl_is_symlinkoption(self) -> bool: """it's a symlinkoption """ return True + def impl_is_leader(self) -> bool: + return False + + def impl_is_follower(self) -> bool: + return False + def impl_getopt(self) -> BaseOption: """get to linked option """ return self._opt - def issubdyn(self) -> bool: - """it's not a sub dyn option - """ - return False - def impl_is_multi(self) -> bool: """is it a multi? """ - if self._opt.issubdyn(): + if self._opt.impl_is_multi(): return True - return self._opt.impl_is_multi() + if self._opt.issubdyn() or self.issubdyn(): + if self.issubdyn() != self._opt.issubdyn(): + return self._opt.issubdyn() + return self._opt.issubdyn() in self.get_sub_dyns() + return False def impl_is_submulti(self) -> bool: """is it a submulti? diff --git a/tiramisu/option/syndynoption.py b/tiramisu/option/syndynoption.py deleted file mode 100644 index 80d94a0..0000000 --- a/tiramisu/option/syndynoption.py +++ /dev/null @@ -1,351 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2024 Team tiramisu (see AUTHORS for all contributors) -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU Lesser 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 Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program. If not, see . -# -# The original `Config` design model is unproudly borrowed from -# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/ -# the whole pypy projet is under MIT licence -# ____________________________________________________________ -"""SynDynOption internal option, it's an instanciate synoption -""" -import re -from typing import Optional, Iterator, Any, List, Tuple - -from .baseoption import BaseOption -from ..i18n import _ -from ..setting import ConfigBag, undefined - - -NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') - - -class CommonDyn: - def get_path(self, - config_bag, - ): - if config_bag is undefined or \ - config_bag.context.get_description() == self: - return '' - return self.impl_getpath() - - def get_suffixes(self, - parent: 'SubConfig', - ) -> List[str]: - """get dynamic suffixes - """ - subconfig = parent.get_child(self, - None, - False, - properties=None, - ) - values = self._suffixes.execute(subconfig) - if values is None: - values = [] - values_ = [] - if __debug__: - if not isinstance(values, list): - raise ValueError(_('DynOptionDescription suffixes for ' - f'option "{self.impl_get_display_name()}", is not ' - f'a list ({values})')) - for val in values: - cval = self.convert_suffix_to_path(val) - if not isinstance(cval, str) or re.match(NAME_REGEXP, cval) is None: - if __debug__ and cval is not None: - raise ValueError(_('invalid suffix "{}" for option "{}"' - '').format(cval, - self.impl_get_display_name())) - else: - values_.append(val) - if __debug__ and len(values_) > len(set(values_)): - raise ValueError(_(f'DynOptionDescription "{self._name}" suffixes return a list with ' - f'same values "{values_}"''')) - return values_ - - def split_path(self, - option, - *, - dynoption=None, - ) -> Tuple[str, str]: - """self.impl_getpath() is something like root.xxx.dynoption_path - option.impl_getpath() is something like root.xxx.dynoption_path.sub.path - must return ('root.xxx.', '.sub') - """ - if dynoption is None: - self_path = self.impl_getpath() - else: - self_path = dynoption.impl_getpath() - root_path = self_path.rsplit('.', 1)[0] if '.' in self_path else None - # - if self.option_is_self(option): - sub_path = '' - else: - option_path = option.impl_getpath() - if root_path: - if isinstance(option, SynDynLeadership): - count_root_path = option_path.count('.') - root_path.count('.') - root_path = option_path.rsplit('.', count_root_path)[0] - root_path += '.' - self_number_child = self_path.count('.') + 1 - option_sub_path = option_path.split('.', self_number_child)[-1] - sub_path = '.' + option_sub_path.rsplit('.', 1)[0] if '.' in option_sub_path else '' - return root_path, sub_path - - -class Syn: - __slots__ = ('rootpath', - 'opt', - '_current_suffixes', - '__weakref__') - - def __init__(self, - opt: BaseOption, - rootpath: str, - suffixes: list, - ) -> None: - self.opt = opt - self.rootpath = rootpath - self._current_suffixes = suffixes - - def __getattr__(self, - name: str, - ) -> Any: - # if not in SynDynOptionDescription, get value in self.opt - return getattr(self.opt, - name, - ) - - def impl_get_display_name(self) -> str: - return self.opt.impl_get_display_name(self) - - def get_current_suffixes(self) -> str: - """get suffixes - """ - return self.current__suffixes - - def impl_is_dynsymlinkoption(self) -> bool: - """it's a dynsymlinkoption - """ - return True - - def impl_getpath(self) -> str: - """get path - """ - path = self.impl_getname() - if self.rootpath: - path = f'{self.rootpath}.{path}' - return path - - -class SynDescr(Syn): - __slots__ = ('opt', - 'rootpath', - '_current_suffixes', - ) - - def get_child(self, - name: str, - config_bag: ConfigBag, - *, - allow_dynoption: bool=False, - ): - """get children - """ - # if not dyn - option = self.get_child_not_dynamic(name, - allow_dynoption, - ) - if option: - if allow_dynoption and option.impl_is_dynoptiondescription(): - return option - return option.to_dynoption(self.impl_getpath(), - self._current_suffixes, - ) - for child in self.opt._children[1]: # pylint: disable=no-member - if not child.impl_is_dynoptiondescription(): - continue - for suffix in child.get_suffixes(config_bag): - if name != child.impl_getname(suffix): - continue - return child.to_dynoption(self.impl_getpath(), - self._current_suffixes + [suffix], - ) - raise AttributeError(_(f'unknown option "{name}" ' - f'in optiondescription "{self.impl_get_display_name()}"' - )) - - def get_children(self, - config_bag: ConfigBag, - ): - # pylint: disable=unused-argument - """get children - """ - for child in self.opt._children[1]: - if child.impl_is_dynoptiondescription(): - dynchild = self.get_child(child.impl_getname(), - config_bag, - allow_dynoption=True, - ) - for d in dynchild.get_sub_children(dynchild, - config_bag, - ): - yield d.option -# yield from dynchild.get_sub_children(dynchild, -# config_bag, -# ) - #for suffix in dynchild.get_suffixes(config_bag): - # yield child.to_dynoption(self.impl_getpath(), - # self._suffixes + [suffix], - # ) - else: - yield child.to_dynoption(self.impl_getpath(), - self._current_suffixes, - ) - - def get_children_recursively(self, - bytype: Optional[BaseOption], - byname: Optional[str], - config_bag: ConfigBag, - self_opt: BaseOption=None, - ) -> BaseOption: - # pylint: disable=unused-argument - """get children recursively - """ - for option in self.opt.get_children_recursively(bytype, - byname, - config_bag, - self, - ): - yield option - - def get_child_not_dynamic(self, - name, - allow_dynoption, - ): - children = self.opt._children - if name in children[0]: # pylint: disable=no-member - option = children[1][children[0].index(name)] # pylint: disable=no-member - if option.impl_is_dynoptiondescription() and not allow_dynoption: - raise AttributeError(_(f'unknown option "{name}" ' - "in root optiondescription (it's a dynamic option)" - )) - return SubDynOptionDescription(option, - self.impl_getpath(), - self._current_suffixes, - ) - - -class SynDynOption(Syn): - """SynDynOption is an Option include un DynOptionDescription with specified prefix - """ - __slots__ = () - - def impl_get_leadership(self): # pylint: disable=inconsistent-return-statements - """is it a leadership? - """ - leadership = self.opt.impl_get_leadership() - if leadership: - rootpath = self.rootpath.rsplit('.', 1)[0] - return leadership.to_dynoption(rootpath, - self._current_suffixes, - ) -# -# -#class SubDynOptionDescription(SynDescr, CommonDyn): -# def option_is_self(self, -# option, -# ) -> bool: -# return self.opt.option_is_self(option.opt) -# -# def get_sub_children(self, -# option, -# config_bag, -# *, -# index=None, -# properties=undefined, -# ): -# root_path, sub_path = self.split_path(option) -# for suffix in self.get_suffixes(config_bag): -# if self.option_is_self(option): -# parent_path = root_path -# elif root_path: -# parent_path = root_path + self.impl_getname(suffix) + sub_path -# else: -# parent_path = self.impl_getname(suffix) + sub_path -# yield OptionBag(option.to_dynoption(parent_path, -# [suffix], -# ), -# index, -# config_bag, -# properties=properties, -# ori_option=option -# ) -# -# -#class SynDynOptionDescription(SynDescr): -# """SynDynOptionDescription internal option, it's an instanciate synoptiondescription -# """ -# def impl_getname(self) -> str: -# """get name -# """ -# if self.opt.impl_is_dynoptiondescription(): -# return self.opt.impl_getname(self._current_suffixes[-1]) -# return self.opt.impl_getname() -# -# def getsubdyn(self): -# return self.opt -# -# -#class SynDynLeadership(SynDynOptionDescription): -# """SynDynLeadership internal option, it's an instanciate synoptiondescription -# """ -# def get_leader(self) -> SynDynOption: -# """get the leader -# """ -# return self.opt.get_leader().to_dynoption(self.impl_getpath(), -# self._current_suffixes, -# ) -# -# def get_followers(self) -> Iterator[SynDynOption]: -# """get followers -# """ -# subpath = self.impl_getpath() -# for follower in self.opt.get_followers(): -# yield follower.to_dynoption(subpath, -# self._current_suffixes, -# ) -# -# def pop(self, -# *args, -# **kwargs, -# ) -> None: -# """pop value for a follower -# """ -# self.opt.pop(*args, -# followers=self.get_followers(), -# **kwargs, -# ) -# -# def follower_force_store_value(self, -# value, -# config_bag, -# owner, -# ) -> None: -# """force store value for a follower -# """ -# self.opt.follower_force_store_value(value, -# config_bag, -# owner, -# dyn=self, -# ) diff --git a/tiramisu/option/syndynoptiondescription.py b/tiramisu/option/syndynoptiondescription.py deleted file mode 100644 index 355a7ac..0000000 --- a/tiramisu/option/syndynoptiondescription.py +++ /dev/null @@ -1,235 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2017-2023 Team tiramisu (see AUTHORS for all contributors) -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU Lesser 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 Lesser General Public License for more -# details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program. If not, see . -# -# The original `Config` design model is unproudly borrowed from -# the rough pypy's guys: http://codespeak.net/svn/pypy/dist/pypy/config/ -# the whole pypy projet is under MIT licence -# ____________________________________________________________ -"""SynDynOptionDescription and SynDynLeadership internal option -it's an instanciate synoptiondescription -""" -from typing import Optional, Iterator, Any, List - - -from ..i18n import _ -from ..setting import ConfigBag, undefined -from .baseoption import BaseOption -from .syndynoption import SynDynOption - - -class Syn: - __slots__ = ('opt', - 'rootpath', - '_suffixes', - ) - - def __init__(self, - opt: BaseOption, - rootpath: str, - suffixes: list, - ) -> None: - self.opt = opt - self.rootpath = rootpath - self._suffixes = suffixes - - def impl_get_display_name(self) -> str: - return self.opt.impl_get_display_name(self) - - def get_child(self, - name: str, - config_bag: ConfigBag, - *, - allow_dynoption: bool=False, - ): - """get children - """ - # if not dyn - option = self.opt.get_child_not_dynamic(name, - allow_dynoption, - ) - if option: - if allow_dynoption and option.impl_is_dynoptiondescription(): - return option - return option.to_dynoption(self.impl_getpath(), - self._suffixes, - ) - for child in self.opt._children[1]: # pylint: disable=no-member - if not child.impl_is_dynoptiondescription(): - continue - for suffix in child.get_suffixes(config_bag, - dynoption=self, - ): - if name != child.impl_getname(suffix): - continue - return child.to_dynoption(self.impl_getpath(), - self._suffixes + [suffix], - ) - raise AttributeError(_(f'unknown option "{name}" ' - f'in optiondescription "{self.impl_get_display_name()}"' - )) - - def get_children(self, - config_bag: ConfigBag, - ): - # pylint: disable=unused-argument - """get children - """ - for child in self.opt._children[1]: - if child.impl_is_dynoptiondescription(): - for suffix in child.get_suffixes(config_bag, - dynoption=self, - ): - yield child.to_dynoption(self.impl_getpath(), - self._suffixes + [suffix], - ) - else: - yield child.to_dynoption(self.impl_getpath(), - self._suffixes, - ) - - def get_children_recursively(self, - bytype: Optional[BaseOption], - byname: Optional[str], - config_bag: ConfigBag, - self_opt: BaseOption=None, - ) -> BaseOption: - # pylint: disable=unused-argument - """get children recursively - """ - for option in self.opt.get_children_recursively(bytype, - byname, - config_bag, - self, - ): - yield option - - def get_suffixes(self) -> str: - """get suffixes - """ - return self._suffixes - - def impl_is_dynsymlinkoption(self) -> bool: - """it's a dynsymlinkoption - """ - return True - - -class SubDynOptionDescription(Syn): - - def impl_getpath(self) -> str: - """get path - """ - path = self.opt.impl_getname() - if self.rootpath: - path = f'{self.rootpath}.{path}' - return path - - def getsubdyn(self): - return self.opt.getsubdyn() - - def impl_is_optiondescription(self): - return True - - def impl_is_symlinkoption(self): - return False - - def impl_is_leadership(self): - return False - - def impl_is_dynoptiondescription(self) -> bool: - return True - - def impl_getproperties(self): - return self.opt.impl_getproperties() - - -class SynDynOptionDescription(Syn): - """SynDynOptionDescription internal option, it's an instanciate synoptiondescription - """ - def __getattr__(self, - name: str, - ) -> Any: - # if not in SynDynOptionDescription, get value in self.opt - return getattr(self.opt, - name, - ) - - def impl_getname(self) -> str: - """get name - """ - if self.opt.impl_is_dynoptiondescription(): - return self.opt.impl_getname(self._suffixes[-1]) - return self.opt.impl_getname() - - def impl_getpath(self) -> str: - """get path - """ - path = self.impl_getname() - if self.rootpath: - path = f'{self.rootpath}.{path}' - return path - - def getsubdyn(self): - return self.opt - - -class SynDynLeadership(SynDynOptionDescription): - """SynDynLeadership internal option, it's an instanciate synoptiondescription - """ - def get_leader(self) -> SynDynOption: - """get the leader - """ - return self.opt.get_leader().to_dynoption(self.impl_getpath(), - self._suffixes, - ) - - def get_followers(self) -> Iterator[SynDynOption]: - """get followers - """ - subpath = self.impl_getpath() - for follower in self.opt.get_followers(): - yield follower.to_dynoption(subpath, - self._suffixes, - ) - - def pop(self, - *args, - **kwargs, - ) -> None: - """pop value for a follower - """ - self.opt.pop(*args, - followers=self.get_followers(), - **kwargs, - ) - - def follower_force_store_value(self, - value, - config_bag, - owner, - ) -> None: - """force store value for a follower - """ - self.opt.follower_force_store_value(value, - config_bag, - owner, - dyn=self, - ) - - def get_suffixes(self) -> str: - """get suffix - """ - return self._suffixes diff --git a/tiramisu/setting.py b/tiramisu/setting.py index c920b60..bec8784 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -17,7 +17,7 @@ # ____________________________________________________________ from typing import Union, Set from itertools import chain -from .error import PropertiesOptionError, ConstError, ConfigError, LeadershipError +from .error import PropertiesOptionError, ConstError, ConfigError, LeadershipError, display_list from .i18n import _ @@ -156,63 +156,6 @@ class Undefined: undefined = Undefined() -# -# -#class OptionBag: -# """Object to store information for an option -# """ -# __slots__ = ('option', # current option -# 'path', -# 'index', -# 'config_bag', -# 'ori_option', # original option (for example useful for symlinkoption) -# 'properties', # properties of current option -# 'apply_requires', # apply requires or not for this option -# 'suffixes', -# ) -# -# # pylint: disable=too-many-arguments -# def __init__(self, -# option, -# index, -# config_bag, -# *, -# path=None, -# properties=undefined, -# parent: 'SubConfig'=None, -# ori_option=None, -# apply_requires=True, -# suffixes=None -# ): -# self.index = index -# self.config_bag = config_bag -# self.option = option -# if ori_option is not None: -# self.ori_option = ori_option -# if config_bag is undefined: -# self.path = path -# elif option: -# if properties is not undefined: -# self.properties = properties -# self.suffixes = suffixes -# -# def __getattr__(self, key): -# if key == 'ori_option': -# return self.option -# if key == 'apply_requires': -# return True -# return None -# -# def copy(self): -# """copy OptionBag -# """ -# option_bag = OptionBag(None, -# None, -# None, -# ) -# for key in self.__slots__: -# setattr(option_bag, key, getattr(self, key)) -# return option_bag class ConfigBag: @@ -390,7 +333,6 @@ class Settings: 'ro_remove', 'rw_append', 'rw_remove', - 'default_properties', ) def __init__(self): @@ -401,9 +343,8 @@ class Settings: :param storage: the storage type """ # generic owner - self._properties = {} + self._properties = {None: {None: DEFAULT_PROPERTIES}} self._permissives = {} - self.default_properties = DEFAULT_PROPERTIES self.ro_append = RO_APPEND self.ro_remove = RO_REMOVE self.rw_append = RW_APPEND @@ -412,35 +353,19 @@ class Settings: # ____________________________________________________________ # get properties and permissive methods - def get_context_properties(self, - cache, - ): + def get_context_properties(self): """get context properties """ - is_cached, props, _ = cache.getcache(None, - 'context_props', - expiration=False, - ) - if not is_cached: - props = self.get_stored_properties(None, - None, - self.default_properties, - ) - cache.setcache(None, - props, - type_='properties', - ) - return props + return self.get_personalize_properties() - def get_stored_properties(self, - path: Union[None, str], - index: Union[None, int], - default_properties: Set[str], - ) -> Set[str]: + def get_personalize_properties(self, + path: Union[None, str]=None, + index: Union[None, int]=None, + ) -> Set[str]: """Get the properties modified by user for a path or index """ if path not in self._properties or index not in self._properties[path]: - return frozenset(default_properties) + return frozenset() return self._properties[path][index] def getproperties(self, @@ -467,18 +392,17 @@ class Settings: if not is_cached: props = set() # if index, get option's properties (without index) too - p_props = self.get_stored_properties(subconfig.path, - None, - option.impl_getproperties(), - ) + p_props = [option.impl_getproperties()] + props_config = self.get_personalize_properties(subconfig.path) + if props_config: + p_props.append(props_config) if subconfig.index is not None: - p_props = chain(p_props, - self.get_stored_properties(subconfig.path, - subconfig.index, - option.impl_getproperties(), - ) - ) - for prop in p_props: + props_config = self.get_personalize_properties(subconfig.path, + subconfig.index, + ) + if props_config: + p_props.append(props_config) + for prop in chain(*p_props): if uncalculated or isinstance(prop, str): if not help_property: props.add(prop) @@ -520,6 +444,12 @@ class Settings: props, type_='properties', ) + if subconfig.parent and subconfig.parent.raises_properties: + parent_properties = subconfig.parent.raises_properties + parent_properties -= self.getpermissives(subconfig) + if help_property: + parent_properties = {(prop, prop) for prop in parent_properties} + return props | parent_properties return props def get_context_permissives(self): @@ -566,7 +496,7 @@ class Settings: def set_context_properties(self, properties, context): """set context properties """ - self._properties.setdefault(None, {})[None] = properties + self._properties[None][None] = properties context.reset_cache(None) def setproperties(self, @@ -580,8 +510,8 @@ class Settings: if not opt.impl_is_optiondescription() and opt.impl_is_leader(): not_allowed_properties = properties - ALLOWED_LEADER_PROPERTIES if not_allowed_properties: - raise LeadershipError(_('leader cannot have "{list(not_allowed_properties)}" ' - 'property')) + raise LeadershipError(_(f'leader cannot have "{display_list(not_allowed_properties)}" ' + 'property')) if ('force_default_on_freeze' in properties or \ 'force_metaconfig_on_freeze' in properties) and 'frozen' not in properties: raise LeadershipError(_('a leader ({opt.impl_get_display_name()}) cannot have ' @@ -682,9 +612,11 @@ class Settings: # validate properties def calc_raises_properties(self, subconfig, + *, apply_requires=True, uncalculated=False, transitive_raise=True, + not_unrestraint=False, ): """raise if needed """ @@ -698,16 +630,23 @@ class Settings: ) return self._calc_raises_properties(subconfig, option_properties, + not_unrestraint, ) def _calc_raises_properties(self, subconfig, option_properties, + not_unrestraint, ): - raises_properties = subconfig.config_bag.properties - SPECIAL_PROPERTIES + config_bag =subconfig.config_bag + if not_unrestraint and config_bag.is_unrestraint: + context_properties = config_bag.true_properties + else: + context_properties = config_bag.properties + raises_properties = context_properties - SPECIAL_PROPERTIES # remove global permissive properties if raises_properties and 'permissive' in raises_properties: - raises_properties -= subconfig.config_bag.permissives + raises_properties -= config_bag.permissives properties = option_properties & raises_properties # at this point it should not remain any property for the option return properties @@ -736,6 +675,7 @@ class Settings: calc_properties = [] for property_ in self._calc_raises_properties(subconfig, set(help_properties.keys()), + False, ): calc_properties.append(help_properties[property_]) calc_properties = frozenset(calc_properties) @@ -799,10 +739,7 @@ class Settings: append, config_bag, ): - props = self.get_stored_properties(None, - None, - self.default_properties, - ) + props = self.get_personalize_properties() modified = False if remove & props: props = props - remove diff --git a/tiramisu/todict.py b/tiramisu/todict.py index 26a14ec..c044c27 100644 --- a/tiramisu/todict.py +++ b/tiramisu/todict.py @@ -6,7 +6,7 @@ from copy import copy from itertools import chain from .error import ValueWarning, ValueErrorWarning, PropertiesOptionError, ConfigError from .setting import undefined -from .option.syndynoption import SynDynOption +#from .option.syndynoption import SynDynOption from . import RegexpOption, ChoiceOption, ParamOption from .i18n import _ @@ -233,8 +233,8 @@ class Requires(object): def add(self, path, childapi, form): #collect id of all options child = childapi.get() - if isinstance(child, SynDynOption): - child = child.opt +# if isinstance(child, SynDynOption): +# child = child.opt self.options[child] = path current_action = None diff --git a/tiramisu/value.py b/tiramisu/value.py index b3a5384..b4dc302 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -18,7 +18,7 @@ from typing import Union, Optional, List, Any from .error import ConfigError from .setting import owners, undefined, forbidden_owners -from .autolib import Calculation +from .autolib import Calculation, get_calculated_value from .i18n import _ @@ -106,9 +106,9 @@ class Values: # the value is a default value # get it value = self.get_default_value(subconfig) - value, has_calculation = self.get_calculated_value(subconfig, - value, - ) + value, has_calculation = get_calculated_value(subconfig, + value, + ) return value, has_calculation def get_default_value(self, @@ -125,9 +125,9 @@ class Values: return msubconfig.config_bag.context.get_values().get_cached_value(msubconfig) # now try to get calculated value: - value, _has_calculation = self.get_calculated_value(subconfig, - subconfig.option.impl_getdefault(), - ) + value, _has_calculation = get_calculated_value(subconfig, + subconfig.option.impl_getdefault(), + ) if subconfig.index is not None and isinstance(value, (list, tuple)) \ and (not subconfig.option.impl_is_submulti() or \ not value or isinstance(value[0], list)): @@ -139,38 +139,14 @@ class Values: else: # no value for this index, retrieve default multi value # default_multi is already a list for submulti - value, _has_calculation = self.get_calculated_value(subconfig, - subconfig.option.impl_getdefault_multi(), - ) + value, _has_calculation = get_calculated_value(subconfig, + subconfig.option.impl_getdefault_multi(), + ) + self.reset_cache_after_calculation(subconfig, + value, + ) return value - def get_calculated_value(self, - subconfig: "SubConfig", - value: Any, - *, - reset_cache: bool=True, - ) -> Any: - """value could be a calculation, in this case do calculation - """ - has_calculation = False - if isinstance(value, Calculation): - value = value.execute(subconfig) - has_calculation = True - elif isinstance(value, list): - # if value is a list, do subcalculation - for idx, val in enumerate(value): - value[idx], _has_calculation = self.get_calculated_value(subconfig, - val, - reset_cache=False, - ) - if _has_calculation: - has_calculation = True - if reset_cache: - self.reset_cache_after_calculation(subconfig, - value, - ) - return value, has_calculation - #______________________________________________________________________ def check_force_to_metaconfig(self, subconfig: "OptionBag", @@ -210,7 +186,9 @@ class Values: # calculated value is a new value, so reset cache subconfig.config_bag.context.reset_cache(subconfig) # and manage force_store_value -# self._set_force_value_suffix(subconfig) + self._set_force_value_suffix(subconfig, + value, + ) def isempty(self, subconfig: "SubConfig", @@ -279,12 +257,14 @@ class Values: elif 'validator' in setting_properties and has_calculation: cache = subconfig.config_bag.context.get_values_cache() cache.delcache(subconfig.path) -# if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): -# leader = option_bag.option.impl_get_leadership() -# leader.follower_force_store_value(value, -# option_bag.config_bag, -# owners.forced, -# ) + if 'force_store_value' in setting_properties and subconfig.option.impl_is_leader(): + leader = subconfig.option.impl_get_leadership() + parent = subconfig.parent + parent._length = len(value) + leader.follower_force_store_value(value, + parent, + owners.forced, + ) def setvalue_validation(self, subconfig: "SubConfig", @@ -296,10 +276,9 @@ class Values: # First validate properties with this value opt = subconfig.option settings.validate_frozen(subconfig) - val, has_calculation = self.get_calculated_value(subconfig, - value, - reset_cache=False, - ) + val, has_calculation = get_calculated_value(subconfig, + value, + ) settings.validate_mandatory(subconfig, val, ) @@ -327,7 +306,9 @@ class Values: value, owner, ) -# self._set_force_value_suffix(option_bag) + self._set_force_value_suffix(subconfig, + value, + ) def set_storage_value(self, path, @@ -339,47 +320,44 @@ class Values: """ self._values.setdefault(path, {})[index] = [value, owner] -# def _set_force_value_suffix(self, -# option_bag: OptionBag, -# ) -> None: -# """ force store value for an option for suffixes -# """ -# # pylint: disable=too-many-locals -# if 'force_store_value' not in option_bag.config_bag.properties: -# return -# -# for woption in option_bag.option._get_suffixes_dependencies(): # pylint: disable=protected-access -# # options from dependencies are weakref -# option = woption() -# force_store_options = [] -# for coption in option.get_children_recursively(None, -# None, -# option_bag.config_bag, -# option_suffixes=[], -# ): -# if 'force_store_value' in coption.impl_getproperties(): -# force_store_options.append(coption) -# if not force_store_options: -# continue -# for coption in force_store_options: -# if coption.impl_is_follower(): -# leader = coption.impl_get_leadership().get_leader() -# loption_bag = OptionBag(leader, -# None, -# option_bag.config_bag, -# properties=frozenset(), -# ) -# indexes = range(len(self.get_value(loption_bag)[0])) -# else: -# indexes = [None] -# for index in indexes: -# for coption_bag in option.get_sub_children(coption, -# option_bag.config_bag, -# index=index, -# properties=frozenset(), -# ): -# default_value = [self.get_value(coption_bag)[0], owners.forced] -# self._values.setdefault(coption_bag.path, {})[index] = default_value + def _set_force_value_suffix(self, + subconfig: 'SubConfig', + suffix_values, + ) -> None: + """ force store value for an option for suffixes + """ + # pylint: disable=too-many-locals + if 'force_store_value' not in subconfig.config_bag.properties: + return + + config_bag = subconfig.config_bag + context = config_bag.context + for woption in subconfig.option._get_suffixes_dependencies(): # pylint: disable=protected-access + options = subconfig.get_common_child(woption(), + true_path=subconfig.path, + validate_properties=False, + ) + if not isinstance(options, list): + options = [options] + for option in options: + parent = option.parent + for suffix in suffix_values: + name = option.option.impl_getname(suffix) + opt_subconfig = parent.get_child(option.option, + None, + False, + suffix=suffix, + name=name, + ) + + for walk_subconfig in context.walk(opt_subconfig, + no_value=True, + validate_properties=False, + ): + if 'force_store_value' not in walk_subconfig.properties: + continue + default_value = [self.get_value(walk_subconfig)[0], owners.forced] + self._values.setdefault(walk_subconfig.path, {})[walk_subconfig.index] = default_value def _get_modified_parent(self, subconfig: "SubConfig", @@ -462,9 +440,9 @@ class Values: was present :returns: a `setting.owners.Owner` object """ - context = subconfig.config_bag.context - settings = context.get_settings() - settings.validate_properties(subconfig) +# context = subconfig.config_bag.context +# settings = context.get_settings() +# settings.validate_properties(subconfig) if 'frozen' in subconfig.properties and \ 'force_default_on_freeze' in subconfig.properties: return owners.default @@ -509,7 +487,7 @@ class Values: if not self.hasvalue(subconfig.path, index=subconfig.index, ): - raise ConfigError(_(f'no value for {subconfig.path} cannot change owner to {owner}')) + raise ConfigError(_(f'"{subconfig.path}" is a default value, so we cannot change owner to "{owner}"')) subconfig.config_bag.context.get_settings().validate_frozen(subconfig) self._values[subconfig.path][subconfig.index][1] = owner #______________________________________________________________________ @@ -517,59 +495,58 @@ class Values: def reset(self, subconfig: "SubConfig", + *, + validate: bool=True, ) -> None: """reset value for an option """ config_bag = subconfig.config_bag - context = config_bag.context hasvalue = self.hasvalue(subconfig.path) + context = config_bag.context setting_properties = config_bag.properties - if hasvalue and 'validator' in config_bag.properties: - fake_context = context.gen_fake_context() - fake_config_bag = config_bag.copy() - fake_config_bag.remove_validation() - fake_config_bag.context = fake_context - fake_subconfig = fake_context.get_sub_config(fake_config_bag, - subconfig.path, - subconfig.index, - validate_properties=False, - follower_not_apply_requires=False, - ) - fake_values = fake_context.get_values() - fake_values.reset(fake_subconfig) - fake_subconfig.config_bag.properties = setting_properties - value = fake_values.get_default_value(fake_subconfig) - fake_values.setvalue_validation(fake_subconfig, - value, - ) + if validate: + if hasvalue and 'validator' in setting_properties: + fake_context = context.gen_fake_context() + fake_config_bag = config_bag.copy() + fake_config_bag.remove_validation() + fake_config_bag.context = fake_context + fake_subconfig = fake_context.get_sub_config(fake_config_bag, + subconfig.path, + subconfig.index, + validate_properties=False, + ) + fake_values = fake_context.get_values() + fake_values.reset(fake_subconfig) + fake_subconfig.config_bag.properties = setting_properties + value = fake_values.get_default_value(fake_subconfig) + fake_values.setvalue_validation(fake_subconfig, + value, + ) +# if hasvalue: opt = subconfig.option if opt.impl_is_leader(): opt.impl_get_leadership().reset(subconfig.parent) - if hasvalue: - if 'force_store_value' in subconfig.config_bag.properties and \ - 'force_store_value' in subconfig.properties: - value = self.get_default_value(subconfig) + if 'force_store_value' in setting_properties and \ + 'force_store_value' in subconfig.properties: + value = self.get_default_value(subconfig) - self._setvalue(subconfig, - value, - owners.forced, - ) - else: - # for leader only - value = None - if subconfig.path in self._values: - del self._values[subconfig.path] - context.reset_cache(subconfig) -# if 'force_store_value' in setting_properties and option_bag.option.impl_is_leader(): -# if value is None: -# value = self.get_default_value(option_bag, -# parent, -# ) -# leader = option_bag.option.impl_get_leadership() -# leader.follower_force_store_value(value, -# option_bag.config_bag, -# owners.forced, -# ) + self._setvalue(subconfig, + value, + owners.forced, + ) + else: + value = None + if subconfig.path in self._values: + del self._values[subconfig.path] + if 'force_store_value' in setting_properties and subconfig.option.impl_is_leader(): + if value is None: + value = self.get_default_value(subconfig) + leader = subconfig.option.impl_get_leadership() + leader.follower_force_store_value(value, + subconfig.parent, + owners.forced, + ) + context.reset_cache(subconfig) #______________________________________________________________________ # Follower @@ -602,7 +579,6 @@ class Values: subconfig.path, subconfig.index, validate_properties=False, - follower_not_apply_requires=False, ) fake_values = fake_context.get_values() fake_values.reset_follower(fake_subconfig) @@ -611,19 +587,18 @@ class Values: fake_values.setvalue_validation(fake_subconfig, value, ) -# if 'force_store_value' in setting_properties and \ -# 'force_store_value' in option_bag.properties: -# value = self.get_default_value(option_bag, -# parent, -# ) -# -# self._setvalue(option_bag, -# value, -# owners.forced, -# ) -# else: - self.resetvalue_index(subconfig) - context.reset_cache(subconfig) + if 'force_store_value' in setting_properties and \ + 'force_store_value' in subconfig.properties: + value = self.get_default_value(subconfig, + ) + + self._setvalue(subconfig, + value, + owners.forced, + ) + else: + self.resetvalue_index(subconfig) + context.reset_cache(subconfig) def resetvalue_index(self, subconfig: "SubConfig", @@ -688,14 +663,26 @@ class Values: config_bag = subconfig.config_bag context = config_bag.context for key, options in subconfig.option.get_dependencies_information().items(): - for option in options: - option_subconfig = context.get_sub_config(config_bag, - option.impl_getpath(), - None, - validate_properties=False, - follower_not_apply_requires=False, - ) - context.reset_cache(option_subconfig) + if key is None: + continue + for woption in options: + if woption is None: + continue + option = woption() + if option.issubdyn(): + option_subconfigs = subconfig.get_common_child(option, + validate_properties=False, + ) + if not isinstance(option_subconfigs, list): + option_subconfigs = [option_subconfigs] + else: + option_subconfigs = [context.get_sub_config(config_bag, + option.impl_getpath(), + None, + validate_properties=False, + )] + for option_subconfig in option_subconfigs: + context.reset_cache(option_subconfig) def get_information(self, subconfig, @@ -706,18 +693,25 @@ class Values: :param name: the item string (ex: "help") """ - if subconfig is None: - path = None + if subconfig.option.impl_is_symlinkoption(): + option = subconfig.option.impl_getopt() + path = option.impl_getpath() else: + option = subconfig.option path = subconfig.path try: return self._informations[path][name] except KeyError as err: - if subconfig: - return subconfig.option.impl_get_information(name, default) - if default is not undefined: - return default - raise ValueError(_("information's item not found: {0}").format(name)) from err + pass + if option is not None: + return option._get_information(subconfig, + name, + default, + ) + return subconfig.config_bag.context.get_description()._get_information(subconfig, + name, + default, + ) def del_information(self, key: Any,