add _path in reset for performance + more tests

This commit is contained in:
Emmanuel Garette 2013-08-24 16:30:46 +02:00
parent 5beade8b2c
commit c2b16d2605
3 changed files with 37 additions and 12 deletions

View File

@ -345,6 +345,10 @@ def test_reset_properties():
setting.reset(all_properties=True)
assert setting._p_.get_properties(cfg) == {}
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
a = descr.wantref
setting[a].append('test')
setting[a].reset()
def test_reset_multiple():

View File

@ -438,7 +438,12 @@ def test_requires_requirement_append():
od = OptionDescription('service', '', [a, b])
c = Config(od)
c.read_write()
str(c.cfgimpl_get_settings())
str(c.cfgimpl_get_settings()[b])
raises(ValueError, 'c.cfgimpl_get_settings()[b].append("disabled")')
c.activate_service = False
# disabled is now set, test to remove disabled before store in storage
c.cfgimpl_get_settings()[b].append("test")
def test_requires_recursive_path():
@ -450,3 +455,24 @@ def test_requires_recursive_path():
c = Config(od)
c.read_write()
raises(RequirementError, 'c.service.a')
def test_get_properties_with_None_path():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('base', '', [od1])
c = Config(od)
c.read_write()
raises(ValueError, "c.cfgimpl_get_settings()._getproperties(a)")
def test_set_item():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '')
od1 = OptionDescription('service', '', [a, b])
od = OptionDescription('base', '', [od1])
c = Config(od)
c.read_write()
raises(ValueError, 'c.cfgimpl_get_settings()[a] = ("test",)')

View File

@ -175,7 +175,7 @@ class Property(object):
self._setting._setproperties(self._properties, self._opt, self._path)
def reset(self):
self._setting.reset(path=self._path)
self._setting.reset(_path=self._path)
def __contains__(self, propname):
return propname in self._properties
@ -216,10 +216,7 @@ class Settings(object):
return str(list(self._getproperties()))
def __getitem__(self, opt):
if opt is None:
path = None
else:
path = self._get_opt_path(opt)
path = self._get_opt_path(opt)
return self._getitem(opt, path)
def _getitem(self, opt, path):
@ -228,18 +225,16 @@ class Settings(object):
def __setitem__(self, opt, value):
raise ValueError('you must only append/remove properties')
def reset(self, opt=None, all_properties=False):
if all_properties and opt:
def reset(self, opt=None, _path=None, all_properties=False):
if all_properties and (_path or opt):
raise ValueError(_('opt and all_properties must not be set '
'together in reset'))
if all_properties:
self._p_.reset_all_propertives()
else:
if opt is None:
path = None
else:
path = self._get_opt_path(opt)
self._p_.reset_properties(path)
if opt is not None and _path is None:
_path = self._get_opt_path(opt)
self._p_.reset_properties(_path)
self.context.cfgimpl_reset_cache()
def _getproperties(self, opt=None, path=None, is_apply_req=True):