2012-07-13 09:42:14 +02:00
|
|
|
# coding: utf-8
|
2012-11-19 10:45:03 +01:00
|
|
|
"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()
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
PasswordOption, StrOption, DateOption, OptionDescription, Config, getapi
|
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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
assert not 'frozen' in api.option('gc.dummy').property.get()
|
2012-07-13 09:42:14 +02:00
|
|
|
# setattr
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False")
|
2012-07-13 09:42:14 +02:00
|
|
|
# getattr
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
2013-04-17 21:33:34 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_group_is_hidden():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('gc').property.add('hidden')
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()")
|
|
|
|
assert 'hidden' in api.option('gc').property.get()
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.float').value.get()")
|
2012-07-13 09:42:14 +02:00
|
|
|
# manually set the subconfigs to "show"
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc').property.pop('hidden')
|
|
|
|
assert not 'hidden' in api.option('gc').property.get()
|
|
|
|
assert api.option('gc.float').value.get() == 2.3
|
2012-07-13 09:42:14 +02:00
|
|
|
#dummy est en hide
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('gc.dummy').value.set(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
|
|
|
|
|
|
|
|
|
|
|
|
def test_group_is_hidden_multi():
|
|
|
|
descr = make_description()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('objspace').property.add('hidden')
|
|
|
|
raises(PropertiesOptionError, "api.option('objspace').value.get()")
|
|
|
|
assert 'hidden' in api.option('objspace').property.get()
|
2013-04-17 23:19:53 +02:00
|
|
|
prop = []
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('objspace').value.set(['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
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('objspace').property.pop('hidden')
|
|
|
|
assert not 'hidden' in api.option('objspace').property.get()
|
|
|
|
api.option('objspace').value.set(['std', '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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('gc.dummy').property.add('hidden')
|
|
|
|
assert 'hidden' in api.option('gc.dummy').property.get()
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == 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()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
|
|
|
|
#setting = config.cfgimpl_get_settings()
|
|
|
|
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get()
|
|
|
|
assert api.option('gc.subgroup.booltwo').value.get() is False
|
|
|
|
api.option('gc.subgroup.booltwo').property.add('hidden')
|
2017-02-04 10:21:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_password_option():
|
|
|
|
o = PasswordOption('o', '')
|
|
|
|
d = OptionDescription('d', '', [o])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(d))
|
2017-02-04 10:21:44 +01:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('o').value.set('a_valid_password')
|
|
|
|
raises(ValueError, "api.option('o').value.set(1)")
|
2017-02-04 10:21:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_date_option():
|
|
|
|
o = DateOption('o', '')
|
|
|
|
d = OptionDescription('d', '', [o])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(d))
|
|
|
|
|
|
|
|
api.option('o').value.set('2017-02-04')
|
|
|
|
api.option('o').value.set('2017-2-4')
|
|
|
|
raises(ValueError, "api.option('o').value.set(1)")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2017-13-20')")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2017-11-31')")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2017-12-32')")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2017-2-29')")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2-2-2017')")
|
|
|
|
raises(ValueError, "api.option('o').value.set('2017/2/2')")
|