tiramisu/test/test_option_consistency.py

259 lines
12 KiB
Python
Raw Normal View History

import autopath
from py.test import raises
from tiramisu.config import *
from tiramisu.option import *
from error import ConfigError
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)
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('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)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
def make_description_duplicates():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
## dummy 1
gcdummy = BoolOption('dummy', 'dummy', default=False)
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('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)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
2012-08-16 11:42:24 +02:00
# dummy2 (same path)
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
2012-08-16 11:42:24 +02:00
# dummy3 (same name)
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
2012-08-16 11:42:24 +02:00
intoption, boolop, gcdummy3])
return descr
2012-08-16 11:42:24 +02:00
def test_identical_paths():
2012-11-12 12:06:58 +01:00
"""If in the schema (the option description) there is something that
have the same name, an exection is raised
2012-11-12 12:06:58 +01:00
"""
2013-04-03 12:20:26 +02:00
raises(ConflictConfigError, "make_description_duplicates()")
def make_description2():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
floatoption = FloatOption('float', 'Test float option', default=2.3)
2012-11-12 12:06:58 +01:00
objspaceoption = ChoiceOption('objspace', 'Object space',
['std', 'thunk'], 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc")
# first multi
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
boolop.enable_multi()
wantref_option = BoolOption('wantref', 'Test requires', default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
# second multi
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
wantframework_option.enable_multi()
2012-11-12 12:06:58 +01:00
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
2012-12-10 14:10:05 +01:00
# FIXME: il faudra tester les validations sur les multis
#def test_multi_constraints():
# "a multi in a constraint has to have the same length"
# descr = make_description2()
# cfg = Config(descr)
# cfg.boolop = [True, True, False]
# cfg.wantframework = [False, False, True]
2012-11-12 12:06:58 +01:00
#
#def test_multi_raise():
# "a multi in a constraint has to have the same length"
# # FIXME fusionner les deux tests, MAIS PROBLEME :
# # il ne devrait pas etre necessaire de refaire une config
2012-11-12 12:06:58 +01:00
# # si la valeur est modifiee une deuxieme fois ->
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
# # ExceptionFailure: 'DID NOT RAISE'
# descr = make_description2()
# cfg = Config(descr)
# cfg.boolop = [True]
# raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
# ____________________________________________________________
# adding dynamically new options description schema
2013-04-03 12:20:26 +02:00
#def test_newoption_add_in_descr():
# descr = make_description()
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
# descr.add_child(newoption)
# config = Config(descr)
# assert config.newoption == False
2013-04-03 12:20:26 +02:00
#def test_newoption_add_in_subdescr():
# descr = make_description()
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
# descr.gc.add_child(newoption)
# config = Config(descr)
# config.bool = False
# assert config.gc.newoption == False
2013-02-07 16:20:21 +01:00
#def test_newoption_add_in_config():
# descr = make_description()
# config = Config(descr)
# config.bool = False
# newoption = BoolOption('newoption', 'dummy twoo', default=False)
# descr.add_child(newoption)
# config.cfgimpl_update()
# assert config.newoption == False
# ____________________________________________________________
def make_description_requires():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
floatoption = FloatOption('float', 'Test float option', default=2.3)
2012-11-12 12:06:58 +01:00
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('std', 'thunk'), 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
2012-11-12 12:06:58 +01:00
stroption = StrOption('str', 'Test string option', default="abc",
2013-04-03 12:20:26 +02:00
requires=(('int', 1, 'hidden'),))
2012-11-12 12:06:58 +01:00
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
stroption, intoption])
return descr
def test_hidden_if_in():
descr = make_description_requires()
cfg = Config(descr)
2013-04-03 12:20:26 +02:00
setting = cfg.cfgimpl_get_settings()
setting.read_write()
intoption = cfg.unwrap_from_path('int')
stroption = cfg.unwrap_from_path('str')
2013-04-03 12:20:26 +02:00
assert not setting.has_property('hidden', stroption)
cfg.int = 1
raises(PropertiesOptionError, "cfg.str")
raises(PropertiesOptionError, 'cfg.str="uvw"')
2013-04-03 12:20:26 +02:00
assert setting.has_property('hidden', stroption)
def test_hidden_if_in_with_group():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
floatoption = FloatOption('float', 'Test float option', default=2.3)
2012-11-12 12:06:58 +01:00
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('std', 'thunk'), 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc")
2012-11-12 12:06:58 +01:00
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
2013-04-03 12:20:26 +02:00
requires=(('int', 1, 'hidden'),))
2012-11-12 12:06:58 +01:00
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
cfg = Config(descr)
2013-04-03 12:20:26 +02:00
setting = cfg.cfgimpl_get_settings()
setting.read_write()
assert not setting.has_property('hidden', stroption)
cfg.int = 1
raises(PropertiesOptionError, "cfg.gc.name")
def test_disabled_with_group():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
floatoption = FloatOption('float', 'Test float option', default=2.3)
2012-11-12 12:06:58 +01:00
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('std', 'thunk'), 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc")
2012-11-12 12:06:58 +01:00
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
2013-04-03 12:20:26 +02:00
requires=(('int', 1, 'disabled'),))
2012-11-12 12:06:58 +01:00
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
cfg = Config(descr)
2013-04-03 12:20:26 +02:00
setting = cfg.cfgimpl_get_settings()
setting.read_write()
assert cfg.gc.name
cfg.int = 1
raises(PropertiesOptionError, "cfg.gc.name")
2012-12-10 14:10:05 +01:00
#____________________________________________________________
def make_description_callback():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
2012-12-10 14:10:05 +01:00
gcdummy = BoolOption('dummy', 'dummy', callback="toto")
objspaceoption = ChoiceOption('objspace', 'Object space',
2013-04-03 12:20:26 +02:00
('std', 'thunk'), 'std')
2012-12-10 14:10:05 +01: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-12-10 14:10:05 +01:00
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
2013-04-03 12:20:26 +02:00
requires=(('boolop', True, 'hidden'),))
2012-12-10 14:10:05 +01:00
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
def test_has_callback():
descr = make_description_callback()
# here the owner is 'default'
config = Config(descr)
2013-04-03 12:20:26 +02:00
setting = config.cfgimpl_get_settings()
setting.read_write()
2012-12-10 14:10:05 +01:00
config.bool = False
# because dummy has a callback
dummy = config.unwrap_from_path('gc.dummy')
2013-04-03 12:20:26 +02:00
setting.enable_property('freeze')
setting.add_property('frozen', dummy)
raises(PropertiesOptionError, "config.gc.dummy = True")
2012-12-10 14:10:05 +01:00
def test_freeze_and_has_callback():
2012-12-10 14:10:05 +01:00
descr = make_description_callback()
config = Config(descr)
2013-04-03 12:20:26 +02:00
setting = config.cfgimpl_get_settings()
setting.read_write()
2012-12-10 14:10:05 +01:00
config.bool = False
2013-04-03 12:20:26 +02:00
config.cfgimpl_get_settings().enable_property('freeze')
2012-12-10 14:10:05 +01:00
dummy = config.unwrap_from_path('gc.dummy')
2013-04-03 12:20:26 +02:00
config.cfgimpl_get_settings().add_property('frozen', dummy)
raises(PropertiesOptionError, "config.gc.dummy = True")
2012-12-10 14:10:05 +01:00
#____________________________________________________________