pass force_properties to value's _setitem and remove config's setoption

This commit is contained in:
Emmanuel Garette 2013-04-17 23:19:53 +02:00
parent 5e67522f91
commit d5e1cb6576
5 changed files with 42 additions and 29 deletions

View File

@ -245,7 +245,7 @@ def test_has_callback():
setting.add_property('frozen', dummy) setting.add_property('frozen', dummy)
raises(PropertiesOptionError, "config.gc.dummy = True") raises(PropertiesOptionError, "config.gc.dummy = True")
def test_freeze_and_has_callback_with_setoption(): def test_freeze_and_has_callback():
descr = make_description_callback() descr = make_description_callback()
config = Config(descr) config = Config(descr)
setting = config.cfgimpl_get_settings() setting = config.cfgimpl_get_settings()
@ -254,5 +254,5 @@ def test_freeze_and_has_callback_with_setoption():
config.cfgimpl_get_settings().enable_property('freeze') config.cfgimpl_get_settings().enable_property('freeze')
dummy = config.unwrap_from_path('gc.dummy') dummy = config.unwrap_from_path('gc.dummy')
config.cfgimpl_get_settings().add_property('frozen', 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")
#____________________________________________________________ #____________________________________________________________

View File

@ -398,8 +398,7 @@ def test_allow_multiple_changes_from_config():
suboption = OptionDescription("bip", "", [s2]) suboption = OptionDescription("bip", "", [s2])
descr = OptionDescription("options", "", [s, suboption]) descr = OptionDescription("options", "", [s, suboption])
config = Config(descr) config = Config(descr)
config.setoption("string", s, 'blah') config.string = "oh"
config.setoption("string", s, "oh")
assert config.string == "oh" assert config.string == "oh"
config.set(string2='blah') config.set(string2='blah')
assert config.bip.string2 == 'blah' assert config.bip.string2 == 'blah'

View File

@ -13,7 +13,7 @@ def make_description():
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref') gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),)) gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),))
objspaceoption = ChoiceOption('objspace', 'Object space', objspaceoption = ChoiceOption('objspace', 'Object space',
('std', 'thunk'), 'std') ('std', 'thunk'), ['std'], multi=True)
booloption = BoolOption('bool', 'Test boolean option', default=True) booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
floatoption = FloatOption('float', 'Test float option', default=2.3) 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 not config.cfgimpl_get_settings().has_property('hidden', gc)
assert config.gc.float == 2.3 assert config.gc.float == 2.3
#dummy est en hide #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(): def test_global_show():

View File

@ -23,7 +23,7 @@
#from inspect import getmembers, ismethod #from inspect import getmembers, ismethod
from tiramisu.error import PropertiesOptionError, ConflictOptionError from tiramisu.error import PropertiesOptionError, ConflictOptionError
from tiramisu.option import OptionDescription, Option, SymLinkOption 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.value import Values
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -78,7 +78,8 @@ class SubConfig(object):
return homeconfig.__setattr__(name, value) return homeconfig.__setattr__(name, value)
child = getattr(self._cfgimpl_descr, name) child = getattr(self._cfgimpl_descr, name)
if type(child) != SymLinkOption: if type(child) != SymLinkOption:
self.setoption(name, child, value, force_permissive) self.cfgimpl_get_values()._setitem(child, value,
force_permissive=force_permissive)
else: else:
child.setoption(self.cfgimpl_get_context(), value) child.setoption(self.cfgimpl_get_context(), value)
@ -127,22 +128,10 @@ class SubConfig(object):
name)) name))
return SubConfig(opt_or_descr, self._cfgimpl_context) return SubConfig(opt_or_descr, self._cfgimpl_context)
else: else:
value = self.cfgimpl_get_values()._getitem(opt_or_descr, return self.cfgimpl_get_values()._getitem(opt_or_descr,
validate=validate, validate=validate,
force_properties=force_properties, force_properties=force_properties,
force_permissive=force_permissive) 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
def cfgimpl_get_home_by_path(self, path, force_permissive=False, force_properties=None): def cfgimpl_get_home_by_path(self, path, force_permissive=False, force_properties=None):
""":returns: tuple (config, name)""" """:returns: tuple (config, name)"""
@ -399,7 +388,7 @@ class Config(SubConfig):
#except PropertiesOptionError, e: #except PropertiesOptionError, e:
# raise e # HiddenOptionError or DisabledOptionError # raise e # HiddenOptionError or DisabledOptionError
child = getattr(homeconfig._cfgimpl_descr, name) child = getattr(homeconfig._cfgimpl_descr, name)
homeconfig.setoption(name, child, value) self.cfgimpl_get_values()[child] = value
elif len(candidates) > 1: elif len(candidates) > 1:
raise ConflictOptionError( raise ConflictOptionError(
_('more than one option that ends with {}').format(key)) _('more than one option that ends with {}').format(key))

View File

@ -144,10 +144,9 @@ class Values(object):
return value return value
def __setitem__(self, opt, value): def __setitem__(self, opt, value):
#valid config self._setitem(opt, value)
#FIXME:
force_permissive = False def _setitem(self, opt, value, force_permissive=False, force_properties=None):
force_properties = None
setting = self.context.cfgimpl_get_settings() setting = self.context.cfgimpl_get_settings()
setting.validate_properties(opt, False, True, setting.validate_properties(opt, False, True,
value=value, force_permissive=force_permissive, value=value, force_permissive=force_permissive,