can make_dict with disabled suboption
authorEmmanuel Garette <egarette@cadoles.com>
Wed, 12 Mar 2014 13:57:36 +0000 (14:57 +0100)
committerEmmanuel Garette <egarette@cadoles.com>
Wed, 12 Mar 2014 13:57:36 +0000 (14:57 +0100)
test/test_config_api.py
tiramisu/config.py

index 4be9e80..93f8c95 100644 (file)
@@ -115,6 +115,18 @@ def test_make_dict():
     raises(ValueError, 'd2 = config.make_dict(withvalue="3")')
 
 
+def test_make_dict_with_disabled():
+    descr = OptionDescription("opt", "", [
+        OptionDescription("s1", "", [
+            BoolOption("a", "", default=False),
+            BoolOption("b", "", default=False, properties=('disabled',))]),
+        IntOption("int", "", default=42)])
+    config = Config(descr)
+    config.read_only()
+    d = config.make_dict()
+    assert d == {"s1.a": False, "int": 42}
+
+
 def test_find_in_config():
     "finds option in config"
     descr = make_description()
index c9fb992..4c59dbe 100644 (file)
@@ -448,17 +448,20 @@ class SubConfig(object):
         return pathsvalues
 
     def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
-        if isinstance(opt, OptionDescription):
-            pathsvalues += getattr(self, path).make_dict(flatten,
-                                                         _currpath +
-                                                         path.split('.'))
-        else:
-            value = self._getattr(opt._name)
-            if flatten:
-                name = opt._name
+        try:
+            if isinstance(opt, OptionDescription):
+                pathsvalues += getattr(self, path).make_dict(flatten,
+                                                             _currpath +
+                                                             path.split('.'))
             else:
-                name = '.'.join(_currpath + [opt._name])
-            pathsvalues.append((name, value))
+                value = self._getattr(opt._name)
+                if flatten:
+                    name = opt._name
+                else:
+                    name = '.'.join(_currpath + [opt._name])
+                pathsvalues.append((name, value))
+        except PropertiesOptionError:
+            pass
 
     def cfgimpl_get_path(self):
         descr = self.cfgimpl_get_description()