remove _cache_paths (path is now directly in option)

better TiramisuAPI support
This commit is contained in:
Emmanuel Garette 2018-09-08 20:17:20 +02:00
parent e0cab0063e
commit aa9aef6e78
13 changed files with 627 additions and 633 deletions

View File

@ -70,6 +70,299 @@ def autocheck(func):
return wrapper 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 @autocheck
def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_option_multi(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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 isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread).owner.get() == 'default' 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.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): elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") 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()") 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: else:
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).owner.get()") 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.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.config(conf).unrestraint.option(pathread).owner.get() == 'default'
assert cfg.unrestraint.config(conf).option(pathread).owner.isdefault() assert cfg.config(conf).unrestraint.option(pathread).owner.isdefault()
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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).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.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): elif not kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") 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()") 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: else:
raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).owner.get()") 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.config(conf).option(pathread, 0).owner.isdefault()")
raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault()") raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread, 0).owner.isdefault()")
assert cfg.unrestraint.config(conf).option(pathread, 0).owner.get() == 'default' assert cfg.config(conf).unrestraint.option(pathread, 0).owner.get() == 'default'
assert cfg.unrestraint.config(conf).option(pathread, 0).owner.isdefault() assert cfg.config(conf).unrestraint.option(pathread, 0).owner.isdefault()
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(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 @autocheck
def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_default_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
_autocheck_default_value(cfg, pathread, confread, **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 @autocheck
def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_set_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
_set_value(cfg, pathwrite, 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 isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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, 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_: if submulti_:
assert cfg.config(conf).option(pathread, 1).value.get() == SUBLIST_SECOND_VALUE[1] 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: else:
assert cfg.config(conf).option(pathread, 1).value.get() == LIST_SECOND_VALUE[1] 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): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") 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.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_: 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: 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: else:
raises(PropertiesOptionError, "assert cfg.config(conf).option(pathread, 0).value.get()") 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.config(conf).option(pathread, 1).value.get()")
raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 0).value.get()") raises(PropertiesOptionError, "assert cfg.config(conf).forcepermissive.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, 1).value.get()")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
assert cfg.config(conf).option(pathread).value.get() == first_value 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): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") 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: else:
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") 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: with warnings.catch_warnings(record=True) as w:
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(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 @autocheck
def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_get_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
_set_value(cfg, pathwrite, confwrite, set_permissive=False, **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() isslave = cfg.unrestraint.option(pathread).option.isslave()
if not isslave: if not isslave:
if kwargs.get('propertyerror', False): 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 return
if kwargs.get('propertyerror', False): if kwargs.get('propertyerror', False):
raises(PropertiesOptionError, "cfg.option(pathread).value.len()") raises(PropertiesOptionError, "cfg.option(pathread).value.len()")
@ -421,10 +549,10 @@ def autocheck_value_slave(cfg, mcfg, pathread, pathwrite, confread, confwrite, *
def do(conf): def do(conf):
if not kwargs.get('permissive', False): if not kwargs.get('permissive', False):
length = cfg.config(conf).option(pathread).value.len() 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: else:
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.len()") 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 assert length == 2
do(confread) do(confread)
if confread != confwrite: 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] assert cfg.config(conf).option(pathread, 1).value.get() == second_value[1]
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).value.get()") raises(PropertiesOptionError, "cfg.config(conf).option(pathread, 0).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
assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get() == second_value[1] assert cfg.config(conf).forcepermissive.option(pathread, 1).value.get() == second_value[1]
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread).value.get() == empty_value assert cfg.config(conf).option(pathread).value.get() == empty_value
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") 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: with warnings.catch_warnings(record=True) as w:
do(confread) do(confread)
if confread != confwrite: 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: with warnings.catch_warnings(record=True) as w:
if not kwargs.get('propertyerror', False): 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) len_value = len(master_value)
master_value.append(undefined) 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: with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) 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) len_new = len(new_master_value)
assert len_value + 1 == len_new assert len_value + 1 == len_new
assert new_master_value[-1] == kwargs['default_multi'] assert new_master_value[-1] == kwargs['default_multi']
@ -533,16 +661,16 @@ def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite,
else: else:
slave_path += '.third' slave_path += '.third'
for idx in range(len_new): 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_: if not submulti_:
value = 'value' value = 'value'
else: else:
value = ['value'] value = ['value']
master_value.append(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) 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 @autocheck
@ -568,32 +696,32 @@ def autocheck_pop_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(values) cfg.forcepermissive.config(confwrite).option(pathread).value.set(values)
cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value) 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'] cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value
assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False
cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True assert cfg.config(confread).forcepermissive.option(a_slave, 2).owner.isdefault() is True
cfg.forcepermissive.config(confread).option(a_slave, 3).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 3).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 3).owner.isdefault() is True 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(confwrite).option(pathread).value.pop(3)
cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == slave_value cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == slave_value
assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is False assert cfg.config(confread).forcepermissive.option(a_slave, 1).owner.isdefault() is False
cfg.forcepermissive.config(confread).option(a_slave, 2).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 2).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 2).owner.isdefault() is True 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(confwrite).option(pathread).value.pop(0)
cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == slave_value cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == slave_value
assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is False assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is False
cfg.forcepermissive.config(confread).option(a_slave, 1).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 1).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 1).owner.isdefault() is True 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(confwrite).option(pathread).value.pop(0)
cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] cfg.config(confread).forcepermissive.option(a_slave, 0).value.get() == kwargs['default_multi']
assert cfg.forcepermissive.config(confread).option(a_slave, 0).owner.isdefault() is True assert cfg.config(confread).forcepermissive.option(a_slave, 0).owner.isdefault() is True
@autocheck @autocheck
@ -640,69 +768,6 @@ def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwa
assert(cfg.config(confwrite).config.dict()) == make_dict_value 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 @autocheck
def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_property(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
"""get property from path """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) 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) _check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props)
# set properties without permissive # set properties without permissive
for prop in properties: for prop in properties:
cfg.unrestraint.config(confread).option(pathwrite).property.add(prop) cfg.unrestraint.config(confwrite).option(pathwrite).property.add(prop)
_check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties) if confread == confwrite:
#if confread != confwrite: _check_properties(cfg, mcfg, pathread, confread, kwargs, properties, properties)
# _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')
else: else:
default_props = [] _check_properties(cfg, mcfg, pathread, confwrite, kwargs, properties, properties)
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, 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 @autocheck
@ -780,8 +812,9 @@ def autocheck_reset_property(cfg, mcfg, pathread, pathwrite, confread, confwrite
# reset properties without permissive # reset properties without permissive
cfg.unrestraint.config(confwrite).option(pathwrite).property.reset() 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) _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() cfg.unrestraint.option(pathwrite).property.reset()
_check_properties(cfg, mcfg, pathread, confwrite, kwargs, default_props, default_props) _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 @autocheck
@ -809,34 +840,6 @@ def autocheck_context_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite,
assert owner == kwargs['owner'] 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 @autocheck
def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs): def autocheck_owner_with_value(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
"""value is now changed, check owner in this case """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 # test if is default owner with permissive
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
if not isslave: 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: else:
assert cfg.forcepermissive.config(conf).option(pathread, 0).owner.isdefault() is True assert cfg.config(conf).forcepermissive.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, 1).owner.isdefault() is False
#FIXME else: #FIXME else:
# raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).owner.isdefault()") # raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.isdefault()")
do(confwrite) do(confwrite)
if confwrite != confread: if confwrite != confread:
do(confread) do(confread)
@ -1015,30 +1018,28 @@ def autocheck_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **
call_path = pathread + 'call' call_path = pathread + 'call'
cfg.unrestraint.config(confwrite).option(call_path).permissive.set(frozenset(['disabled'])) 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']) assert cfg.unrestraint.config(confwrite).option(pathread).permissive.get() == frozenset(['disabled'])
#if confwrite != confread: #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 # can access to disabled value
ckwargs = copy(kwargs) ckwargs = copy(kwargs)
ckwargs['propertyerror'] = False 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']: 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 # can access to all value except when optiondescript have hidden
if not ckwargs.get('permissive_od', False): if not ckwargs.get('permissive_od', False):
ckwargs['permissive'] = False ckwargs['permissive'] = False
_autocheck_default_value(cfg, pathread, confread, **ckwargs) _autocheck_default_value(cfg, pathread, confread, **ckwargs)
if confread != confwrite:
_autocheck_default_value(cfg, pathread, confwrite, **ckwargs)
if ckwargs.get('permissive_od', False): if ckwargs.get('permissive_od', False):
# set permissive to OptionDescription # 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'])) 'hidden']))
ckwargs['permissive'] = False ckwargs['permissive'] = False
_autocheck_default_value(cfg, pathread, confread, **ckwargs) _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) # _autocheck_default_value(cfg, pathread, confwrite, **ckwargs)
# only hidden # only hidden
cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset(['hidden'])) cfg.config(confread).unrestraint.option(pathwrite).permissive.set(frozenset(['hidden']))
if callback: 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): if ckwargs.get('permissive_od', False):
_autocheck_default_value(cfg, pathread, confread, **ckwargs) _autocheck_default_value(cfg, pathread, confread, **ckwargs)
if confread != confwrite: cfg.config(confread).unrestraint.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden']))
_autocheck_default_value(cfg, pathread, confwrite, **ckwargs)
cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset(['hidden']))
ckwargs = copy(kwargs) ckwargs = copy(kwargs)
ckwargs['permissive'] = False ckwargs['permissive'] = False
_autocheck_default_value(cfg, pathread, confread, **ckwargs) _autocheck_default_value(cfg, pathread, confread, **ckwargs)
#if confread != confwrite:
# _autocheck_default_value(cfg, pathread, confwrite, **ckwargs)
# no permissive # no permissive
cfg.unrestraint.config(confwrite).option(pathwrite).permissive.set(frozenset()) cfg.config(confread).unrestraint.option(pathwrite).permissive.set(frozenset())
if callback: 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): if ckwargs.get('permissive_od', False):
_autocheck_default_value(cfg, pathread, confread, **ckwargs) _autocheck_default_value(cfg, pathread, confread, **ckwargs)
if confread != confwrite: cfg.config(confread).unrestraint.option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset())
_autocheck_default_value(cfg, pathread, confwrite, **ckwargs)
cfg.unrestraint.config(confwrite).option(pathwrite.rsplit('.', 1)[0]).permissive.set(frozenset())
_autocheck_default_value(cfg, pathread, confread, **kwargs) _autocheck_default_value(cfg, pathread, confread, **kwargs)
#if confread != confwrite:
# _autocheck_default_value(cfg, pathread, confwrite, **kwargs)
@autocheck @autocheck
@ -1106,15 +1099,15 @@ def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs
def do(conf): def do(conf):
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): 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.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): elif kwargs.get('permissive', False):
raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") 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: else:
raises(AttributeError, "cfg.config(conf).option.find(name, first=True)") raises(AttributeError, "cfg.config(conf).option.find(name, first=True)")
raises(AttributeError, "cfg.forcepermissive.config(conf).option.find(name, first=True)") raises(AttributeError, "cfg.config(conf).forcepermissive.option.find(name, first=True)")
assert option == _getoption(cfg.unrestraint.config(conf).option.find(name, first=True)) assert option == _getoption(cfg.config(conf).unrestraint.option.find(name, first=True))
assert [option] == _getoptions(cfg.unrestraint.config(conf).option.find(name)) assert [option] == _getoptions(cfg.config(conf).unrestraint.option.find(name))
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(confwrite) do(confwrite)
@ -1648,7 +1641,7 @@ DICT_PATHS = [
OrderedDict([('first', {}), OrderedDict([('first', {}),
('second', {'second': {'disabled': True}}), ('second', {'second': {'disabled': True}}),
('third', {'third': {'hidden': True}}) ('third', {'third': {'hidden': True}})
]), ]),
#test a config with two optiondescription #test a config with two optiondescription
OrderedDict([('subod.subsubod.first', {}), OrderedDict([('subod.subsubod.first', {}),
('subod.subsubod.second', {'second': {'disabled': True}}), ('subod.subsubod.second', {'second': {'disabled': True}}),
@ -1748,7 +1741,8 @@ def test_options(paths):
continue continue
for default in (False, True): for default in (False, True):
for multi in (False, True, submulti): for multi in (False, True, submulti):
# for meta in (False,): pass
# for meta in (True,):
# for callback in (False,): # for callback in (False,):
# for consistency in (False,): # for consistency in (False,):
# for require in (False,): # for require in (False,):
@ -1757,7 +1751,7 @@ def test_options(paths):
# if callback and default_multi: # if callback and default_multi:
# continue # continue
# for default in (False,): # for default in (False,):
# for multi in (True,): # for multi in (False,):
# print(meta, callback, consistency, require, default_multi, symlink, default, multi) # print(meta, callback, consistency, require, default_multi, symlink, default, multi)
if multi is submulti and default: if multi is submulti and default:
continue continue

View File

@ -47,8 +47,8 @@ def test_cache_config():
def test_cache(): def test_cache():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
values = cfg._config.cfgimpl_get_values() values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings() settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get() cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
@ -98,8 +98,8 @@ def test_cache_importation_permissive():
def test_cache_reset(): def test_cache_reset():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
values = cfg._config.cfgimpl_get_values() values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings() settings = cfg._config_bag.context.cfgimpl_get_settings()
#when change a value #when change a value
cfg.option('u1').value.get() cfg.option('u1').value.get()
cfg.option('u2').value.get() cfg.option('u2').value.get()
@ -158,8 +158,8 @@ def test_cache_reset():
def test_cache_reset_multi(): def test_cache_reset_multi():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
values = cfg._config.cfgimpl_get_values() values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings() settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get() cfg.option('u1').value.get()
cfg.option('u3').value.get() cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
@ -210,12 +210,12 @@ def test_cache_reset_multi():
def test_reset_cache(): def test_reset_cache():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
values = cfg._config.cfgimpl_get_values() values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings() settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get() cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached() assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._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 values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached() assert 'u1' not in settings._p_.get_cached()
cfg.option('u1').value.get() cfg.option('u1').value.get()
@ -227,7 +227,7 @@ def test_reset_cache():
assert 'u1' in settings._p_.get_cached() assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached() assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._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 values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached() assert 'u1' not in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached() assert 'u2' not in values._p_.get_cached()
@ -237,8 +237,8 @@ def test_reset_cache():
def test_cache_not_cache(): def test_cache_not_cache():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)
values = cfg._config.cfgimpl_get_values() values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings() settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.property.pop('cache') cfg.property.pop('cache')
cfg.option('u1').value.get() cfg.option('u1').value.get()
assert 'u1' not in values._p_.get_cached() assert 'u1' not in values._p_.get_cached()
@ -253,13 +253,13 @@ def test_cache_master_slave():
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig) cfg = Config(maconfig)
cfg.property.read_write() 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._config.cfgimpl_get_settings()._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.set(['192.168.1.2'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() 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', 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: if TIRAMISU_VERSION == 2:
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0']) assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
else: else:
@ -269,7 +269,7 @@ def test_cache_master_slave():
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None]) #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'][None][0] == [None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is 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.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'].keys()) == set([None])
assert set(cache['ip_admin_eth0.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.ip_admin_eth0').value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).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: if TIRAMISU_VERSION == 2:
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0']) assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
else: 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'][None][0] == [None, None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is 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 #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.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'].keys()) == set([None])
assert set(cache['ip_admin_eth0.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: if TIRAMISU_VERSION == 2:
cfg.property.pop('expire') cfg.property.pop('expire')
cfg.config.dict() 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)}} # '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)}, 'val2': {None: ('val', None)},
'val3': {None: ('yes', None)}, 'val3': {None: ('yes', None)},
'val4': {None: ('val', None)}, 'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.option('val1').value.set('new') 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)}} # '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)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() 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)}} # '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)}, 'val2': {None: ('new', None)},
'val3': {None: ('yes', None)}, 'val3': {None: ('yes', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.option('val3').value.set('new2') 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {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)}, 'val2': {None: ('new', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {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)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new', None)}, 'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.option('val4').value.set('new3') 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
# 'val4': {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)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.config.dict() 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
# 'val4': {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)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}, 'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}}) 'val5': {None: (['yes'], None)}})
cfg.option('val5').value.set([undefined, 'new4']) 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}, # 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), 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)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}}) 'val4': {None: ('new3', None)}})
cfg.config.dict() 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)}, # 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}, # 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}, # 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), 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)}, 'val2': {None: ('new', None)},
'val3': {None: ('new2', None)}, 'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}, 'val4': {None: ('new3', None)},
@ -435,19 +435,19 @@ def test_cache_master_and_slaves_master():
#None because no value #None because no value
idx_val2 = None idx_val2 = None
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else: 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': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {idx_val2: (val1_val2_props, None)}}) 'val1.val2': {idx_val2: (val1_val2_props, None)}})
# len is 0 so don't get any value # 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]) 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() cfg.config.dict()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
val_val2 = [None] val_val2 = [None]
@ -457,30 +457,30 @@ def test_cache_master_and_slaves_master():
idx_val2 = 0 idx_val2 = 0
val_val2 = None val_val2 = None
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), 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': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': val_val2_props}) '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)}}) 'val1.val2': {idx_val2: (val_val2, None)}})
cfg.option('val1.val1').value.set([undefined, undefined]) cfg.option('val1.val1').value.set([undefined, undefined])
cfg.config.dict() cfg.config.dict()
cfg.option('val1.val2', 1).value.set('oui') 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)}}) 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() == {}
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)} val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
else: else:
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)} 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': {None: (val1_props, None)},
# 'val1.val1': {None: (val1_val1_props, None)}, # 'val1.val1': {None: (val1_val1_props, None)},
# 'val1.val2': val1_val2_props} # 'val1.val2': val1_val2_props}
#if TIRAMISU_VERSION == 2: #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)}} # 'val1.val2': {None: ([None, 'oui'], None)}}
#else: #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)}} # '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_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props) val1_val2_props = frozenset(val1_val2_props)
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {} assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else: 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': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)}, 'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {None: (val1_val2_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]) 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() 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)}} # '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)} # 'val1.val2': {None: ([None], None)}
# } # }
@ -538,46 +538,46 @@ def test_cache_requires():
cfg.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
cfg.property.pop('expire') 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 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2: 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: 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)}}) 'activate_service': {None: (True, None)}})
cfg.config.dict() 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_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)}}) 'activate_service': {None: (True, None)}})
cfg.option('ip_address_service').value.set('1.1.1.1') 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)}}) '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() 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_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)}}) 'activate_service': {None: (True, None)}})
cfg.option('activate_service').value.set(False) 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() 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), 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(): def test_cache_global_properties():
@ -587,25 +587,25 @@ def test_cache_global_properties():
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() 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 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2: 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: 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)}}) 'activate_service': {None: (True, None)}})
cfg.property.pop('disabled') cfg.property.pop('disabled')
assert cfg.option('ip_address_service').value.get() == None 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})
cfg.property.add('test') cfg.property.add('test')
assert cfg.option('ip_address_service').value.get() == None 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)}, 'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}}) 'ip_address_service': {None: (set([]), None)}})

