diff --git a/test/auto/test_auto.py b/test/auto/test_auto.py index 6e58bcf..04cffb7 100644 --- a/test/auto/test_auto.py +++ b/test/auto/test_auto.py @@ -70,6 +70,299 @@ def autocheck(func): return wrapper +def _autocheck_default_value(cfg, path, conf, **kwargs): + """set and get values + """ + # check if is a multi, a master or a slave + multi = cfg.unrestraint.option(path).option.ismulti() + submulti_ = cfg.unrestraint.option(path).option.issubmulti() + isslave = cfg.unrestraint.option(path).option.isslave() + + # set default value (different if value is multi or not) + empty_value = kwargs['default'] + + # test default value (should be empty) + # cannot test for slave (we cannot get all values for a slave) + with warnings.catch_warnings(record=True) as w: + if not isslave: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(path).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(path).value.get() == empty_value + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") + assert cfg.config(conf).forcepermissive.option(path).value.get() == empty_value + else: + raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(path).value.get()") + else: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(path, 0).value.get() == empty_value + assert cfg.config(conf).option(path, 1).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(path, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(path, 1).value.get() == empty_value + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") + assert cfg.config(conf).forcepermissive.option(path, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(path, 1).value.get() == empty_value + else: + raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).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).option.ismulti() + submulti_ = cfg.unrestraint.option(pathwrite).option.issubmulti() + ismaster = cfg.unrestraint.option(pathwrite).option.ismaster() + isslave = cfg.unrestraint.option(pathwrite).option.isslave() + if not multi: + first_value = FIRST_VALUE + elif submulti_ is False: + if not isslave: + first_value = LIST_FIRST_VALUE + else: + second_value = LIST_SECOND_VALUE[1] + + else: + if not isslave: + first_value = SUBLIST_FIRST_VALUE + else: + second_value = SUBLIST_SECOND_VALUE[1] + + # for slave should have an index and good length + # for master must append, not set + with warnings.catch_warnings(record=True) as w: + if ismaster: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])") + if not set_permissive: + cfg.config(conf).option(pathwrite).value.set([first_value[0]]) + else: + cfg.config(conf).forcepermissive.option(pathwrite).value.set([first_value[0]]) + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") + if set_permissive: + cfg.config(conf).forcepermissive.option(pathwrite).value.set([first_value[0]]) + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") + raises(PropertiesOptionError, + "cfg.config(conf).forcepermissive.option(pathwrite).value.set([first_value[0]])") + if len(first_value) > 1: + raises(APIError, "cfg.config(conf).unrestraint.option(pathwrite).value.set(first_value[1])") + elif isslave: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + if not set_permissive: + cfg.config(conf).option(pathwrite, 1).value.set(second_value) + else: + cfg.config(conf).forcepermissive.option(pathwrite, 1).value.set(second_value) + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") + if set_permissive: + cfg.config(conf).forcepermissive.option(pathwrite, 1).value.set(second_value) + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") + raises(PropertiesOptionError, + "cfg.config(conf).forcepermissive.option(pathwrite, 1).value.set(second_value)") + raises(APIError, + "cfg.config(conf).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.config(conf).option(pathwrite).value.set(first_value) + else: + cfg.config(conf).forcepermissive.option(pathwrite).value.set(first_value) + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") + if set_permissive: + cfg.config(conf).forcepermissive.option(pathwrite).value.set(first_value) + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathwrite).value.set(first_value)") + #FIXME raises(APIError, "cfg.config(conf).unrestraint.option(pathwrite).value.set(first_value)") + + +def _getproperties(multi, isslave, kwargs): + # define properties + properties = copy(PROPERTIES_LIST) + if multi and not isslave: + default_props = ['empty'] + properties.append('empty') + 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 not cfg.unrestraint.option(pathread).option.isslave(): + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert set(cfg.config(conf).option(pathread).property.get()) == set(props_permissive) + assert set(cfg.config(conf).option(pathread).property.get()) == set(props) + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") + if not kwargs.get('propertyerror', False): + assert set(cfg.config(conf).forcepermissive.option(pathread).property.get()) == set(props_permissive) + assert set(cfg.config(conf).forcepermissive.option(pathread).property.get()) == set(props) + else: + assert PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).property.get()" + assert PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).property.get()" + assert set(cfg.config(conf).unrestraint.option(pathread).property.get()) == set(props_permissive) + assert set(cfg.config(conf).unrestraint.option(pathread).property.get()) == set(props) + else: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props) + # + assert set(cfg.config(conf).option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.config(conf).option(pathread, 1).property.get()) == set(props) + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).property.get()") + # + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") + if not kwargs.get('propertyerror', False): + assert set(cfg.config(conf).forcepermissive.option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.config(conf).forcepermissive.option(pathread, 0).property.get()) == set(props) + # + assert set(cfg.config(conf).forcepermissive.option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.config(conf).forcepermissive.option(pathread, 1).property.get()) == set(props) + else: + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).property.get()") + # + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 1).property.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 1).property.get()") + assert set(cfg.config(conf).unrestraint.option(pathread, 0).property.get()) == set(props_permissive) + assert set(cfg.config(conf).unrestraint.option(pathread, 0).property.get()) == set(props) + # + assert set(cfg.config(conf).unrestraint.option(pathread, 1).property.get()) == set(props_permissive) + assert set(cfg.config(conf).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 slave + multi = cfg.unrestraint.option(pathread).option.ismulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() + + # define properties + properties = copy(PROPERTIES_LIST) + if multi and not isslave: + default_props = ['empty'] + properties.append('empty') + 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, isslave, 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 not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + cfg.config(confread).option(pathwrite).property.add(prop) + elif not kwargs.get('propertyerror', False): + cfg.config(confread).forcepermissive.option(pathwrite).property.add(prop) + else: + cfg.config(confread).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).option.ismulti() + submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() + isslave = cfg.unrestraint.option(pathread).option.isslave() + empty_value = kwargs['default'] + if not multi: + first_value = FIRST_VALUE + elif submulti_ is False: + if not isslave: + first_value = LIST_FIRST_VALUE + else: + second_value = LIST_SECOND_VALUE[1] + + else: + if not isslave: + first_value = SUBLIST_FIRST_VALUE + else: + second_value = SUBLIST_SECOND_VALUE[1] + + # get value after set value without permissive + with warnings.catch_warnings(record=True) as w: + if isslave: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).option(pathread, 1).value.get() == second_value + assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == second_value + elif kwargs.get('permissive', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") + assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value + if set_permissive: + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == second_value + else: + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == empty_value + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).value.get()") + else: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == first_value + elif kwargs.get('permissive', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + if set_permissive: + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == first_value + else: + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == empty_value + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).value.get()") + + +def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner): + isslave = cfg.unrestraint.option(pathread).option.isslave() + if not isslave: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(pathread).owner.get() == owner + assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == owner + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == permissive_owner + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.get()") + else: + if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): + assert cfg.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).option(pathread, 1).owner.get() == owner + assert cfg.config(conf).forcepermissive.option(pathread, 1).owner.get() == owner + elif not kwargs.get('propertyerror', False): + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).owner.get()") + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread, 1).owner.get() == permissive_owner + else: + raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).owner.get()") + + @autocheck def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): @@ -110,90 +403,51 @@ def autocheck_default_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, if not isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert cfg.config(conf).option(pathread).owner.get() == 'default' - assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == 'default' # assert cfg.config(conf).option(pathread).owner.isdefault() - assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() + assert cfg.config(conf).forcepermissive.option(pathread).owner.isdefault() elif not kwargs.get('propertyerror', False): raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") - assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread).owner.get() == 'default' # raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.isdefault()") - assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() + assert cfg.config(conf).forcepermissive.option(pathread).owner.isdefault() else: raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.get()") # raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.isdefault()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.isdefault()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.isdefault()") # - assert cfg.unrestraint.config(conf).option(pathread).owner.get() == 'default' - assert cfg.unrestraint.config(conf).option(pathread).owner.isdefault() + assert cfg.config(conf).unrestraint.option(pathread).owner.get() == 'default' + assert cfg.config(conf).unrestraint.option(pathread).owner.isdefault() else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert cfg.config(conf).option(pathread, 0).owner.get() == 'default' - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.get() == 'default' # assert cfg.config(conf).option(pathread, 0).owner.isdefault() - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault() elif not kwargs.get('propertyerror', False): raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.get() == 'default' # raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.isdefault()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault() else: raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).owner.get()") # raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.isdefault()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()") - assert cfg.unrestraint.config(conf).option(pathread, 0).owner.get() == 'default' - assert cfg.unrestraint.config(conf).option(pathread, 0).owner.isdefault() + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault()") + assert cfg.config(conf).unrestraint.option(pathread, 0).owner.get() == 'default' + assert cfg.config(conf).unrestraint.option(pathread, 0).owner.isdefault() do(confread) if confread != confwrite: do(confwrite) -def _autocheck_default_value(cfg, path, conf, **kwargs): - """set and get values - """ - # check if is a multi, a master or a slave - multi = cfg.unrestraint.option(path).option.ismulti() - submulti_ = cfg.unrestraint.option(path).option.issubmulti() - isslave = cfg.unrestraint.option(path).option.isslave() - - # set default value (different if value is multi or not) - empty_value = kwargs['default'] - - # test default value (should be empty) - # cannot test for slave (we cannot get all values for a slave) - with warnings.catch_warnings(record=True) as w: - if not isslave: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(path).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(path).value.get() == empty_value - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") - assert cfg.forcepermissive.config(conf).option(path).value.get() == empty_value - else: - raises(PropertiesOptionError, "cfg.config(conf).option(path).value.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(path).value.get()") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(path, 0).value.get() == empty_value - assert cfg.config(conf).option(path, 1).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(path, 0).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(path, 1).value.get() == empty_value - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") - assert cfg.forcepermissive.config(conf).option(path, 0).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(path, 1).value.get() == empty_value - else: - raises(PropertiesOptionError, "cfg.config(conf).option(path, 0).value.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(path, 0).value.get()") - - @autocheck def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _autocheck_default_value(cfg, pathread, confread, **kwargs) @@ -202,79 +456,6 @@ def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, -def _set_value(cfg, pathwrite, conf, **kwargs): - set_permissive = kwargs.get('set_permissive', True) - multi = cfg.unrestraint.option(pathwrite).option.ismulti() - submulti_ = cfg.unrestraint.option(pathwrite).option.issubmulti() - ismaster = cfg.unrestraint.option(pathwrite).option.ismaster() - isslave = cfg.unrestraint.option(pathwrite).option.isslave() - if not multi: - first_value = FIRST_VALUE - elif submulti_ is False: - if not isslave: - first_value = LIST_FIRST_VALUE - else: - second_value = LIST_SECOND_VALUE[1] - - else: - if not isslave: - first_value = SUBLIST_FIRST_VALUE - else: - second_value = SUBLIST_SECOND_VALUE[1] - - # for slave should have an index and good length - # for master must append, not set - with warnings.catch_warnings(record=True) as w: - if ismaster: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])") - if not set_permissive: - cfg.config(conf).option(pathwrite).value.set([first_value[0]]) - else: - cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") - if set_permissive: - cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]]) - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set([first_value[0]])") - raises(PropertiesOptionError, - "cfg.forcepermissive.config(conf).option(pathwrite).value.set([first_value[0]])") - if len(first_value) > 1: - raises(APIError, "cfg.unrestraint.config(conf).option(pathwrite).value.set(first_value[1])") - elif isslave: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - if not set_permissive: - cfg.config(conf).option(pathwrite, 1).value.set(second_value) - else: - cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") - if set_permissive: - cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value) - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite, 1).value.set(second_value)") - raises(PropertiesOptionError, - "cfg.forcepermissive.config(conf).option(pathwrite, 1).value.set(second_value)") - raises(APIError, - "cfg.unrestraint.config(conf).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.config(conf).option(pathwrite).value.set(first_value) - else: - cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value) - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") - if set_permissive: - cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value) - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathwrite).value.set(first_value)") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathwrite).value.set(first_value)") - #FIXME raises(APIError, "cfg.unrestraint.config(conf).option(pathwrite).value.set(first_value)") - - @autocheck def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _set_value(cfg, pathwrite, confwrite, **kwargs) @@ -299,96 +480,43 @@ def autocheck_get_value_permissive(cfg, mcfg, pathread, pathwrite, confread, con if isslave: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert cfg.config(conf).option(pathread, 0).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value if submulti_: assert cfg.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] else: assert cfg.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] elif kwargs.get('permissive', False): raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 1).value.get()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value if submulti_: - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] else: - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] else: raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 1).value.get()") - raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get()") - raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get()") + raises(PropertiesOptionError, "assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get()") + raises(PropertiesOptionError, "assert cfg.config(conf).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.config(conf).option(pathread).value.get() == first_value - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == first_value elif kwargs.get('permissive', False): raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == first_value else: raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()") + raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).value.get()") with warnings.catch_warnings(record=True) as w: do(confread) if confread != confwrite: do(confwrite) -def _autocheck_get_value(cfg, pathread, conf, **kwargs): - set_permissive = kwargs.get('set_permissive', True) - multi = cfg.unrestraint.option(pathread).option.ismulti() - submulti_ = cfg.unrestraint.option(pathread).option.issubmulti() - isslave = cfg.unrestraint.option(pathread).option.isslave() - empty_value = kwargs['default'] - if not multi: - first_value = FIRST_VALUE - elif submulti_ is False: - if not isslave: - first_value = LIST_FIRST_VALUE - else: - second_value = LIST_SECOND_VALUE[1] - - else: - if not isslave: - first_value = SUBLIST_FIRST_VALUE - else: - second_value = SUBLIST_SECOND_VALUE[1] - - # get value after set value without permissive - with warnings.catch_warnings(record=True) as w: - if isslave: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(pathread, 0).value.get() == empty_value - assert cfg.config(conf).option(pathread, 1).value.get() == second_value - assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value - elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value - if set_permissive: - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value - else: - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == empty_value - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).value.get()") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(pathread).value.get() == first_value - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value - elif kwargs.get('permissive', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") - if set_permissive: - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value - else: - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == empty_value - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()") - - @autocheck def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): _set_value(cfg, pathwrite, confwrite, set_permissive=False, **kwargs) @@ -407,7 +535,7 @@ def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, * isslave = cfg.unrestraint.option(pathread).option.isslave() if not isslave: if kwargs.get('propertyerror', False): - raises(APIError, "cfg.unrestraint.config(confread).option(pathread).value.len()") + raises(APIError, "cfg.config(confread).unrestraint.option(pathread).value.len()") return if kwargs.get('propertyerror', False): raises(PropertiesOptionError, "cfg.option(pathread).value.len()") @@ -421,10 +549,10 @@ def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, * def do(conf): if not kwargs.get('permissive', False): length = cfg.config(conf).option(pathread).value.len() - assert cfg.forcepermissive.config(conf).option(pathread).value.len() == length + assert cfg.config(conf).forcepermissive.option(pathread).value.len() == length else: raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.len()") - length = cfg.forcepermissive.config(conf).option(pathread).value.len() + length = cfg.config(conf).forcepermissive.option(pathread).value.len() assert length == 2 do(confread) if confread != confwrite: @@ -494,14 +622,14 @@ def autocheck_reset_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, * assert cfg.config(conf).option(pathread, 1).value.get() == second_value[1] elif kwargs.get('permissive', False): raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get() == empty_value - assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value[1] + assert cfg.config(conf).forcepermissive.option(pathread, 0).value.get() == empty_value + assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == second_value[1] else: if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert cfg.config(conf).option(pathread).value.get() == empty_value elif kwargs.get('permissive', False): raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") - assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value + assert cfg.config(conf).forcepermissive.option(pathread).value.get() == first_value with warnings.catch_warnings(record=True) as w: do(confread) if confread != confwrite: @@ -517,13 +645,13 @@ def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, with warnings.catch_warnings(record=True) as w: if not kwargs.get('propertyerror', False): - master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() + master_value = cfg.config(confread).forcepermissive.option(pathread).value.get() len_value = len(master_value) master_value.append(undefined) - assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len_value + assert len(cfg.config(confread).forcepermissive.option(pathread).value.get()) == len_value with warnings.catch_warnings(record=True) as w: cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) - new_master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() + new_master_value = cfg.config(confread).forcepermissive.option(pathread).value.get() len_new = len(new_master_value) assert len_value + 1 == len_new assert new_master_value[-1] == kwargs['default_multi'] @@ -533,16 +661,16 @@ def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, else: slave_path += '.third' for idx in range(len_new): - assert cfg.forcepermissive.config(confread).option(slave_path, idx).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(slave_path, idx).value.get() == kwargs['default_multi'] # if not submulti_: value = 'value' else: value = ['value'] master_value.append(value) - assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len(new_master_value) + assert len(cfg.config(confread).forcepermissive.option(pathread).value.get()) == len(new_master_value) cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) - assert cfg.forcepermissive.config(confread).option(pathread).value.get()[-1] == value + assert cfg.config(confread).forcepermissive.option(pathread).value.get()[-1] == value @autocheck @@ -568,32 +696,32 @@ def autocheck_pop_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k with warnings.catch_warnings(record=True) as w: cfg.forcepermissive.config(confwrite).option(pathread).value.set(values) cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value) - cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True - cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value - assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False - cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True - cfg.forcepermissive.config(confread).option(a_slave, 3).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 3).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value + assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False + cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 2).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 3).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 3).owner.isdefault() is True # cfg.forcepermissive.config(confwrite).option(pathread).value.pop(3) - cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True - cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value - assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False - cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value + assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False + cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 2).owner.isdefault() is True # cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0) - cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value - assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False - cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == slave_value + assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is False + cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is True # cfg.forcepermissive.config(confwrite).option(pathread).value.pop(0) - cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] - assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True + cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi'] + assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True @autocheck @@ -640,69 +768,6 @@ def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwa assert(cfg.config(confwrite).config.dict()) == make_dict_value -def _getproperties(multi, isslave, kwargs): - # define properties - properties = copy(PROPERTIES_LIST) - if multi and not isslave: - default_props = ['empty'] - properties.append('empty') - 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 not cfg.unrestraint.option(pathread).option.isslave(): - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert set(cfg.config(conf).option(pathread).property.get()) == set(props_permissive) - assert set(cfg.config(conf).option(pathread).property.get()) == set(props) - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).property.get()") - if not kwargs.get('propertyerror', False): - assert set(cfg.forcepermissive.config(conf).option(pathread).property.get()) == set(props_permissive) - assert set(cfg.forcepermissive.config(conf).option(pathread).property.get()) == set(props) - else: - assert PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).property.get()" - assert PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).property.get()" - assert set(cfg.unrestraint.config(conf).option(pathread).property.get()) == set(props_permissive) - assert set(cfg.unrestraint.config(conf).option(pathread).property.get()) == set(props) - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props_permissive) - assert set(cfg.config(conf).option(pathread, 0).property.get()) == set(props) - # - assert set(cfg.config(conf).option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg.config(conf).option(pathread, 1).property.get()) == set(props) - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).property.get()") - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).property.get()") - # - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).property.get()") - if not kwargs.get('propertyerror', False): - assert set(cfg.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props_permissive) - assert set(cfg.forcepermissive.config(conf).option(pathread, 0).property.get()) == set(props) - # - assert set(cfg.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg.forcepermissive.config(conf).option(pathread, 1).property.get()) == set(props) - else: - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).property.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).property.get()") - # - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 1).property.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 1).property.get()") - assert set(cfg.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props_permissive) - assert set(cfg.unrestraint.config(conf).option(pathread, 0).property.get()) == set(props) - # - assert set(cfg.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props_permissive) - assert set(cfg.unrestraint.config(conf).option(pathread, 1).property.get()) == set(props) - - @autocheck def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """get property from path @@ -713,52 +778,19 @@ def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kw default_props, properties = _getproperties(multi, isslave, kwargs) - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - if confread != confwrite: + 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: - cfg.unrestraint.config(confread).option(pathwrite).property.add(prop) - _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) - #if confread != confwrite: - # _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) - - - -def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): - # check if is a multi or a slave - multi = cfg.unrestraint.option(pathread).option.ismulti() - isslave = cfg.unrestraint.option(pathread).option.isslave() - - # define properties - properties = copy(PROPERTIES_LIST) - if multi and not isslave: - default_props = ['empty'] - properties.append('empty') + cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop) + if confread == confwrite: + _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) 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, isslave, kwargs) + _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - #if confwrite != confread: - # _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - - # set properties with permissive - for prop in properties: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - cfg.config(confread).option(pathwrite).property.add(prop) - if not kwargs.get('propertyerror', False): - cfg.forcepermissive.config(confread).option(pathwrite).property.add(prop) - cfg.unrestraint.config(confread).option(pathwrite).property.add(prop) - - _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties) - #if confwrite != confread: - # _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) @autocheck @@ -780,8 +812,9 @@ def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite # reset properties without permissive cfg.unrestraint.config(confwrite).option(pathwrite).property.reset() - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) - if confread != confwrite: + 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) @@ -799,8 +832,6 @@ def autocheck_reset_property_permissive(cfg, mcfg, pathread, pathwrite, confread cfg.unrestraint.option(pathwrite).property.reset() _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) - if confread != confwrite: - _check_properties(cfg, mcfg, pathread, confread, kwargs, default_props, default_props) @autocheck @@ -809,34 +840,6 @@ def autocheck_context_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, assert owner == kwargs['owner'] -def _check_owner(cfg, pathread, conf, kwargs, owner, permissive_owner): - isslave = cfg.unrestraint.option(pathread).option.isslave() - if not isslave: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(pathread).owner.get() == owner - assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == owner - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") - assert cfg.forcepermissive.config(conf).option(pathread).owner.get() == permissive_owner - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.get()") - else: - if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): - assert cfg.config(conf).option(pathread, 0).owner.get() == 'default' - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' - assert cfg.config(conf).option(pathread, 1).owner.get() == owner - assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.get() == owner - elif not kwargs.get('propertyerror', False): - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 1).owner.get()") - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.get() == 'default' - assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.get() == permissive_owner - else: - raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") - raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.get()") - - @autocheck def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): """value is now changed, check owner in this case @@ -884,12 +887,12 @@ def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite # test if is default owner with permissive if not kwargs.get('propertyerror', False): if not isslave: - assert cfg.forcepermissive.config(conf).option(pathread).owner.isdefault() is False + assert cfg.config(conf).forcepermissive.option(pathread).owner.isdefault() is False else: - assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True - assert cfg.forcepermissive.config(conf).option(pathread, 1).owner.isdefault() is False + assert cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault() is True + assert cfg.config(conf).forcepermissive.option(pathread, 1).owner.isdefault() is False #FIXME else: - # raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.isdefault()") + # raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.isdefault()") do(confwrite) if confwrite != confread: do(confread) @@ -1015,30 +1018,28 @@ def autocheck_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, ** call_path = pathread + 'call' cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled'])) - # have permissive + # have permissive? assert cfg.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled']) #if confwrite != confread: - # assert cfg.unrestraint.config(confread).option(pathread).permissive.get() == frozenset(['disabled']) + # 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, confread, **ckwargs) + _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) - cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['disabled', 'hidden'])) + cfg.config(confread).unrestraint.option(pathwrite).permissive.set(frozenset(['disabled', 'hidden'])) if kwargs['callback']: - cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled', 'hidden'])) + cfg.config(confread).unrestraint.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 confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) if ckwargs.get('permissive_od', False): # set permissive to OptionDescription - cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled', + cfg.config(confread).unrestraint.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['disabled', 'hidden'])) ckwargs['permissive'] = False _autocheck_default_value(cfg, pathread, confread, **ckwargs) @@ -1046,32 +1047,24 @@ def autocheck_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, ** # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # only hidden - cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden'])) + cfg.config(confread).unrestraint.option(pathwrite).permissive.set(frozenset(['hidden'])) if callback: - cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['hidden'])) + cfg.config(confread).unrestraint.option(call_path).permissive.set(frozenset(['hidden'])) if ckwargs.get('permissive_od', False): _autocheck_default_value(cfg, pathread, confread, **ckwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) - cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden'])) + cfg.config(confread).unrestraint.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden'])) ckwargs = copy(kwargs) ckwargs['permissive'] = False _autocheck_default_value(cfg, pathread, confread, **ckwargs) - #if confread != confwrite: - # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) # no permissive - cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset()) + cfg.config(confread).unrestraint.option(pathwrite).permissive.set(frozenset()) if callback: - cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset()) + cfg.config(confread).unrestraint.option(call_path).permissive.set(frozenset()) if ckwargs.get('permissive_od', False): _autocheck_default_value(cfg, pathread, confread, **ckwargs) - if confread != confwrite: - _autocheck_default_value(cfg, pathread, confwrite, **ckwargs) - cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset()) + cfg.config(confread).unrestraint.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset()) _autocheck_default_value(cfg, pathread, confread, **kwargs) - #if confread != confwrite: - # _autocheck_default_value(cfg, pathread, confwrite, **kwargs) @autocheck @@ -1106,15 +1099,15 @@ def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs def do(conf): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): assert option == _getoption(cfg.config(conf).option.find(name, first=True)) - assert option == _getoption(cfg.forcepermissive.config(conf).option.find(name, first=True)) + assert option == _getoption(cfg.config(conf).forcepermissive.option.find(name, first=True)) elif kwargs.get('permissive', False): raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") - assert option == _getoption(cfg.forcepermissive.config(conf).option.find(name, first=True)) + assert option == _getoption(cfg.config(conf).forcepermissive.option.find(name, first=True)) else: raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") - raises(AttributeError, "cfg.forcepermissive.config(conf).option.find(name, first=True)") - assert option == _getoption(cfg.unrestraint.config(conf).option.find(name, first=True)) - assert [option] == _getoptions(cfg.unrestraint.config(conf).option.find(name)) + raises(AttributeError, "cfg.config(conf).forcepermissive.option.find(name, first=True)") + assert option == _getoption(cfg.config(conf).unrestraint.option.find(name, first=True)) + assert [option] == _getoptions(cfg.config(conf).unrestraint.option.find(name)) do(confread) if confread != confwrite: do(confwrite) @@ -1648,7 +1641,7 @@ DICT_PATHS = [ 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}}), @@ -1748,7 +1741,8 @@ def test_options(paths): continue for default in (False, True): for multi in (False, True, submulti): -# for meta in (False,): + pass +# for meta in (True,): # for callback in (False,): # for consistency in (False,): # for require in (False,): @@ -1757,7 +1751,7 @@ def test_options(paths): # if callback and default_multi: # continue # for default in (False,): -# for multi in (True,): +# for multi in (False,): # print(meta, callback, consistency, require, default_multi, symlink, default, multi) if multi is submulti and default: continue diff --git a/test/test_cache.py b/test/test_cache.py index 3dcbc88..9725a2c 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -47,8 +47,8 @@ def test_cache_config(): def test_cache(): od1 = make_description() cfg = Config(od1) - values = cfg._config.cfgimpl_get_values() - settings = cfg._config.cfgimpl_get_settings() + values = cfg._config_bag.context.cfgimpl_get_values() + settings = cfg._config_bag.context.cfgimpl_get_settings() cfg.option('u1').value.get() assert 'u1' in values._p_.get_cached() assert 'u1' in settings._p_.get_cached() @@ -98,8 +98,8 @@ def test_cache_importation_permissive(): def test_cache_reset(): od1 = make_description() cfg = Config(od1) - values = cfg._config.cfgimpl_get_values() - settings = cfg._config.cfgimpl_get_settings() + values = cfg._config_bag.context.cfgimpl_get_values() + settings = cfg._config_bag.context.cfgimpl_get_settings() #when change a value cfg.option('u1').value.get() cfg.option('u2').value.get() @@ -158,8 +158,8 @@ def test_cache_reset(): def test_cache_reset_multi(): od1 = make_description() cfg = Config(od1) - values = cfg._config.cfgimpl_get_values() - settings = cfg._config.cfgimpl_get_settings() + values = cfg._config_bag.context.cfgimpl_get_values() + settings = cfg._config_bag.context.cfgimpl_get_settings() cfg.option('u1').value.get() cfg.option('u3').value.get() assert 'u1' in values._p_.get_cached() @@ -210,12 +210,12 @@ def test_cache_reset_multi(): def test_reset_cache(): od1 = make_description() cfg = Config(od1) - values = cfg._config.cfgimpl_get_values() - settings = cfg._config.cfgimpl_get_settings() + values = cfg._config_bag.context.cfgimpl_get_values() + settings = cfg._config_bag.context.cfgimpl_get_settings() cfg.option('u1').value.get() assert 'u1' in values._p_.get_cached() assert 'u1' in settings._p_.get_cached() - cfg._config.cfgimpl_reset_cache(None, None) + cfg._config_bag.context.cfgimpl_reset_cache(None, None) assert 'u1' not in values._p_.get_cached() assert 'u1' not in settings._p_.get_cached() cfg.option('u1').value.get() @@ -227,7 +227,7 @@ def test_reset_cache(): assert 'u1' in settings._p_.get_cached() assert 'u2' in values._p_.get_cached() assert 'u2' in settings._p_.get_cached() - cfg._config.cfgimpl_reset_cache(None, None) + cfg._config_bag.context.cfgimpl_reset_cache(None, None) assert 'u1' not in values._p_.get_cached() assert 'u1' not in settings._p_.get_cached() assert 'u2' not in values._p_.get_cached() @@ -237,8 +237,8 @@ def test_reset_cache(): def test_cache_not_cache(): od1 = make_description() cfg = Config(od1) - values = cfg._config.cfgimpl_get_values() - settings = cfg._config.cfgimpl_get_settings() + values = cfg._config_bag.context.cfgimpl_get_values() + settings = cfg._config_bag.context.cfgimpl_get_settings() cfg.property.pop('cache') cfg.option('u1').value.get() assert 'u1' not in values._p_.get_cached() @@ -253,13 +253,13 @@ def test_cache_master_slave(): maconfig = OptionDescription('toto', '', [interface1]) cfg = Config(maconfig) cfg.property.read_write() - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {} # cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() - cache = cfg._config.cfgimpl_get_values()._p_.get_cached() + cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() if TIRAMISU_VERSION == 2: assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0']) else: @@ -269,7 +269,7 @@ def test_cache_master_slave(): #assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None]) #assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None] #assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None - cache = cfg._config.cfgimpl_get_settings()._p_.get_cached() + cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.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['ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None]) @@ -282,7 +282,7 @@ def test_cache_master_slave(): cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() - cache = cfg._config.cfgimpl_get_values()._p_.get_cached() + cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() if TIRAMISU_VERSION == 2: assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0']) else: @@ -293,7 +293,7 @@ def test_cache_master_slave(): #assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None] #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 = cfg._config.cfgimpl_get_settings()._p_.get_cached() + cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.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['ip_admin_eth0'].keys()) == set([None]) assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None]) @@ -329,79 +329,79 @@ def test_cache_callback(): if TIRAMISU_VERSION == 2: cfg.property.pop('expire') cfg.config.dict() - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)}, 'val2': {None: ('val', None)}, 'val3': {None: ('yes', None)}, 'val4': {None: ('val', None)}, 'val5': {None: (['yes'], None)}}) cfg.option('val1').value.set('new') - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)}, 'val5': {None: (['yes'], None)}}) cfg.config.dict() - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('yes', None)}, 'val4': {None: ('new', None)}, 'val5': {None: (['yes'], None)}}) cfg.option('val3').value.set('new2') - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val4': {None: ('new', None)}, 'val5': {None: (['yes'], None)}}) cfg.config.dict() - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, 'val4': {None: ('new', None)}, 'val5': {None: (['yes'], None)}}) cfg.option('val4').value.set('new3') - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, 'val5': {None: (['yes'], None)}}) cfg.config.dict() - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, 'val4': {None: ('new3', None)}, 'val5': {None: (['yes'], None)}}) cfg.option('val5').value.set([undefined, 'new4']) - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}, # 'val5': {None: (set(['empty']), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, 'val4': {None: ('new3', None)}}) cfg.config.dict() - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}, # 'val3': {None: (set([]), None)}, # 'val4': {None: (set([]), None)}, # 'val5': {None: (set(['empty']), None)}} - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)}, 'val2': {None: ('new', None)}, 'val3': {None: ('new2', None)}, 'val4': {None: ('new3', None)}, @@ -435,19 +435,19 @@ def test_cache_master_and_slaves_master(): #None because no value idx_val2 = None if TIRAMISU_VERSION == 2: - assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {} - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} else: - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, 'val1': {None: (val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)}, 'val1.val2': {idx_val2: (val1_val2_props, None)}}) # len is 0 so don't get any value - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) # cfg.option('val1.val1').value.set([undefined]) - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} cfg.config.dict() if TIRAMISU_VERSION == 2: val_val2 = [None] @@ -457,30 +457,30 @@ def test_cache_master_and_slaves_master(): idx_val2 = 0 val_val2 = None val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)} - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, 'val1': {None: (val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)}, 'val1.val2': val_val2_props}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)}, 'val1.val2': {idx_val2: (val_val2, None)}}) cfg.option('val1.val1').value.set([undefined, undefined]) cfg.config.dict() cfg.option('val1.val2', 1).value.set('oui') - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} if TIRAMISU_VERSION == 2: val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)} else: val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)} - #assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)}, + #assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)}, # 'val1': {None: (val1_props, None)}, # 'val1.val1': {None: (val1_val1_props, None)}, # 'val1.val2': val1_val2_props} #if TIRAMISU_VERSION == 2: - # assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)}, + # assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)}, # 'val1.val2': {None: ([None, 'oui'], None)}} #else: - # assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)}, + # assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)}, # 'val1.val2': {0: (None, None), 1: ('oui', None)}} @@ -509,22 +509,22 @@ def test_cache_master_callback(): val1_val1_props = frozenset(val1_val1_props) val1_val2_props = frozenset(val1_val2_props) if TIRAMISU_VERSION == 2: - assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {} - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} else: - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)}, 'val1': {None: (val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)}, 'val1.val2': {None: (val1_val2_props, None)}}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}}) cfg.option('val1.val1').value.set([undefined]) - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} cfg.config.dict() - #FIXMEassert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + #FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, # 'val1': {None: (set([]), None)}} - #FIXMEassert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)}, + #FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)}, # 'val1.val2': {None: ([None], None)} # } @@ -538,46 +538,46 @@ def test_cache_requires(): cfg.property.read_write() if TIRAMISU_VERSION == 2: cfg.property.pop('expire') - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg.option('ip_address_service').value.get() == None - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) if TIRAMISU_VERSION == 2: - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}} else: - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) cfg.config.dict() - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) cfg.option('ip_address_service').value.set('1.1.1.1') - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}}) + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}}) cfg.config.dict() - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)}, 'activate_service': {None: (True, None)}}) cfg.option('activate_service').value.set(False) - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}) - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} cfg.config.dict() - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set(['disabled']), None)}}) - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}}) + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}}) def test_cache_global_properties(): @@ -587,25 +587,25 @@ def test_cache_global_properties(): od = OptionDescription('service', '', [a, b]) cfg = Config(od) cfg.property.read_write() - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {} assert cfg.option('ip_address_service').value.get() == None - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) if TIRAMISU_VERSION == 2: - assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}} + assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}} else: - compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, + compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)}, 'activate_service': {None: (True, None)}}) cfg.property.pop('disabled') assert cfg.option('ip_address_service').value.get() == None - compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)}, '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(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)}, + compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)}, 'activate_service': {None: (set([]), None)}, 'ip_address_service': {None: (set([]), None)}}) diff --git a/test/test_config.py b/test/test_config.py index bdacc0a..f81582c 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -145,17 +145,6 @@ def test_information_config(): raises(ValueError, "config.information.reset('noinfo')") -def test_config_impl_get_path_by_opt(): - descr = make_description() - config = Config(descr) - dummy = config.option('gc.dummy').option.get() - boo = config.option('bool').option.get() - unknown = IntOption('test', '') - unknown - assert config._config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool' - assert config._config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy' - - def to_tuple(val): ret = [] for v in val: diff --git a/test/test_dereference.py b/test/test_dereference.py index cae0596..1030a67 100644 --- a/test/test_dereference.py +++ b/test/test_dereference.py @@ -19,7 +19,7 @@ def test_deref_storage(): b = BoolOption('b', '') o = OptionDescription('od', '', [b]) c = Config(o) - w = weakref.ref(c._config.cfgimpl_get_values()._p_) + w = weakref.ref(c._config_bag.context.cfgimpl_get_values()._p_) del(c) assert w() is None @@ -28,7 +28,7 @@ def test_deref_value(): b = BoolOption('b', '') o = OptionDescription('od', '', [b]) c = Config(o) - w = weakref.ref(c._config.cfgimpl_get_values()) + w = weakref.ref(c._config_bag.context.cfgimpl_get_values()) del(c) assert w() is None @@ -37,7 +37,7 @@ def test_deref_setting(): b = BoolOption('b', '') o = OptionDescription('od', '', [b]) c = Config(o) - w = weakref.ref(c._config.cfgimpl_get_settings()) + w = weakref.ref(c._config_bag.context.cfgimpl_get_settings()) del(c) assert w() is None diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index 40e48b4..9565fb2 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -199,26 +199,26 @@ def test_meta_meta_set(): errors2 = meta.value.set('od1.i6', 7, only_config=True) assert len(errors1) == 0 assert len(errors2) == 2 - conf1 = meta.config('meta.conf1')._config - conf2 = meta.config('meta.conf2')._config + conf1 = meta.config('meta.conf1')._config_bag.context + conf2 = meta.config('meta.conf2')._config_bag.context assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7 # dconfigs = [] for conf in meta.config.find('i1', value=7, first=True).config.list(): - dconfigs.append(conf._config) + dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs meta.config('meta.conf1').option('od1.i1').value.set(8) # dconfigs = [] for conf in meta.config.find('i1', first=True).config.list(): - dconfigs.append(conf._config) + dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs - assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config - assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config + assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config_bag.context + assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config_bag.context # dconfigs = [] for conf in meta.config.find('i5', value=2, first=True).config.list(): - dconfigs.append(conf._config) + dconfigs.append(conf._config_bag.context) assert [conf1, conf2] == dconfigs # raises(AttributeError, "meta.config.find('i1', value=10, first=True)") @@ -258,8 +258,8 @@ def test_group_find_firsts(): conf2 = Config(od2, session_id='conf2') grp = GroupConfig([conf1, conf2]) itr = grp.config.find('i1', first=True).config.list() - conf1._config == next(itr)._config - conf2._config == next(itr)._config + conf1._config_bag.context == next(itr)._config_bag.context + conf2._config_bag.context == next(itr)._config_bag.context def test_group_group(): @@ -307,20 +307,20 @@ def test_meta_master_slaves(): meta = MetaConfig([conf1, conf2]) meta.property.read_only() itr = meta.config.find('ip_admin_eth0', first=True).config.list() - assert conf1._config == next(itr)._config - assert conf2._config == next(itr)._config + assert conf1._config_bag.context == next(itr)._config_bag.context + assert conf2._config_bag.context == next(itr)._config_bag.context itr = meta.config.find('netmask_admin_eth0', first=True).config.list() - assert conf1._config == next(itr)._config - assert conf2._config == next(itr)._config + assert conf1._config_bag.context == next(itr)._config_bag.context + assert conf2._config_bag.context == next(itr)._config_bag.context meta.property.read_write() raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)") itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list() - assert conf1._config == next(itr)._config - assert conf2._config == next(itr)._config + assert conf1._config_bag.context == next(itr)._config_bag.context + assert conf2._config_bag.context == next(itr)._config_bag.context meta.property.read_only() itr = meta.config.find('netmask_admin_eth0', first=True).config.list() - assert conf1._config == next(itr)._config - assert conf2._config == next(itr)._config + assert conf1._config_bag.context == next(itr)._config_bag.context + assert conf2._config_bag.context == next(itr)._config_bag.context def test_meta_master_slaves_value2(): diff --git a/test/test_permissive.py b/test/test_permissive.py index f52ed6e..84a5d77 100644 --- a/test/test_permissive.py +++ b/test/test_permissive.py @@ -79,6 +79,7 @@ def test_permissive_frozen(): api.property.read_write() api.unrestraint.permissive.set(frozenset(['frozen', 'disabled'])) assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled']) + assert api.permissive.get() == frozenset(['frozen', 'disabled']) try: api.option('u1').value.set(1) except PropertiesOptionError as err: diff --git a/test/test_slots.py b/test/test_slots.py index acdef51..1a9c5ae 100644 --- a/test/test_slots.py +++ b/test/test_slots.py @@ -150,14 +150,14 @@ def test_slots_config(): od1 = OptionDescription('a', '', []) od2 = OptionDescription('a', '', [od1]) c = Config(od2) - raises(AttributeError, "c._config.x = 1") - raises(AttributeError, "c._config.cfgimpl_x = 1") + raises(AttributeError, "c._config_bag.context.x = 1") + raises(AttributeError, "c._config_bag.context.cfgimpl_x = 1") option_bag = OptionBag() option_bag.set_option(od2, 'a', None, - ConfigBag(c._config)) - sc = c._config.get_subconfig('a', option_bag) + ConfigBag(c._config_bag.context)) + sc = c._config_bag.context.get_subconfig('a', option_bag) assert isinstance(sc, SubConfig) raises(AttributeError, "sc.x = 1") raises(AttributeError, "sc.cfgimpl_x = 1") @@ -167,7 +167,7 @@ def test_slots_setting(): od1 = OptionDescription('a', '', []) od2 = OptionDescription('a', '', [od1]) c = Config(od2) - s = c._config.cfgimpl_get_settings() + s = c._config_bag.context.cfgimpl_get_settings() s raises(AttributeError, "s.x = 1") @@ -176,6 +176,6 @@ def test_slots_value(): od1 = OptionDescription('a', '', []) od2 = OptionDescription('a', '', [od1]) c = Config(od2) - v = c._config.cfgimpl_get_values() + v = c._config_bag.context.cfgimpl_get_values() v raises(AttributeError, "v.x = 1") diff --git a/test/test_state.py b/test/test_state.py index 4f9a110..eb8013b 100644 --- a/test/test_state.py +++ b/test/test_state.py @@ -223,7 +223,7 @@ def test_diff_information_config(): b.impl_set_information('info2', 'oh') o = OptionDescription('o', '', [b]) o1 = OptionDescription('o1', '', [o]) - c = Config(o1)._config + c = Config(o1)._config_bag.context raises(NotImplementedError, "dumps(c)") diff --git a/tiramisu/api.py b/tiramisu/api.py index 74fa33d..5d35588 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -113,7 +113,7 @@ class CommonTiramisu(TiramisuHelp): if option is None: option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name, self.option_bag.config_bag, - self.subconfig) + self.subconfig.cfgimpl_get_path()) self.option_bag.set_option(option, self.option_bag.path, self.option_bag.index, @@ -145,8 +145,8 @@ class CommonTiramisuOption(CommonTiramisu): self.option_bag = option_bag self._name = name self.subconfig = subconfig + # for help() if option_bag is not None: - # for help() self._get_option() if option_bag.config_bag is not None and self.slave_need_index: self._test_slave_index() @@ -548,11 +548,21 @@ class TiramisuOption(CommonTiramisu): """find an option by name (only for optiondescription)""" if not first: ret = [] - for path in self.config_bag.context.find(byname=name, - byvalue=value, - bytype=type, - _subpath=self._path, - config_bag=self.config_bag): + option = self._get_option() + oname = option.impl_getname() + path = self.subconfig._get_subpath(oname) + option_bag = OptionBag() + option_bag.set_option(option, + path, + None, + self.config_bag) + subconfig = self.subconfig.get_subconfig(oname, + option_bag) + for path in subconfig.find(byname=name, + byvalue=value, + bytype=type, + _subpath=self._path, + config_bag=self.config_bag): subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path, self.config_bag) t_option = TiramisuOption(name, @@ -569,7 +579,7 @@ class TiramisuOption(CommonTiramisu): self._get_option() current_option = self.option_bag.option.impl_getchild(name, self.config_bag, - self.subconfig) + self.subconfig.cfgimpl_get_path) path = self.option_bag.path + '.' + name option_bag= OptionBag() option_bag.set_option(current_option, @@ -614,8 +624,8 @@ class TiramisuOption(CommonTiramisu): self.subconfig.get_subconfig(name, option_bag) else: - self.subconfig.getattr(name, - option_bag) + subconfig.getattr(name, + option_bag) option = self._get_option() name = option.impl_getname() @@ -738,10 +748,7 @@ class TiramisuContextProperty(TiramisuContext): """set configuration to read only mode""" settings = self.config_bag.context.cfgimpl_get_settings() settings.read_only(self.config_bag.context) - try: - del self.config_bag.properties - except AttributeError: - pass + del self.config_bag.properties def read_write(self): """set configuration to read and write mode""" @@ -750,17 +757,15 @@ class TiramisuContextProperty(TiramisuContext): # #FIXME ? permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden'])) settings.set_context_permissives(permissives) - try: - del self.config_bag.properties - except AttributeError: - pass #/FIXME ? + del self.config_bag.properties def add(self, prop): """add a configuration property""" props = self.get() props.add(prop) self.set(frozenset(props)) + del self.config_bag.properties def pop(self, prop): """remove a configuration property""" @@ -768,6 +773,7 @@ class TiramisuContextProperty(TiramisuContext): if prop in props: props.remove(prop) self.set(frozenset(props)) + del self.config_bag.properties def get(self): """get all configuration properties""" @@ -778,12 +784,14 @@ class TiramisuContextProperty(TiramisuContext): context = self.config_bag.context context.cfgimpl_get_settings().set_context_properties(props, context) + del self.config_bag.properties def reset(self): """remove configuration properties""" context = self.config_bag.context context.cfgimpl_get_settings().reset(None, context) + del self.config_bag.properties def exportation(self): """export configuration properties""" @@ -794,6 +802,7 @@ class TiramisuContextProperty(TiramisuContext): self.config_bag.context.cfgimpl_get_settings()._p_.importation(properties) self.config_bag.context.cfgimpl_reset_cache(None, None) + del self.config_bag.properties class TiramisuContextPermissive(TiramisuContext): @@ -806,6 +815,7 @@ class TiramisuContextPermissive(TiramisuContext): def set(self, permissives): """set configuration permissives""" self.config_bag.context.cfgimpl_get_settings().set_context_permissives(permissives) + del self.config_bag.permissives def exportation(self): """export configuration permissives""" @@ -816,6 +826,7 @@ class TiramisuContextPermissive(TiramisuContext): self.config_bag.context.cfgimpl_get_settings()._pp_.importation(permissives) self.config_bag.context.cfgimpl_reset_cache(None, None) + del self.config_bag.permissives @@ -918,9 +929,9 @@ class TiramisuContextConfig(TiramisuContext): first: bool=False): """find a path from option name and optionnaly a value to MetaConfig or GroupConfig""" if first: - return TiramisuAPI(self.config_bag.context.find_firsts(byname=name, - byvalue=value, - config_bag=self.config_bag)) + return Config(self.config_bag.context.find_firsts(byname=name, + byvalue=value, + config_bag=self.config_bag)) else: raise APIError('not implemented yet') @@ -929,25 +940,25 @@ class TiramisuContextConfig(TiramisuContext): def _c_copy(self, session_id=None): - return TiramisuAPI(self.config_bag.context.duplicate(session_id)) + return Config(self.config_bag.context.duplicate(session_id)) def _c_deepcopy(self, session_id=None): - return TiramisuAPI(self.config_bag.context.duplicate(session_id, - deep=True)) + return Config(self.config_bag.context.duplicate(session_id, + deep=True)) def _c_meta(self): - return TiramisuAPI(self.config_bag.context.cfgimpl_get_meta()) + return Config(self.config_bag.context.cfgimpl_get_meta()) def _m_new(self, name): - return TiramisuAPI(self.config_bag.context.new_config(name)) + return Config(self.config_bag.context.new_config(name)) def _m_list(self): return self._g_list() def _g_list(self): for child in self.config_bag.context.cfgimpl_get_children(): - yield TiramisuAPI(child) + yield Config(child) def __getattr__(self, name: str) -> Callable: @@ -990,32 +1001,25 @@ class TiramisuAPI(TiramisuHelp): def __init__(self, config) -> None: - self._config = config + if not isinstance(config, ConfigBag): + config = ConfigBag(context=config) + self._config_bag = config if not self.registers: registers(self.registers, 'TiramisuContext') registers(self.registers, 'TiramisuDispatcher') def __getattr__(self, subfunc: str) -> Any: if subfunc == 'forcepermissive': - if isinstance(self._config, ConfigBag): - config_bag = self._config.copy() - del config_bag.properties - else: - config_bag = ConfigBag(context=self._config) + config_bag = self._config_bag.copy() config_bag.set_permissive() return TiramisuAPI(config_bag) elif subfunc == 'unrestraint': - if isinstance(self._config, ConfigBag): - config_bag = self._config.copy() - else: - config_bag = ConfigBag(context=self._config) + config_bag = self._config_bag.copy() config_bag.properties = frozenset() return TiramisuAPI(config_bag) elif subfunc in self.registers: - if not isinstance(self._config, ConfigBag): - config_bag = ConfigBag(context=self._config) - else: - config_bag = self._config + config_bag = self._config_bag + del config_bag.permissives return self.registers[subfunc](config_bag) else: raise APIError(_('please specify a valid sub function ({})').format(subfunc)) @@ -1055,7 +1059,7 @@ class Config(TiramisuAPI): session_id: str=None, persistent: bool=False, storage=None) -> None: - if not isinstance(descr, (KernelConfig, KernelMetaConfig)): + if isinstance(descr, OptionDescription): config = KernelConfig(descr, session_id=session_id, persistent=persistent, @@ -1075,7 +1079,7 @@ class MetaConfig(TiramisuAPI): _children = [] for child in children: if isinstance(child, TiramisuAPI): - _children.append(child._config) + _children.append(child._config_bag.context) else: _children.append(child) @@ -1095,7 +1099,7 @@ class GroupConfig(TiramisuAPI): storage=None) -> None: _children = [] for child in children: - _children.append(child._config) + _children.append(child._config_bag.context) config = KernelGroupConfig(_children, session_id=session_id, diff --git a/tiramisu/config.py b/tiramisu/config.py index 0f32797..fcccefa 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -199,7 +199,7 @@ class SubConfig(object): option_bag = OptionBag() option = self.cfgimpl_get_description().impl_getchild(step, config_bag, - self) + self.cfgimpl_get_path()) subpath = self._get_subpath(step) option_bag.set_option(option, subpath, @@ -371,7 +371,7 @@ class SubConfig(object): """ def _filter_by_value(soption_bag): try: - value = self.getattr(path, + value = context.getattr(path, soption_bag) except PropertiesOptionError: return False @@ -386,8 +386,10 @@ class SubConfig(object): else: options = self.cfgimpl_get_description().impl_get_options_paths(bytype, byname, - _subpath, + self.cfgimpl_get_path(), config_bag) + options = list(options) + context = self.cfgimpl_get_context() for path, option in options: option_bag = OptionBag() option_bag.set_option(option, @@ -400,14 +402,14 @@ class SubConfig(object): #remove option with propertyerror, ... try: if '.' in path: - subconfig, subpath = self.cfgimpl_get_home_by_path(path, + subconfig, subpath = context.cfgimpl_get_home_by_path(path, config_bag) else: subconfig = self subpath = path subconfig.cfgimpl_get_description().impl_getchild(subpath, config_bag, - subconfig) + subconfig.cfgimpl_get_path()) self.cfgimpl_get_settings().validate_properties(option_bag) except PropertiesOptionError: continue @@ -508,7 +510,7 @@ class SubConfig(object): subpath = path opt = subconfig.cfgimpl_get_description().impl_getchild(subpath, config_bag, - subconfig) + subconfig.cfgimpl_get_path()) soption_bag = OptionBag() soption_bag.set_option(opt, path, @@ -874,7 +876,7 @@ class KernelGroupConfig(_CommonConfig): cconfig_bag) option = subconfig.cfgimpl_get_description().impl_getchild(name, cconfig_bag, - child) + child.cfgimpl_get_path()) option_bag = OptionBag() option_bag.set_option(option, path, @@ -919,7 +921,8 @@ class KernelGroupConfig(_CommonConfig): config_bag=config_bag, raise_if_not_found=raise_if_not_found)) byname = None - byoption = self.cfgimpl_get_description().impl_get_opt_by_path(bypath) + byoption = self.cfgimpl_get_description().impl_get_opt_by_path(bypath, + config_bag) ret = [] for child in self._impl_children: @@ -1040,7 +1043,8 @@ class KernelMetaConfig(KernelGroupConfig): if force_default and force_dont_change_value: raise ValueError(_('force_default and force_dont_change_value' ' cannot be set together')) - opt = self.cfgimpl_get_description().impl_get_opt_by_path(path) + opt = self.cfgimpl_get_description().impl_get_opt_by_path(path, + config_bag) for child in self._impl_children: cconfig_bag = config_bag.copy() cconfig_bag.context = child @@ -1048,7 +1052,7 @@ class KernelMetaConfig(KernelGroupConfig): cconfig_bag) option = subconfig.cfgimpl_get_description().impl_getchild(name, cconfig_bag, - child) + child.cfgimpl_get_path()) option_bag = OptionBag() option_bag.set_option(option, path, @@ -1080,7 +1084,7 @@ class KernelMetaConfig(KernelGroupConfig): config_bag) option = subconfig.cfgimpl_get_description().impl_getchild(name, config_bag, - self) + self.cfgimpl_get_path()) option_bag = OptionBag() option_bag.set_option(option, path, @@ -1102,7 +1106,7 @@ class KernelMetaConfig(KernelGroupConfig): config_bag) option = subconfig.cfgimpl_get_description().impl_getchild(name, config_bag, - self) + self.cfgimpl_get_path()) option_bag = OptionBag() option_bag.set_option(option, path, diff --git a/tiramisu/option/optiondescription.py b/tiramisu/option/optiondescription.py index 6f42c93..c9032ce 100644 --- a/tiramisu/option/optiondescription.py +++ b/tiramisu/option/optiondescription.py @@ -30,7 +30,7 @@ from ..error import ConfigError, ConflictError class CacheOptionDescription(BaseOption): - __slots__ = ('_cache_paths', '_cache_consistencies', '_cache_force_store_values') + __slots__ = ('_cache_consistencies', '_cache_force_store_values') def _build_cache(self, config, @@ -154,7 +154,7 @@ class CacheOptionDescription(BaseOption): self._set_readonly() def impl_already_build_caches(self): - if hasattr(self, '_cache_paths'): + if hasattr(self, '_cache_consistencies'): return True return False @@ -192,11 +192,10 @@ class CacheOptionDescription(BaseOption): values._p_.commit() def _build_cache_option(self, - _currpath=None, - cache_path=None, - cache_option=None): + _currpath=None): - if self.impl_is_readonly() or (_currpath is None and getattr(self, '_cache_paths', None) is not None): + if self.impl_is_readonly() or \ + (_currpath is None and getattr(self, '_cache_consistencies', None) is not None): # cache already set return if _currpath is None: @@ -204,24 +203,17 @@ class CacheOptionDescription(BaseOption): _currpath = [] else: save = False - if cache_path is None: - cache_path = [] - cache_option = [] for option in self.impl_getchildren(config_bag=undefined, dyn=False): attr = option.impl_getname() path = str('.'.join(_currpath + [attr])) - cache_option.append(option) - cache_path.append(path) option._path = path if option.impl_is_optiondescription(): _currpath.append(attr) - option._build_cache_option(_currpath, - cache_path, - cache_option) + option._build_cache_option(_currpath) _currpath.pop() - if save: - self._cache_paths = (tuple(cache_option), tuple(cache_path)) + if save and not hasattr(self, '_cache_consistencies'): + self._cache_consistencies = None class OptionDescriptionWalk(CacheOptionDescription): @@ -248,57 +240,43 @@ class OptionDescriptionWalk(CacheOptionDescription): bytype, byname, _subpath, - config_bag): - def _filter_by_type(path, - option): - if isinstance(option, - bytype): - return _filter_by_name(path, option) + config_bag, + self_opt=None): + if self_opt is None: + self_opt = self + def _filter_by_name(option): + return byname is None or option.impl_getname() == byname - def _filter_by_name(path, - option): - name = option.impl_getname() - if option.issubdyn(): - if byname.startswith(name): - option_bag = OptionBag() - option_bag.set_option(option, - path, - None, - config_bag) - for doption in self.build_dynoptions(option_bag): - if byname == doption.impl_getname(): - dpath = doption.impl_getpath() - return (dpath, doption) - elif byname == name: - return (path, option) - - def _filter(path, option): - if bytype is not None: - return _filter_by_type(path, option) - return _filter_by_name(path, option) - - opts, paths = self._cache_paths - for index, option in enumerate(opts): + for option in self_opt.impl_getchildren(config_bag): + if _subpath is None: + path = option.impl_getname() + else: + path = _subpath + '.' + option.impl_getname() if option.impl_is_optiondescription(): - continue - path = paths[index] - if _subpath is not None and not path.startswith(_subpath + '.'): - continue - ret = _filter(path, option) - if ret: - yield ret + for subopt in option.impl_get_options_paths(bytype, + byname, + path, + config_bag): + yield subopt + else: + if bytype is not None: + if isinstance(option, bytype) and \ + _filter_by_name(option): + yield (path, option) + elif _filter_by_name(option): + yield (path, option) def impl_getchild(self, name, config_bag, - subconfig): + subpath): if name in self._children[0]: child = self._children[1][self._children[0].index(name)] if not child.impl_is_dynoptiondescription(): return child else: child = self._impl_search_dynchild(name, - subconfig, + subpath, config_bag) if child: return child @@ -307,12 +285,19 @@ class OptionDescriptionWalk(CacheOptionDescription): '').format(name, self.impl_getname())) def impl_get_opt_by_path(self, - path): - return self._cache_paths[0][self._cache_paths[1].index(path)] - - def impl_get_path_by_opt(self, - opt): - return self._cache_paths[1][self._cache_paths[0].index(opt)] + path, + config_bag): + opt = self + subpath = None + for step in path.split('.'): + opt = opt.impl_getchild(step, + config_bag, + subpath) + if subpath is None: + subpath = step + else: + subpath += '.' + step + return opt def impl_getchildren(self, config_bag, @@ -347,7 +332,7 @@ class OptionDescriptionWalk(CacheOptionDescription): def _impl_search_dynchild(self, name, - subconfig, + subpath, config_bag): for child in self._impl_st_getchildren(only_dyn=True): #sconfig_bag = config_bag.copy('nooption') @@ -356,13 +341,13 @@ class OptionDescriptionWalk(CacheOptionDescription): if name.startswith(cname): option_bag = OptionBag() option_bag.set_option(child, - subconfig.cfgimpl_get_path(), + subpath, None, config_bag) for value in child.impl_get_suffixes(option_bag): if name == cname + value: return SynDynOptionDescription(child, - subconfig.cfgimpl_get_path(), + subpath, value) def _impl_get_dynchild(self, @@ -424,7 +409,7 @@ class OptionDescription(OptionDescriptionWalk): 'the dynoptiondescription\'s name "{}"').format(child, dynopt)) old = child self._children = children_ - self._cache_consistencies = None + #self._cache_consistencies = None # the group_type is useful for filtering OptionDescriptions in a config self._group_type = groups.default diff --git a/tiramisu/option/syndynoptiondescription.py b/tiramisu/option/syndynoptiondescription.py index 2082026..8a6cf0d 100644 --- a/tiramisu/option/syndynoptiondescription.py +++ b/tiramisu/option/syndynoptiondescription.py @@ -44,14 +44,14 @@ class SynDynOptionDescription(object): def impl_getchild(self, name, config_bag, - subconfig): + subpath): try: if name.endswith(self._suffix): oname = name[:-len(self._suffix)] child = self._children[1][self._children[0].index(oname)] return self._impl_get_dynchild(child, self._suffix, - subconfig.cfgimpl_get_path()) + subpath) except ValueError: # when oname not in self._children pass @@ -72,6 +72,17 @@ class SynDynOptionDescription(object): self._suffix, subpath)) + def impl_get_options_paths(self, + bytype, + byname, + _subpath, + config_bag): + return self._opt.impl_get_options_paths(bytype, + byname, + _subpath, + config_bag, + self) + def impl_getpath(self): subpath = self._subpath if subpath != '': diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 8081247..d7ecce4 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -175,7 +175,6 @@ class ConfigBag: 'permissives', # permissives for current context ) def __init__(self, context, **kwargs): - #self.force_permissive = False self.context = context for key, value in kwargs.items(): setattr(self, key, value) @@ -196,10 +195,17 @@ class ConfigBag: self.properties = frozenset(self.properties | {'permissive'}) def __delattr__(self, key): - if key == 'properties': + if key in ['properties', 'permissives']: + try: + super().__delattr__(key) + except AttributeError: + pass return raise KeyError('unknown key {} for ConfigBag'.format(key)) + #def __setattr__(self, key, value): + # super().__setattr__(key, value) + def copy(self): kwargs = {} for key in self.__slots__: