opt.hidden and opt.disabled is replaced by opt.properties

This commit is contained in:
gwen 2012-08-13 12:49:58 +02:00
parent 1d5330f15e
commit 753b0a55c7
8 changed files with 55 additions and 49 deletions

View file

@ -156,8 +156,8 @@ def test_hidden_if_in():
stroption = cfg.unwrap_from_path('str')
assert not stroption._is_hidden()
cfg.int = 1
raises(HiddenOptionError, "cfg.str")
raises(HiddenOptionError, 'cfg.str= "uvw"')
raises(PropertiesOptionError, "cfg.str")
raises(PropertiesOptionError, 'cfg.str= "uvw"')
assert stroption._is_hidden()
def test_hidden_if_in_with_group():
@ -178,8 +178,7 @@ def test_hidden_if_in_with_group():
cfg = Config(descr)
assert not gcgroup._is_hidden()
cfg.int = 1
raises(HiddenOptionError, "cfg.gc.name")
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
raises(PropertiesOptionError, "cfg.gc.name")
assert gcgroup._is_hidden()
def test_disabled_with_group():
@ -200,8 +199,7 @@ def test_disabled_with_group():
cfg = Config(descr)
assert not gcgroup._is_disabled()
cfg.int = 1
raises(DisabledOptionError, "cfg.gc.name")
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
raises(PropertiesOptionError, "cfg.gc.name")
assert gcgroup._is_disabled()

View file

@ -91,7 +91,7 @@ def test_auto_owner():
descr = make_description()
config = Config(descr, bool=False)
config.gc.setoption('dummy', True, 'auto')
raises(HiddenOptionError, "config.gc.dummy")
raises(PropertiesOptionError, "config.gc.dummy")
raises(ConflictConfigError, "config.gc.setoption('dummy', False, 'auto')")
# shall return an auto value...
#assert config.gc.dummy == 'auto_dummy_value'

View file

@ -130,7 +130,7 @@ def test_multi_with_requires():
config = Config(descr)
assert stroption._is_hidden() == False
config.int = 1
raises(HiddenOptionError, "config.str = ['a', 'b']")
raises(PropertiesOptionError, "config.str = ['a', 'b']")
assert stroption._is_hidden()
def test__requires_with_inverted():
@ -155,7 +155,7 @@ def test_multi_with_requires_in_another_group():
config = Config(descr2)
assert stroption._is_hidden() == False
config.int = 1
raises(HiddenOptionError, "config.opt.str = ['a', 'b']")
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
assert stroption._is_hidden()
def test_apply_requires_from_config():
@ -204,7 +204,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
config = Config(descr2)
assert stroption._is_disabled() == False
config.int = 1
raises(DisabledOptionError, "config.opt.str = ['a', 'b']")
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
assert stroption._is_disabled()
def test_multi_with_requires_that_is_multi():
@ -216,7 +216,7 @@ def test_multi_with_requires_that_is_multi():
config = Config(descr)
assert stroption._is_hidden() == False
config.int = [1, 1]
raises(HiddenOptionError, "config.str = ['a', 'b']")
raises(PropertiesOptionError, "config.str = ['a', 'b']")
assert stroption._is_hidden()
def test_multi_with_bool():
@ -292,7 +292,7 @@ def test_set_with_hidden_option():
IntOption("int", "", default=42)])
d = {'s1.a': True, 'int': 23}
config = Config(descr)
raises(HiddenOptionError, "config.set(**d)")
raises(PropertiesOptionError, "config.set(**d)")
def test_set_with_unknown_option():
boolopt = BoolOption("b", "", default=False)
@ -406,5 +406,5 @@ def test_access_by_get_whith_hide():
BoolOption("d1", ""),
])
c = Config(descr)
raises(HiddenOptionError, "c.get('b1')")
raises(PropertiesOptionError, "c.get('b1')")

View file

