validate name in symlinkoption
This commit is contained in:
parent
688525f98e
commit
c4bb4f90a1
3 changed files with 12 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
@ -24,9 +24,11 @@ def test_option_valid_name():
|
|||
IntOption('test', '')
|
||||
raises(ValueError, 'IntOption(1, "")')
|
||||
# raises(ValueError, 'IntOption("1test", "")')
|
||||
IntOption("test1", "")
|
||||
i = IntOption("test1", "")
|
||||
# raises(ValueError, 'IntOption("_test", "")')
|
||||
# raises(ValueError, 'IntOption(" ", "")')
|
||||
raises(ValueError, 'SymLinkOption(1, i)')
|
||||
i = SymLinkOption("test1", i)
|
||||
|
||||
|
||||
def test_option_with_callback():
|
||||
|
|
|
@ -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]:
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in a new issue