tiramisu/test/test_option_owner.py

169 lines
6.9 KiB
Python
Raw Normal View History

2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
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
2018-03-19 08:33:53 +01:00
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
2018-08-14 23:07:07 +02:00
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config
2018-03-19 08:33:53 +01:00
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError
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])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
api.option('dummy').value.set(True)
owner = api.owner.get()
assert api.option('dummy').owner.get() == owner
def test_hidden_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
descr = OptionDescription('tiramisu', '', [gcdummy])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()")
#raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()")
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.isdefault()")
api.permissive.set(frozenset(['hidden']))
api.forcepermissive.option('dummy').value.get()
api.forcepermissive.option('dummy').owner.isdefault()
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])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
assert api.option('dummy').owner.isdefault()
api.owner.set('gen_config')
api.option('dummy').value.set(True)
assert api.option('dummy').owner.get() == owners.gen_config
assert not api.option('dummy').owner.isdefault()
2012-12-10 14:38:25 +01:00
def test_addowner_multiple_time():
2018-03-19 08:33:53 +01:00
owners.addowner("testowner2")
raises(ConstError, 'owners.addowner("testowner2")')
def test_delete_owner():
2018-03-19 08:33:53 +01:00
owners.addowner('deleted2')
raises(ConstError, '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])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == owners.default
assert api.option('dummy').owner.get() == 'default'
assert isinstance(api.option('dummy').owner.get(), owners.Owner)
api.option('dummy').value.set(True)
assert api.option('dummy').owner.get() == '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])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
def test_setowner_for_value():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
owners.addowner("new2")
raises(ConfigError, "api.option('dummy').owner.set('new2')")
api.option('dummy').value.set(False)
assert api.option('dummy').owner.get() == owners.user
api.option('dummy').owner.set('new2')
assert api.option('dummy').owner.get() == owners.new2
def test_setowner_read_only():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
api.property.read_write()
assert api.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default'
owners.addowner("readonly2")
api.option('dummy').value.set(False)
assert api.option('dummy').owner.get() == owners.user
api.property.read_only()
raises(PropertiesOptionError,
2018-03-19 08:33:53 +01:00
"api.option('dummy').owner.set('readonly2')")
assert api.option('dummy').owner.get() == owners.user
def test_setowner_optiondescription():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
raises(APIError, "api.option('tiramisu').owner.get()")
raises(APIError, "api.option('tiramisu').owner.set('user')")
def test_setowner_symlinkoption():
gcdummy = BoolOption('dummy', 'dummy', default=False)
s = SymLinkOption('symdummy', gcdummy)
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
descr = OptionDescription('tiramisu', '', [descr1])
2018-08-14 23:07:07 +02:00
api = Config(descr)
2018-03-19 08:33:53 +01:00
assert api.option('tiramisu.symdummy').owner.isdefault()
api.option('tiramisu.dummy').value.set(True)
assert not api.option('tiramisu.symdummy').owner.isdefault()
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('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)
2017-10-14 13:33:25 +02:00
descr = MasterSlaves("int", "", [b, c])
2018-03-19 08:33:53 +01:00
od = OptionDescription('od', '', [descr])
2018-08-14 23:07:07 +02:00
api = Config(od)
2018-03-19 08:33:53 +01:00
raises(ConfigError, "api.option('int.str', 0).owner.set('user')")
api.option('int.int').value.set([0, 1])
api.option('int.str', 0).value.set('yes')
assert not api.option('int.str', 0).owner.isdefault()
assert api.option('int.str', 1).owner.isdefault()
api.option('int.str', 0).owner.set('user')
assert api.option('int.str', 0).owner.get() == owners.user
assert api.option('int.str', 1).owner.isdefault()
assert api.option('int.str', 0).value.get() == 'yes'
assert api.option('int.str', 1).value.get() == None