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
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
from tiramisu.setting import owners, groups
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
|
|
|
|
getapi
|
2016-03-07 16:13:41 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
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)
|
2013-04-18 20:26:40 +02:00
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
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)
|
2013-04-17 21:33:34 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
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
|
|
|
|
|
|
|
|
|
2013-04-17 21:33:34 +02:00
|
|
|
def test_freeze_whole_config():
|
|
|
|
descr = make_description_freeze()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.add('everything_frozen')
|
|
|
|
assert api.option('gc.dummy').value.get() is False
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.dummy').value.set(True)
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
2018-03-19 08:33:53 +01:00
|
|
|
assert api.option('gc.dummy').value.get() is False
|
|
|
|
#
|
|
|
|
api.property.pop('everything_frozen')
|
|
|
|
api.option('gc.dummy').value.set(True)
|
|
|
|
assert api.option('gc.dummy').value.get() is True
|
2015-12-31 18:20:36 +01:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.add('everything_frozen')
|
|
|
|
owners.addowner("everythingfrozen2")
|
2014-10-26 08:51:45 +01:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.dummy').owner.set('everythingfrozen2')
|
2014-10-26 08:51:45 +01:00
|
|
|
except PropertiesOptionError as err:
|
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
2013-04-17 21:33:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_one_option():
|
|
|
|
"freeze an option "
|
|
|
|
descr = make_description_freeze()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
2013-04-17 21:33:34 +02:00
|
|
|
#freeze only one option
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.dummy').property.add('frozen')
|
|
|
|
assert api.option('gc.dummy').value.get() is False
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.dummy').value.set(True)
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_frozen_value():
|
|
|
|
"setattr a frozen value at the config level"
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.add('frozen')
|
|
|
|
api.option('string').property.add('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('string').value.set('egg')
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze():
|
|
|
|
"freeze a whole configuration object"
|
|
|
|
descr = make_description_freeze()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.add('frozen')
|
|
|
|
api.option('gc.name').property.add('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.name').value.set('framework')
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_multi():
|
|
|
|
descr = make_description_freeze()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.add('frozen')
|
|
|
|
api.option('boolop').property.add('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('boolop').value.set([True])
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'frozen' in prop
|
2013-04-18 20:26:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(conf)
|
|
|
|
assert api.value.get_modified() == {'wantref': ('forced', False),
|
|
|
|
'wantref2': ('forced', False),
|
|
|
|
'wantref3': ('forced', (False,))}
|
|
|
|
api.option('wantref').value.set(True)
|
|
|
|
assert api.value.get_modified() == {'wantref': ('user', True),
|
|
|
|
'wantref2': ('forced', False),
|
|
|
|
'wantref3': ('forced', (False,))}
|
|
|
|
api.option('wantref').value.reset()
|
|
|
|
assert api.value.get_modified() == {'wantref': ('forced', False),
|
|
|
|
'wantref2': ('forced', False),
|
|
|
|
'wantref3': ('forced', (False,))}
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_no_requirement():
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
try:
|
|
|
|
BoolOption('wantref', 'Test requires', default=False,
|
|
|
|
requires=({'option': booloption, 'expected': True, 'action': 'force_store_value'},))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2013-04-23 19:01:03 +02:00
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def test_force_store_value_masterslaves_slave():
|
|
|
|
b = IntOption('int', 'Test int option', multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
|
2017-10-14 13:33:25 +02:00
|
|
|
descr = MasterSlaves("int", "", [b, c])
|
2016-03-07 16:13:41 +01:00
|
|
|
raises(ConfigError, "conf = Config(descr)")
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
#def test_force_store_value_masterslaves():
|
|
|
|
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
|
|
|
# c = StrOption('str', 'Test string option', multi=True)
|
|
|
|
# descr = MasterSlaves("int", "", [b, c])
|
|
|
|
# api = getapi(Config(descr))
|
|
|
|
# assert api.value.get() == {'int': ('forced', ())}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_masterslaves_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)
|
2017-10-14 13:33:25 +02:00
|
|
|
descr = MasterSlaves("int", "", [b, c])
|
2018-03-19 08:33:53 +01:00
|
|
|
odr = OptionDescription('odr', '', [descr])
|
|
|
|
api = getapi(Config(odr))
|
|
|
|
assert api.value.get_modified() == {'int.int': ('forced', ())}
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def test_force_store_value_callback():
|
|
|
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
|
|
|
descr = OptionDescription("int", "", [b])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.value.get_modified() == {'int': ('forced', 1)}
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def test_force_store_value_callback_params():
|
|
|
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
|
|
|
descr = OptionDescription("int", "", [b])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.value.get_modified() == {'int': ('forced', 2)}
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def test_force_store_value_callback_params_2():
|
|
|
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
|
|
|
descr = OptionDescription("int", "", [b])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.value.get_modified() == {'int': ('forced', 2)}
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
|
2016-03-07 16:13:41 +01:00
|
|
|
def test_force_store_value_callback_params_with_opt():
|
|
|
|
a = IntOption('val1', "", 2)
|
|
|
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
|
|
|
descr = OptionDescription("int", "", [a, b])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
assert api.value.get_modified() == {'int': ('forced', 2)}
|