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():
|
|
|
|
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_override_are_default_owner():
|
|
|
|
"config.override() implies that the owner is 'default' again"
|
|
|
|
descr = make_description2()
|
|
|
|
config = Config(descr, bool=False)
|
|
|
|
# default
|
|
|
|
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
|
|
|
# user
|
|
|
|
config.gc.dummy = True
|
|
|
|
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
|
|
|
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
|
|
|
#Options have an available default setting and can give it back
|
|
|
|
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
|
|
|
config.override({'gc.dummy':True})
|
|
|
|
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
|
|
|
# user again
|
|
|
|
config.gc.dummy = False
|
|
|
|
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
|
|
|
|
2012-08-14 10:55:08 +02:00
|
|
|
def test_has_callback():
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = make_description()
|
|
|
|
# here the owner is 'default'
|
|
|
|
config = Config(descr, bool=False)
|
2012-08-14 10:55:08 +02:00
|
|
|
# because dummy has a callback
|
2012-09-12 10:38:41 +02:00
|
|
|
raises(TypeError, "config.gc.dummy = True")
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
#____________________________________________________________
|
2012-08-14 10:55:08 +02:00
|
|
|
def test_has_callback_with_setoption():
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr, bool=False)
|
2012-09-12 10:38:41 +02:00
|
|
|
raises(TypeError, "config.gc.setoption('dummy', True, 'gen_config')")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2012-09-12 10:38:41 +02:00
|
|
|
def test_cannot_override():
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = make_description()
|
|
|
|
config = Config(descr, bool=False)
|
2012-09-12 10:38:41 +02:00
|
|
|
raises(TypeError, "config.override({'gc.dummy': True})")
|
2012-07-13 09:42:14 +02:00
|
|
|
|