add more tests
This commit is contained in:
parent
1e880f4bc6
commit
c58de18b62
5 changed files with 103 additions and 2 deletions
|
@ -152,8 +152,10 @@ def test_config_impl_get_path_by_opt():
|
|||
config = Config(descr)
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
boo = config.unwrap_from_path('bool')
|
||||
unknown = IntOption('test', '')
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool'
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy'
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_path_by_opt(unknown)")
|
||||
|
||||
|
||||
def test_config_impl_get_opt_by_path():
|
||||
|
@ -163,6 +165,7 @@ def test_config_impl_get_opt_by_path():
|
|||
boo = config.unwrap_from_path('bool')
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
|
||||
|
||||
def test_information_display():
|
||||
|
@ -254,3 +257,20 @@ def test_config_multi():
|
|||
assert config.test3 == [2]
|
||||
config.test3.append()
|
||||
assert config.test3 == [2, 1]
|
||||
|
||||
|
||||
def test_no_validation():
|
||||
i1 = IntOption('test1', '')
|
||||
od = OptionDescription('test', '', [i1])
|
||||
c = Config(od)
|
||||
setting = c.cfgimpl_get_settings()
|
||||
c.test1 = 1
|
||||
raises(ValueError, 'c.test1 = "yes"')
|
||||
assert c.test1 == 1
|
||||
setting.remove('validator')
|
||||
c.test1 = "yes"
|
||||
assert c.test1 == "yes"
|
||||
setting.append('validator')
|
||||
raises(ValueError, 'c.test1')
|
||||
del(c.test1)
|
||||
assert c.test1 == None
|
||||
|
|
|
@ -4,7 +4,11 @@ and to compare them
|
|||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.option import BoolOption, IntOption
|
||||
from tiramisu.option import IntOption, OptionDescription
|
||||
|
||||
|
||||
def a_func():
|
||||
return None
|
||||
|
||||
|
||||
#def test_option_comparison():
|
||||
|
@ -47,16 +51,50 @@ def test_option_valid_name():
|
|||
raises(ValueError, 'IntOption("unwrap_from_path", "")')
|
||||
|
||||
|
||||
def test_option_with_callback():
|
||||
#no default value with callback
|
||||
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
||||
|
||||
|
||||
def test_option_get_information():
|
||||
i = IntOption('test', '')
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
i = IntOption('test', description)
|
||||
i.impl_set_information('info', string)
|
||||
assert i.impl_get_information('info') == string
|
||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert i.impl_get_information('doc') == description
|
||||
assert i.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_optiondescription_get_information():
|
||||
description = "it's ok"
|
||||
string = 'some informations'
|
||||
o = OptionDescription('test', description, [])
|
||||
o.impl_set_information('info', string)
|
||||
assert o.impl_get_information('info') == string
|
||||
raises(ValueError, "o.impl_get_information('noinfo')")
|
||||
assert o.impl_get_information('noinfo', 'default') == 'default'
|
||||
assert o.impl_get_information('doc') == description
|
||||
assert o.impl_getdoc() == description
|
||||
|
||||
|
||||
def test_option_multi():
|
||||
IntOption('test', '', multi=True)
|
||||
IntOption('test', '', multi=True, default_multi=1)
|
||||
IntOption('test', '', default=[1], multi=True, default_multi=1)
|
||||
#add default_multi to not multi's option
|
||||
raises(ValueError, "IntOption('test', '', default_multi=1)")
|
||||
#unvalid default_multi
|
||||
raises(ValueError, "IntOption('test', '', multi=True, default_multi='yes')")
|
||||
#not default_multi with callback
|
||||
raises(ValueError, "IntOption('test', '', multi=True, default_multi=1, callback=a_func)")
|
||||
|
||||
|
||||
def test_option_is_multi_by_default():
|
||||
assert IntOption('test', '').impl_is_empty_by_default() is True
|
||||
assert IntOption('test', '', 1).impl_is_empty_by_default() is False
|
||||
assert IntOption('test', '', multi=True).impl_is_empty_by_default() is True
|
||||
assert IntOption('test', '', [1], multi=True).impl_is_empty_by_default() is False
|
||||
assert IntOption('test', '', multi=True, default_multi=1).impl_is_empty_by_default() is True
|
||||
|
|
|
@ -243,6 +243,19 @@ def test_callback():
|
|||
assert cfg.val1 == 'val'
|
||||
|
||||
|
||||
def test_callback_params_without_callback():
|
||||
raises(ValueError, "StrOption('val2', '', callback_params={'': ('yes',)})")
|
||||
|
||||
|
||||
def test_callback_invalid():
|
||||
raises(ValueError, 'val1 = StrOption("val1", "", callback="string")')
|
||||
raises(ValueError, 'val1 = StrOption("val1", "", callback=return_val, callback_params="string")')
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
raises(ValueError, "StrOption('val2', '', callback=return_value, callback_params={'': 'string'})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': (('string', False),)})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, 'string'),)})")
|
||||
|
||||
|
||||
def test_callback_value():
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
|
||||
|
|
|
@ -8,6 +8,17 @@ from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
|||
from tiramisu.error import ConfigError
|
||||
|
||||
|
||||
def test_consistency():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
#consistency to itself
|
||||
raises(ConfigError, "a.impl_add_consistency('not_equal', a)")
|
||||
#consistency with string
|
||||
raises(ConfigError, "a.impl_add_consistency('not_equal', 'a')")
|
||||
|
||||
|
||||
def test_consistency_not_equal():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
|
|
|
@ -26,6 +26,20 @@ def test_requires():
|
|||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_requires_invalid():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires='string')")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'unknown': True}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'transitive': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'same_action': 'string'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': 'string', 'expected': False, 'action': 'disabled'}])")
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
||||
|
||||
|
||||
def test_requires_same_action():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = BoolOption('activate_service_web', '', True,
|
||||
|
@ -504,6 +518,11 @@ def test_requires_requirement_append():
|
|||
c.cfgimpl_get_settings()[b].append("test")
|
||||
|
||||
|
||||
def test_requires_different_inverse():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])")
|
||||
|
||||
|
||||
def test_requires_recursive_path():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
|
|
Loading…
Reference in a new issue