parent
0a83a9261f
commit
2dcdbb137e
|
@ -4,7 +4,7 @@ from py.test import raises
|
|||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, FileOption, OptionDescription
|
||||
BoolOption, FilenameOption, OptionDescription
|
||||
|
||||
|
||||
def make_description():
|
||||
|
@ -139,8 +139,8 @@ def test_does_not_find_in_config():
|
|||
raises(AttributeError, "conf.find(byname='IDontExist')")
|
||||
|
||||
|
||||
def test_file():
|
||||
a = FileOption('a', '')
|
||||
def test_filename():
|
||||
a = FilenameOption('a', '')
|
||||
o = OptionDescription('o', '', [a])
|
||||
c = Config(o)
|
||||
c.a = u'/'
|
||||
|
|
|
@ -6,7 +6,7 @@ from tiramisu.config import Config, SubConfig
|
|||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
||||
StrOption, SymLinkOption, UnicodeOption, IPOption, OptionDescription, \
|
||||
PortOption, NetworkOption, NetmaskOption, DomainnameOption, EmailOption, \
|
||||
URLOption, FileOption
|
||||
URLOption, FilenameOption
|
||||
|
||||
|
||||
def test_slots_option():
|
||||
|
@ -40,7 +40,7 @@ def test_slots_option():
|
|||
raises(AttributeError, "c.x = 1")
|
||||
c = URLOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
c = FileOption('a', '')
|
||||
c = FilenameOption('a', '')
|
||||
raises(AttributeError, "c.x = 1")
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ def test_slots_option_readonly():
|
|||
l = DomainnameOption('l', '')
|
||||
o = EmailOption('o', '')
|
||||
p = URLOption('p', '')
|
||||
q = FileOption('q', '')
|
||||
q = FilenameOption('q', '')
|
||||
m = OptionDescription('m', '', [a, b, c, d, e, g, h, i, j, k, l, o, p, q])
|
||||
a._requires = 'a'
|
||||
b._requires = 'b'
|
||||
|
|
|
@ -425,7 +425,7 @@ class Option(BaseOption):
|
|||
self._validate(_value)
|
||||
except ValueError as err:
|
||||
raise ValueError(_('invalid value for option {0}: {1}'
|
||||
'').format(self._name, err.message))
|
||||
'').format(self._name, err))
|
||||
try:
|
||||
# valid with self._validator
|
||||
val_validator(_value)
|
||||
|
@ -435,7 +435,7 @@ class Option(BaseOption):
|
|||
self._second_level_validation(_value)
|
||||
except ValueError as err:
|
||||
msg = _("invalid value for option {0}: {1}").format(
|
||||
self._name, err.message)
|
||||
self._name, err)
|
||||
if self._warnings_only:
|
||||
warnings.warn_explicit(ValueWarning(msg, self),
|
||||
ValueWarning,
|
||||
|
@ -1096,7 +1096,7 @@ class URLOption(DomainnameOption):
|
|||
raise ValueError(_('invalid url, should ends with filename'))
|
||||
|
||||
|
||||
class FileOption(Option):
|
||||
class FilenameOption(Option):
|
||||
__slots__ = tuple()
|
||||
_opt_type = 'file'
|
||||
path_re = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$")
|
||||
|
|
Loading…
Reference in New Issue