diff --git a/test/test_option.py b/test/test_option.py index f5db1d7..7cb4d16 100644 --- a/test/test_option.py +++ b/test/test_option.py @@ -7,7 +7,7 @@ do_autopath() from py.test import raises from tiramisu.error import APIError, ConfigError -from tiramisu import IntOption, OptionDescription, Config +from tiramisu import IntOption, SymLinkOption, OptionDescription, Config from tiramisu.setting import groups from tiramisu.storage import list_sessions @@ -23,14 +23,16 @@ def a_func(): def test_option_valid_name(): IntOption('test', '') raises(ValueError, 'IntOption(1, "")') - #raises(ValueError, 'IntOption("1test", "")') - IntOption("test1", "") - #raises(ValueError, 'IntOption("_test", "")') - #raises(ValueError, 'IntOption(" ", "")') + # raises(ValueError, 'IntOption("1test", "")') + i = IntOption("test1", "") + # raises(ValueError, 'IntOption("_test", "")') + # raises(ValueError, 'IntOption(" ", "")') + raises(ValueError, 'SymLinkOption(1, i)') + i = SymLinkOption("test1", i) def test_option_with_callback(): - #no default value with callback + # no default value with callback raises(ValueError, "IntOption('test', '', default=1, callback=a_func)") diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 5800380..aff4a2a 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -299,7 +299,7 @@ class Base: _setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())])) def impl_is_readonly(self) -> str: - # _path is None when initialise SymlinkOption + # _path is None when initialise SymLinkOption return hasattr(self, '_path') and self._path is not None def impl_getproperties(self) -> FrozenSet[str]: diff --git a/tiramisu/option/symlinkoption.py b/tiramisu/option/symlinkoption.py index d26eb96..da98ed3 100644 --- a/tiramisu/option/symlinkoption.py +++ b/tiramisu/option/symlinkoption.py @@ -19,7 +19,7 @@ # the whole pypy projet is under MIT licence # ____________________________________________________________ from typing import Any -from .baseoption import BaseOption +from .baseoption import BaseOption, valid_name from ..i18n import _ @@ -29,6 +29,8 @@ class SymLinkOption(BaseOption): def __init__(self, name: str, opt: BaseOption) -> None: + if not valid_name(name): + raise ValueError(_('"{0}" is an invalid name for an option').format(name)) if not isinstance(opt, BaseOption) or \ opt.impl_is_optiondescription() or \ opt.impl_is_symlinkoption():