tiramisu/test/test_option_owner.py

62 lines
2.7 KiB
Python

import autopath
from py.test import raises
from tiramisu.config import *
from tiramisu.option import *
from tiramisu.setting import owners
def make_description():
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)
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False)
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
def test_default_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
cfg.dummy = True
assert cfg.cfgimpl_get_values().getowner(dm) == owners.user
def test_add_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
owners.add_owner("gen_config")
cfg.cfgimpl_get_settings().setowner(owners.gen_config)
cfg.dummy = True
assert cfg.cfgimpl_get_values().getowner(dm) == owners.gen_config
def test_owner_is_not_a_string():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert cfg.cfgimpl_get_values().getowner(dm) == owners.default
assert cfg.cfgimpl_get_values().getowner(dm) == 'default'
assert isinstance(cfg.cfgimpl_get_values().getowner(dm), owners.Owner)
cfg.dummy = True
assert cfg.cfgimpl_get_values().getowner(dm) == 'user'