tiramisu/test/test_permissive.py

280 lines
8.5 KiB
Python
Raw Normal View History

# coding: utf-8
2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
2013-08-23 09:29:42 +02:00
from py.test import raises
2018-08-14 23:07:07 +02:00
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config
from tiramisu.error import PropertiesOptionError
2018-03-19 08:33:53 +01:00
from tiramisu.api import TIRAMISU_VERSION
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()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.property.read_write()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
api.unrestraint.permissive.set(frozenset(['disabled']))
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
def test_permissive_mandatory():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
2018-03-19 08:33:53 +01:00
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_frozen():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'frozen'])
else:
assert frozenset(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:
2018-03-19 08:33:53 +01:00
api.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'frozen'])
else:
assert frozenset(props) == frozenset(['disabled'])
2013-08-23 09:29:42 +02:00
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 3:
def test_invalid_permissive():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])")
def test_permissive_option():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
api.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert frozenset(props) == frozenset()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2018-03-19 08:33:53 +01:00
api.property.add('permissive')
api.option('u1').value.get()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2018-03-19 08:33:53 +01:00
api.property.pop('permissive')
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
2017-07-21 18:03:34 +02:00
props = err.proptype
2018-03-19 08:33:53 +01:00
assert frozenset(props) == frozenset()
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2017-07-21 18:03:34 +02:00
def test_permissive_option_cache():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
2017-07-21 18:03:34 +02:00
2018-03-19 08:33:53 +01:00
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2017-07-21 18:03:34 +02:00
api.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
2018-03-19 08:33:53 +01:00
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert frozenset(props) == frozenset()
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2017-07-21 18:03:34 +02:00
2018-03-19 08:33:53 +01:00
api.property.add('permissive')
api.option('u1').value.get()
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2017-07-21 18:03:34 +02:00
2018-03-19 08:33:53 +01:00
api.property.pop('permissive')
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
2017-07-21 18:03:34 +02:00
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert frozenset(props) == frozenset()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
def test_permissive_option_mandatory():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_only()
props = frozenset()
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
2018-03-19 08:33:53 +01:00
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try:
2018-03-19 08:33:53 +01:00
api.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
if TIRAMISU_VERSION == 2:
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_option_frozen():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
api.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
2018-03-19 08:33:53 +01:00
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
if TIRAMISU_VERSION == 3:
def test_invalid_option_permissive():
descr = make_description()
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
raises(TypeError, "api.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
2017-04-20 11:20:37 +02:00
def test_remove_option_permissive():
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1])
2018-08-14 23:07:07 +02:00
api = Config(rootod)
2018-03-19 08:33:53 +01:00
api.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
2018-03-19 08:33:53 +01:00
assert api.option('od1.var1').value.get() == 'value'
api.forcepermissive.option('od1.var1').permissive.set(frozenset())
2018-03-19 08:33:53 +01:00
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")