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 py.test import raises
|
||||||
|
|
||||||
from tiramisu.error import APIError, ConfigError
|
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.setting import groups
|
||||||
from tiramisu.storage import list_sessions
|
from tiramisu.storage import list_sessions
|
||||||
|
|
||||||
|
@ -23,14 +23,16 @@ def a_func():
|
||||||
def test_option_valid_name():
|
def test_option_valid_name():
|
||||||
IntOption('test', '')
|
IntOption('test', '')
|
||||||
raises(ValueError, 'IntOption(1, "")')
|
raises(ValueError, 'IntOption(1, "")')
|
||||||
#raises(ValueError, 'IntOption("1test", "")')
|
# raises(ValueError, 'IntOption("1test", "")')
|
||||||
IntOption("test1", "")
|
i = IntOption("test1", "")
|
||||||
#raises(ValueError, 'IntOption("_test", "")')
|
# raises(ValueError, 'IntOption("_test", "")')
|
||||||
#raises(ValueError, 'IntOption(" ", "")')
|
# raises(ValueError, 'IntOption(" ", "")')
|
||||||
|
raises(ValueError, 'SymLinkOption(1, i)')
|
||||||
|
i = SymLinkOption("test1", i)
|
||||||
|
|
||||||
|
|
||||||
def test_option_with_callback():
|
def test_option_with_callback():
|
||||||
#no default value with callback
|
# no default value with callback
|
||||||
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,7 @@ class Base:
|
||||||
_setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())]))
|
_setattr(self, '_extra', tuple([tuple(extra.keys()), tuple(extra.values())]))
|
||||||
|
|
||||||
def impl_is_readonly(self) -> str:
|
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
|
return hasattr(self, '_path') and self._path is not None
|
||||||
|
|
||||||
def impl_getproperties(self) -> FrozenSet[str]:
|
def impl_getproperties(self) -> FrozenSet[str]:
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
# the whole pypy projet is under MIT licence
|
# the whole pypy projet is under MIT licence
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from .baseoption import BaseOption
|
from .baseoption import BaseOption, valid_name
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ class SymLinkOption(BaseOption):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name: str,
|
name: str,
|
||||||
opt: BaseOption) -> None:
|
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 \
|
if not isinstance(opt, BaseOption) or \
|
||||||
opt.impl_is_optiondescription() or \
|
opt.impl_is_optiondescription() or \
|
||||||
opt.impl_is_symlinkoption():
|
opt.impl_is_symlinkoption():
|
||||||
|
|
Loading…
Reference in a new issue