@ -89,9 +89,9 @@ def test_is_hidden():
config = Config(descr)
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
# setattr
raises(HiddenOptionError, "config.gc.dummy == False")
raises(PropertiesOptionError, "config.gc.dummy == False")
# getattr
raises(HiddenOptionError, "config.gc.dummy")
raises(PropertiesOptionError, "config.gc.dummy")
# I want to access to this option anyway
path = 'gc.dummy'
homeconfig, name = config._cfgimpl_get_home_by_path(path)
@ -103,21 +103,21 @@ def test_group_is_hidden():
gc = config.unwrap_from_path('gc')
gc.hide()
dummy = config.unwrap_from_path('gc.dummy')
raises(HiddenOptionError, "config.gc.dummy")
raises(PropertiesOptionError, "config.gc.dummy")
assert gc._is_hidden()
raises(HiddenOptionError, "config.gc.float")
raises(PropertiesOptionError, "config.gc.float")
# manually set the subconfigs to "show"
gc.show()
assert gc._is_hidden() == False
assert config.gc.float == 2.3
#dummy est en hide
raises(HiddenOptionError, "config.gc.dummy == False")
raises(PropertiesOptionError, "config.gc.dummy == False")
def test_global_show():
descr = make_description()
config = Config(descr)
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
raises(HiddenOptionError, "config.gc.dummy == False")
raises(PropertiesOptionError, "config.gc.dummy == False")
def test_with_many_subgroups():
descr = make_description()

View file

@ -19,7 +19,7 @@
# the whole pypy projet is under MIT licence
# ____________________________________________________________
"enables us to carry out a calculation and return an option's value"
from tiramisu.error import DisabledOptionError, SpecialOwnersError
from tiramisu.error import PropertiesOptionError, SpecialOwnersError
# ____________________________________________________________
# automatic Option object
special_owners = ['auto', 'fill']
@ -45,10 +45,10 @@ def calc_factory(name, callback, callback_params, config):
try:
opt_value = getattr(config, path)
opt = config.unwrap_from_path(path)
except DisabledOptionError, e:
except PropertiesOptionError, e:
if chek_disabled:
continue
raise DisabledOptionError(e)
raise PropertiesOptionError(e)
is_multi = opt.is_multi()
if is_multi:
if opt_value != None:

View file

@ -21,7 +21,11 @@
# the whole pypy projet is under MIT licence
# ____________________________________________________________
class HiddenBaseType(object):
class BaseType(object):
def has_properties(self):
return bool(len(self.properties))
class HiddenBaseType(BaseType):
def hide(self):
if not 'hidden' in self.properties:
self.properties.append('hidden')
@ -32,7 +36,7 @@ class HiddenBaseType(object):
# dangerous method: how an Option() can determine its status by itself ?
return 'hidden' in self.properties
class DisabledBaseType(object):
class DisabledBaseType(BaseType):
def disable(self):
if not 'disabled' in self.properties:
self.properties.append('disabled')

View file

