d4ef47759e
c.cfgimpl_get_settings().has_property('hidden') => 'hidden' in c.cfgimpl_get_settings() c.cfgimpl_get_settings().has_property('hidden', option1) => 'frozen' in c.cfgimpl_get_settings()[opt] c.cfgimpl_get_settings().get_properties(option1) => c.cfgimpl_get_settings()[option1] c.cfgimpl_get_settings().get_properties(option1) => c.cfgimpl_get_settings()[option1] c.cfgimpl_get_settings().add_property('hidden', option1) => c.cfgimpl_get_settings()[optiont1].append('hidden') c.cfgimpl_get_settings().del_property('hidden', option1) => c.cfgimpl_get_settings()[optiont1].remove('hidden') c.cfgimpl_get_settings().enable_property('hidden') => c.cfgimpl_get_settings().append('hidden') c.cfgimpl_get_settings().disable_property('hidden') => c.cfgimpl_get_settings().remove('hidden')
147 lines
4.6 KiB
Python
147 lines
4.6 KiB
Python
# 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)
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
|
requires=(('boolop', True, 'hidden'),))
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
default=False,
|
|
requires=(('boolop', True, 'hidden'),))
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
|
wantref_option, stroption,
|
|
wantframework_option,
|
|
intoption, boolop])
|
|
return descr
|
|
|
|
|
|
def test_freeze_whole_config():
|
|
descr = make_description_freeze()
|
|
conf = Config(descr)
|
|
setting = conf.cfgimpl_get_settings()
|
|
setting.read_write()
|
|
setting.append('everything_frozen')
|
|
assert conf.gc.dummy is False
|
|
prop = []
|
|
try:
|
|
conf.gc.dummy = True
|
|
except PropertiesOptionError, err:
|
|
prop = err.proptype
|
|
assert 'frozen' in prop
|
|
setting.remove('everything_frozen')
|
|
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()
|
|
setting.read_write()
|
|
#freeze only one option
|
|
dummy = conf.unwrap_from_path('gc.dummy')
|
|
setting[dummy].append('frozen')
|
|
assert conf.gc.dummy is False
|
|
prop = []
|
|
try:
|
|
conf.gc.dummy = True
|
|
except PropertiesOptionError, err:
|
|
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()
|
|
setting.read_write()
|
|
setting.append('frozen')
|
|
setting[s].append('frozen')
|
|
prop = []
|
|
try:
|
|
config.string = "egg"
|
|
except PropertiesOptionError, err:
|
|
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()
|
|
setting.read_write()
|
|
setting.append('frozen')
|
|
name = conf.unwrap_from_path("gc.name")
|
|
setting[name].append('frozen')
|
|
prop = []
|
|
try:
|
|
conf.gc.name = 'framework'
|
|
except PropertiesOptionError, err:
|
|
prop = err.proptype
|
|
assert 'frozen' in prop
|
|
|
|
|
|
def test_freeze_multi():
|
|
descr = make_description_freeze()
|
|
conf = Config(descr)
|
|
setting = conf.cfgimpl_get_settings()
|
|
setting.read_write()
|
|
setting.append('frozen')
|
|
obj = conf.unwrap_from_path('boolop')
|
|
setting[obj].append('frozen')
|
|
prop = []
|
|
try:
|
|
conf.boolop = [True]
|
|
except PropertiesOptionError, err:
|
|
prop = err.proptype
|
|
assert 'frozen' in prop
|
|
|
|
|
|
def test_freeze_get_multi():
|
|
descr = make_description_freeze()
|
|
conf = Config(descr)
|
|
setting = conf.cfgimpl_get_settings()
|
|
setting.read_write()
|
|
setting.append('frozen')
|
|
valmulti = conf.boolop
|
|
valmulti.append(False)
|
|
obj = conf.unwrap_from_path('boolop')
|
|
setting[obj].append('frozen')
|
|
prop = []
|
|
try:
|
|
valmulti.append(False)
|
|
except PropertiesOptionError, err:
|
|
prop = err.proptype
|
|
assert 'frozen' in prop
|
|
|
|
|
|
def test_force_store_value():
|
|
descr = make_description_freeze()
|
|
conf = Config(descr)
|
|
opt = conf.unwrap_from_path('wantref')
|
|
assert conf.cfgimpl_get_values().getowner(opt) == 'default'
|
|
conf.wantref
|
|
assert conf.cfgimpl_get_values().getowner(opt) == 'user'
|