tiramisu/test/new_api/test_permissive.py
2017-12-28 11:47:40 +01:00

258 lines
7.5 KiB
Python

# coding: utf-8
from .autopath import do_autopath
do_autopath()
from py.test import raises
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config, getapi
from tiramisu.error import PropertiesOptionError
def make_description():
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
return OptionDescription('od1', '', [u1, u2])
def test_permissive():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
api.property.read_write()
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.permissive.set(frozenset(['disabled']))
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
def test_permissive_mandatory():
descr = make_description()
api = getapi(Config(descr))
api.property.read_only()
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
api.permissive.set(frozenset(['mandatory', 'disabled']))
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
def test_permissive_frozen():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
api.permissive.set(frozenset(['frozen', 'disabled']))
try:
api.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
api.property.add('permissive')
api.option('u1').value.set(1)
assert api.option('u1').value.get() == 1
api.property.pop('permissive')
try:
api.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
def test_invalid_permissive():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
raises(TypeError, "api.permissive.set(['frozen', 'disabled'])")
def test_permissive_option():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.option('u1').permissive.set(frozenset(['disabled']))
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.property.add('permissive')
api.option('u1').value.get()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.property.pop('permissive')
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
def test_permissive_option_cache():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.option('u1').permissive.set(frozenset(['disabled']))
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.property.add('permissive')
api.option('u1').value.get()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
api.property.pop('permissive')
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset()
props = frozenset()
try:
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == {'disabled'}
def test_permissive_option_mandatory():
descr = make_description()
api = getapi(Config(descr))
api.property.read_only()
props = frozenset()
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
api.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try:
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
def test_permissive_option_frozen():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
api.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
api.option('u1').value.set(1)
assert api.option('u1').value.get() == 1
api.property.add('permissive')
assert api.option('u1').value.get() == 1
api.property.pop('permissive')
assert api.option('u1').value.get() == 1
def test_invalid_option_permissive():
descr = make_description()
api = getapi(Config(descr))
api.property.read_write()
raises(TypeError, "api.option('u1').permissive.set(['frozen', 'disabled'])")
def test_remove_option_permissive():
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1])
api = getapi(Config(rootod))
api.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
api.option('od1.var1').permissive.set(frozenset(['hidden']))
assert api.option('od1.var1').value.get() == 'value'
api.option('od1.var1').permissive.set(frozenset())
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")