View File

@ -145,17 +145,6 @@ def test_information_config():
raises(ValueError, "config.information.reset('noinfo')") 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): def to_tuple(val):
ret = [] ret = []
for v in val: for v in val:

View File

@ -19,7 +19,7 @@ def test_deref_storage():
b = BoolOption('b', '') b = BoolOption('b', '')
o = OptionDescription('od', '', [b]) o = OptionDescription('od', '', [b])
c = Config(o) 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) del(c)
assert w() is None assert w() is None
@ -28,7 +28,7 @@ def test_deref_value():
b = BoolOption('b', '') b = BoolOption('b', '')
o = OptionDescription('od', '', [b]) o = OptionDescription('od', '', [b])
c = Config(o) c = Config(o)
w = weakref.ref(c._config.cfgimpl_get_values()) w = weakref.ref(c._config_bag.context.cfgimpl_get_values())
del(c) del(c)
assert w() is None assert w() is None
@ -37,7 +37,7 @@ def test_deref_setting():
b = BoolOption('b', '') b = BoolOption('b', '')
o = OptionDescription('od', '', [b]) o = OptionDescription('od', '', [b])
c = Config(o) c = Config(o)
w = weakref.ref(c._config.cfgimpl_get_settings()) w = weakref.ref(c._config_bag.context.cfgimpl_get_settings())
del(c) del(c)
assert w() is None assert w() is None

