tiramisu/option.py:
separate _consistencies (for Option) and _cache_consistencies (for OptionDescription) _launch_consistency need index for multi's option _cons_not_equal support multi options tiramisu/value.py: Multi._validate support consistency
This commit is contained in:
@ -5,6 +5,7 @@ from tiramisu.setting import owners, groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
|
||||
BroadcastOption, SymLinkOption, OptionDescription
|
||||
from tiramisu.error import ConfigError
|
||||
|
||||
|
||||
def test_consistency_not_equal():
|
||||
@ -22,6 +23,60 @@ def test_consistency_not_equal():
|
||||
c.b = 2
|
||||
|
||||
|
||||
def test_consistency_not_equal_many_opts():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
c = IntOption('c', '')
|
||||
d = IntOption('d', '')
|
||||
e = IntOption('e', '')
|
||||
f = IntOption('f', '')
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
a.impl_add_consistency('not_equal', b, c, d, e, f)
|
||||
c = Config(od)
|
||||
assert c.a is None
|
||||
assert c.b is None
|
||||
#
|
||||
c.a = 1
|
||||
del(c.a)
|
||||
#
|
||||
c.a = 1
|
||||
raises(ValueError, "c.b = 1")
|
||||
#
|
||||
c.b = 2
|
||||
raises(ValueError, "c.f = 2")
|
||||
raises(ValueError, "c.f = 1")
|
||||
#
|
||||
c.d = 3
|
||||
raises(ValueError, "c.f = 3")
|
||||
raises(ValueError, "c.a = 3")
|
||||
raises(ValueError, "c.c = 3")
|
||||
raises(ValueError, "c.e = 3")
|
||||
|
||||
|
||||
def test_consistency_not_in_config():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od2 = OptionDescription('od2', '', [b])
|
||||
od = OptionDescription('root', '', [od1])
|
||||
raises(ConfigError, "Config(od)")
|
||||
od = OptionDescription('root', '', [od1, od2])
|
||||
Config(od)
|
||||
#with subconfig
|
||||
raises(ConfigError, "Config(od.od1)")
|
||||
|
||||
|
||||
def test_consistency_afer_config():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
od1 = OptionDescription('od1', '', [a])
|
||||
od2 = OptionDescription('od2', '', [b])
|
||||
od = OptionDescription('root', '', [od1, od2])
|
||||
Config(od)
|
||||
raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_symlink():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
@ -29,7 +84,7 @@ def test_consistency_not_equal_symlink():
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
c = Config(od)
|
||||
assert set(od._consistencies.keys()) == set([a, b])
|
||||
assert set(od._cache_consistencies.keys()) == set([a, b])
|
||||
|
||||
|
||||
def test_consistency_not_equal_multi():
|
||||
@ -53,6 +108,14 @@ def test_consistency_default():
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
|
||||
|
||||
def test_consistency_default_multi():
|
||||
a = IntOption('a', '', [2, 1], multi=True)
|
||||
b = IntOption('b', '', [1, 1], multi=True)
|
||||
c = IntOption('c', '', [1, 2], multi=True)
|
||||
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
|
||||
a.impl_add_consistency('not_equal', c)
|
||||
|
||||
|
||||
def test_consistency_default_diff():
|
||||
a = IntOption('a', '', 3)
|
||||
b = IntOption('b', '', 1)
|
||||
@ -99,7 +162,7 @@ def test_consistency_ip_netmask_error_multi():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
raises(ValueError, "b.impl_add_consistency('ip_netmask', a)")
|
||||
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_multi():
|
||||
@ -170,11 +233,42 @@ def test_consistency_broadcast():
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a, b)
|
||||
c = Config(od)
|
||||
#first, test network_netmask
|
||||
c.a = ['192.168.1.128']
|
||||
raises(ValueError, "c.b = ['255.255.255.0']")
|
||||
#
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
c.c = ['192.168.1.255']
|
||||
raises(ValueError, "c.a = ['192.168.1.1']")
|
||||
#
|
||||
c.a = ['192.168.1.0', '192.168.2.128']
|
||||
c.b = ['255.255.255.0', '255.255.255.128']
|
||||
c.c = ['192.168.1.255', '192.168.2.255']
|
||||
raises(ValueError, "c.c[1] = '192.168.2.128'")
|
||||
c.c[1] = '192.168.2.255'
|
||||
|
||||
|
||||
def test_consistency_broadcast_default():
|
||||
a = NetworkOption('a', '', '192.168.1.0')
|
||||
b = NetmaskOption('b', '', '255.255.255.128')
|
||||
c = BroadcastOption('c', '', '192.168.2.127')
|
||||
d = BroadcastOption('d', '', '192.168.1.127')
|
||||
od = OptionDescription('a', '', [a, b, c])
|
||||
raises(ValueError, "c.impl_add_consistency('broadcast', a, b)")
|
||||
od2 = OptionDescription('a', '', [a, b, d])
|
||||
d.impl_add_consistency('broadcast', a, b)
|
||||
|
||||
|
||||
def test_consistency_not_all():
|
||||
#_cache_consistencies is not None by not options has consistencies
|
||||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = OptionDescription('a', '', [a, b, c])
|
||||
od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c = Config(od)
|
||||
c.a = ['192.168.1.0']
|
||||
c.b = ['255.255.255.0']
|
||||
c.c = ['192.168.1.255']
|
||||
|
Reference in New Issue
Block a user