tiramisu/tests/test_permissive.py

444 lines
17 KiB
Python
Raw Permalink 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
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
2020-01-22 20:46:18 +01:00
from .config import config_type, get_config, event_loop
def make_description():
u1 = IntOption('u1', '', properties=('frozen', 'mandatory', 'disabled', ))
u2 = IntOption('u2', '', properties=('frozen', 'mandatory', 'disabled', ))
return OptionDescription('od1', '', [u1, u2])
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive(config_type):
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.permissive.add('disabled')
await cfg_ori.unrestraint.permissive.pop('hidden')
assert await cfg_ori.unrestraint.permissive.get() == frozenset(['disabled'])
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.add('permissive')
cfg = await get_config(cfg_ori, config_type)
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.pop('permissive')
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_add(config_type):
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.permissive.add('disabled')
assert await cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.add('permissive')
cfg = await get_config(cfg_ori, config_type)
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.pop('permissive')
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_pop():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.property.read_write()
props = frozenset()
try:
await cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
await cfg.unrestraint.permissive.add('disabled')
assert await cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
2019-12-24 15:24:20 +01:00
await cfg.forcepermissive.option('u1').value.get()
2020-01-22 20:46:18 +01:00
await cfg.unrestraint.permissive.pop('disabled')
props = frozenset()
try:
await cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_reset():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
assert await cfg.unrestraint.permissive.get() == frozenset(['hidden'])
#
await cfg.unrestraint.permissive.add('disabled')
await cfg.unrestraint.permissive.pop('hidden')
assert await cfg.unrestraint.permissive.get() == frozenset(['disabled'])
#
await cfg.unrestraint.permissive.reset()
assert await cfg.unrestraint.permissive.get() == frozenset()
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_mandatory():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_only()
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
await cfg.unrestraint.permissive.add('mandatory')
await cfg.unrestraint.permissive.add('disabled')
assert await cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
await cfg.property.add('permissive')
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
await cfg.property.pop('permissive')
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_frozen():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.unrestraint.permissive.pop('hidden')
await cfg.unrestraint.permissive.add('frozen')
await cfg.unrestraint.permissive.add('disabled')
assert await cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert await cfg.permissive.get() == frozenset(['frozen', 'disabled'])
try:
await cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
await cfg.property.add('permissive')
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.set(1)
2020-01-22 20:46:18 +01:00
assert await cfg.option('u1').value.get() == 1
await cfg.property.pop('permissive')
try:
await cfg.option('u1').value.set(1)
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
assert not await list_sessions()
2013-08-23 09:29:42 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_invalid_permissive():
2018-09-15 22:44:49 +02:00
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
# FIXME with pytest.raises(TypeError):
# await cfg.unrestraint.permissive.set(['frozen', 'disabled'])")
assert not await list_sessions()
2018-09-15 22:44:49 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_forbidden_permissive():
2018-09-15 22:44:49 +02:00
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.permissive.add('force_default_on_freeze')
with pytest.raises(ConfigError):
await cfg.permissive.add('force_metaconfig_on_freeze')
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_option(config_type):
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.add('permissive')
cfg = await get_config(cfg_ori, config_type)
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.pop('permissive')
cfg = await get_config(cfg_ori, config_type)
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
assert not await list_sessions()
2017-07-21 18:03:34 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_option_cache():
2017-07-21 18:03:34 +02:00
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
await cfg.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
await cfg.property.add('permissive')
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
await cfg.property.pop('permissive')
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset()
props = frozenset()
try:
await cfg.option('u2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled'}
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_option_mandatory():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_only()
props = frozenset()
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
await cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
assert await cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
await cfg.property.add('permissive')
2019-12-24 15:24:20 +01:00
await cfg.option('u1').value.get()
2020-01-22 20:46:18 +01:00
await cfg.property.pop('permissive')
try:
await cfg.option('u1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_permissive_option_frozen():
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
await cfg.option('u1').value.set(1)
assert await cfg.option('u1').value.get() == 1
await cfg.property.add('permissive')
assert await cfg.option('u1').value.get() == 1
await cfg.property.pop('permissive')
assert await cfg.option('u1').value.get() == 1
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_invalid_option_permissive():
2019-07-04 20:43:47 +02:00
descr = make_description()
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
with pytest.raises(TypeError):
await cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])
assert not await list_sessions()
2019-07-04 20:43:47 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async 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])
2020-01-22 20:46:18 +01:00
descr = OptionDescription('rootod', '', [od1])
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.var1').value.get()
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert await cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset())
assert await cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.var1').value.get()
assert not await list_sessions()
2019-07-04 20:43:47 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async 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])
2020-01-22 20:46:18 +01:00
descr = OptionDescription('rootod', '', [od1])
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.var1').value.get()
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert await cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.forcepermissive.option('od1.var1').permissive.reset()
assert await cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.var1').value.get()
assert not await list_sessions()