Merge branch 'master' into orm
authorEmmanuel Garette <egarette@cadoles.com>
Thu, 12 Dec 2013 16:50:42 +0000 (17:50 +0100)
committerEmmanuel Garette <egarette@cadoles.com>
Thu, 12 Dec 2013 16:50:42 +0000 (17:50 +0100)
Conflicts:
test/test_config.py
tiramisu/autolib.py
tiramisu/option.py
tiramisu/value.py

1  2 
test/test_config.py
test/test_option_calculation.py
test/test_option_consistency.py
test/test_requires.py
tiramisu/autolib.py
tiramisu/config.py
tiramisu/option.py
tiramisu/setting.py
tiramisu/value.py

@@@ -142,9 -144,9 +144,10 @@@ def test_information_config()
      config.impl_set_information('info', string)
      assert config.impl_get_information('info') == string
      raises(ValueError, "config.impl_get_information('noinfo')")
+     assert config.impl_get_information('noinfo', 'default') == 'default'
  
  
 +#FIXME test impl_get_xxx pour OD ou ne pas cacher
  def test_config_impl_get_path_by_opt():
      descr = make_description()
      config = Config(descr)
@@@ -226,15 -231,13 +232,16 @@@ def test_duplicated_option()
      g1 = IntOption('g1', '', 1)
      #in same OptionDescription
      raises(ConflictError, "d1 = OptionDescription('od', '', [g1, g1])")
 +
 +
 +def test_duplicated_option_diff_od():
 +    g1 = IntOption('g1', '', 1)
      d1 = OptionDescription('od1', '', [g1])
 -    d2 = OptionDescription('od2', '', [g1])
 -    root = OptionDescription('root', '', [d1, d2])
      #in different OptionDescription
 -    raises(ConflictError, "config = Config(root)")
 +    raises(ConflictError, "d2 = OptionDescription('od2', '', [g1])")
 +
  
  def test_cannot_assign_value_to_option_description():
      descr = make_description()
      cfg = Config(descr)
