2012-07-13 09:42:14 +02:00
|
|
|
# coding: utf-8
|
2012-11-19 10:45:03 +01:00
|
|
|
"frozen and hidden values"
|
2015-07-24 17:54:10 +02:00
|
|
|
from autopath import do_autopath
|
|
|
|
do_autopath()
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2013-04-17 21:33:34 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2017-02-04 10:21:44 +01:00
|
|
|
PasswordOption, StrOption, DateOption, OptionDescription
|
2013-04-17 21:33:34 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError
|
|
|
|
|
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-17 23:19:53 +02:00
|
|
|
('std', 'thunk'), ['std'], multi=True)
|
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-06-29 18:41:14 +02:00
|
|
|
requires=({'option': gcoption, 'expected': 'ref', 'action': 'hidden'},))
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': gcoption, 'expected': 'framework', 'action': '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,
|
2013-04-17 21:33:34 +02:00
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption])
|
2012-07-13 09:42:14 +02:00
|
|
|
return descr
|
2012-11-19 10:45:03 +01:00
|
|
|
|
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()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-03 12:20:26 +02:00
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'frozen' in setting[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")
|
2013-04-17 21:33:34 +02:00
|
|
|
|
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()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2012-07-13 09:42:14 +02:00
|
|
|
gc = config.unwrap_from_path('gc')
|
2013-04-17 21:33:34 +02:00
|
|
|
config.unwrap_from_path('gc.dummy')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[gc].append('hidden')
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy")
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[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-20 17:30:05 +02:00
|
|
|
setting[gc].remove('hidden')
|
|
|
|
assert not 'hidden' in setting[gc]
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.gc.float == 2.3
|
|
|
|
#dummy est en hide
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
config.gc.dummy = False
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'hidden' in prop
|
|
|
|
|
2014-01-06 14:40:29 +01:00
|
|
|
def test_extend_properties():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
gc = config.unwrap_from_path('gc')
|
|
|
|
config.unwrap_from_path('gc.dummy')
|
|
|
|
setting[gc].extend(['hidden', 'user_defined_property'])
|
|
|
|
assert 'hidden' in setting[gc]
|
|
|
|
assert 'user_defined_property' in setting[gc]
|
2013-04-17 23:19:53 +02:00
|
|
|
|
|
|
|
def test_group_is_hidden_multi():
|
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-17 23:19:53 +02:00
|
|
|
obj = config.unwrap_from_path('objspace')
|
|
|
|
objspace = config.objspace
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[obj].append('hidden')
|
2013-04-17 23:19:53 +02:00
|
|
|
raises(PropertiesOptionError, "config.objspace")
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[obj]
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
|
|
|
objspace.append('std')
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = err.proptype
|
|
|
|
assert 'hidden' in prop
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[obj].remove('hidden')
|
|
|
|
assert not 'hidden' in setting[obj]
|
2013-04-17 23:19:53 +02:00
|
|
|
config.objspace.append('std')
|
2012-11-19 10:45:03 +01:00
|
|
|
|
2013-04-17 21:33:34 +02: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()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-03 12:20:26 +02:00
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[dummy].append('hidden')
|
|
|
|
assert 'hidden' in setting[dummy]
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.gc.dummy == False")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:33:34 +02:00
|
|
|
|
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')
|
2013-04-20 17:30:05 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
assert not 'hidden' in setting[booltwo]
|
2013-04-17 21:33:34 +02:00
|
|
|
assert config.gc.subgroup.booltwo is False
|
2013-04-20 17:30:05 +02:00
|
|
|
setting[booltwo].append('hidden')
|
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"
|
2013-05-08 18:14:42 +02:00
|
|
|
getattr(homeconfig.cfgimpl_get_description(), name)
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[booltwo]
|
2017-02-04 10:21:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_password_option():
|
|
|
|
o = PasswordOption('o', '')
|
|
|
|
d = OptionDescription('d', '', [o])
|
|
|
|
c = Config(d)
|
|
|
|
|
|
|
|
c.o = u'a_valid_password'
|
|
|
|
raises(ValueError, "c.o = 1")
|
|
|
|
|
|
|
|
|
|
|
|
def test_date_option():
|
|
|
|
o = DateOption('o', '')
|
|
|
|
d = OptionDescription('d', '', [o])
|
|
|
|
c = Config(d)
|
|
|
|
|
|
|
|
c.o = u'2017-02-04'
|
|
|
|
c.o = u'2017-2-4'
|
|
|
|
raises(ValueError, "c.o = 1")
|
|
|
|
raises(ValueError, "c.o = u'2017-13-20'")
|
|
|
|
raises(ValueError, "c.o = u'2017-11-31'")
|
|
|
|
raises(ValueError, "c.o = u'2017-12-32'")
|
|
|
|
raises(ValueError, "c.o = u'2017-2-29'")
|
|
|
|
raises(ValueError, "c.o = u'2-2-2017'")
|
|
|
|
raises(ValueError, "c.o = u'2017/2/2'")
|