optimisations
This commit is contained in:
@ -83,6 +83,22 @@ def test_consistency_warnings_only_more_option():
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_consistency_warnings_only_option():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', warnings_only=True)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
a.impl_add_consistency('not_equal', b)
|
||||
api = Config(od)
|
||||
api.option('a').value.set(1)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('b').value.set(1)
|
||||
assert w != []
|
||||
api.option('a').value.reset()
|
||||
api.option('b').value.set(1)
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
|
||||
|
||||
def test_consistency_not_equal():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '')
|
||||
@ -786,6 +802,48 @@ def test_consistency_with_callback():
|
||||
api.option('c').value.get()
|
||||
|
||||
|
||||
def test_consistency_warnings_only_options():
|
||||
a = IPOption('a', '', warnings_only=True)
|
||||
b = IPOption('b', '')
|
||||
c = NetworkOption('c', '', default='192.168.1.0')
|
||||
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
|
||||
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(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_double_warnings():
|
||||
a = IntOption('a', '')
|
||||
b = IntOption('b', '', 1)
|
||||
@ -802,10 +860,7 @@ def test_consistency_double_warnings():
|
||||
assert len(w) == 2
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.c').value.set(2)
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert len(w) == 0
|
||||
else:
|
||||
assert len(w) == 1
|
||||
assert len(w) == 0
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('od.a').value.set(2)
|
||||
assert w != []
|
||||
|
Reference in New Issue
Block a user