tiramisu/tests/test_permissive.py

410 lines
13 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()
2019-07-04 20:43:47 +02:00
from .config import config_type, get_config
2015-07-24 17:54:10 +02:00
2013-08-23 09:29:42 +02:00
from py.test import raises
2019-12-08 09:09:48 +01:00
from tiramisu import IntOption, StrOption, OptionDescription, Config
2018-09-15 22:44:49 +02:00
from tiramisu.error import PropertiesOptionError, ConfigError
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions, delete_session
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
return OptionDescription('od1', '', [u1, u2])
2019-07-04 20:43:47 +02:00
def test_permissive(config_type):
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
2019-12-08 09:09:48 +01:00
cfg_ori.unrestraint.permissive.add('disabled')
cfg_ori.unrestraint.permissive.pop('hidden')
2019-07-04 20:43:47 +02:00
assert cfg_ori.unrestraint.permissive.get() == frozenset(['disabled'])
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
def test_permissive_add(config_type):
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.permissive.add('disabled')
assert cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
def test_permissive_pop():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
cfg.property.read_write()
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
cfg.unrestraint.permissive.add('disabled')
assert cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
cfg.forcepermissive.option('u1').value.get()
cfg.unrestraint.permissive.pop('disabled')
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
def test_permissive_reset():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
assert cfg.unrestraint.permissive.get() == frozenset(['hidden'])
#
2019-12-08 09:09:48 +01:00
cfg.unrestraint.permissive.add('disabled')
cfg.unrestraint.permissive.pop('hidden')
2019-07-04 20:43:47 +02:00
assert cfg.unrestraint.permissive.get() == frozenset(['disabled'])
#
2019-07-04 20:43:47 +02:00
cfg.unrestraint.permissive.reset()
assert cfg.unrestraint.permissive.get() == frozenset()
def test_permissive_mandatory():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_only()
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
2019-12-08 09:09:48 +01:00
cfg.unrestraint.permissive.add('mandatory')
cfg.unrestraint.permissive.add('disabled')
2019-07-04 20:43:47 +02:00
assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.get()
cfg.property.pop('permissive')
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_frozen():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
2019-12-08 09:09:48 +01:00
cfg.unrestraint.permissive.pop('hidden')
cfg.unrestraint.permissive.add('frozen')
cfg.unrestraint.permissive.add('disabled')
2019-07-04 20:43:47 +02:00
assert cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.set(1)
assert cfg.option('u1').value.get() == 1
cfg.property.pop('permissive')
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
2013-08-23 09:29:42 +02:00
2018-09-15 22:44:49 +02:00
def test_invalid_permissive():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
2019-12-08 09:09:48 +01:00
# FIXME raises(TypeError, "cfg.unrestraint.permissive.set(['frozen', 'disabled'])")
2018-09-15 22:44:49 +02:00
def test_forbidden_permissive():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
2019-12-08 09:09:48 +01:00
raises(ConfigError, "cfg.permissive.add('force_default_on_freeze')")
raises(ConfigError, "cfg.permissive.add('force_metaconfig_on_freeze')")
2019-07-04 20:43:47 +02:00
def test_permissive_option(config_type):
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
2018-03-19 08:33:53 +01:00
assert set(props) == {'disabled'}
2019-07-04 20:43:47 +02:00
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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
2019-07-04 20:43:47 +02:00
cfg.property.add('permissive')
cfg.option('u1').value.get()
2018-03-19 08:33:53 +01:00
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2019-07-04 20:43:47 +02:00
cfg.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
2019-07-04 20:43:47 +02:00
cfg.property.pop('permissive')
2018-03-19 08:33:53 +01:00
props = frozenset()
2017-07-21 18:03:34 +02:00
try:
2019-07-04 20:43:47 +02:00
cfg.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:
2019-07-04 20:43:47 +02:00
cfg.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()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_only()
2018-03-19 08:33:53 +01:00
props = frozenset()
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.get()
cfg.property.pop('permissive')
try:
2019-07-04 20:43:47 +02:00
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
2019-07-04 20:43:47 +02:00
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_option_frozen():
descr = make_description()
2019-07-04 20:43:47 +02:00
cfg = Config(descr)
cfg.property.read_write()
cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
cfg.option('u1').value.set(1)
assert cfg.option('u1').value.get() == 1
cfg.property.add('permissive')
assert cfg.option('u1').value.get() == 1
cfg.property.pop('permissive')
assert cfg.option('u1').value.get() == 1
def test_invalid_option_permissive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
raises(TypeError, "cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
def test_remove_option_permissive(config_type):
2019-12-08 09:09:48 +01:00
var1 = StrOption('var1', '', u'value', properties=('hidden',))
2017-04-20 11:20:37 +02:00
od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1])
2019-07-04 20:43:47 +02:00
cfg_ori = Config(rootod)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset())
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
def test_reset_option_permissive(config_type):
2019-12-08 09:09:48 +01:00
var1 = StrOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1])
2019-07-04 20:43:47 +02:00
cfg_ori = Config(rootod)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.reset()
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")