View File

@ -199,26 +199,26 @@ def test_meta_meta_set():
errors2 = meta.value.set('od1.i6', 7, only_config=True) errors2 = meta.value.set('od1.i6', 7, only_config=True)
assert len(errors1) == 0 assert len(errors1) == 0
assert len(errors2) == 2 assert len(errors2) == 2
conf1 = meta.config('meta.conf1')._config conf1 = meta.config('meta.conf1')._config_bag.context
conf2 = meta.config('meta.conf2')._config 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 assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7
# #
dconfigs = [] dconfigs = []
for conf in meta.config.find('i1', value=7, first=True).config.list(): 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 assert [conf1, conf2] == dconfigs
meta.config('meta.conf1').option('od1.i1').value.set(8) meta.config('meta.conf1').option('od1.i1').value.set(8)
# #
dconfigs = [] dconfigs = []
for conf in meta.config.find('i1', first=True).config.list(): 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 [conf1, conf2] == dconfigs
assert conf2 == list(meta.config.find('i1', value=7, 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 assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config_bag.context
# #
dconfigs = [] dconfigs = []
for conf in meta.config.find('i5', value=2, first=True).config.list(): 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 assert [conf1, conf2] == dconfigs
# #
raises(AttributeError, "meta.config.find('i1', value=10, first=True)") 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') conf2 = Config(od2, session_id='conf2')
grp = GroupConfig([conf1, conf2]) grp = GroupConfig([conf1, conf2])
itr = grp.config.find('i1', first=True).config.list() itr = grp.config.find('i1', first=True).config.list()
conf1._config == next(itr)._config conf1._config_bag.context == next(itr)._config_bag.context
conf2._config == next(itr)._config conf2._config_bag.context == next(itr)._config_bag.context
def test_group_group(): def test_group_group():
@ -307,20 +307,20 @@ def test_meta_master_slaves():
meta = MetaConfig([conf1, conf2]) meta = MetaConfig([conf1, conf2])
meta.property.read_only() meta.property.read_only()
itr = meta.config.find('ip_admin_eth0', first=True).config.list() itr = meta.config.find('ip_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config == next(itr)._config assert conf2._config_bag.context == next(itr)._config_bag.context
itr = meta.config.find('netmask_admin_eth0', first=True).config.list() itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config == next(itr)._config assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_write() meta.property.read_write()
raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)") raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)")
itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list() itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config == next(itr)._config assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_only() meta.property.read_only()
itr = meta.config.find('netmask_admin_eth0', first=True).config.list() itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config == next(itr)._config assert conf2._config_bag.context == next(itr)._config_bag.context
def test_meta_master_slaves_value2(): def test_meta_master_slaves_value2():

View File

@ -79,6 +79,7 @@ def test_permissive_frozen():
api.property.read_write() api.property.read_write()
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled'])) api.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled']) assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert api.permissive.get() == frozenset(['frozen', 'disabled'])
try: try:
api.option('u1').value.set(1) api.option('u1').value.set(1)
except PropertiesOptionError as err: except PropertiesOptionError as err:

