2013-04-20 17:30:05 +02:00
|
|
|
# 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-03-19 08:33:53 +01:00
|
|
|
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config, getapi
|
2013-04-20 17:30:05 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu.api import TIRAMISU_VERSION
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def make_description():
|
|
|
|
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
|
2013-12-09 15:29:37 +01:00
|
|
|
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
|
|
|
|
return OptionDescription('od1', '', [u1, u2])
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.read_write()
|
|
|
|
props = frozenset()
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2018-04-06 08:30:32 +02:00
|
|
|
api.unrestraint.permissive.set(frozenset(['disabled']))
|
2018-03-19 08:33:53 +01:00
|
|
|
props = frozenset()
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
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()
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_mandatory():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_only()
|
|
|
|
props = frozenset()
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
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'])
|
2018-04-06 08:30:32 +02:00
|
|
|
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')
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
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'])
|
2013-04-20 17:30:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_frozen():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2018-04-06 08:30:32 +02:00
|
|
|
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.set(1)
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
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')
|
2013-04-20 17:30:05 +02:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.set(1)
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-20 17:30:05 +02:00
|
|
|
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()
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2018-04-06 08:30:32 +02:00
|
|
|
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])")
|
2013-12-09 15:29:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2013-12-09 15:29:37 +01:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2013-12-09 15:29:37 +01:00
|
|
|
|
2018-04-06 08:30:32 +02:00
|
|
|
api.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
|
2018-03-19 08:33:53 +01:00
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert frozenset(props) == frozenset()
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2013-12-09 15:29:37 +01:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.add('permissive')
|
|
|
|
api.option('u1').value.get()
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2013-12-09 15:29:37 +01:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.pop('permissive')
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
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-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
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
|
|
|
|
2018-04-06 08:30:32 +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:
|
2013-12-09 15:29:37 +01:00
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert frozenset(props) == frozenset()
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u2').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
2018-03-19 08:33:53 +01:00
|
|
|
assert set(props) == {'disabled'}
|
2013-12-09 15:29:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option_mandatory():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_only()
|
|
|
|
props = frozenset()
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
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'])
|
2018-04-06 08:30:32 +02:00
|
|
|
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')
|
2013-12-09 15:29:37 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('u1').value.get()
|
2013-12-09 15:29:37 +01:00
|
|
|
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'])
|
2013-12-09 15:29:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_permissive_option_frozen():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2018-04-06 08:30:32 +02:00
|
|
|
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()
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2018-04-06 08:30:32 +02:00
|
|
|
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-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(rootod))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|
2018-04-06 08:30:32 +02:00
|
|
|
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'
|
2018-04-06 08:30:32 +02:00
|
|
|
api.forcepermissive.option('od1.var1').permissive.set(frozenset())
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(PropertiesOptionError, "api.option('od1.var1').value.get()")
|