Simple merge
Simple merge
@@@ -489,21 -503,26 +503,26 @@@ def test_requires_multi_disabled_invers
          assert props == ['disabled']
  
  
 -def test_requires_requirement_append():
 -    a = BoolOption('activate_service', '', True)
 -    b = IPOption('ip_address_service', '',
 -                 requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
 -    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_requirement_append():
 +#    a = BoolOption('activate_service', '', True)
 +#    b = IPOption('ip_address_service', '',
 +#                 requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
 +#    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_different_inverse():
+     a = BoolOption('activate_service', '', True)
+     raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])")
  def test_requires_recursive_path():
      a = BoolOption('activate_service', '', True)
      b = IPOption('ip_address_service', '',
@@@ -28,7 -29,7 +29,8 @@@ def carry_out_calculation(option, confi
                            index=None, max_len=None):
      """a function that carries out a calculation for an option's value
  
 +    :param name: the option name (`opt.impl_getname()`)
+     :param name: the option
      :param config: the context config in order to have
                     the whole options available
      :param callback: the name of the callback function
Simple merge
@@@ -608,36 -400,19 +606,36 @@@ class Option(BaseOption)
  
          def val_validator(val):
              if self._validator is not None:
 -                if self._validator[1] is not None:
 -                    validator_params = deepcopy(self._validator[1])
 -                    if '' in validator_params:
 -                        lst = list(validator_params[''])
 -                        lst.insert(0, val)
 -                        validator_params[''] = tuple(lst)
 -                    else:
 -                        validator_params[''] = (val,)
 +                class FakeCallbackParamOption(object):
 +                    def __init__(self, option=None,
 +                                 force_permissive=None,
 +                                 value=None):
 +                        self.option = option
 +                        self.force_permissive = force_permissive
 +                        self.value = value
 +
 +                class FakeCallbackParam(object):
 +                    def __init__(self, key, params):
 +                        self.name = key
 +                        self.params = params
 +                if self._validator_params != []:
 +                    validator_params = []
 +                    validator_params_option = [FakeCallbackParamOption(value=val)]
 +                    #if '' in self._validator_params:
 +                    #    for param in self._validator_params['']:
 +                    #        if isinstance(param, tuple):
 +                    #            validator_params_option.append(FakeCallbackParamOption(option=param[0], force_permissive=param[1]))
 +                    #        else:
 +                    #            validator_params_option.append(FakeCallbackParamOption(value=param))
 +                    validator_params.append(FakeCallbackParam('', validator_params_option))
 +                    for key in self._validator_params:
 +                        if key.name != '':
 +                            validator_params.append(key)
                  else:
 -                    validator_params = {'': (val,)}
 +                    validator_params = (FakeCallbackParam('', (FakeCallbackParamOption(value=val),)),)
                  # Raise ValueError if not valid
-                 carry_out_calculation(self.impl_getname(), config=context,
+                 carry_out_calculation(self, config=context,
 -                                      callback=self._validator[0],
 +                                      callback=self._validator,
                                        callback_params=validator_params)
  
          def do_validation(_value, _index=None):
              do_validation(value, force_index)
          else:
              if not isinstance(value, list):
-                 raise ValueError(_("which must be a list").format(value,
-                                                                   self.impl_getname()))
 -                raise ValueError(_("invalid value {0} for option {1} which must be a list").format(value, self._name))
++                raise ValueError(_("invalid value {0} for option {1} which must be a list").format(value, self.impl_getname()))
              for index, val in enumerate(value):
                  do_validation(val, index)
  
@@@ -1525,15 -1245,14 +1525,14 @@@ class OptionDescription(BaseOption)
          :param group_type: an instance of `GroupType` or `MasterGroupType`
                                that lives in `setting.groups`
          """
 -        if self._group_type != groups.default:
 +        if self._optiondescription_group_type != groups.default:
              raise TypeError(_('cannot change group_type if already set '
 -                            '(old {0}, new {1})').format(self._group_type,
 +                            '(old {0}, new {1})').format(self._optiondescription_group_type,
                                                           group_type))
          if isinstance(group_type, groups.GroupType):
 -            self._group_type = group_type
 +            self._optiondescription_group_type = group_type
              if isinstance(group_type, groups.MasterGroupType):
                  #if master (same name has group) is set
-                 identical_master_child_name = False
                  #for collect all slaves
                  slaves = []
                  master = None
                          raise ValueError(_("not allowed option {0} "
                                           "in group {1}"
                                           ": this option is not a multi"
 -                                         "").format(child._name, self._name))
 -                    if child._name == self._name:
 +                                         "").format(child.impl_getname(), self.impl_getname()))
-                     if child.impl_getname() == self.impl_getname():
-                         identical_master_child_name = True
++                    if child._name == self.impl_getname():
                          child._multitype = multitypes.master
                          master = child
                      else:
                  if master is None:
                      raise ValueError(_('master group with wrong'
                                         ' master name for {0}'
 -                                       ).format(self._name))
 +                                       ).format(self.impl_getname()))
+                 if master._callback is not None and master._callback[1] is not None:
+                     for key, callbacks in master._callback[1].items():
+                         for callbk in callbacks:
+                             if isinstance(callbk, tuple):
+                                 if callbk[0] in slaves:
+                                     raise ValueError(_("callback of master's option shall "
+                                                        "not refered a slave's ones"))
                  master._master_slaves = tuple(slaves)
                  for child in self.impl_getchildren():
                      if child != master:
Simple merge
@@@ -134,10 -134,10 +134,10 @@@ class Values(object)
          :type index: int
          :returns: a calculated value
          """
 -        callback, callback_params = opt._callback
 +        callback, callback_params = opt.impl_get_callback()
          if callback_params is None:
              callback_params = {}
-         return carry_out_calculation(opt.impl_getname(), config=self.context(),
+         return carry_out_calculation(opt, config=self.context(),
                                       callback=callback,
                                       callback_params=callback_params,
                                       index=index, max_len=max_len)
@@@ -468,10 -467,10 +467,10 @@@ class Multi(list)
          if not force:
              if self.opt.impl_get_multitype() == multitypes.slave:
                  raise SlaveError(_("cannot append a value on a multi option {0}"
 -                                   " which is a slave").format(self.opt._name))
 +                                   " which is a slave").format(self.opt.impl_getname()))
              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):