option names shall be valid names

This commit is contained in:
gwen 2013-02-25 16:06:10 +01:00
parent a02cb26d5f
commit eb632c002d
2 changed files with 12 additions and 13 deletions

View File

@ -45,16 +45,8 @@ def test_root_config_answers_ok():
assert cfg.boolop == True assert cfg.boolop == True
def test_optname_shall_not_start_with_numbers(): def test_optname_shall_not_start_with_numbers():
"if you hide the root config, the options in this namespace behave normally" raises(NameError, "gcdummy = BoolOption('123dummy', 'dummy', default=False)")
gcdummy = BoolOption('123dummy', 'dummy', default=False) raises(NameError, "descr = OptionDescription('123tiramisu', '', [])")
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
cfg = Config(descr)
# FIXME devrait lever une exception NameError
settings = cfg.cfgimpl_get_settings()
settings.enable_property('hiddend') #cfgimpl_hide()
# assert cfg.123dummy == False
assert cfg.boolop == True
def test_option_has_an_api_name(): def test_option_has_an_api_name():
gcdummy = BoolOption('cfgimpl_get_settings', 'dummy', default=False) gcdummy = BoolOption('cfgimpl_get_settings', 'dummy', default=False)

View File

@ -41,9 +41,13 @@ for act1, act2 in requires_actions:
name_regexp = re.compile(r'^\d+') name_regexp = re.compile(r'^\d+')
def valid_name(name): def valid_name(name):
return re.match(name_regexp, name) if re.match(name_regexp, name) is None:
return True
else:
return False
#____________________________________________________________
# #
class Option(HiddenBaseType, DisabledBaseType): class Option(HiddenBaseType, DisabledBaseType):
""" """
Abstract base class for configuration option's. Abstract base class for configuration option's.
@ -74,7 +78,8 @@ class Option(HiddenBaseType, DisabledBaseType):
validation of the value validation of the value
:param validator_args: the validator's parameters :param validator_args: the validator's parameters
""" """
if not valid_name(name):
raise NameError("invalid name: {0} for option".format(name))
self._name = name self._name = name
self.doc = doc self.doc = doc
self._requires = requires self._requires = requires
@ -374,6 +379,8 @@ class OptionDescription(HiddenBaseType, DisabledBaseType):
:param children: is a list of option descriptions (including :param children: is a list of option descriptions (including
``OptionDescription`` instances for nested namespaces). ``OptionDescription`` instances for nested namespaces).
""" """
if not valid_name(name):
raise NameError("invalid name: {0} for option descr".format(name))
self._name = name self._name = name
self.doc = doc self.doc = doc
self._children = children self._children = children