coverage for tiramisu/option/option.py
This commit is contained in:
@ -22,6 +22,10 @@ def return_calc_list(val):
|
||||
return [val]
|
||||
|
||||
|
||||
def return_error():
|
||||
raise Exception('test')
|
||||
|
||||
|
||||
def test_choiceoption_function():
|
||||
ch = ChoiceOption('ch', '', values=return_list)
|
||||
od = OptionDescription('od', '', [ch])
|
||||
@ -39,6 +43,14 @@ def test_choiceoption_function():
|
||||
assert ch.impl_get_values(cfg) == ['val1', 'val2']
|
||||
|
||||
|
||||
def test_choiceoption_function_error():
|
||||
ch = ChoiceOption('ch', '', values=return_error)
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
raises(Exception, "cfg.ch = 'no'")
|
||||
|
||||
|
||||
def test_choiceoption_calc_function():
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
od = OptionDescription('od', '', [ch])
|
||||
@ -70,6 +82,15 @@ def test_choiceoption_calc_opt_function():
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function_propertyerror():
|
||||
st = StrOption('st', '', 'val1', properties=('disabled',))
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ((st, False),)})
|
||||
od = OptionDescription('od', '', [st, ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_multi_function():
|
||||
st = StrOption('st', '', ['val1'], multi=True)
|
||||
ch = ChoiceOption('ch', "", default_multi='val2', values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
|
@ -146,6 +146,7 @@ def test_email():
|
||||
c.e = u'foo-bar.baz@example.com'
|
||||
c.e = u'root@foo.com'
|
||||
c.e = u'root@domain'
|
||||
raises(ValueError, "c.e = 1")
|
||||
raises(ValueError, "c.e = u'root'")
|
||||
raises(ValueError, "c.e = u'root[]@domain'")
|
||||
|
||||
@ -158,6 +159,7 @@ def test_url():
|
||||
c.u = 'http://foo.com'
|
||||
c.u = 'https://foo.com'
|
||||
c.u = 'https://foo.com/'
|
||||
raises(ValueError, "c.u = 1")
|
||||
raises(ValueError, "c.u = 'ftp://foo.com'")
|
||||
raises(ValueError, "c.u = 'foo.com'")
|
||||
raises(ValueError, "c.u = ':/foo.com'")
|
||||
|
@ -5,7 +5,7 @@ import warnings
|
||||
from py.test import raises
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, \
|
||||
PortOption, OptionDescription
|
||||
PortOption, BroadcastOption, OptionDescription
|
||||
from tiramisu.error import ValueWarning
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ def test_ip():
|
||||
raises(ValueError, "c.b = '88.88.88.88'")
|
||||
c.b = '0.0.0.0'
|
||||
raises(ValueError, "c.b = '255.255.255.0'")
|
||||
raises(ValueError, "c.a = '333.0.1.20'")
|
||||
|
||||
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@ -64,7 +65,11 @@ def test_network():
|
||||
c.a = '192.168.1.0'
|
||||
c.a = '88.88.88.88'
|
||||
c.a = '0.0.0.0'
|
||||
raises(ValueError, "c.a = 1")
|
||||
raises(ValueError, "c.a = '1.1.1.1.1'")
|
||||
raises(ValueError, "c.a = '255.255.255.0'")
|
||||
raises(ValueError, "c.a = '192.168.001.0'")
|
||||
raises(ValueError, "c.a = '333.168.1.1'")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
c.b = '255.255.255.0'
|
||||
assert len(w) == 1
|
||||
@ -78,9 +83,25 @@ def test_netmask():
|
||||
a = NetmaskOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = '192.168.1.1.1'")
|
||||
raises(ValueError, "c.a = '192.168.1.1'")
|
||||
raises(ValueError, "c.a = '192.168.1.0'")
|
||||
raises(ValueError, "c.a = '88.88.88.88'")
|
||||
raises(ValueError, "c.a = '255.255.255.000'")
|
||||
raises(ValueError, "c.a = 2")
|
||||
c.a = '0.0.0.0'
|
||||
c.a = '255.255.255.0'
|
||||
|
||||
|
||||
def test_broadcast():
|
||||
a = BroadcastOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.a = '192.168.1.255.1'")
|
||||
raises(ValueError, "c.a = '192.168.001.255'")
|
||||
raises(ValueError, "c.a = '192.168.0.300'")
|
||||
raises(ValueError, "c.a = 1")
|
||||
raises(ValueError, "c.a = 2")
|
||||
c.a = '0.0.0.0'
|
||||
c.a = '255.255.255.0'
|
||||
|
||||
|
@ -7,7 +7,7 @@ from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription
|
||||
PasswordOption, StrOption, DateOption, OptionDescription
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
@ -133,3 +133,28 @@ def test_with_many_subgroups():
|
||||
assert name == "booltwo"
|
||||
getattr(homeconfig.cfgimpl_get_description(), name)
|
||||
assert 'hidden' in setting[booltwo]
|
||||
|
||||
|
||||
def test_password_option():
|
||||
o = PasswordOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
c = Config(d)
|
||||
|
||||
c.o = u'a_valid_password'
|
||||
raises(ValueError, "c.o = 1")
|
||||
|
||||
|
||||
def test_date_option():
|
||||
o = DateOption('o', '')
|
||||
d = OptionDescription('d', '', [o])
|
||||
c = Config(d)
|
||||
|
||||
c.o = u'2017-02-04'
|
||||
c.o = u'2017-2-4'
|
||||
raises(ValueError, "c.o = 1")
|
||||
raises(ValueError, "c.o = u'2017-13-20'")
|
||||
raises(ValueError, "c.o = u'2017-11-31'")
|
||||
raises(ValueError, "c.o = u'2017-12-32'")
|
||||
raises(ValueError, "c.o = u'2017-2-29'")
|
||||
raises(ValueError, "c.o = u'2-2-2017'")
|
||||
raises(ValueError, "c.o = u'2017/2/2'")
|
||||
|
Reference in New Issue
Block a user