pass force_properties to value's _setitem and remove config's setoption
authorEmmanuel Garette <egarette@cadoles.com>
Wed, 17 Apr 2013 21:19:53 +0000 (23:19 +0200)
committerEmmanuel Garette <egarette@cadoles.com>
Wed, 17 Apr 2013 21:19:53 +0000 (23:19 +0200)
test/test_option_consistency.py
test/test_option_setting.py
test/test_option_type.py
tiramisu/config.py
tiramisu/value.py

index 735724f..c8699a4 100644 (file)
@@ -245,7 +245,7 @@ def test_has_callback():
     setting.add_property('frozen', dummy)
     raises(PropertiesOptionError, "config.gc.dummy = True")
 
-def test_freeze_and_has_callback_with_setoption():
+def test_freeze_and_has_callback():
     descr = make_description_callback()
     config = Config(descr)
     setting = config.cfgimpl_get_settings()
@@ -254,5 +254,5 @@ def test_freeze_and_has_callback_with_setoption():
     config.cfgimpl_get_settings().enable_property('freeze')
     dummy = config.unwrap_from_path('gc.dummy')
     config.cfgimpl_get_settings().add_property('frozen', dummy)
-    raises(PropertiesOptionError, "config.gc.setoption('dummy', descr.gc.dummy, True)")
+    raises(PropertiesOptionError, "config.gc.dummy = True")
 #____________________________________________________________
index 924d68e..aa5e674 100644 (file)
@@ -398,8 +398,7 @@ def test_allow_multiple_changes_from_config():
     suboption = OptionDescription("bip", "", [s2])
     descr = OptionDescription("options", "", [s, suboption])
     config = Config(descr)
-    config.setoption("string", s, 'blah')
-    config.setoption("string", s, "oh")
+    config.string = "oh"
     assert config.string == "oh"
     config.set(string2='blah')
     assert config.bip.string2 == 'blah'
index 12a777d..6ecd73e 100644 (file)
@@ -13,7 +13,7 @@ def make_description():
     gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
     gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),))
     objspaceoption = ChoiceOption('objspace', 'Object space',
-                                  ('std', 'thunk'), 'std')
+                                  ('std', 'thunk'), ['std'], multi=True)
     booloption = BoolOption('bool', 'Test boolean option', default=True)
     intoption = IntOption('int', 'Test int option', default=0)
     floatoption = FloatOption('float', 'Test float option', default=2.3)
@@ -68,7 +68,33 @@ def test_group_is_hidden():
     assert not config.cfgimpl_get_settings().has_property('hidden', gc)
     assert config.gc.float == 2.3
     #dummy est en hide
-    raises(PropertiesOptionError, "config.gc.dummy == False")
+    prop = []
+    try:
+        config.gc.dummy = False
+    except PropertiesOptionError, err:
+        prop = err.proptype
+    assert 'hidden' in prop
+
+
+def test_group_is_hidden_multi():
+    descr = make_description()
+    config = Config(descr)
+    setting = config.cfgimpl_get_settings()
+    setting.read_write()
+    obj = config.unwrap_from_path('objspace')
+    objspace = config.objspace
+    config.cfgimpl_get_settings().add_property('hidden', obj)
+    raises(PropertiesOptionError, "config.objspace")
+    assert config.cfgimpl_get_settings().has_property('hidden', obj)
+    prop = []
+    try:
+        objspace.append('std')
+    except PropertiesOptionError, err:
+        prop = err.proptype
+    assert 'hidden' in prop
+    config.cfgimpl_get_settings().del_property('hidden', obj)
+    assert not config.cfgimpl_get_settings().has_property('hidden', obj)
+    config.objspace.append('std')
 
 
 def test_global_show():
index f689914..add91b2 100644 (file)
@@ -23,7 +23,7 @@
 #from inspect import getmembers, ismethod
 from tiramisu.error import PropertiesOptionError, ConflictOptionError
 from tiramisu.option import OptionDescription, Option, SymLinkOption
-from tiramisu.setting import groups, Setting, apply_requires
+from tiramisu.setting import groups, Setting
 from tiramisu.value import Values
 from tiramisu.i18n import _
 
@@ -78,7 +78,8 @@ class SubConfig(object):
             return homeconfig.__setattr__(name, value)
         child = getattr(self._cfgimpl_descr, name)
         if type(child) != SymLinkOption:
-            self.setoption(name, child, value, force_permissive)
+            self.cfgimpl_get_values()._setitem(child, value,
+                                               force_permissive=force_permissive)
         else:
             child.setoption(self.cfgimpl_get_context(), value)
 
@@ -127,22 +128,10 @@ class SubConfig(object):
                                                                 name))
             return SubConfig(opt_or_descr, self._cfgimpl_context)
         else:
-            value = self.cfgimpl_get_values()._getitem(opt_or_descr,
-                                                       validate=validate,
-                                                       force_properties=force_properties,
-                                                       force_permissive=force_permissive)
-            return value
-
-    def setoption(self, name, child, value, force_permissive=False):
-        """effectively modifies the value of an Option()
-        (typically called by the __setattr__)
-        """
-        #needed ?
-        apply_requires(child, self)
-        if child not in self._cfgimpl_descr._children[1]:
-            raise AttributeError(_('unknown option {0}').format(name))
-
-        self.cfgimpl_get_values()[child] = value
+            return self.cfgimpl_get_values()._getitem(opt_or_descr,
+                                                      validate=validate,
+                                                      force_properties=force_properties,
+                                                      force_permissive=force_permissive)
 
     def cfgimpl_get_home_by_path(self, path, force_permissive=False, force_properties=None):
         """:returns: tuple (config, name)"""
@@ -399,7 +388,7 @@ class Config(SubConfig):
                 #except PropertiesOptionError, e:
                 #    raise e  # HiddenOptionError or DisabledOptionError
                 child = getattr(homeconfig._cfgimpl_descr, name)
-                homeconfig.setoption(name, child, value)
+                self.cfgimpl_get_values()[child] = value
             elif len(candidates) > 1:
                 raise ConflictOptionError(
                     _('more than one option that ends with {}').format(key))
index f039e77..5709c4a 100644 (file)
@@ -144,10 +144,9 @@ class Values(object):
         return value
 
     def __setitem__(self, opt, value):
-        #valid config
-        #FIXME:
-        force_permissive = False
-        force_properties = None
+        self._setitem(opt, value)
+
+    def _setitem(self, opt, value, force_permissive=False, force_properties=None):
         setting = self.context.cfgimpl_get_settings()
         setting.validate_properties(opt, False, True,
                                     value=value, force_permissive=force_permissive,