View File

@ -150,14 +150,14 @@ def test_slots_config():
od1 = OptionDescription('a', '', []) od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1]) od2 = OptionDescription('a', '', [od1])
c = Config(od2) c = Config(od2)
raises(AttributeError, "c._config.x = 1") raises(AttributeError, "c._config_bag.context.x = 1")
raises(AttributeError, "c._config.cfgimpl_x = 1") raises(AttributeError, "c._config_bag.context.cfgimpl_x = 1")
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(od2, option_bag.set_option(od2,
'a', 'a',
None, None,
ConfigBag(c._config)) ConfigBag(c._config_bag.context))
sc = c._config.get_subconfig('a', option_bag) sc = c._config_bag.context.get_subconfig('a', option_bag)
assert isinstance(sc, SubConfig) assert isinstance(sc, SubConfig)
raises(AttributeError, "sc.x = 1") raises(AttributeError, "sc.x = 1")
raises(AttributeError, "sc.cfgimpl_x = 1") raises(AttributeError, "sc.cfgimpl_x = 1")
@ -167,7 +167,7 @@ def test_slots_setting():
od1 = OptionDescription('a', '', []) od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1]) od2 = OptionDescription('a', '', [od1])
c = Config(od2) c = Config(od2)
s = c._config.cfgimpl_get_settings() s = c._config_bag.context.cfgimpl_get_settings()
s s
raises(AttributeError, "s.x = 1") raises(AttributeError, "s.x = 1")
@ -176,6 +176,6 @@ def test_slots_value():
od1 = OptionDescription('a', '', []) od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1]) od2 = OptionDescription('a', '', [od1])
c = Config(od2) c = Config(od2)
v = c._config.cfgimpl_get_values() v = c._config_bag.context.cfgimpl_get_values()
v v
raises(AttributeError, "v.x = 1") raises(AttributeError, "v.x = 1")

