add _path in reset for performance + more tests
authorEmmanuel Garette <egarette@cadoles.com>
Sat, 24 Aug 2013 14:30:46 +0000 (16:30 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Sat, 24 Aug 2013 14:30:46 +0000 (16:30 +0200)
test/test_option_setting.py
test/test_requires.py
tiramisu/setting.py

index 70332d2..a181941 100644 (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)')
     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():
 
 
 def test_reset_multiple():
index 899c1c3..804c767 100644 (file)
@@ -438,7 +438,12 @@ def test_requires_requirement_append():
     od = OptionDescription('service', '', [a, b])
     c = Config(od)
     c.read_write()
     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")')
     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():
 
 
 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')
     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",)')
index 852e833..25e9485 100644 (file)
@@ -175,7 +175,7 @@ class Property(object):
             self._setting._setproperties(self._properties, self._opt, self._path)
 
     def reset(self):
             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
 
     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):
         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):
         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 __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:
             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):
         self.context.cfgimpl_reset_cache()
 
     def _getproperties(self, opt=None, path=None, is_apply_req=True):