@ -21,9 +21,9 @@
# the whole pypy projet is under MIT licence
# ____________________________________________________________
from copy import copy
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
from tiramisu.error import (PropertiesOptionError, ConfigError, NotFoundError,
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
SpecialOwnersError, MandatoryError, MethodCallError, DisabledOptionError)
SpecialOwnersError, MandatoryError, MethodCallError)
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
group_types, Multi, apply_requires)
from tiramisu.autolib import special_owners, special_owner_factory
@ -32,8 +32,7 @@ from tiramisu.autolib import special_owners, special_owner_factory
default_owner = 'user'
# ____________________________________________________________
class Config(object):
_cfgimpl_hidden = True
_cfgimpl_disabled = True
_cfgimpl_properties = ['hidden', 'disabled']
_cfgimpl_mandatory = True
_cfgimpl_frozen = False
_cfgimpl_owner = default_owner
@ -126,33 +125,40 @@ class Config(object):
if isinstance(child, OptionDescription):
self._cfgimpl_values[child._name].cfgimpl_set_owner(owner)
# ____________________________________________________________
def _cfgimpl_has_properties(self):
return bool(len(self._cfgimpl_properties))
def cfgimpl_hide(self):
if self._cfgimpl_parent != None:
raise MethodCallError("this method root_hide() shall not be"
"used with non-root Config() object")
rootconfig = self._cfgimpl_get_toplevel()
rootconfig._cfgimpl_hidden = True
if 'hidden' not in rootconfig._cfgimpl_properties:
rootconfig._cfgimpl_properties.append('hidden')
def cfgimpl_show(self):
if self._cfgimpl_parent != None:
raise MethodCallError("this method root_hide() shall not be"
"used with non-root Config() object")
rootconfig = self._cfgimpl_get_toplevel()
rootconfig._cfgimpl_hidden = False
# ____________________________________________________________
if 'hidden' in rootconfig._cfgimpl_properties:
rootconfig._cfgimpl_properties.remove('hidden')
def cfgimpl_disable(self):
if self._cfgimpl_parent != None:
raise MethodCallError("this method root_hide() shall not be"
"used with non-root Confit() object")
rootconfig = self._cfgimpl_get_toplevel()
rootconfig._cfgimpl_disabled = True
if 'disabled' not in rootconfig._cfgimpl_properties:
rootconfig._cfgimpl_properties.append('disabled')
def cfgimpl_enable(self):
if self._cfgimpl_parent != None:
raise MethodCallError("this method root_hide() shall not be"
"used with non-root Confit() object")
rootconfig = self._cfgimpl_get_toplevel()
rootconfig._cfgimpl_disabled = False
if 'disabled' in rootconfig._cfgimpl_properties:
rootconfig._cfgimpl_properties.remove('disabled')
# ____________________________________________________________
def __setattr__(self, name, value):
if '.' in name:
@ -172,16 +178,16 @@ class Config(object):
def _validate(self, name, opt_or_descr):
apply_requires(opt_or_descr, self)
if not type(opt_or_descr) == OptionDescription:
# hidden options
if self._cfgimpl_toplevel._cfgimpl_hidden and \
(opt_or_descr._is_hidden() or self._cfgimpl_descr._is_hidden()):
raise HiddenOptionError("trying to access to a hidden option:"
" {0}".format(name))
# disabled options
if self._cfgimpl_toplevel._cfgimpl_disabled and \
(opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()):
raise DisabledOptionError("this option is disabled:"
" {0}".format(name))
# hidden or disabled options
# XXX let's have a group with a hidden property
# and an option with a disabled property,
# then it matches anyway... is it important to fix this ?
if self._cfgimpl_toplevel._cfgimpl_has_properties() and \
(opt_or_descr.has_properties() or \
self._cfgimpl_descr.has_properties()):
raise PropertiesOptionError("trying to access to the option: {0} "
"with properties: {1}".format(name,
str(opt_or_descr.properties)))
def __getattr__(self, name):
# attribute access by passing a path,
@ -500,7 +506,7 @@ class Config(object):
def getpaths(self, include_groups=False, allpaths=False, mandatory=False):
"""returns a list of all paths in self, recursively, taking care of
the context (hidden/disabled)
the context of properties (hidden/disabled)
"""
paths = []
for path in self._cfgimpl_descr.getpaths(include_groups=include_groups):
@ -528,7 +534,7 @@ def make_dict(config, flatten=False):
value = getattr(config, path)
pathsvalues.append((pathname, value))
except:
pass # this just a hidden or disabled option
pass # this just a hidden or disabled option
options = dict(pathsvalues)
return options

View file

@ -6,10 +6,8 @@ class ConfigError(Exception):
pass
class ConflictConfigError(ConfigError):
pass
class HiddenOptionError(AttributeError):
class PropertiesOptionError(AttributeError):
pass
class DisabledOptionError(AttributeError):
pass
class NotFoundError(Exception):
pass
class MethodCallError(Exception):