opt.hidden and opt.disabled is replaced by opt.properties
This commit is contained in:
parent
1d5330f15e
commit
753b0a55c7
|
@ -156,8 +156,8 @@ def test_hidden_if_in():
|
||||||
stroption = cfg.unwrap_from_path('str')
|
stroption = cfg.unwrap_from_path('str')
|
||||||
assert not stroption._is_hidden()
|
assert not stroption._is_hidden()
|
||||||
cfg.int = 1
|
cfg.int = 1
|
||||||
raises(HiddenOptionError, "cfg.str")
|
raises(PropertiesOptionError, "cfg.str")
|
||||||
raises(HiddenOptionError, 'cfg.str= "uvw"')
|
raises(PropertiesOptionError, 'cfg.str= "uvw"')
|
||||||
assert stroption._is_hidden()
|
assert stroption._is_hidden()
|
||||||
|
|
||||||
def test_hidden_if_in_with_group():
|
def test_hidden_if_in_with_group():
|
||||||
|
@ -178,8 +178,7 @@ def test_hidden_if_in_with_group():
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
assert not gcgroup._is_hidden()
|
assert not gcgroup._is_hidden()
|
||||||
cfg.int = 1
|
cfg.int = 1
|
||||||
raises(HiddenOptionError, "cfg.gc.name")
|
raises(PropertiesOptionError, "cfg.gc.name")
|
||||||
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
|
|
||||||
assert gcgroup._is_hidden()
|
assert gcgroup._is_hidden()
|
||||||
|
|
||||||
def test_disabled_with_group():
|
def test_disabled_with_group():
|
||||||
|
@ -200,8 +199,7 @@ def test_disabled_with_group():
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
assert not gcgroup._is_disabled()
|
assert not gcgroup._is_disabled()
|
||||||
cfg.int = 1
|
cfg.int = 1
|
||||||
raises(DisabledOptionError, "cfg.gc.name")
|
raises(PropertiesOptionError, "cfg.gc.name")
|
||||||
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
|
|
||||||
assert gcgroup._is_disabled()
|
assert gcgroup._is_disabled()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ def test_auto_owner():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr, bool=False)
|
config = Config(descr, bool=False)
|
||||||
config.gc.setoption('dummy', True, 'auto')
|
config.gc.setoption('dummy', True, 'auto')
|
||||||
raises(HiddenOptionError, "config.gc.dummy")
|
raises(PropertiesOptionError, "config.gc.dummy")
|
||||||
raises(ConflictConfigError, "config.gc.setoption('dummy', False, 'auto')")
|
raises(ConflictConfigError, "config.gc.setoption('dummy', False, 'auto')")
|
||||||
# shall return an auto value...
|
# shall return an auto value...
|
||||||
#assert config.gc.dummy == 'auto_dummy_value'
|
#assert config.gc.dummy == 'auto_dummy_value'
|
||||||
|
|
|
@ -130,7 +130,7 @@ def test_multi_with_requires():
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert stroption._is_hidden() == False
|
assert stroption._is_hidden() == False
|
||||||
config.int = 1
|
config.int = 1
|
||||||
raises(HiddenOptionError, "config.str = ['a', 'b']")
|
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||||
assert stroption._is_hidden()
|
assert stroption._is_hidden()
|
||||||
|
|
||||||
def test__requires_with_inverted():
|
def test__requires_with_inverted():
|
||||||
|
@ -155,7 +155,7 @@ def test_multi_with_requires_in_another_group():
|
||||||
config = Config(descr2)
|
config = Config(descr2)
|
||||||
assert stroption._is_hidden() == False
|
assert stroption._is_hidden() == False
|
||||||
config.int = 1
|
config.int = 1
|
||||||
raises(HiddenOptionError, "config.opt.str = ['a', 'b']")
|
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||||
assert stroption._is_hidden()
|
assert stroption._is_hidden()
|
||||||
|
|
||||||
def test_apply_requires_from_config():
|
def test_apply_requires_from_config():
|
||||||
|
@ -204,7 +204,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||||
config = Config(descr2)
|
config = Config(descr2)
|
||||||
assert stroption._is_disabled() == False
|
assert stroption._is_disabled() == False
|
||||||
config.int = 1
|
config.int = 1
|
||||||
raises(DisabledOptionError, "config.opt.str = ['a', 'b']")
|
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
||||||
assert stroption._is_disabled()
|
assert stroption._is_disabled()
|
||||||
|
|
||||||
def test_multi_with_requires_that_is_multi():
|
def test_multi_with_requires_that_is_multi():
|
||||||
|
@ -216,7 +216,7 @@ def test_multi_with_requires_that_is_multi():
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert stroption._is_hidden() == False
|
assert stroption._is_hidden() == False
|
||||||
config.int = [1, 1]
|
config.int = [1, 1]
|
||||||
raises(HiddenOptionError, "config.str = ['a', 'b']")
|
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||||
assert stroption._is_hidden()
|
assert stroption._is_hidden()
|
||||||
|
|
||||||
def test_multi_with_bool():
|
def test_multi_with_bool():
|
||||||
|
@ -292,7 +292,7 @@ def test_set_with_hidden_option():
|
||||||
IntOption("int", "", default=42)])
|
IntOption("int", "", default=42)])
|
||||||
d = {'s1.a': True, 'int': 23}
|
d = {'s1.a': True, 'int': 23}
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
raises(HiddenOptionError, "config.set(**d)")
|
raises(PropertiesOptionError, "config.set(**d)")
|
||||||
|
|
||||||
def test_set_with_unknown_option():
|
def test_set_with_unknown_option():
|
||||||
boolopt = BoolOption("b", "", default=False)
|
boolopt = BoolOption("b", "", default=False)
|
||||||
|
@ -406,5 +406,5 @@ def test_access_by_get_whith_hide():
|
||||||
BoolOption("d1", ""),
|
BoolOption("d1", ""),
|
||||||
])
|
])
|
||||||
c = Config(descr)
|
c = Config(descr)
|
||||||
raises(HiddenOptionError, "c.get('b1')")
|
raises(PropertiesOptionError, "c.get('b1')")
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,9 @@ def test_is_hidden():
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
|
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
|
||||||
# setattr
|
# setattr
|
||||||
raises(HiddenOptionError, "config.gc.dummy == False")
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
||||||
# getattr
|
# getattr
|
||||||
raises(HiddenOptionError, "config.gc.dummy")
|
raises(PropertiesOptionError, "config.gc.dummy")
|
||||||
# I want to access to this option anyway
|
# I want to access to this option anyway
|
||||||
path = 'gc.dummy'
|
path = 'gc.dummy'
|
||||||
homeconfig, name = config._cfgimpl_get_home_by_path(path)
|
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 = config.unwrap_from_path('gc')
|
||||||
gc.hide()
|
gc.hide()
|
||||||
dummy = config.unwrap_from_path('gc.dummy')
|
dummy = config.unwrap_from_path('gc.dummy')
|
||||||
raises(HiddenOptionError, "config.gc.dummy")
|
raises(PropertiesOptionError, "config.gc.dummy")
|
||||||
assert gc._is_hidden()
|
assert gc._is_hidden()
|
||||||
raises(HiddenOptionError, "config.gc.float")
|
raises(PropertiesOptionError, "config.gc.float")
|
||||||
# manually set the subconfigs to "show"
|
# manually set the subconfigs to "show"
|
||||||
gc.show()
|
gc.show()
|
||||||
assert gc._is_hidden() == False
|
assert gc._is_hidden() == False
|
||||||
assert config.gc.float == 2.3
|
assert config.gc.float == 2.3
|
||||||
#dummy est en hide
|
#dummy est en hide
|
||||||
raises(HiddenOptionError, "config.gc.dummy == False")
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
||||||
|
|
||||||
def test_global_show():
|
def test_global_show():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
|
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():
|
def test_with_many_subgroups():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
"enables us to carry out a calculation and return an option's value"
|
"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
|
# automatic Option object
|
||||||
special_owners = ['auto', 'fill']
|
special_owners = ['auto', 'fill']
|
||||||
|
@ -45,10 +45,10 @@ def calc_factory(name, callback, callback_params, config):
|
||||||
try:
|
try:
|
||||||
opt_value = getattr(config, path)
|
opt_value = getattr(config, path)
|
||||||
opt = config.unwrap_from_path(path)
|
opt = config.unwrap_from_path(path)
|
||||||
except DisabledOptionError, e:
|
except PropertiesOptionError, e:
|
||||||
if chek_disabled:
|
if chek_disabled:
|
||||||
continue
|
continue
|
||||||
raise DisabledOptionError(e)
|
raise PropertiesOptionError(e)
|
||||||
is_multi = opt.is_multi()
|
is_multi = opt.is_multi()
|
||||||
if is_multi:
|
if is_multi:
|
||||||
if opt_value != None:
|
if opt_value != None:
|
||||||
|
|
|
@ -21,7 +21,11 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# 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):
|
def hide(self):
|
||||||
if not 'hidden' in self.properties:
|
if not 'hidden' in self.properties:
|
||||||
self.properties.append('hidden')
|
self.properties.append('hidden')
|
||||||
|
@ -32,7 +36,7 @@ class HiddenBaseType(object):
|
||||||
# dangerous method: how an Option() can determine its status by itself ?
|
# dangerous method: how an Option() can determine its status by itself ?
|
||||||
return 'hidden' in self.properties
|
return 'hidden' in self.properties
|
||||||
|
|
||||||
class DisabledBaseType(object):
|
class DisabledBaseType(BaseType):
|
||||||
def disable(self):
|
def disable(self):
|
||||||
if not 'disabled' in self.properties:
|
if not 'disabled' in self.properties:
|
||||||
self.properties.append('disabled')
|
self.properties.append('disabled')
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from tiramisu.error import (HiddenOptionError, ConfigError, NotFoundError,
|
from tiramisu.error import (PropertiesOptionError, ConfigError, NotFoundError,
|
||||||
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
|
||||||
SpecialOwnersError, MandatoryError, MethodCallError, DisabledOptionError)
|
SpecialOwnersError, MandatoryError, MethodCallError)
|
||||||
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
|
from tiramisu.option import (OptionDescription, Option, SymLinkOption,
|
||||||
group_types, Multi, apply_requires)
|
group_types, Multi, apply_requires)
|
||||||
from tiramisu.autolib import special_owners, special_owner_factory
|
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'
|
default_owner = 'user'
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
class Config(object):
|
class Config(object):
|
||||||
_cfgimpl_hidden = True
|
_cfgimpl_properties = ['hidden', 'disabled']
|
||||||
_cfgimpl_disabled = True
|
|
||||||
_cfgimpl_mandatory = True
|
_cfgimpl_mandatory = True
|
||||||
_cfgimpl_frozen = False
|
_cfgimpl_frozen = False
|
||||||
_cfgimpl_owner = default_owner
|
_cfgimpl_owner = default_owner
|
||||||
|
@ -126,33 +125,40 @@ class Config(object):
|
||||||
if isinstance(child, OptionDescription):
|
if isinstance(child, OptionDescription):
|
||||||
self._cfgimpl_values[child._name].cfgimpl_set_owner(owner)
|
self._cfgimpl_values[child._name].cfgimpl_set_owner(owner)
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
def _cfgimpl_has_properties(self):
|
||||||
|
return bool(len(self._cfgimpl_properties))
|
||||||
|
|
||||||
def cfgimpl_hide(self):
|
def cfgimpl_hide(self):
|
||||||
if self._cfgimpl_parent != None:
|
if self._cfgimpl_parent != None:
|
||||||
raise MethodCallError("this method root_hide() shall not be"
|
raise MethodCallError("this method root_hide() shall not be"
|
||||||
"used with non-root Config() object")
|
"used with non-root Config() object")
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
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):
|
def cfgimpl_show(self):
|
||||||
if self._cfgimpl_parent != None:
|
if self._cfgimpl_parent != None:
|
||||||
raise MethodCallError("this method root_hide() shall not be"
|
raise MethodCallError("this method root_hide() shall not be"
|
||||||
"used with non-root Config() object")
|
"used with non-root Config() object")
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
rootconfig = self._cfgimpl_get_toplevel()
|
||||||
rootconfig._cfgimpl_hidden = False
|
if 'hidden' in rootconfig._cfgimpl_properties:
|
||||||
# ____________________________________________________________
|
rootconfig._cfgimpl_properties.remove('hidden')
|
||||||
|
|
||||||
def cfgimpl_disable(self):
|
def cfgimpl_disable(self):
|
||||||
if self._cfgimpl_parent != None:
|
if self._cfgimpl_parent != None:
|
||||||
raise MethodCallError("this method root_hide() shall not be"
|
raise MethodCallError("this method root_hide() shall not be"
|
||||||
"used with non-root Confit() object")
|
"used with non-root Confit() object")
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
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):
|
def cfgimpl_enable(self):
|
||||||
if self._cfgimpl_parent != None:
|
if self._cfgimpl_parent != None:
|
||||||
raise MethodCallError("this method root_hide() shall not be"
|
raise MethodCallError("this method root_hide() shall not be"
|
||||||
"used with non-root Confit() object")
|
"used with non-root Confit() object")
|
||||||
rootconfig = self._cfgimpl_get_toplevel()
|
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):
|
def __setattr__(self, name, value):
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
|
@ -172,16 +178,16 @@ class Config(object):
|
||||||
def _validate(self, name, opt_or_descr):
|
def _validate(self, name, opt_or_descr):
|
||||||
apply_requires(opt_or_descr, self)
|
apply_requires(opt_or_descr, self)
|
||||||
if not type(opt_or_descr) == OptionDescription:
|
if not type(opt_or_descr) == OptionDescription:
|
||||||
# hidden options
|
# hidden or disabled options
|
||||||
if self._cfgimpl_toplevel._cfgimpl_hidden and \
|
# XXX let's have a group with a hidden property
|
||||||
(opt_or_descr._is_hidden() or self._cfgimpl_descr._is_hidden()):
|
# and an option with a disabled property,
|
||||||
raise HiddenOptionError("trying to access to a hidden option:"
|
# then it matches anyway... is it important to fix this ?
|
||||||
" {0}".format(name))
|
if self._cfgimpl_toplevel._cfgimpl_has_properties() and \
|
||||||
# disabled options
|
(opt_or_descr.has_properties() or \
|
||||||
if self._cfgimpl_toplevel._cfgimpl_disabled and \
|
self._cfgimpl_descr.has_properties()):
|
||||||
(opt_or_descr._is_disabled() or self._cfgimpl_descr._is_disabled()):
|
raise PropertiesOptionError("trying to access to the option: {0} "
|
||||||
raise DisabledOptionError("this option is disabled:"
|
"with properties: {1}".format(name,
|
||||||
" {0}".format(name))
|
str(opt_or_descr.properties)))
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# attribute access by passing a path,
|
# attribute access by passing a path,
|
||||||
|
@ -500,7 +506,7 @@ class Config(object):
|
||||||
|
|
||||||
def getpaths(self, include_groups=False, allpaths=False, mandatory=False):
|
def getpaths(self, include_groups=False, allpaths=False, mandatory=False):
|
||||||
"""returns a list of all paths in self, recursively, taking care of
|
"""returns a list of all paths in self, recursively, taking care of
|
||||||
the context (hidden/disabled)
|
the context of properties (hidden/disabled)
|
||||||
"""
|
"""
|
||||||
paths = []
|
paths = []
|
||||||
for path in self._cfgimpl_descr.getpaths(include_groups=include_groups):
|
for path in self._cfgimpl_descr.getpaths(include_groups=include_groups):
|
||||||
|
|
|
@ -6,9 +6,7 @@ class ConfigError(Exception):
|
||||||
pass
|
pass
|
||||||
class ConflictConfigError(ConfigError):
|
class ConflictConfigError(ConfigError):
|
||||||
pass
|
pass
|
||||||
class HiddenOptionError(AttributeError):
|
class PropertiesOptionError(AttributeError):
|
||||||
pass
|
|
||||||
class DisabledOptionError(AttributeError):
|
|
||||||
pass
|
pass
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue