From c2b16d2605d09f366bca482b498b9675deadc552 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 24 Aug 2013 16:30:46 +0200 Subject: [PATCH] add _path in reset for performance + more tests --- test/test_option_setting.py | 4 ++++ test/test_requires.py | 26 ++++++++++++++++++++++++++ tiramisu/setting.py | 19 +++++++------------ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 70332d2..a181941 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -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(): diff --git a/test/test_requires.py b/test/test_requires.py index 899c1c3..804c767 100644 --- a/test/test_requires.py +++ b/test/test_requires.py @@ -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",)') diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 852e833..25e9485 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -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):