tiramisu/test/test_option_consistency.py
Emmanuel Garette 6de65859b4 * config herite from BaseInformation class
* _cfgimpl_ => _impl_
* optimpl_ => impl_
* properties/permissives are now set/frozenset
* validation raise ValueError if not valid, didn't return anything otherwise
* consistencies are now validate in setting and when deleting value
* ip/network with netmask consistency now works
* DomainnameOption now works
* if no validation, don't set cache for value
* symlinkoption: remove path (not used)
2013-05-08 18:14:42 +02:00

70 lines
1.8 KiB
Python

import autopath
from py.test import raises
from tiramisu.setting import owners
from tiramisu.config import Config
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, IntOption,\
OptionDescription
def test_consistency_not_equal():
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', (a, b))
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
def test_consistency_default():
a = IntOption('a', '', 1)
b = IntOption('b', '', 1)
raises(ValueError, "a.impl_add_consistency('not_equal', (a, b))")
def test_consistency_default_diff():
a = IntOption('a', '', 3)
b = IntOption('b', '', 1)
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', (a, b))
c = Config(od)
raises(ValueError, "c.a = 1")
c.a = 2
c.b = 3
assert c.getowner('a') is owners.user
raises(ValueError, "del(c.a)")
assert c.getowner('a') is owners.user
def test_consistency_ip_netmask():
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', (b, a))
c = Config(od)
c.a = '192.168.1.1'
c.b = '255.255.255.0'
c.a = '192.168.1.2'
c.b = '255.255.255.255'
c.b = '255.255.255.0'
raises(ValueError, "c.a = '192.168.1.0'")
def test_consistency_network_netmask():
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('network_netmask', (b, a))
c = Config(od)
c.a = '192.168.1.1'
c.b = '255.255.255.255'
del(c.b)
c.a = '192.168.1.0'
c.b = '255.255.255.0'
raises(ValueError, "c.a = '192.168.1.1'")