diff --git a/test/test_option_with_special_name.py b/test/test_option_with_special_name.py index 9adaf33..b2bf376 100644 --- a/test/test_option_with_special_name.py +++ b/test/test_option_with_special_name.py @@ -45,16 +45,8 @@ def test_root_config_answers_ok(): assert cfg.boolop == True def test_optname_shall_not_start_with_numbers(): - "if you hide the root config, the options in this namespace behave normally" - gcdummy = BoolOption('123dummy', 'dummy', default=False) - 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 + raises(NameError, "gcdummy = BoolOption('123dummy', 'dummy', default=False)") + raises(NameError, "descr = OptionDescription('123tiramisu', '', [])") def test_option_has_an_api_name(): gcdummy = BoolOption('cfgimpl_get_settings', 'dummy', default=False) diff --git a/tiramisu/option.py b/tiramisu/option.py index d8de012..9fc559a 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -41,9 +41,13 @@ for act1, act2 in requires_actions: name_regexp = re.compile(r'^\d+') 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): """ Abstract base class for configuration option's. @@ -74,7 +78,8 @@ class Option(HiddenBaseType, DisabledBaseType): validation of the value :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.doc = doc self._requires = requires @@ -374,6 +379,8 @@ class OptionDescription(HiddenBaseType, DisabledBaseType): :param children: is a list of option descriptions (including ``OptionDescription`` instances for nested namespaces). """ + if not valid_name(name): + raise NameError("invalid name: {0} for option descr".format(name)) self._name = name self.doc = doc self._children = children