View File

@ -223,7 +223,7 @@ def test_diff_information_config():
b.impl_set_information('info2', 'oh') b.impl_set_information('info2', 'oh')
o = OptionDescription('o', '', [b]) o = OptionDescription('o', '', [b])
o1 = OptionDescription('o1', '', [o]) o1 = OptionDescription('o1', '', [o])
c = Config(o1)._config c = Config(o1)._config_bag.context
raises(NotImplementedError, "dumps(c)") raises(NotImplementedError, "dumps(c)")

View File

@ -113,7 +113,7 @@ class CommonTiramisu(TiramisuHelp):
if option is None: if option is None:
option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name, option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name,
self.option_bag.config_bag, self.option_bag.config_bag,
self.subconfig) self.subconfig.cfgimpl_get_path())
self.option_bag.set_option(option, self.option_bag.set_option(option,
self.option_bag.path, self.option_bag.path,
self.option_bag.index, self.option_bag.index,
@ -145,8 +145,8 @@ class CommonTiramisuOption(CommonTiramisu):
self.option_bag = option_bag self.option_bag = option_bag
self._name = name self._name = name
self.subconfig = subconfig self.subconfig = subconfig
# for help()
if option_bag is not None: if option_bag is not None:
# for help()
self._get_option() self._get_option()
if option_bag.config_bag is not None and self.slave_need_index: if option_bag.config_bag is not None and self.slave_need_index:
self._test_slave_index() self._test_slave_index()
@ -548,11 +548,21 @@ class TiramisuOption(CommonTiramisu):
"""find an option by name (only for optiondescription)""" """find an option by name (only for optiondescription)"""
if not first: if not first:
ret = [] ret = []
for path in self.config_bag.context.find(byname=name, option = self._get_option()
byvalue=value, oname = option.impl_getname()
bytype=type, path = self.subconfig._get_subpath(oname)
_subpath=self._path, option_bag = OptionBag()
config_bag=self.config_bag): 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, subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag) self.config_bag)
t_option = TiramisuOption(name, t_option = TiramisuOption(name,
@ -569,7 +579,7 @@ class TiramisuOption(CommonTiramisu):
self._get_option() self._get_option()
current_option = self.option_bag.option.impl_getchild(name, current_option = self.option_bag.option.impl_getchild(name,
self.config_bag, self.config_bag,
self.subconfig) self.subconfig.cfgimpl_get_path)
path = self.option_bag.path + '.' + name path = self.option_bag.path + '.' + name
option_bag= OptionBag() option_bag= OptionBag()
option_bag.set_option(current_option, option_bag.set_option(current_option,
@ -614,8 +624,8 @@ class TiramisuOption(CommonTiramisu):
self.subconfig.get_subconfig(name, self.subconfig.get_subconfig(name,
option_bag) option_bag)
else: else:
self.subconfig.getattr(name, subconfig.getattr(name,
option_bag) option_bag)
option = self._get_option() option = self._get_option()
name = option.impl_getname() name = option.impl_getname()
@ -738,10 +748,7 @@ class TiramisuContextProperty(TiramisuContext):
"""set configuration to read only mode""" """set configuration to read only mode"""
settings = self.config_bag.context.cfgimpl_get_settings() settings = self.config_bag.context.cfgimpl_get_settings()
settings.read_only(self.config_bag.context) settings.read_only(self.config_bag.context)
try: del self.config_bag.properties
del self.config_bag.properties
except AttributeError:
pass
def read_write(self): def read_write(self):
"""set configuration to read and write mode""" """set configuration to read and write mode"""
@ -750,17 +757,15 @@ class TiramisuContextProperty(TiramisuContext):
# #FIXME ? # #FIXME ?
permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden'])) permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden']))
settings.set_context_permissives(permissives) settings.set_context_permissives(permissives)
try:
del self.config_bag.properties
except AttributeError:
pass
#/FIXME ? #/FIXME ?
del self.config_bag.properties
def add(self, prop): def add(self, prop):
"""add a configuration property""" """add a configuration property"""
props = self.get() props = self.get()
props.add(prop) props.add(prop)
self.set(frozenset(props)) self.set(frozenset(props))
del self.config_bag.properties
def pop(self, prop): def pop(self, prop):
"""remove a configuration property""" """remove a configuration property"""
@ -768,6 +773,7 @@ class TiramisuContextProperty(TiramisuContext):
if prop in props: if prop in props:
props.remove(prop) props.remove(prop)
self.set(frozenset(props)) self.set(frozenset(props))
del self.config_bag.properties
def get(self): def get(self):
"""get all configuration properties""" """get all configuration properties"""
@ -778,12 +784,14 @@ class TiramisuContextProperty(TiramisuContext):
context = self.config_bag.context context = self.config_bag.context
context.cfgimpl_get_settings().set_context_properties(props, context.cfgimpl_get_settings().set_context_properties(props,
context) context)
del self.config_bag.properties
def reset(self): def reset(self):
"""remove configuration properties""" """remove configuration properties"""
context = self.config_bag.context context = self.config_bag.context
context.cfgimpl_get_settings().reset(None, context.cfgimpl_get_settings().reset(None,
context) context)
del self.config_bag.properties
def exportation(self): def exportation(self):
"""export configuration properties""" """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_get_settings()._p_.importation(properties)
self.config_bag.context.cfgimpl_reset_cache(None, self.config_bag.context.cfgimpl_reset_cache(None,
None) None)
del self.config_bag.properties
class TiramisuContextPermissive(TiramisuContext): class TiramisuContextPermissive(TiramisuContext):
@ -806,6 +815,7 @@ class TiramisuContextPermissive(TiramisuContext):
def set(self, permissives): def set(self, permissives):
"""set configuration permissives""" """set configuration permissives"""
self.config_bag.context.cfgimpl_get_settings().set_context_permissives(permissives) self.config_bag.context.cfgimpl_get_settings().set_context_permissives(permissives)
del self.config_bag.permissives
def exportation(self): def exportation(self):
"""export configuration permissives""" """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_get_settings()._pp_.importation(permissives)
self.config_bag.context.cfgimpl_reset_cache(None, self.config_bag.context.cfgimpl_reset_cache(None,
None) None)
del self.config_bag.permissives
@ -918,9 +929,9 @@ class TiramisuContextConfig(TiramisuContext):
first: bool=False): first: bool=False):
"""find a path from option name and optionnaly a value to MetaConfig or GroupConfig""" """find a path from option name and optionnaly a value to MetaConfig or GroupConfig"""
if first: if first:
return TiramisuAPI(self.config_bag.context.find_firsts(byname=name, return Config(self.config_bag.context.find_firsts(byname=name,
byvalue=value, byvalue=value,
config_bag=self.config_bag)) config_bag=self.config_bag))
else: else:
raise APIError('not implemented yet') raise APIError('not implemented yet')
@ -929,25 +940,25 @@ class TiramisuContextConfig(TiramisuContext):
def _c_copy(self, def _c_copy(self,
session_id=None): 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, def _c_deepcopy(self,
session_id=None): session_id=None):
return TiramisuAPI(self.config_bag.context.duplicate(session_id, return Config(self.config_bag.context.duplicate(session_id,
deep=True)) deep=True))
def _c_meta(self): 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): 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): def _m_list(self):
return self._g_list() return self._g_list()
def _g_list(self): def _g_list(self):
for child in self.config_bag.context.cfgimpl_get_children(): for child in self.config_bag.context.cfgimpl_get_children():
yield TiramisuAPI(child) yield Config(child)
def __getattr__(self, def __getattr__(self,
name: str) -> Callable: name: str) -> Callable:
@ -990,32 +1001,25 @@ class TiramisuAPI(TiramisuHelp):
def __init__(self, def __init__(self,
config) -> None: config) -> None:
self._config = config if not isinstance(config, ConfigBag):
config = ConfigBag(context=config)
self._config_bag = config
if not self.registers: if not self.registers:
registers(self.registers, 'TiramisuContext') registers(self.registers, 'TiramisuContext')
registers(self.registers, 'TiramisuDispatcher') registers(self.registers, 'TiramisuDispatcher')
def __getattr__(self, subfunc: str) -> Any: def __getattr__(self, subfunc: str) -> Any:
if subfunc == 'forcepermissive': if subfunc == 'forcepermissive':
if isinstance(self._config, ConfigBag): config_bag = self._config_bag.copy()
config_bag = self._config.copy()
del config_bag.properties
else:
config_bag = ConfigBag(context=self._config)
config_bag.set_permissive() config_bag.set_permissive()
return TiramisuAPI(config_bag) return TiramisuAPI(config_bag)
elif subfunc == 'unrestraint': elif subfunc == 'unrestraint':
if isinstance(self._config, ConfigBag): config_bag = self._config_bag.copy()
config_bag = self._config.copy()
else:
config_bag = ConfigBag(context=self._config)
config_bag.properties = frozenset() config_bag.properties = frozenset()
return TiramisuAPI(config_bag) return TiramisuAPI(config_bag)
elif subfunc in self.registers: elif subfunc in self.registers:
if not isinstance(self._config, ConfigBag): config_bag = self._config_bag
config_bag = ConfigBag(context=self._config) del config_bag.permissives
else:
config_bag = self._config
return self.registers[subfunc](config_bag) return self.registers[subfunc](config_bag)
else: else:
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@ -1055,7 +1059,7 @@ class Config(TiramisuAPI):
session_id: str=None, session_id: str=None,
persistent: bool=False, persistent: bool=False,
storage=None) -> None: storage=None) -> None:
if not isinstance(descr, (KernelConfig, KernelMetaConfig)): if isinstance(descr, OptionDescription):
config = KernelConfig(descr, config = KernelConfig(descr,
session_id=session_id, session_id=session_id,
persistent=persistent, persistent=persistent,
@ -1075,7 +1079,7 @@ class MetaConfig(TiramisuAPI):
_children = [] _children = []
for child in children: for child in children:
if isinstance(child, TiramisuAPI): if isinstance(child, TiramisuAPI):
_children.append(child._config) _children.append(child._config_bag.context)
else: else:
_children.append(child) _children.append(child)
@ -1095,7 +1099,7 @@ class GroupConfig(TiramisuAPI):
storage=None) -> None: storage=None) -> None:
_children = [] _children = []
for child in children: for child in children:
_children.append(child._config) _children.append(child._config_bag.context)
config = KernelGroupConfig(_children, config = KernelGroupConfig(_children,
session_id=session_id, session_id=session_id,

View File

@ -199,7 +199,7 @@ class SubConfig(object):
option_bag = OptionBag() option_bag = OptionBag()
option = self.cfgimpl_get_description().impl_getchild(step, option = self.cfgimpl_get_description().impl_getchild(step,
config_bag, config_bag,
self) self.cfgimpl_get_path())
subpath = self._get_subpath(step) subpath = self._get_subpath(step)
option_bag.set_option(option, option_bag.set_option(option,
subpath, subpath,
@ -371,7 +371,7 @@ class SubConfig(object):
""" """
def _filter_by_value(soption_bag): def _filter_by_value(soption_bag):
try: try:
value = self.getattr(path, value = context.getattr(path,
soption_bag) soption_bag)
except PropertiesOptionError: except PropertiesOptionError:
return False return False
@ -386,8 +386,10 @@ class SubConfig(object):
else: else:
options = self.cfgimpl_get_description().impl_get_options_paths(bytype, options = self.cfgimpl_get_description().impl_get_options_paths(bytype,
byname, byname,
_subpath, self.cfgimpl_get_path(),
config_bag) config_bag)
options = list(options)
context = self.cfgimpl_get_context()
for path, option in options: for path, option in options:
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
@ -400,14 +402,14 @@ class SubConfig(object):
#remove option with propertyerror, ... #remove option with propertyerror, ...
try: try:
if '.' in path: if '.' in path:
subconfig, subpath = self.cfgimpl_get_home_by_path(path, subconfig, subpath = context.cfgimpl_get_home_by_path(path,
config_bag) config_bag)
else: else:
subconfig = self subconfig = self
subpath = path subpath = path
subconfig.cfgimpl_get_description().impl_getchild(subpath, subconfig.cfgimpl_get_description().impl_getchild(subpath,
config_bag, config_bag,
subconfig) subconfig.cfgimpl_get_path())
self.cfgimpl_get_settings().validate_properties(option_bag) self.cfgimpl_get_settings().validate_properties(option_bag)
except PropertiesOptionError: except PropertiesOptionError:
continue continue
@ -508,7 +510,7 @@ class SubConfig(object):
subpath = path subpath = path
opt = subconfig.cfgimpl_get_description().impl_getchild(subpath, opt = subconfig.cfgimpl_get_description().impl_getchild(subpath,
config_bag, config_bag,
subconfig) subconfig.cfgimpl_get_path())
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(opt, soption_bag.set_option(opt,
path, path,
@ -874,7 +876,7 @@ class KernelGroupConfig(_CommonConfig):
cconfig_bag) cconfig_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name, option = subconfig.cfgimpl_get_description().impl_getchild(name,
cconfig_bag, cconfig_bag,
child) child.cfgimpl_get_path())
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, path,
@ -919,7 +921,8 @@ class KernelGroupConfig(_CommonConfig):
config_bag=config_bag, config_bag=config_bag,
raise_if_not_found=raise_if_not_found)) raise_if_not_found=raise_if_not_found))
byname = None 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 = [] ret = []
for child in self._impl_children: for child in self._impl_children:
@ -1040,7 +1043,8 @@ class KernelMetaConfig(KernelGroupConfig):
if force_default and force_dont_change_value: if force_default and force_dont_change_value:
raise ValueError(_('force_default and force_dont_change_value' raise ValueError(_('force_default and force_dont_change_value'
' cannot be set together')) ' 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: for child in self._impl_children:
cconfig_bag = config_bag.copy() cconfig_bag = config_bag.copy()
cconfig_bag.context = child cconfig_bag.context = child
@ -1048,7 +1052,7 @@ class KernelMetaConfig(KernelGroupConfig):
cconfig_bag) cconfig_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name, option = subconfig.cfgimpl_get_description().impl_getchild(name,
cconfig_bag, cconfig_bag,
child) child.cfgimpl_get_path())
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, path,
@ -1080,7 +1084,7 @@ class KernelMetaConfig(KernelGroupConfig):
config_bag) config_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name, option = subconfig.cfgimpl_get_description().impl_getchild(name,
config_bag, config_bag,
self) self.cfgimpl_get_path())
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, path,
@ -1102,7 +1106,7 @@ class KernelMetaConfig(KernelGroupConfig):
config_bag) config_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name, option = subconfig.cfgimpl_get_description().impl_getchild(name,
config_bag, config_bag,
self) self.cfgimpl_get_path())
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, path,

