display correct name in consistency
This commit is contained in:
parent
b31a94e449
commit
721ff8643d
|
@ -695,6 +695,11 @@ def test_consistency_dyndescription():
|
|||
raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')")
|
||||
api.option('od.dodval2.st2val2').value.set('yes')
|
||||
raises(ValueError, "api.option('od.dodval2.stval2').value.set('yes')")
|
||||
#
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
api.option('od.dodval2.st2val2').value.reset()
|
||||
api.option('od.dodval1.st2val1').value.set('yes')
|
||||
raises(ValueError, "api.option('od.dodval1.stval1').value.set('yes')")
|
||||
|
||||
|
||||
def test_consistency_dyndescription_default():
|
||||
|
|
|
@ -229,6 +229,21 @@ def test_consistency_not_equal_symlink():
|
|||
assert set(od._cache_consistencies.keys()) == set([a, b])
|
||||
|
||||
|
||||
def test_consistency_mix():
|
||||
b = IntOption('b', '', multi=True)
|
||||
c = IntOption('c', '', multi=True)
|
||||
d = IntOption('d', '', multi=True)
|
||||
od = MasterSlaves('c', '', [c, d])
|
||||
od2 = OptionDescription('a', '', [b, od])
|
||||
c.impl_add_consistency('not_equal', b, d)
|
||||
cfg = Config(od2)
|
||||
cfg.option('b').value.set([1, 2, 3])
|
||||
cfg.option('c.c').value.set([4, 5])
|
||||
raises(ValueError, "cfg.option('c.c').value.set([1, 2])")
|
||||
raises(ValueError, "cfg.option('c.d', 0).value.set(1)")
|
||||
raises(ValueError, "cfg.option('c.d', 1).value.set(4)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_submulti():
|
||||
a = IntOption('a', '', multi=submulti)
|
||||
b = IntOption('b', '', multi=submulti)
|
||||
|
@ -249,7 +264,6 @@ def test_consistency_not_equal_masterslave():
|
|||
b = IntOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('b', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = Config(od2)
|
||||
assert api.option('a.a').value.get() == []
|
||||
|
@ -268,7 +282,6 @@ def test_consistency_not_equal_masterslave_error_multi1():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
c = NetmaskOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = OptionDescription('b', '', [od, c])
|
||||
c.impl_add_consistency('ip_netmask', a)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
@ -279,13 +292,33 @@ def test_consistency_not_equal_masterslave_error_multi2():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
c = IPOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
od2 = OptionDescription('b', '', [od, c])
|
||||
b.impl_add_consistency('ip_netmask', c)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_not_equal_masterslave_error_othermaster():
|
||||
def test_consistency_ip_netmask_masterslave_error_not_master():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = OptionDescription('a', '', [a, b])
|
||||
od2 = OptionDescription('b', '', [od])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_masterslave_error_master_and_not():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = IPOption('c', '', multi=True)
|
||||
d = NetmaskOption('d', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('c', '', [c, d])
|
||||
od3 = OptionDescription('b', '', [od, od2])
|
||||
d.impl_add_consistency('ip_netmask', a)
|
||||
raises(ConfigError, "Config(od3)")
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_masterslave_error_othermaster():
|
||||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
c = IPOption('c', '', multi=True)
|
||||
|
@ -422,9 +455,8 @@ def test_consistency_ip_netmask():
|
|||
|
||||
|
||||
def test_consistency_ip_netmask_invalid():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
od = OptionDescription('od', '', [b])
|
||||
raises(ConfigError, "b.impl_add_consistency('ip_netmask')")
|
||||
|
||||
|
||||
|
@ -443,9 +475,8 @@ def test_consistency_network_netmask():
|
|||
|
||||
|
||||
def test_consistency_network_netmask_invalid():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
od = OptionDescription('od', '', [b])
|
||||
raises(ConfigError, "b.impl_add_consistency('network_netmask')")
|
||||
|
||||
|
||||
|
@ -521,7 +552,6 @@ def test_consistency_network_netmask_multi_slave_default_multi():
|
|||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
api = Config(od2)
|
||||
api.property.read_write()
|
||||
|
@ -534,7 +564,6 @@ def test_consistency_network_netmask_multi_slave_default():
|
|||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -570,7 +599,6 @@ def test_consistency_network_netmask_multi_slave_callback():
|
|||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -593,7 +621,6 @@ def test_consistency_network_netmask_multi_slave_callback_value():
|
|||
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
|
||||
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -618,7 +645,6 @@ def test_consistency_ip_netmask_multi_master():
|
|||
a = IPOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -637,7 +663,6 @@ def test_consistency_network_netmask_multi_master():
|
|||
a = NetworkOption('a', '', multi=True)
|
||||
b = NetmaskOption('b', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -654,7 +679,6 @@ def test_consistency_broadcast():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a, b)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
|
@ -731,7 +755,6 @@ def test_consistency_not_all():
|
|||
b = NetmaskOption('b', '', multi=True)
|
||||
c = BroadcastOption('c', '', multi=True)
|
||||
od = MasterSlaves('a', '', [a, b, c])
|
||||
#od.impl_set_group_type(groups.master)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
od2 = OptionDescription('od2', '', [od])
|
||||
api = Config(od2)
|
||||
|
@ -825,25 +848,27 @@ def test_consistency_warnings_only_options():
|
|||
assert len(w) == 1
|
||||
|
||||
|
||||
#def test_consistency_warnings_only_options_callback():
|
||||
# a = IPOption('a', '', warnings_only=True)
|
||||
# b = IPOption('b', '')
|
||||
# c = NetworkOption('c', '', default='192.168.1.0')
|
||||
# d = NetmaskOption('d', '', callback=return_netmask2, callback_params=Params(ParamOption(a)))
|
||||
# od = OptionDescription('od', '', [a, b, c, d])
|
||||
# a.impl_add_consistency('not_equal', b)
|
||||
# a.impl_add_consistency('in_network', c, d, transitive=False)
|
||||
# api = Config(od)
|
||||
# api.property.read_write()
|
||||
# api.option('a').value.set('192.168.1.1')
|
||||
# raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
||||
# api.option('a').value.set('192.168.2.1')
|
||||
# #
|
||||
# api.option('a').value.set('192.168.1.1')
|
||||
# api.property.pop('disabled')
|
||||
# with warnings.catch_warnings(record=True) as w:
|
||||
# api.option('a').value.set('192.168.2.1')
|
||||
# assert len(w) == 1
|
||||
def test_consistency_warnings_only_options_callback():
|
||||
a = IPOption('a', '', warnings_only=True)
|
||||
b = IPOption('b', '')
|
||||
c = NetworkOption('c', '', default='192.168.1.0')
|
||||
d = NetmaskOption('d', '', callback=return_netmask2, callback_params=Params(ParamOption(c)))
|
||||
od = OptionDescription('od', '', [a, b, c, d])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
a.impl_add_consistency('in_network', c, d, transitive=False)
|
||||
api = Config(od)
|
||||
api.property.read_write()
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
raises(ValueError, "api.option('b').value.set('192.168.1.1')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('a').value.set('192.168.2.1')
|
||||
assert len(w) == 1
|
||||
#
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.property.pop('disabled')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('a').value.set('192.168.2.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_consistency_double_warnings():
|
||||
|
|
|
@ -314,7 +314,7 @@ class Option(OnlyOption):
|
|||
msg = _('"{0}" is an invalid {1} for "{2}"'
|
||||
'').format(val,
|
||||
self._display_name,
|
||||
self.impl_get_display_name())
|
||||
option_bag.ori_option.impl_get_display_name())
|
||||
err_msg = '{0}'.format(err)
|
||||
if err_msg:
|
||||
msg += ', {}'.format(err_msg)
|
||||
|
@ -534,10 +534,7 @@ class Option(OnlyOption):
|
|||
if descr._cache_consistencies is None:
|
||||
return
|
||||
# get consistencies for this option
|
||||
if option_bag.option.impl_is_dynsymlinkoption():
|
||||
consistencies = descr._cache_consistencies.get(option_bag.option.impl_getopt())
|
||||
else:
|
||||
consistencies = descr._cache_consistencies.get(option_bag.option)
|
||||
consistencies = descr._cache_consistencies.get(option_bag.option)
|
||||
else:
|
||||
# is no context, get consistencies in option
|
||||
consistencies = option_bag.option.get_consistencies()
|
||||
|
@ -665,6 +662,13 @@ class Option(OnlyOption):
|
|||
cons_id,
|
||||
value,
|
||||
func):
|
||||
if option_bag.ori_option == current_option:
|
||||
# orig_option is current option
|
||||
# we have already value, so use it
|
||||
return value
|
||||
if option_bag.config_bag is undefined:
|
||||
#if no context get default value
|
||||
return current_option.impl_getdefault()
|
||||
if func in ALLOWED_CONST_LIST:
|
||||
index = None
|
||||
index_ = None
|
||||
|
@ -674,13 +678,6 @@ class Option(OnlyOption):
|
|||
else:
|
||||
index = option_bag.index
|
||||
index_ = index
|
||||
if option_bag.ori_option == current_option:
|
||||
# orig_option is current option
|
||||
# we have already value, so use it
|
||||
return value
|
||||
if option_bag.config_bag is undefined:
|
||||
#if no context get default value
|
||||
return current_option.impl_getdefault()
|
||||
#otherwise calculate value
|
||||
path = current_option.impl_getpath()
|
||||
coption_bag = OptionBag()
|
||||
|
|
Loading…
Reference in New Issue