tiramisu/test/test_option_owner.py

72 lines
3.4 KiB
Python
Raw Normal View History

import autopath
from py.test import raises
from tiramisu.config import *
from tiramisu.option import *
2012-11-19 10:45:03 +01:00
from tiramisu.setting import settings
def make_description():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcdummy = BoolOption('dummy', 'dummy', callback="toto")
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)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=['boolop'])
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=['boolop'])
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
def make_description2():
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)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=['boolop'])
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=['boolop'])
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()
# here the owner is 'default'
2012-11-12 12:06:58 +01:00
config = Config(descr)
config.bool = False
2012-10-15 15:06:41 +02:00
# because dummy has a callback
dummy = config.unwrap_from_path('gc.dummy')
2012-11-19 10:45:03 +01:00
settings.freeze()
dummy.freeze()
2012-09-12 10:38:41 +02:00
raises(TypeError, "config.gc.dummy = True")
#____________________________________________________________
2012-09-19 09:31:02 +02:00
def test_freeze_and_has_callback_with_setoption():
descr = make_description()
2012-11-12 12:06:58 +01:00
config = Config(descr)
config.bool = False
2012-11-19 10:45:03 +01:00
settings.freeze()
dummy = config.unwrap_from_path('gc.dummy')
dummy.freeze()
2012-09-12 10:38:41 +02:00
raises(TypeError, "config.gc.setoption('dummy', True, 'gen_config')")