View File

@ -30,7 +30,7 @@ from ..error import ConfigError, ConflictError
class CacheOptionDescription(BaseOption): class CacheOptionDescription(BaseOption):
__slots__ = ('_cache_paths', '_cache_consistencies', '_cache_force_store_values') __slots__ = ('_cache_consistencies', '_cache_force_store_values')
def _build_cache(self, def _build_cache(self,
config, config,
@ -154,7 +154,7 @@ class CacheOptionDescription(BaseOption):
self._set_readonly() self._set_readonly()
def impl_already_build_caches(self): def impl_already_build_caches(self):
if hasattr(self, '_cache_paths'): if hasattr(self, '_cache_consistencies'):
return True return True
return False return False
@ -192,11 +192,10 @@ class CacheOptionDescription(BaseOption):
values._p_.commit() values._p_.commit()
def _build_cache_option(self, def _build_cache_option(self,
_currpath=None, _currpath=None):
cache_path=None,
cache_option=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 # cache already set
return return
if _currpath is None: if _currpath is None:
@ -204,24 +203,17 @@ class CacheOptionDescription(BaseOption):
_currpath = [] _currpath = []
else: else:
save = False save = False
if cache_path is None:
cache_path = []
cache_option = []
for option in self.impl_getchildren(config_bag=undefined, for option in self.impl_getchildren(config_bag=undefined,
dyn=False): dyn=False):
attr = option.impl_getname() attr = option.impl_getname()
path = str('.'.join(_currpath + [attr])) path = str('.'.join(_currpath + [attr]))
cache_option.append(option)
cache_path.append(path)
option._path = path option._path = path
if option.impl_is_optiondescription(): if option.impl_is_optiondescription():
_currpath.append(attr) _currpath.append(attr)
option._build_cache_option(_currpath, option._build_cache_option(_currpath)
cache_path,
cache_option)
_currpath.pop() _currpath.pop()
if save: if save and not hasattr(self, '_cache_consistencies'):
self._cache_paths = (tuple(cache_option), tuple(cache_path)) self._cache_consistencies = None
class OptionDescriptionWalk(CacheOptionDescription): class OptionDescriptionWalk(CacheOptionDescription):
@ -248,57 +240,43 @@ class OptionDescriptionWalk(CacheOptionDescription):
bytype, bytype,
byname, byname,
_subpath, _subpath,
config_bag): config_bag,
def _filter_by_type(path, self_opt=None):
option): if self_opt is None:
if isinstance(option, self_opt = self
bytype): def _filter_by_name(option):
return _filter_by_name(path, option) return byname is None or option.impl_getname() == byname
def _filter_by_name(path, for option in self_opt.impl_getchildren(config_bag):
option): if _subpath is None:
name = option.impl_getname() path = option.impl_getname()
if option.issubdyn(): else:
if byname.startswith(name): path = _subpath + '.' + option.impl_getname()
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):
if option.impl_is_optiondescription(): if option.impl_is_optiondescription():
continue for subopt in option.impl_get_options_paths(bytype,
path = paths[index] byname,
if _subpath is not None and not path.startswith(_subpath + '.'): path,
continue config_bag):
ret = _filter(path, option) yield subopt
if ret: else:
yield ret 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, def impl_getchild(self,
name, name,
config_bag, config_bag,
subconfig): subpath):
if name in self._children[0]: if name in self._children[0]:
child = self._children[1][self._children[0].index(name)] child = self._children[1][self._children[0].index(name)]
if not child.impl_is_dynoptiondescription(): if not child.impl_is_dynoptiondescription():
return child return child
else: else:
child = self._impl_search_dynchild(name, child = self._impl_search_dynchild(name,
subconfig, subpath,
config_bag) config_bag)
if child: if child:
return child return child
@ -307,12 +285,19 @@ class OptionDescriptionWalk(CacheOptionDescription):
'').format(name, self.impl_getname())) '').format(name, self.impl_getname()))
def impl_get_opt_by_path(self, def impl_get_opt_by_path(self,
path): path,
return self._cache_paths[0][self._cache_paths[1].index(path)] config_bag):
opt = self
def impl_get_path_by_opt(self, subpath = None
opt): for step in path.split('.'):
return self._cache_paths[1][self._cache_paths[0].index(opt)] opt = opt.impl_getchild(step,
config_bag,
subpath)
if subpath is None:
subpath = step
else:
subpath += '.' + step
return opt
def impl_getchildren(self, def impl_getchildren(self,
config_bag, config_bag,
@ -347,7 +332,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
def _impl_search_dynchild(self, def _impl_search_dynchild(self,
name, name,
subconfig, subpath,
config_bag): config_bag):
for child in self._impl_st_getchildren(only_dyn=True): for child in self._impl_st_getchildren(only_dyn=True):
#sconfig_bag = config_bag.copy('nooption') #sconfig_bag = config_bag.copy('nooption')
@ -356,13 +341,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
if name.startswith(cname): if name.startswith(cname):
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(child, option_bag.set_option(child,
subconfig.cfgimpl_get_path(), subpath,
None, None,
config_bag) config_bag)
for value in child.impl_get_suffixes(option_bag): for value in child.impl_get_suffixes(option_bag):
if name == cname + value: if name == cname + value:
return SynDynOptionDescription(child, return SynDynOptionDescription(child,
subconfig.cfgimpl_get_path(), subpath,
value) value)
def _impl_get_dynchild(self, def _impl_get_dynchild(self,
@ -424,7 +409,7 @@ class OptionDescription(OptionDescriptionWalk):
'the dynoptiondescription\'s name "{}"').format(child, dynopt)) 'the dynoptiondescription\'s name "{}"').format(child, dynopt))
old = child old = child
self._children = children_ self._children = children_
self._cache_consistencies = None #self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config # the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default self._group_type = groups.default

