2012-07-13 09:42:14 +02:00
|
|
|
import autopath
|
2013-08-23 09:29:42 +02:00
|
|
|
from py.test import raises
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-02-07 16:20:21 +01:00
|
|
|
from tiramisu.setting import owners
|
2013-04-22 09:19:05 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
StrOption, OptionDescription
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def make_description():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
2012-12-10 14:10:05 +01:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
2012-07-13 09:42:14 +02:00
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
2013-04-22 09:19:05 +02:00
|
|
|
['std', 'thunk'], 'std')
|
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")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
2012-12-10 14:10:05 +01:00
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
2012-12-10 14:10:05 +01:00
|
|
|
default=False)
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
2012-12-10 14:10:05 +01:00
|
|
|
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
2013-04-22 09:19:05 +02:00
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
2012-07-13 09:42:14 +02:00
|
|
|
return descr
|
|
|
|
|
2013-04-22 09:19:05 +02:00
|
|
|
|
2012-12-10 14:10:05 +01:00
|
|
|
def test_default_owner():
|
2012-07-13 09:42:14 +02:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
2012-12-10 14:10:05 +01:00
|
|
|
descr = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
assert cfg.dummy is False
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == 'default'
|
2013-04-03 12:20:26 +02:00
|
|
|
cfg.dummy = True
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == owners.user
|
2013-04-22 09:19:05 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2012-12-10 14:38:25 +01:00
|
|
|
def test_add_owner():
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
assert cfg.dummy is False
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == 'default'
|
2012-12-10 14:38:25 +01:00
|
|
|
owners.add_owner("gen_config")
|
2013-04-03 12:20:26 +02:00
|
|
|
cfg.cfgimpl_get_settings().setowner(owners.gen_config)
|
|
|
|
cfg.dummy = True
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == owners.gen_config
|
2013-04-22 09:19:05 +02:00
|
|
|
|
2012-12-10 14:38:25 +01:00
|
|
|
|
2012-12-10 14:10:05 +01:00
|
|
|
def test_owner_is_not_a_string():
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
assert cfg.dummy is False
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == owners.default
|
|
|
|
assert cfg.getowner(gcdummy) == 'default'
|
|
|
|
assert isinstance(cfg.getowner(gcdummy), owners.Owner)
|
2013-04-03 12:20:26 +02:00
|
|
|
cfg.dummy = True
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == 'user'
|
2013-08-23 09:29:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_setowner_without_valid_owner():
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(descr)
|
|
|
|
assert cfg.dummy is False
|
2013-08-24 22:32:54 +02:00
|
|
|
assert cfg.getowner(gcdummy) == 'default'
|
2013-08-23 09:29:42 +02:00
|
|
|
raises(TypeError, "cfg.cfgimpl_get_settings().setowner('gen_config')")
|