tiramisu/test/test_option_owner.py

164 lines
6.1 KiB
Python
Raw Normal View History

2015-07-24 17:54:10 +02:00
from autopath import do_autopath
do_autopath()
2013-08-23 09:29:42 +02:00
from py.test import raises
2016-01-25 16:22:28 +01:00
from tiramisu.setting import owners, groups
from tiramisu.config import Config
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError
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 is False
2013-08-24 22:32:54 +02:00
assert cfg.getowner(gcdummy) == 'default'
2014-02-04 21:14:30 +01:00
raises(TypeError, "cfg.getowner('gcdummy')")
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
def test_hidden_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
cfg.read_write()
raises(PropertiesOptionError, "cfg.getowner(gcdummy)")
2013-08-27 16:12:53 +02:00
def test_addowner():
2012-12-10 14:38:25 +01:00
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-27 16:12:53 +02:00
owners.addowner("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
2012-12-10 14:38:25 +01:00
def test_addowner_multiple_time():
owners.addowner("testowner")
raises(ConstError, 'owners.addowner("testowner")')
def test_delete_owner():
owners.addowner('deleted')
raises(ConstError, 'del(owners.deleted)')
raises(ValueError, 'del(owners.deleted2)')
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 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')")
def test_setowner_for_value():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
assert cfg.dummy is False
assert cfg.getowner(gcdummy) == 'default'
2013-08-27 16:12:53 +02:00
owners.addowner("new")
raises(ConfigError, "cfg.cfgimpl_get_values().setowner(gcdummy, owners.new)")
cfg.dummy = False
assert cfg.getowner(gcdummy) == owners.user
cfg.cfgimpl_get_values().setowner(gcdummy, owners.new)
assert cfg.getowner(gcdummy) == owners.new
raises(TypeError, "cfg.cfgimpl_get_values().setowner(gcdummy, 'new')")
def test_setowner_read_only():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
cfg.read_write()
assert cfg.dummy is False
assert cfg.getowner(gcdummy) == 'default'
owners.addowner("readonly")
cfg.dummy = False
assert cfg.getowner(gcdummy) == owners.user
cfg.read_only()
raises(PropertiesOptionError,
"cfg.cfgimpl_get_values().setowner(gcdummy, owners.readonly)")
assert cfg.getowner(gcdummy) == owners.user
def test_setowner_optiondescription():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1])
cfg = Config(descr)
2016-01-25 16:22:28 +01:00
cfg
raises(ConfigError, 'cfg.cfgimpl_get_values().getowner(descr1)')
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(descr1, owners.user)')
def test_setowner_symlinkoption():
gcdummy = BoolOption('dummy', 'dummy', default=False)
s = SymLinkOption('symdummy', gcdummy)
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
descr = OptionDescription('tiramisu', '', [descr1])
cfg = Config(descr)
assert cfg.cfgimpl_get_values().getowner(s) == owners.default
cfg.tiramisu.dummy = True
assert cfg.cfgimpl_get_values().getowner(s) == owners.user
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(s, owners.user)')
2016-01-25 16:22:28 +01:00
def test_owner_masterslaves():
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
descr = OptionDescription("int", "", [b, c])
descr.impl_set_group_type(groups.master)
cfg = Config(descr)
raises(ConfigError, 'cfg.cfgimpl_get_values().setowner(c, owners.user)')
cfg.int.append(1)
cfg.str[0] = 'yes'
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user
cfg.cfgimpl_get_values().setowner(c, owners.user, 0)
assert cfg.cfgimpl_get_values().getowner(c, 0) == owners.user