2012-07-13 09:42:14 +02:00
|
|
|
# coding: utf-8
|
2012-11-19 10:45:03 +01:00
|
|
|
"frozen and hidden values"
|
2012-07-13 09:42:14 +02:00
|
|
|
import autopath
|
|
|
|
from py.test import raises
|
|
|
|
|
2012-07-23 14:52:08 +02:00
|
|
|
from tiramisu.config import *
|
|
|
|
from tiramisu.option import *
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def make_description():
|
2013-04-03 12:20:26 +02:00
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=(('hidden'),))
|
2012-07-13 09:42:14 +02:00
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
2013-04-03 12:20:26 +02:00
|
|
|
('std', 'thunk'), 'std')
|
2012-07-13 09:42:14 +02:00
|
|
|
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")
|
|
|
|
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=(('gc.name', 'ref', 'hidden'),))
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=(('gc.name', 'framework', 'hidden'),))
|
2012-11-19 10:45:03 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
# ____________________________________________________________
|
|
|
|
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)
|
|
|
|
subgroup = OptionDescription('subgroup', '', [booloptiontwo])
|
|
|
|
# ____________________________________________________________
|
2012-11-19 10:45:03 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [subgroup, gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('trs', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption])
|
|
|
|
return descr
|
|
|
|
#____________________________________________________________
|
|
|
|
#freeze
|
|
|
|
def make_description_freeze():
|
2013-04-03 12:20:26 +02:00
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
2012-07-13 09:42:14 +02:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
2013-04-03 12:20:26 +02:00
|
|
|
('std', 'thunk'), 'std')
|
2012-07-13 09:42:14 +02:00
|
|
|
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)
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=(('boolop', True, 'hidden'),))
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=(('boolop', True, 'hidden'),))
|
2012-11-19 10:45:03 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
|
|
|
return descr
|
|
|
|
|
2013-02-06 14:59:24 +01:00
|
|
|
def test_freeze_whole_config():
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
2013-02-07 16:20:21 +01:00
|
|
|
settings = conf.cfgimpl_get_settings()
|
2013-04-03 12:20:26 +02:00
|
|
|
settings.enable_property('everything_frozen')
|
2013-02-06 14:59:24 +01:00
|
|
|
assert conf.gc.dummy == False
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ConfigError, "conf.gc.dummy = True")
|
2013-04-03 12:20:26 +02:00
|
|
|
settings.disable_property('everything_frozen')
|
2013-02-06 14:59:24 +01:00
|
|
|
conf.gc.dummy = True
|
|
|
|
assert conf.gc.dummy == True
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_freeze_one_option():
|
|
|
|
"freeze an option "
|
|
|
|
descr = make_description_freeze()
|
|
|
|
conf = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = conf.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
2012-07-13 09:42:14 +02:00
|
|
|
#freeze only one option
|
2013-04-03 12:20:26 +02:00
|
|
|
dummy = conf.unwrap_from_path('gc.dummy')
|
|
|
|
conf.gc.cfgimpl_get_settings().add_property('frozen', dummy)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert conf.gc.dummy == False
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ConfigError, "conf.gc.dummy = True")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_frozen_value():
|
|
|
|
"setattr a frozen value at the config level"
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
settings = config.cfgimpl_get_settings().enable_property('frozen')
|
|
|
|
config.cfgimpl_get_settings().add_property('frozen', s)
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ConfigError, 'config.string = "egg"')
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_freeze():
|
|
|
|
"freeze a whole configuration object"
|
|
|
|
descr = make_description()
|
|
|
|
conf = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
settings = conf.cfgimpl_get_settings().enable_property('frozen')
|
2012-09-19 09:31:02 +02:00
|
|
|
name = conf.unwrap_from_path("gc.name")
|
2013-04-03 12:20:26 +02:00
|
|
|
conf.cfgimpl_get_settings().add_property('frozen', name)
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ConfigError, "conf.gc.name = 'framework'")
|
2012-07-13 09:42:14 +02:00
|
|
|
# ____________________________________________________________
|
|
|
|
def test_is_hidden():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('frozen', dummy)
|
2012-07-13 09:42:14 +02:00
|
|
|
# setattr
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
2012-07-13 09:42:14 +02:00
|
|
|
# getattr
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy")
|
2012-07-13 09:42:14 +02:00
|
|
|
# I want to access to this option anyway
|
2013-02-07 16:20:21 +01:00
|
|
|
opt = config.unwrap_from_path("gc.dummy")
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values()[opt] == False
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_group_is_hidden():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
2012-07-13 09:42:14 +02:00
|
|
|
gc = config.unwrap_from_path('gc')
|
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
2013-04-03 12:20:26 +02:00
|
|
|
config.cfgimpl_get_settings().add_property('hidden', gc)
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy")
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', gc)
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.float")
|
2012-07-13 09:42:14 +02:00
|
|
|
# manually set the subconfigs to "show"
|
2013-04-03 12:20:26 +02:00
|
|
|
config.cfgimpl_get_settings().del_property('hidden', gc)
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', gc)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.gc.float == 2.3
|
|
|
|
#dummy est en hide
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
2012-11-19 10:45:03 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_global_show():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
|
|
|
config.cfgimpl_get_settings().add_property('hidden', dummy)
|
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', dummy)
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_with_many_subgroups():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', booltwo)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.gc.subgroup.booltwo == False
|
2013-04-03 12:20:26 +02:00
|
|
|
config.cfgimpl_get_settings().add_property('hidden', booltwo)
|
2012-07-13 09:42:14 +02:00
|
|
|
path = 'gc.subgroup.booltwo'
|
2013-03-15 09:24:43 +01:00
|
|
|
homeconfig, name = config.cfgimpl_get_home_by_path(path)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert name == "booltwo"
|
|
|
|
option = getattr(homeconfig._cfgimpl_descr, name)
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', booltwo)
|