Important behavior change : to add default_multi value, now use Multi.append(), not...
authorEmmanuel Garette <egarette@cadoles.com>
Mon, 9 Dec 2013 16:59:39 +0000 (17:59 +0100)
committerEmmanuel Garette <egarette@cadoles.com>
Mon, 9 Dec 2013 16:59:39 +0000 (17:59 +0100)
test/test_config.py
test/test_option_calculation.py
tiramisu/setting.py
tiramisu/value.py

index f6f9fdf..6a4f6b4 100644 (file)
@@ -239,3 +239,18 @@ def test_cannot_assign_value_to_option_description():
     descr = make_description()
     cfg = Config(descr)
     raises(TypeError, "cfg.gc = 3")
+
+
+def test_config_multi():
+    i1 = IntOption('test1', '', multi=True)
+    i2 = IntOption('test2', '', multi=True, default_multi=1)
+    i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
+    od = OptionDescription('test', '', [i1, i2, i3])
+    config = Config(od)
+    assert config.test1 == []
+    assert config.test2 == []
+    config.test2.append()
+    assert config.test2 == [1]
+    assert config.test3 == [2]
+    config.test3.append()
+    assert config.test3 == [2, 1]
index 680303d..7994aa1 100644 (file)
@@ -393,7 +393,7 @@ def test_callback_master_and_slaves_master():
     cfg = Config(maconfig)
     cfg.read_write()
     assert cfg.val1.val1 == ['val']
-    cfg.val1.val1.append(None)
+    cfg.val1.val1.append()
     assert cfg.val1.val1 == ['val', 'val']
     assert cfg.val1.val2 == [None, None]
 
@@ -408,7 +408,7 @@ def test_callback_master_and_slaves_master_list():
     cfg.read_write()
     assert cfg.val1.val1 == ['val', 'val']
     assert cfg.val1.val2 == [None, None]
-    cfg.val1.val1.append(None)
+    cfg.val1.val1.append()
     assert cfg.val1.val1 == ['val', 'val', None]
     assert cfg.val1.val2 == [None, None, None]
     del(cfg.val1.val1)
index e8feae5..470ec94 100644 (file)
@@ -243,6 +243,12 @@ populate_multitypes()
 
 
 # ____________________________________________________________
+class Undefined():
+    pass
+
+
+undefined = Undefined()
+# ____________________________________________________________
 class Property(object):
     "a property is responsible of the option's value access rules"
     __slots__ = ('_setting', '_properties', '_opt', '_path')
index ed7d39d..8c50373 100644 (file)
@@ -22,7 +22,7 @@ from copy import copy
 import sys
 import weakref
 from tiramisu.error import ConfigError, SlaveError
-from tiramisu.setting import owners, multitypes, expires_time
+from tiramisu.setting import owners, multitypes, expires_time, undefined
 from tiramisu.autolib import carry_out_calculation
 from tiramisu.i18n import _
 from tiramisu.option import SymLinkOption
@@ -452,8 +452,7 @@ class Multi(list):
                                 values._getcallback_value(slave, index=index),
                                 force=True)
                         else:
-                            value_slave.append(slave.impl_getdefault_multi(),
-                                               force=True)
+                            value_slave.append(undefined, force=True)
 
     def __setitem__(self, index, value):
         self._validate(value, index)
@@ -461,7 +460,7 @@ class Multi(list):
         super(Multi, self).__setitem__(index, value)
         self.context().cfgimpl_get_values()._setvalue(self.opt, self.path, self)
 
-    def append(self, value, force=False):
+    def append(self, value=undefined, force=False):
         """the list value can be updated (appened)
         only if the option is a master
         """
@@ -471,12 +470,14 @@ class Multi(list):
                                    " which is a slave").format(self.opt._name))
             elif self.opt.impl_get_multitype() == multitypes.master:
                 values = self.context().cfgimpl_get_values()
-                if value is None and self.opt.impl_has_callback():
+                if value is undefined and self.opt.impl_has_callback():
                     value = values._getcallback_value(self.opt)
                     #Force None il return a list
                     if isinstance(value, list):
                         value = None
         index = self.__len__()
+        if value is undefined:
+            value = self.opt.impl_getdefault_multi()
         self._validate(value, index)
         super(Multi, self).append(value)
         self.context().cfgimpl_get_values()._setvalue(self.opt, self.path,