- can reset directly custom settings for an option: setting[option].reset()
- option properties are now tuple in internal, and change it to set when needed (that coping data)
This commit is contained in:
parent
a95f19d5f4
commit
de44daafeb
3 changed files with 78 additions and 14 deletions
|
@ -308,3 +308,59 @@ def test_access_by_get_whith_hide():
|
||||||
c = Config(descr)
|
c = Config(descr)
|
||||||
c.read_write()
|
c.read_write()
|
||||||
raises(AttributeError, "c.find(byname='b1')")
|
raises(AttributeError, "c.find(byname='b1')")
|
||||||
|
|
||||||
|
|
||||||
|
def test_append_properties():
|
||||||
|
descr = make_description()
|
||||||
|
cfg = Config(descr)
|
||||||
|
setting = cfg.cfgimpl_get_settings()
|
||||||
|
option = cfg.cfgimpl_get_description().gc.dummy
|
||||||
|
assert option._properties == tuple()
|
||||||
|
assert not 'test' in setting[option]
|
||||||
|
setting[option].append('test')
|
||||||
|
assert option._properties == tuple()
|
||||||
|
assert 'test' in setting[option]
|
||||||
|
|
||||||
|
|
||||||
|
def test_reset_properties():
|
||||||
|
descr = make_description()
|
||||||
|
cfg = Config(descr)
|
||||||
|
setting = cfg.cfgimpl_get_settings()
|
||||||
|
option = cfg.cfgimpl_get_description().gc.dummy
|
||||||
|
assert setting._properties == {}
|
||||||
|
setting.append('frozen')
|
||||||
|
assert setting._properties == {None: set(('frozen', 'expire', 'validator'))}
|
||||||
|
setting.reset()
|
||||||
|
assert setting._properties == {}
|
||||||
|
setting[option].append('test')
|
||||||
|
assert setting._properties == {option: set(('test',))}
|
||||||
|
setting.reset()
|
||||||
|
assert setting._properties == {option: set(('test',))}
|
||||||
|
setting.append('frozen')
|
||||||
|
assert setting._properties == {None: set(('frozen', 'expire', 'validator')), option: set(('test',))}
|
||||||
|
setting.reset(option)
|
||||||
|
assert setting._properties == {None: set(('frozen', 'expire', 'validator'))}
|
||||||
|
setting[option].append('test')
|
||||||
|
assert setting._properties == {None: set(('frozen', 'expire', 'validator')), option: set(('test',))}
|
||||||
|
setting.reset(all_properties=True)
|
||||||
|
assert setting._properties == {}
|
||||||
|
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
||||||
|
|
||||||
|
|
||||||
|
def test_reset_multiple():
|
||||||
|
descr = make_description()
|
||||||
|
cfg = Config(descr)
|
||||||
|
setting = cfg.cfgimpl_get_settings()
|
||||||
|
option = cfg.cfgimpl_get_description().gc.dummy
|
||||||
|
setting.append('frozen')
|
||||||
|
setting[option].append('test')
|
||||||
|
setting.reset()
|
||||||
|
setting.reset()
|
||||||
|
setting.append('frozen')
|
||||||
|
setting[option].append('test')
|
||||||
|
setting.reset(option)
|
||||||
|
setting.reset(option)
|
||||||
|
setting.append('frozen')
|
||||||
|
setting[option].append('test')
|
||||||
|
setting.reset(all_properties=True)
|
||||||
|
setting.reset(all_properties=True)
|
||||||
|
|
|
@ -170,7 +170,7 @@ class Option(BaseInformation):
|
||||||
if not isinstance(properties, tuple):
|
if not isinstance(properties, tuple):
|
||||||
raise TypeError(_('invalid properties type {0} for {1},'
|
raise TypeError(_('invalid properties type {0} for {1},'
|
||||||
' must be a tuple').format(type(properties), self._name))
|
' must be a tuple').format(type(properties), self._name))
|
||||||
self._properties = set(properties) # 'hidden', 'disabled'...
|
self._properties = properties # 'hidden', 'disabled'...
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"Option comparison"
|
"Option comparison"
|
||||||
|
@ -728,7 +728,7 @@ class OptionDescription(BaseInformation):
|
||||||
if not isinstance(properties, tuple):
|
if not isinstance(properties, tuple):
|
||||||
raise TypeError(_('invalid properties type {0} for {1},'
|
raise TypeError(_('invalid properties type {0} for {1},'
|
||||||
' must be a tuple').format(type(properties), self._name))
|
' must be a tuple').format(type(properties), self._name))
|
||||||
self._properties = set(properties) # 'hidden', 'disabled'...
|
self._properties = properties # 'hidden', 'disabled'...
|
||||||
# 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
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ from tiramisu.error import RequirementError, PropertiesOptionError
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
|
|
||||||
default_encoding = 'utf-8'
|
default_encoding = 'utf-8'
|
||||||
|
|
||||||
expires_time = 5
|
expires_time = 5
|
||||||
ro_remove = ('permissive', 'hidden')
|
ro_remove = ('permissive', 'hidden')
|
||||||
ro_append = ('frozen', 'disabled', 'validator', 'everything_frozen', 'mandatory')
|
ro_append = ('frozen', 'disabled', 'validator', 'everything_frozen', 'mandatory')
|
||||||
rw_remove = ('permissive', 'everything_frozen', 'mandatory')
|
rw_remove = ('permissive', 'everything_frozen', 'mandatory')
|
||||||
rw_append = ('frozen', 'disabled', 'validator', 'hidden')
|
rw_append = ('frozen', 'disabled', 'validator', 'hidden')
|
||||||
default_properties = set(('expire', 'validator'))
|
default_properties = ('expire', 'validator')
|
||||||
|
|
||||||
|
|
||||||
class _const:
|
class _const:
|
||||||
"""convenient class that emulates a module
|
"""convenient class that emulates a module
|
||||||
|
@ -159,13 +159,14 @@ class Property(object):
|
||||||
def append(self, propname):
|
def append(self, propname):
|
||||||
self._properties.add(propname)
|
self._properties.add(propname)
|
||||||
self._setting._set_properties(self._properties, self._opt)
|
self._setting._set_properties(self._properties, self._opt)
|
||||||
self._setting.context.cfgimpl_reset_cache()
|
|
||||||
|
|
||||||
def remove(self, propname):
|
def remove(self, propname):
|
||||||
if propname in self._properties:
|
if propname in self._properties:
|
||||||
self._properties.remove(propname)
|
self._properties.remove(propname)
|
||||||
self._setting._set_properties(self._properties, self._opt)
|
self._setting._set_properties(self._properties, self._opt)
|
||||||
self._setting.context.cfgimpl_reset_cache()
|
|
||||||
|
def reset(self):
|
||||||
|
self._setting.reset(opt=self._opt)
|
||||||
|
|
||||||
def __contains__(self, propname):
|
def __contains__(self, propname):
|
||||||
return propname in self._properties
|
return propname in self._properties
|
||||||
|
@ -204,16 +205,22 @@ class Setting(object):
|
||||||
def __setitem__(self, opt, value):
|
def __setitem__(self, opt, value):
|
||||||
raise ValueError('you must only append/remove properties')
|
raise ValueError('you must only append/remove properties')
|
||||||
|
|
||||||
def reset(self):
|
def reset(self, opt=None, all_properties=False):
|
||||||
|
if all_properties and opt:
|
||||||
|
raise ValueError(_('opt and all_properties must not be set '
|
||||||
|
'together in reset'))
|
||||||
|
if all_properties:
|
||||||
|
self._properties = {}
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
del(self._properties[None])
|
del(self._properties[opt])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
self.context.cfgimpl_reset_cache()
|
self.context.cfgimpl_reset_cache()
|
||||||
|
|
||||||
def _get_properties(self, opt=None, is_apply_req=True):
|
def _get_properties(self, opt=None, is_apply_req=True):
|
||||||
if opt is None:
|
if opt is None:
|
||||||
props = self._properties.get(opt, copy(default_properties))
|
props = self._properties.get(opt, set(default_properties))
|
||||||
else:
|
else:
|
||||||
exp = None
|
exp = None
|
||||||
if opt in self._cache:
|
if opt in self._cache:
|
||||||
|
@ -223,7 +230,7 @@ class Setting(object):
|
||||||
return props
|
return props
|
||||||
if is_apply_req:
|
if is_apply_req:
|
||||||
self.apply_requires(opt)
|
self.apply_requires(opt)
|
||||||
props = self._properties.get(opt, opt._properties)
|
props = self._properties.get(opt, set(opt._properties))
|
||||||
self._set_cache(opt, props, exp)
|
self._set_cache(opt, props, exp)
|
||||||
return props
|
return props
|
||||||
|
|
||||||
|
@ -242,11 +249,12 @@ class Setting(object):
|
||||||
if opt is None:
|
if opt is None:
|
||||||
self._properties[opt] = properties
|
self._properties[opt] = properties
|
||||||
else:
|
else:
|
||||||
if opt._properties == properties:
|
if set(opt._properties) == properties:
|
||||||
if opt in self._properties:
|
if opt in self._properties:
|
||||||
del(self._properties[opt])
|
del(self._properties[opt])
|
||||||
else:
|
else:
|
||||||
self._properties[opt] = properties
|
self._properties[opt] = properties
|
||||||
|
self.context.cfgimpl_reset_cache()
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
def validate_properties(self, opt_or_descr, is_descr, is_write,
|
def validate_properties(self, opt_or_descr, is_descr, is_write,
|
||||||
|
|
Loading…
Reference in a new issue