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
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2016-01-25 16:22:28 +01:00
|
|
|
from tiramisu.setting import owners, groups
|
2013-04-22 09:19:05 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2014-10-26 08:51:45 +01:00
|
|
|
StrOption, OptionDescription, SymLinkOption
|
2014-03-29 20:31:56 +01:00
|
|
|
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError
|
2013-04-22 09:19:05 +02:00
|
|
|
|
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'
|
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
|
2013-04-22 09:19:05 +02:00
|
|
|
|
2014-03-29 20:31:56 +01:00
|
|
|
|
|
|
|
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)")
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
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)
|
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-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
|
2013-04-22 09:19:05 +02:00
|
|
|
|
2012-12-10 14:38:25 +01:00
|
|
|
|
2013-12-09 15:29:37 +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)
|
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')")
|
2013-08-25 18:06:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
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")
|
2013-08-25 18:06:07 +02:00
|
|
|
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')")
|
2014-10-26 08:51:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2014-10-26 08:51:45 +01:00
|
|
|
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
|