2013-04-17 21:33:34 +02:00
|
|
|
# coding: utf-8
|
|
|
|
"frozen and hidden values"
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2013-04-17 21:33:34 +02:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
2016-03-07 16:13:41 +01:00
|
|
|
|
|
|
|
from tiramisu.setting import owners, groups
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2019-02-23 19:06:23 +01:00
|
|
|
StrOption, OptionDescription, SymLinkOption, Leadership, Config, \
|
2020-01-22 20:46:18 +01:00
|
|
|
Calculation, Params, ParamOption, ParamValue, calc_value, delete_session
|
2016-03-07 16:13:41 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
2018-10-31 08:00:19 +01:00
|
|
|
from tiramisu.storage import list_sessions
|
2020-01-22 20:46:18 +01:00
|
|
|
from .config import event_loop
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2018-06-09 18:59:40 +02:00
|
|
|
def compare(calculated, expected):
|
|
|
|
def convert_list(val):
|
|
|
|
if isinstance(val, list):
|
|
|
|
val = tuple(val)
|
|
|
|
return val
|
|
|
|
# convert to tuple
|
|
|
|
for idx in range(len(calculated[0])):
|
|
|
|
right_idx = expected[0].index(calculated[0][idx])
|
|
|
|
for typ in range(4):
|
|
|
|
assert convert_list(calculated[typ][idx]) == expected[typ][right_idx]
|
|
|
|
|
|
|
|
|
2013-04-17 21:33:34 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
#freeze
|
|
|
|
def make_description_freeze():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
2019-09-01 09:41:53 +02:00
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
|
|
|
|
'expected': ParamValue(True),
|
|
|
|
'default': ParamValue(None)}))
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value', hidden_property))
|
2014-03-28 17:35:27 +01:00
|
|
|
wantref2_option = BoolOption('wantref2', 'Test requires', default=False, properties=('force_store_value', 'hidden'))
|
2014-04-18 21:33:15 +02:00
|
|
|
wantref3_option = BoolOption('wantref3', 'Test requires', default=[False], multi=True, properties=('force_store_value',))
|
2016-03-24 19:43:41 +01:00
|
|
|
st2 = SymLinkOption('st2', wantref3_option)
|
2019-09-01 09:41:53 +02:00
|
|
|
hidden_property = Calculation(calc_value,
|
|
|
|
Params(ParamValue('hidden'),
|
|
|
|
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
|
|
|
|
'expected': ParamValue(True),
|
|
|
|
'default': ParamValue(None)}))
|
2013-04-17 21:33:34 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2019-09-01 09:41:53 +02:00
|
|
|
properties=(hidden_property,))
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
2016-03-24 19:43:41 +01:00
|
|
|
wantref_option, wantref2_option, wantref3_option, st2, stroption,
|
2013-04-17 21:33:34 +02:00
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def return_val():
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
def return_val2(value):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def return_val3(context, value):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_freeze_whole_config():
|
2013-04-17 21:33:34 +02:00
|
|
|
descr = make_description_freeze()
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.property.add('everything_frozen')
|
|
|
|
assert await cfg.option('gc.dummy').value.get() is False
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('gc.dummy').value.set(True)
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert await cfg.option('gc.dummy').value.get() is False
|
|
|
|
#
|
|
|
|
await cfg.property.pop('everything_frozen')
|
2019-12-24 15:24:20 +01:00
|
|
|
await cfg.option('gc.dummy').value.set(True)
|
2020-01-22 20:46:18 +01:00
|
|
|
assert await cfg.option('gc.dummy').value.get() is True
|
|
|
|
#
|
|
|
|
await cfg.property.add('everything_frozen')
|
|
|
|
owners.addowner("everythingfrozen2")
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('gc.dummy').owner.set('everythingfrozen2')
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert not await list_sessions()
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_freeze_one_option():
|
2013-04-17 21:33:34 +02:00
|
|
|
"freeze an option "
|
|
|
|
descr = make_description_freeze()
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
await cfg.property.read_write()
|
|
|
|
#freeze only one option
|
|
|
|
await cfg.option('gc.dummy').property.add('frozen')
|
|
|
|
assert await cfg.option('gc.dummy').value.get() is False
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('gc.dummy').value.set(True)
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert not await list_sessions()
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_frozen_value():
|
2013-04-17 21:33:34 +02:00
|
|
|
"setattr a frozen value at the config level"
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.property.add('frozen')
|
|
|
|
await cfg.option('string').property.add('frozen')
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('string').value.set('egg')
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert not await list_sessions()
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_freeze():
|
2013-04-17 21:33:34 +02:00
|
|
|
"freeze a whole configuration object"
|
|
|
|
descr = make_description_freeze()
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.property.add('frozen')
|
|
|
|
await cfg.option('gc.name').property.add('frozen')
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('gc.name').value.set('framework')
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert not await list_sessions()
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_freeze_multi():
|
2013-04-17 21:33:34 +02:00
|
|
|
descr = make_description_freeze()
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
await cfg.property.read_write()
|
|
|
|
await cfg.property.add('frozen')
|
|
|
|
await cfg.option('boolop').property.add('frozen')
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
await cfg.option('boolop').value.set([True])
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
assert not await list_sessions()
|
2013-04-18 20:26:40 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_force_store_value():
|
2013-04-18 20:26:40 +02:00
|
|
|
descr = make_description_freeze()
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
|
|
|
|
await cfg.option('wantref').value.set(True)
|
|
|
|
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (True, False, (False,)), ('user', 'forced', 'forced')))
|
|
|
|
await cfg.option('wantref').value.reset()
|
|
|
|
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
|
|
|
|
assert not await list_sessions()
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_force_store_value_leadership_sub():
|
2016-03-07 16:13:41 +01:00
|
|
|
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
|
|
|
c = StrOption('str', 'Test string option', multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
descr = Leadership("int", "", [b, c])
|
2018-03-19 08:33:53 +01:00
|
|
|
odr = OptionDescription('odr', '', [descr])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(odr) as cfg:
|
|
|
|
compare(await cfg.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',)))
|
|
|
|
assert not await list_sessions()
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_force_store_value_callback():
|
2019-09-28 16:32:48 +02:00
|
|
|
b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',))
|
2016-03-07 16:13:41 +01:00
|
|
|
descr = OptionDescription("int", "", [b])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
compare(await cfg.value.exportation(), (('int',), (None,), (1,), ('forced',)))
|
|
|
|
assert not await list_sessions()
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_force_store_value_callback_params():
|
2019-09-28 16:32:48 +02:00
|
|
|
b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',))
|
2016-03-07 16:13:41 +01:00
|
|
|
descr = OptionDescription("int", "", [b])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
compare(await cfg.value.exportation(), (('int',), (None,), (2,), ('forced',)))
|
|
|
|
assert not await list_sessions()
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_force_store_value_callback_params_with_opt():
|
2016-03-07 16:13:41 +01:00
|
|
|
a = IntOption('val1', "", 2)
|
2019-09-28 16:32:48 +02:00
|
|
|
b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',))
|
2016-03-07 16:13:41 +01:00
|
|
|
descr = OptionDescription("int", "", [a, b])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(descr) as cfg:
|
|
|
|
compare(await cfg.value.exportation(), (('int',), (None,), (2,), ('forced',)))
|
|
|
|
assert not await list_sessions()
|