tiramisu/test/test_option_owner.py

62 lines
2.5 KiB
Python
Raw Normal View History

import autopath
from py.test import raises
from tiramisu.config import *
from tiramisu.option import *
2013-02-07 16:20:21 +01:00
from tiramisu.setting import owners
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)
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)
2012-12-10 14:10:05 +01:00
wantref_option = BoolOption('wantref', 'Test requires', default=False)
wantframework_option = BoolOption('wantframework', 'Test requires',
2012-12-10 14:10:05 +01:00
default=False)
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
2012-12-10 14:10:05 +01:00
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
2012-12-10 14:10:05 +01:00
def test_default_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False)
2012-12-10 14:10:05 +01:00
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert dm.getowner(cfg) == 'default'
dm.setowner(cfg, owners.user)
assert dm.getowner(cfg) == owners.user
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)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert dm.getowner(cfg) == 'default'
owners.add_owner("gen_config")
dm.setowner(cfg, owners.gen_config)
assert dm.getowner(cfg) == owners.gen_config
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)
assert cfg.dummy == False
dm = cfg.unwrap_from_path('dummy')
assert dm.getowner(cfg) == owners.default
assert dm.getowner(cfg) == 'default'
assert isinstance(dm.getowner(cfg), owners.Owner)
dm.setowner(cfg, owners.user)
2012-09-12 10:38:41 +02:00
2012-12-10 14:10:05 +01:00
assert dm.getowner(cfg) == 'user'