tiramisu/test/test_requires.py

264 lines
7.1 KiB
Python

# coding: utf-8
import autopath
from tiramisu import setting
setting.expires_time = 1
from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption
from tiramisu.config import Config
from tiramisu.error import PropertiesOptionError, RequirementError
from py.test import raises
def test_requires():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '',
requires=[(a, False, 'disabled')])
od = OptionDescription('service', '', [a, b])
c = Config(od)
c.read_write()
c.ip_address_service
c.activate_service = False
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_same_action():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'new')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled', False, True, False)])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.cfgimpl_get_settings().append('new')
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['new']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_transitive_bis():
a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, True, 'disabled', True)])
d = IPOption('ip_address_service_web', '',
requires=[(b, True, 'disabled', True)])
od = OptionDescription('service', '', [a, abis, b, d])
c = Config(od)
c.read_write()
#
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_transitive_hidden_disabled():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'hidden')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['hidden']
raises(RequirementError, 'c.ip_address_service_web')
def test_requires_not_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled', False, False)])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
c.ip_address_service_web
def test_requires_None():
a = BoolOption('activate_service', '')
b = IPOption('ip_address_service', '',
requires=[(a, None, 'disabled')])
od = OptionDescription('service', '', [a, b])
c = Config(od)
c.read_write()
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = False
c.ip_address_service
def test_requires_multi_disabled():
a = BoolOption('activate_service', '')
b = IntOption('num_service', '')
c = IPOption('ip_address_service', '',
requires=[(a, True, 'disabled'), (b, 1, 'disabled')])
od = OptionDescription('service', '', [a, b, c])
c = Config(od)
c.read_write()
c.ip_address_service
c.activate_service = True
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = False
c.ip_address_service
c.num_service = 1
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = True
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_multi_disabled_inverse():
a = BoolOption('activate_service', '')
b = IntOption('num_service', '')
c = IPOption('ip_address_service', '',
requires=[(a, True, 'disabled', True), (b, 1, 'disabled', True)])
od = OptionDescription('service', '', [a, b, c])
c = Config(od)
c.read_write()
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = True
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = False
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.num_service = 1
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
c.activate_service = True
c.ip_address_service