2013-04-17 21:33:34 +02:00
|
|
|
# coding: utf-8
|
|
|
|
"frozen and hidden values"
|
|
|
|
import autopath
|
|
|
|
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
StrOption, OptionDescription
|
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.error import PropertiesOptionError
|
|
|
|
|
|
|
|
|
|
|
|
#____________________________________________________________
|
|
|
|
#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'))
|
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,
|
2014-03-28 17:35:27 +01:00
|
|
|
wantref_option, wantref2_option, stroption,
|
2013-04-17 21:33:34 +02:00
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_whole_config():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
setting = conf.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
conf.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('everything_frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
assert conf.gc.dummy is False
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
conf.gc.dummy = 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-20 17:30:05 +02:00
|
|
|
setting.remove('everything_frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
conf.gc.dummy = True
|
|
|
|
assert conf.gc.dummy is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_one_option():
|
|
|
|
"freeze an option "
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
setting = conf.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
conf.read_write()
|
2013-04-17 21:33:34 +02:00
|
|
|
#freeze only one option
|
|
|
|
dummy = conf.unwrap_from_path('gc.dummy')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[dummy].append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
assert conf.gc.dummy is False
|
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
conf.gc.dummy = 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])
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('frozen')
|
|
|
|
setting[s].append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.string = "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()
|
|
|
|
conf = Config(descr)
|
|
|
|
setting = conf.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
conf.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
name = conf.unwrap_from_path("gc.name")
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[name].append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
conf.gc.name = '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()
|
|
|
|
conf = Config(descr)
|
|
|
|
setting = conf.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
conf.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
obj = conf.unwrap_from_path('boolop')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[obj].append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
conf.boolop = [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_freeze_get_multi():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
setting = conf.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
conf.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
setting.append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
valmulti = conf.boolop
|
|
|
|
valmulti.append(False)
|
|
|
|
obj = conf.unwrap_from_path('boolop')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[obj].append('frozen')
|
2013-04-17 21:33:34 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
valmulti.append(False)
|
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)
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
2013-04-18 20:26:40 +02:00
|
|
|
conf.wantref
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_ro():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.read_only()
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
2013-04-23 19:01:03 +02:00
|
|
|
conf.wantref
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False)}
|
2014-03-28 17:35:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_hidden():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
|
|
|
conf.read_write()
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
2014-03-31 22:34:57 +02:00
|
|
|
conf.getattr('wantref2', force_permissive=True)
|
2014-03-29 20:31:56 +01:00
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref2': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_owner():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.getowner(conf.unwrap_from_path('wantref'))
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_owner_ro():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.read_only()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.getowner(conf.unwrap_from_path('wantref'))
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_owner_hidden():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
|
|
|
conf.read_write()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.getowner(conf.unwrap_from_path('wantref2'), force_permissive=True)
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref2': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_modified():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.cfgimpl_get_values().get_modified_values()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False), 'wantref2': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_modified_ro():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.read_only()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.cfgimpl_get_values().get_modified_values()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False), 'wantref2': ('user', False)}
|
|
|
|
|
|
|
|
|
|
|
|
def test_force_store_value_modified_hidden():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
|
|
|
conf.cfgimpl_get_settings().setpermissive(('hidden',))
|
|
|
|
conf.read_write()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {}
|
|
|
|
conf.cfgimpl_get_values().get_modified_values()
|
|
|
|
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', False), 'wantref2': ('user', False)}
|