tiramisu/tests/test_permissive.py

422 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()
2013-08-23 09:29:42 +02:00
2019-12-24 15:24:20 +01:00
import pytest
2019-12-08 09:09:48 +01:00
from tiramisu import IntOption, StrOption, OptionDescription, Config
2023-04-27 11:44:52 +02:00
from tiramisu.error import PropertiesOptionError, ConfigError
from .config import config_type, get_config
def make_description():
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
return OptionDescription('od1', '', [u1, u2])
def test_forcepermissive_and_unrestraint(config_type):
od1 = make_description()
cfg_ori = Config(od1)
cfg_ori.property.read_write()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
2023-04-27 11:44:52 +02:00
with pytest.raises(ConfigError):
2024-06-20 12:56:27 +02:00
cfg_ori.forcepermissive.add('disabled')
def test_permissive(config_type):
od1 = make_description()
cfg_ori = Config(od1)
cfg_ori.property.read_write()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
cfg.send()
2024-06-20 12:56:27 +02:00
cfg_ori.permissive.add('disabled')
cfg_ori.permissive.remove('hidden')
assert cfg_ori.permissive.get() == frozenset(['disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
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.remove('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
# assert not list_sessions()
def test_permissive_add(config_type):
od1 = make_description()
cfg_ori = Config(od1)
cfg_ori.property.read_write()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
cfg.send()
2024-06-20 12:56:27 +02:00
cfg_ori.permissive.add('disabled')
assert cfg_ori.permissive.get() == frozenset(['hidden', 'disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
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.remove('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
# assert not list_sessions()
def test_permissive_pop():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
cfg.property.read_write()
props = frozenset()
try:
cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
2024-06-20 12:56:27 +02:00
cfg.permissive.add('disabled')
assert cfg.permissive.get() == frozenset(['hidden', 'disabled'])
cfg.forcepermissive.option('u1').value.get()
2024-06-20 12:56:27 +02:00
cfg.permissive.remove('disabled')
props = frozenset()
try:
cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
# assert not list_sessions()
def test_permissive_reset():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
2024-06-20 12:56:27 +02:00
assert cfg.permissive.get() == frozenset(['hidden'])
#
2024-06-20 12:56:27 +02:00
cfg.permissive.add('disabled')
cfg.permissive.remove('hidden')
assert cfg.permissive.get() == frozenset(['disabled'])
#
2024-06-20 12:56:27 +02:00
cfg.permissive.reset()
assert cfg.permissive.get() == frozenset(['hidden'])
# assert not list_sessions()
def test_permissive_mandatory():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
2024-06-20 12:56:27 +02:00
cfg.permissive.add('mandatory')
cfg.permissive.add('disabled')
assert cfg.permissive.get() == frozenset(['hidden', 'mandatory', 'disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.get()
cfg.property.remove('permissive')
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
# assert not list_sessions()
def test_permissive_frozen():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
2024-06-20 12:56:27 +02:00
cfg.permissive.remove('hidden')
cfg.permissive.add('frozen')
cfg.permissive.add('disabled')
assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
try:
cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.set(1)
assert cfg.option('u1').value.get() == 1
cfg.property.remove('permissive')
try:
cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
# assert not list_sessions()
def test_forbidden_permissive():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
with pytest.raises(ConfigError):
cfg.permissive.add('force_default_on_freeze')
with pytest.raises(ConfigError):
cfg.permissive.add('force_metaconfig_on_freeze')
# assert not list_sessions()
def test_permissive_option(config_type):
od1 = make_description()
cfg_ori = Config(od1)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
cfg.send()
2024-06-20 12:56:27 +02:00
cfg_ori.option('u1').permissive.add('disabled')
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.remove('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
# assert not list_sessions()
def test_permissive_option_cache():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
2024-06-20 12:56:27 +02:00
cfg.option('u1').permissive.add('disabled')
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
cfg.property.add('permissive')
cfg.option('u1').value.get()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
cfg.property.remove('permissive')
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
# assert not list_sessions()
def test_permissive_option_mandatory():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_only()
props = frozenset()
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
2024-06-20 12:56:27 +02:00
cfg.option('u1').permissive.add('mandatory')
cfg.option('u1').permissive.add('disabled')
assert cfg.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
cfg.property.add('permissive')
cfg.option('u1').value.get()
cfg.property.remove('permissive')
try:
cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
# assert not list_sessions()
def test_permissive_option_frozen():
od1 = make_description()
cfg = Config(od1)
cfg.property.read_write()
2024-06-20 12:56:27 +02:00
cfg.option('u1').permissive.add('disabled')
cfg.option('u1').permissive.add('frozen')
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.remove('permissive')
assert cfg.option('u1').value.get() == 1
# assert not list_sessions()
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])
od2 = OptionDescription('rootod', '', [od1])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
cfg.option('od1.var1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
2024-06-20 12:56:27 +02:00
cfg_ori.forcepermissive.option('od1.var1').permissive.add('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()
2024-06-20 12:56:27 +02:00
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)
with pytest.raises(PropertiesOptionError):
cfg.option('od1.var1').value.get()
# assert not list_sessions()
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])
od2 = OptionDescription('rootod', '', [od1])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
cfg.option('od1.var1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
2024-06-20 12:56:27 +02:00
cfg_ori.forcepermissive.option('od1.var1').permissive.add('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)
with pytest.raises(PropertiesOptionError):
cfg.option('od1.var1').value.get()
# assert not list_sessions()