View File

@ -44,14 +44,14 @@ class SynDynOptionDescription(object):
def impl_getchild(self, def impl_getchild(self,
name, name,
config_bag, config_bag,
subconfig): subpath):
try: try:
if name.endswith(self._suffix): if name.endswith(self._suffix):
oname = name[:-len(self._suffix)] oname = name[:-len(self._suffix)]
child = self._children[1][self._children[0].index(oname)] child = self._children[1][self._children[0].index(oname)]
return self._impl_get_dynchild(child, return self._impl_get_dynchild(child,
self._suffix, self._suffix,
subconfig.cfgimpl_get_path()) subpath)
except ValueError: except ValueError:
# when oname not in self._children # when oname not in self._children
pass pass
@ -72,6 +72,17 @@ class SynDynOptionDescription(object):
self._suffix, self._suffix,
subpath)) 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): def impl_getpath(self):
subpath = self._subpath subpath = self._subpath
if subpath != '': if subpath != '':

View File

@ -175,7 +175,6 @@ class ConfigBag:
'permissives', # permissives for current context 'permissives', # permissives for current context
) )
def __init__(self, context, **kwargs): def __init__(self, context, **kwargs):
#self.force_permissive = False
self.context = context self.context = context
for key, value in kwargs.items(): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)
@ -196,10 +195,17 @@ class ConfigBag:
self.properties = frozenset(self.properties | {'permissive'}) self.properties = frozenset(self.properties | {'permissive'})
def __delattr__(self, key): def __delattr__(self, key):
if key == 'properties': if key in ['properties', 'permissives']:
try:
super().__delattr__(key)
except AttributeError:
pass
return return
raise KeyError('unknown key {} for ConfigBag'.format(key)) raise KeyError('unknown key {} for ConfigBag'.format(key))
#def __setattr__(self, key, value):
# super().__setattr__(key, value)
def copy(self): def copy(self):
kwargs = {} kwargs = {}
for key in self.__slots__: for key in self.__slots__: