- 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
|
@ -308,3 +308,59 @@ def test_access_by_get_whith_hide():
|
|||
c = Config(descr)
|
||||
c.read_write()
|
||||
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):
|
||||
raise TypeError(_('invalid properties type {0} for {1},'
|
||||
' must be a tuple').format(type(properties), self._name))
|
||||
self._properties = set(properties) # 'hidden', 'disabled'...
|
||||
self._properties = properties # 'hidden', 'disabled'...
|
||||
|
||||
def __eq__(self, other):
|
||||
"Option comparison"
|
||||
|
@ -728,7 +728,7 @@ class OptionDescription(BaseInformation):
|
|||
if not isinstance(properties, tuple):
|
||||
raise TypeError(_('invalid properties type {0} for {1},'
|
||||
' 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
|
||||
self._group_type = groups.default
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ from tiramisu.error import RequirementError, PropertiesOptionError
|
|||
from tiramisu.i18n import _
|
||||
|
||||
default_encoding = 'utf-8'
|
||||
|
||||
expires_time = 5
|
||||
ro_remove = ('permissive', 'hidden')
|
||||
ro_append = ('frozen', 'disabled', 'validator', 'everything_frozen', 'mandatory')
|
||||
rw_remove = ('permissive', 'everything_frozen', 'mandatory')
|
||||
rw_append = ('frozen', 'disabled', 'validator', 'hidden')
|
||||
default_properties = set(('expire', 'validator'))
|
||||
default_properties = ('expire', 'validator')
|
||||
|
||||
|
||||
class _const:
|
||||
"""convenient class that emulates a module
|
||||
|
@ -159,13 +159,14 @@ class Property(object):
|
|||
def append(self, propname):
|
||||
self._properties.add(propname)
|
||||
self._setting._set_properties(self._properties, self._opt)
|
||||
self._setting.context.cfgimpl_reset_cache()
|
||||
|
||||
def remove(self, propname):
|
||||
if propname in self._properties:
|
||||
self._properties.remove(propname)
|
||||
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):
|
||||
return propname in self._properties
|
||||
|
@ -204,16 +205,22 @@ class Setting(object):
|
|||
def __setitem__(self, opt, value):
|
||||
raise ValueError('you must only append/remove properties')
|
||||
|
||||
def reset(self):
|
||||
try:
|
||||
del(self._properties[None])
|
||||
except KeyError:
|
||||
pass
|
||||
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:
|
||||
del(self._properties[opt])
|
||||
except KeyError:
|
||||
pass
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
def _get_properties(self, opt=None, is_apply_req=True):
|
||||
if opt is None:
|
||||
props = self._properties.get(opt, copy(default_properties))
|
||||
props = self._properties.get(opt, set(default_properties))
|
||||
else:
|
||||
exp = None
|
||||
if opt in self._cache:
|
||||
|
@ -223,7 +230,7 @@ class Setting(object):
|
|||
return props
|
||||
if is_apply_req:
|
||||
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)
|
||||
return props
|
||||
|
||||
|
@ -242,11 +249,12 @@ class Setting(object):
|
|||
if opt is None:
|
||||
self._properties[opt] = properties
|
||||
else:
|
||||
if opt._properties == properties:
|
||||
if set(opt._properties) == properties:
|
||||
if opt in self._properties:
|
||||
del(self._properties[opt])
|
||||
else:
|
||||
self._properties[opt] = properties
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
#____________________________________________________________
|
||||
def validate_properties(self, opt_or_descr, is_descr, is_write,
|
||||
|
|
Loading…
Reference in New Issue