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