2012-07-13 09:42:14 +02:00
|
|
|
"config.set() or config.setoption() or option.setoption()"
|
2015-07-24 17:54:10 +02:00
|
|
|
from autopath import do_autopath
|
|
|
|
do_autopath()
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
2016-09-14 20:17:25 +02:00
|
|
|
from tiramisu.i18n import _
|
|
|
|
from tiramisu.error import display_list
|
2015-11-29 23:03:08 +01:00
|
|
|
from tiramisu.setting import owners, groups
|
2013-04-17 21:50:31 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2013-06-13 22:06:49 +02:00
|
|
|
StrOption, OptionDescription
|
2013-04-20 21:58:52 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def make_description():
|
2013-04-03 12:20:26 +02:00
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
2012-07-13 09:42:14 +02:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
2013-04-17 21:50:31 +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)
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
2012-11-12 12:06:58 +01:00
|
|
|
default=False)
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
2013-04-17 21:50:31 +02:00
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
2012-07-13 09:42:14 +02:00
|
|
|
return descr
|
2013-04-17 21:50:31 +02:00
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
# change with __setattr__
|
|
|
|
def test_attribute_access():
|
|
|
|
"Once set, option values can't be changed again by attribute access"
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
# let's try to change it again
|
|
|
|
config.string = "foo"
|
|
|
|
assert config.string == "foo"
|
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_setitem():
|
|
|
|
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
config.string[1] = "titi"
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_reset():
|
|
|
|
"if value is None, resets to default owner"
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
config.string = "foo"
|
|
|
|
assert config.string == "foo"
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == owners.user
|
2013-04-18 20:26:40 +02:00
|
|
|
del(config.string)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == 'string'
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == owners.default
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_reset_with_multi():
|
2013-04-17 21:50:31 +02:00
|
|
|
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2012-11-12 12:06:58 +01:00
|
|
|
# config.string = []
|
2013-04-18 20:26:40 +02:00
|
|
|
del(config.string)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == ["string"]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == 'default'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = ["eggs", "spam", "foo"]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == 'user'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = []
|
2013-04-18 20:26:40 +02:00
|
|
|
del(config.string)
|
2012-11-12 12:06:58 +01:00
|
|
|
# assert config.string == ["string"]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == 'default'
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ValueError, "config.string = None")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_default_with_multi():
|
|
|
|
"default with multi is a list"
|
2013-04-17 21:50:31 +02:00
|
|
|
s = StrOption("string", "", default=[], default_multi="string", multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
assert config.string == []
|
2013-04-17 21:50:31 +02:00
|
|
|
s = StrOption("string", "", default=None, default_multi="string", multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
assert config.string == []
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_idontexist():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
2015-11-29 23:03:08 +01:00
|
|
|
cfg
|
2012-07-13 09:42:14 +02:00
|
|
|
raises(AttributeError, "cfg.idontexist")
|
2013-04-17 21:50:31 +02:00
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
# ____________________________________________________________
|
|
|
|
def test_attribute_access_with_multi():
|
2013-04-17 21:50:31 +02:00
|
|
|
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
config.string = ["foo", "bar"]
|
|
|
|
assert config.string == ["foo", "bar"]
|
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_item_access_with_multi():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
config.string = ["foo", "bar"]
|
|
|
|
assert config.string == ["foo", "bar"]
|
|
|
|
assert config.string[0] == "foo"
|
|
|
|
config.string[0] = 'changetest'
|
2013-04-22 09:19:05 +02:00
|
|
|
assert config.string[0] == 'changetest'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_access_with_multi_default():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == 'default'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = ["foo", "bar"]
|
|
|
|
assert config.string == ["foo", "bar"]
|
2013-08-24 22:32:54 +02:00
|
|
|
assert config.getowner(s) == 'user'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_requires():
|
|
|
|
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2013-04-17 21:50:31 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s, intoption, stroption])
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test__requires_with_inverted():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2013-04-17 21:50:31 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [s, intoption, stroption])
|
|
|
|
config = Config(descr)
|
2013-04-20 17:30:05 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
assert not 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_requires_in_another_group():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("opt", "", [stroption])
|
|
|
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
|
|
|
config = Config(descr2)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2017-01-30 19:23:52 +01:00
|
|
|
def test_multi_with_requires_in_another_group_inverse():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
|
|
|
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
|
|
|
descr = OptionDescription("opt", "", [stroption])
|
|
|
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
|
|
|
config = Config(descr2)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
assert not 'hidden' in setting[stroption]
|
|
|
|
config.int = 1
|
|
|
|
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
|
|
|
assert 'hidden' in setting[stroption]
|
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_apply_requires_from_config():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("opt", "", [stroption])
|
|
|
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
|
|
|
config = Config(descr2)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'hidden' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2013-04-03 12:20:26 +02:00
|
|
|
raises(PropertiesOptionError, 'config.opt.str')
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'hidden' in setting[stroption]
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_apply_requires_with_disabled():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("opt", "", [stroption])
|
|
|
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
|
|
|
config = Config(descr2)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'disabled' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2013-04-03 12:20:26 +02:00
|
|
|
raises(PropertiesOptionError, 'config.opt.str')
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'disabled' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_requires_with_disabled_in_another_group():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("opt", "", [stroption])
|
|
|
|
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
|
|
|
config = Config(descr2)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
2013-04-22 09:19:05 +02:00
|
|
|
config.read_write()
|
2013-04-20 17:30:05 +02:00
|
|
|
assert not 'disabled' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.opt.str = ['a', 'b']")
|
2013-04-20 17:30:05 +02:00
|
|
|
assert 'disabled' in setting[stroption]
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_requires_that_is_multi():
|
2015-11-29 23:03:08 +01:00
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
|
|
|
descr = OptionDescription("opt", "", [b, c])
|
|
|
|
descr
|
|
|
|
raises(ValueError, "Config(descr)")
|
|
|
|
|
|
|
|
|
2017-01-30 19:23:52 +01:00
|
|
|
def test_multi_with_requires_that_is_multi_inverse():
|
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
|
|
|
|
descr = OptionDescription("opt", "", [b, c])
|
|
|
|
descr
|
|
|
|
raises(ValueError, "Config(descr)")
|
|
|
|
|
|
|
|
|
2015-11-29 23:03:08 +01:00
|
|
|
def test_multi_with_requires_that_is_masterslave():
|
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
|
|
|
descr = OptionDescription("int", "", [b, c])
|
|
|
|
descr.impl_set_group_type(groups.master)
|
|
|
|
Config(descr)
|
|
|
|
|
|
|
|
|
|
|
|
def test_multi_with_requires_that_is_masterslave_master():
|
|
|
|
b = IntOption('int', 'Test int option', multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
|
|
|
descr = OptionDescription("str", "", [c, b])
|
|
|
|
descr.impl_set_group_type(groups.master)
|
|
|
|
raises(ValueError, "Config(descr)")
|
|
|
|
|
|
|
|
|
2016-10-12 20:49:56 +02:00
|
|
|
def test_multi_with_requires_that_is_masterslave_slave():
|
2015-11-29 23:03:08 +01:00
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', multi=True)
|
|
|
|
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
|
|
|
|
descr = OptionDescription("int", "", [b, c, d])
|
|
|
|
descr.impl_set_group_type(groups.master)
|
2016-10-12 20:49:56 +02:00
|
|
|
config = Config(descr)
|
|
|
|
config.read_write()
|
|
|
|
assert config.int == [0]
|
|
|
|
assert config.str == [None]
|
|
|
|
assert config.str1 == [None]
|
|
|
|
config.int = [0, 1]
|
|
|
|
assert config.int == [0, 1]
|
|
|
|
assert config.str == [None, None]
|
|
|
|
assert config.str1 == [None, None]
|
|
|
|
config.str = [None, '1']
|
|
|
|
config.read_only()
|
|
|
|
assert config.str1 == [None, None]
|
|
|
|
config.read_write()
|
|
|
|
assert config.str1[0] is None
|
|
|
|
raises(PropertiesOptionError, 'config.str1[1]')
|
2015-11-29 23:03:08 +01:00
|
|
|
|
2017-01-30 19:23:52 +01:00
|
|
|
|
|
|
|
def test_multi_with_requires_that_is_masterslave_slave_inverse():
|
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', multi=True)
|
|
|
|
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
|
|
|
descr = OptionDescription("int", "", [b, c, d])
|
|
|
|
descr.impl_set_group_type(groups.master)
|
|
|
|
config = Config(descr)
|
|
|
|
config.read_write()
|
|
|
|
assert config.int == [0]
|
|
|
|
assert config.str == [None]
|
|
|
|
assert config.str1 == [None]
|
|
|
|
config.int = [0, 1]
|
|
|
|
assert config.int == [0, 1]
|
|
|
|
assert config.str == [None, None]
|
|
|
|
assert config.str1 == [None, None]
|
|
|
|
config.str = [None, '1']
|
|
|
|
config.read_only()
|
|
|
|
assert config.str1 == [None, None]
|
|
|
|
config.read_write()
|
|
|
|
assert config.str1[0] is None
|
|
|
|
raises(PropertiesOptionError, 'config.str1[1]')
|
|
|
|
|
|
|
|
|
2015-11-29 23:03:08 +01:00
|
|
|
def test_multi_with_requires_that_is_not_same_masterslave():
|
|
|
|
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
|
|
|
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
|
|
|
descr1 = OptionDescription("int", "", [b, c])
|
|
|
|
descr1.impl_set_group_type(groups.master)
|
|
|
|
d = IntOption('int1', 'Test int option', default=[0], multi=True)
|
|
|
|
e = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
|
|
|
descr2 = OptionDescription("int1", "", [d, e])
|
|
|
|
descr2.impl_set_group_type(groups.master)
|
|
|
|
descr3 = OptionDescription('val', '', [descr1, descr2])
|
|
|
|
descr3
|
|
|
|
raises(ValueError, "Config(descr3)")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_bool():
|
|
|
|
s = BoolOption("bool", "", default=[False], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2013-05-08 18:14:42 +02:00
|
|
|
assert descr.bool.impl_is_multi() is True
|
2012-07-13 09:42:14 +02:00
|
|
|
config.bool = [True, False]
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values()[s] == [True, False]
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.bool == [True, False]
|
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_multi_with_bool_two():
|
|
|
|
s = BoolOption("bool", "", default=[False], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2015-11-29 23:03:08 +01:00
|
|
|
config
|
2013-05-08 18:14:42 +02:00
|
|
|
assert descr.bool.impl_is_multi() is True
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(ValueError, "config.bool = True")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_choice_access_with_multi():
|
2013-04-03 12:20:26 +02:00
|
|
|
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("options", "", [ch])
|
|
|
|
config = Config(descr)
|
|
|
|
config.t1 = ["a", "b", "a", "b"]
|
|
|
|
assert config.t1 == ["a", "b", "a", "b"]
|
2013-04-17 21:50:31 +02:00
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
#____________________________________________________________
|
2013-04-22 09:19:05 +02:00
|
|
|
def test_accepts_multiple_changes_from_option():
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
|
|
|
config.string = "egg"
|
2013-05-08 18:14:42 +02:00
|
|
|
assert s.impl_getdefault() == "string"
|
2013-04-22 09:19:05 +02:00
|
|
|
assert config.string == "egg"
|
|
|
|
config.string = 'blah'
|
2013-05-08 18:14:42 +02:00
|
|
|
assert s.impl_getdefault() == "string"
|
2013-04-22 09:19:05 +02:00
|
|
|
assert config.string == "blah"
|
|
|
|
config.string = 'bol'
|
|
|
|
assert config.string == 'bol'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_allow_multiple_changes_from_config():
|
|
|
|
"""
|
2012-11-12 12:06:58 +01:00
|
|
|
a `setoption` from the config object is much like the attribute access,
|
|
|
|
except the fact that value owner can bet set
|
2012-07-13 09:42:14 +02:00
|
|
|
"""
|
|
|
|
s = StrOption("string", "", default="string")
|
|
|
|
s2 = StrOption("string2", "", default="string")
|
|
|
|
suboption = OptionDescription("bip", "", [s2])
|
|
|
|
descr = OptionDescription("options", "", [s, suboption])
|
|
|
|
config = Config(descr)
|
2013-04-17 23:19:53 +02:00
|
|
|
config.string = "oh"
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == "oh"
|
2013-04-20 21:58:52 +02:00
|
|
|
config.string = "blah"
|
|
|
|
assert config.string == "blah"
|
2013-04-17 21:50:31 +02:00
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
# ____________________________________________________________
|
2012-12-10 14:10:05 +01:00
|
|
|
# accessing a value by the get method
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_access_by_get():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
2013-04-17 21:50:31 +02:00
|
|
|
raises(AttributeError, "cfg.find(byname='idontexist')")
|
|
|
|
assert cfg.find_first(byname='wantref', type_='value') is False
|
|
|
|
assert cfg.gc.dummy is False
|
|
|
|
assert cfg.find_first(byname='dummy', type_='value') is False
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
def test_access_by_get_whith_hide():
|
2013-04-03 12:20:26 +02:00
|
|
|
b1 = BoolOption("b1", "", properties=(('hidden'),))
|
2013-04-17 21:50:31 +02:00
|
|
|
descr = OptionDescription("opt", "",
|
|
|
|
[OptionDescription("sub", "",
|
|
|
|
[b1, ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
|
|
|
BoolOption("d1", "")]),
|
|
|
|
BoolOption("b2", ""),
|
|
|
|
BoolOption("d1", "")])
|
2012-07-13 09:42:14 +02:00
|
|
|
c = Config(descr)
|
2013-04-22 09:19:05 +02:00
|
|
|
c.read_write()
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(AttributeError, "c.find(byname='b1')")
|
2013-07-13 10:42:10 +02:00
|
|
|
|
|
|
|
|
2014-03-08 18:53:22 +01:00
|
|
|
def test_extend_config_properties():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
2015-04-18 23:11:57 +02:00
|
|
|
assert set(eval(str(setting))) == set(['cache', 'expire', 'validator', 'warnings'])
|
2014-03-08 18:53:22 +01:00
|
|
|
setting.extend(['test', 'test2'])
|
2015-04-18 23:11:57 +02:00
|
|
|
assert set(eval(str(setting))) == set(['test', 'cache', 'test2', 'expire', 'validator', 'warnings'])
|
2014-03-08 18:53:22 +01:00
|
|
|
|
|
|
|
|
2013-07-13 10:42:10 +02:00
|
|
|
def test_append_properties():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
option = cfg.cfgimpl_get_description().gc.dummy
|
2014-01-27 17:16:05 +01:00
|
|
|
assert tuple(option._properties) == tuple()
|
2013-07-13 10:42:10 +02:00
|
|
|
assert not 'test' in setting[option]
|
|
|
|
setting[option].append('test')
|
2014-01-27 17:16:05 +01:00
|
|
|
assert tuple(option._properties) == tuple()
|
2013-07-13 10:42:10 +02:00
|
|
|
assert 'test' in setting[option]
|
|
|
|
|
|
|
|
|
|
|
|
def test_reset_properties():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
option = cfg.cfgimpl_get_description().gc.dummy
|
2013-09-22 20:57:52 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.append('frozen')
|
2015-04-18 23:11:57 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.reset()
|
2013-09-22 20:57:52 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting[option].append('test')
|
2013-09-22 20:57:52 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test',))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.reset()
|
2013-09-22 20:57:52 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test',))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.append('frozen')
|
2015-04-18 23:11:57 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test',))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.reset(option)
|
2015-04-18 23:11:57 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings'))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting[option].append('test')
|
2015-04-18 23:11:57 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test',))}
|
2013-07-13 10:42:10 +02:00
|
|
|
setting.reset(all_properties=True)
|
2013-09-22 20:57:52 +02:00
|
|
|
assert setting._p_.get_modified_properties() == {}
|
2013-07-13 10:42:10 +02:00
|
|
|
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
2013-08-24 16:30:46 +02:00
|
|
|
a = descr.wantref
|
|
|
|
setting[a].append('test')
|
|
|
|
setting[a].reset()
|
|
|
|
|
2013-07-13 10:42:10 +02:00
|
|
|
|
|
|
|
def test_reset_multiple():
|
|
|
|
descr = make_description()
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
option = cfg.cfgimpl_get_description().gc.dummy
|
|
|
|
setting.append('frozen')
|
|
|
|
setting[option].append('test')
|
|
|
|
setting.reset()
|
|
|
|
setting.reset()
|
|
|
|
setting.append('frozen')
|
|
|
|
setting[option].append('test')
|
|
|
|
setting.reset(option)
|
|
|
|
setting.reset(option)
|
|
|
|
setting.append('frozen')
|
|
|
|
setting[option].append('test')
|
|
|
|
setting.reset(all_properties=True)
|
|
|
|
setting.reset(all_properties=True)
|
2014-02-20 14:27:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_properties_cached():
|
|
|
|
b1 = BoolOption("b1", "", properties=('test',))
|
|
|
|
descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])])
|
|
|
|
c = Config(descr)
|
|
|
|
c.read_write()
|
|
|
|
setting = c.cfgimpl_get_settings()
|
|
|
|
option = c.cfgimpl_get_description().sub.b1
|
2015-11-29 23:03:08 +01:00
|
|
|
option
|
2014-02-20 14:27:29 +01:00
|
|
|
c._setattr('sub.b1', True, force_permissive=True)
|
2014-07-06 15:31:57 +02:00
|
|
|
assert str(setting[b1]) in ["['test']", "[u'test']"]
|
2016-01-25 15:49:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_append_properties_force_store_value():
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcdummy])
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup])
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
option = cfg.cfgimpl_get_description().gc.dummy
|
|
|
|
assert tuple(option._properties) == tuple(['force_store_value'])
|
|
|
|
assert not 'test' in setting[option]
|
|
|
|
setting[option].append('test')
|
|
|
|
assert tuple(option._properties) == tuple(['force_store_value'])
|
|
|
|
assert 'test' in setting[option]
|
|
|
|
|
|
|
|
|
|
|
|
def test_reset_properties_force_store_value():
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcdummy])
|
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup])
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
option = cfg.cfgimpl_get_description().gc.dummy
|
|
|
|
assert setting._p_.get_modified_properties() == {}
|
|
|
|
setting.append('frozen')
|
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'cache', 'validator', 'warnings'))}
|
|
|
|
setting.reset()
|
|
|
|
assert setting._p_.get_modified_properties() == {}
|
|
|
|
setting[option].append('test')
|
|
|
|
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test', 'force_store_value'))}
|
|
|
|
setting.reset()
|
|
|
|
assert setting._p_.get_modified_properties() == {'gc.dummy': set(('test', 'force_store_value'))}
|
|
|
|
setting.append('frozen')
|
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test', 'force_store_value'))}
|
|
|
|
setting.reset(option)
|
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings'))}
|
|
|
|
setting[option].append('test')
|
|
|
|
assert setting._p_.get_modified_properties() == {None: set(('frozen', 'expire', 'validator', 'cache', 'warnings')), 'gc.dummy': set(('test', 'force_store_value'))}
|
|
|
|
setting.reset(all_properties=True)
|
|
|
|
assert setting._p_.get_modified_properties() == {}
|
|
|
|
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_pprint():
|
2017-01-19 21:38:16 +01:00
|
|
|
msg_error = _("cannot access to {0} \"{1}\" because has {2} {3}")
|
2016-11-14 21:14:45 +01:00
|
|
|
msg_is = _('the value of "{0}" is "{1}"')
|
|
|
|
msg_is_not = _('the value of "{0}" is not "{1}"')
|
2017-01-19 21:38:16 +01:00
|
|
|
properties = _('properties')
|
|
|
|
prop = _('property')
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
s = StrOption("string", "", default=["string"], default_multi="string", multi=True, properties=('hidden', 'disabled'))
|
|
|
|
s2 = StrOption("string2", "", default="string")
|
|
|
|
s3 = StrOption("string3", "", default=["string"], default_multi="string", multi=True, properties=('hidden',))
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
|
|
|
requires=[{'option': intoption, 'expected': 2, 'action': 'hidden', 'inverse': True},
|
|
|
|
{'option': intoption, 'expected': 3, 'action': 'hidden', 'inverse': True},
|
|
|
|
{'option': intoption, 'expected': 4, 'action': 'hidden', 'inverse': True},
|
|
|
|
{'option': intoption, 'expected': 1, 'action': 'disabled'},
|
|
|
|
{'option': s2, 'expected': 'string', 'action': 'disabled'}])
|
|
|
|
|
|
|
|
val2 = StrOption('val2', "")
|
|
|
|
descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
|
|
|
|
|
|
|
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
|
|
|
|
|
|
|
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
config.int = 1
|
|
|
|
try:
|
|
|
|
config.str
|
|
|
|
except Exception, err:
|
|
|
|
pass
|
|
|
|
|
2016-11-16 22:31:42 +01:00
|
|
|
list_disabled_1 = 'disabled (' + display_list([msg_is.format('string2', 'string'), msg_is.format('Test int option', '1')]) + ')'
|
|
|
|
list_disabled_2 = 'disabled (' + display_list([msg_is.format('Test int option', '1'), msg_is.format('string2', 'string')]) + ')'
|
|
|
|
list_hidden = 'hidden (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or')) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp1 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled_1, list_hidden])))
|
|
|
|
comp2 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled_2, list_hidden])))
|
|
|
|
comp3 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_hidden, list_disabled_1])))
|
|
|
|
comp4 = str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_hidden, list_disabled_2])))
|
2016-11-16 22:31:42 +01:00
|
|
|
assert comp1 or comp2 or comp3 or comp4
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
config.options.val2
|
|
|
|
except Exception, err:
|
|
|
|
pass
|
|
|
|
|
2017-01-19 21:38:16 +01:00
|
|
|
assert str(err) == msg_error.format('optiondescription', 'options', prop, 'hidden (' + msg_is.format('Test int option', 1) + ')')
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
config.val3
|
|
|
|
except Exception, err:
|
|
|
|
pass
|
2016-11-16 22:31:42 +01:00
|
|
|
msg_1 = msg_is.format('string2', 'string')
|
|
|
|
msg_2 = msg_is.format('Test int option', 1)
|
|
|
|
msg_3 = msg_is_not.format('Test int option', display_list([2, 3, 4], 'or'))
|
|
|
|
|
|
|
|
list_hidden = 'hidden (' + display_list([msg_1, msg_2, msg_3]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp1 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
list_hidden = 'hidden (' + display_list([msg_1, msg_3, msg_2]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp2 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
list_hidden = 'hidden (' + display_list([msg_2, msg_1, msg_3]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp3 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
list_hidden = 'hidden (' + display_list([msg_2, msg_3, msg_1]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp4 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
list_hidden = 'hidden (' + display_list([msg_3, msg_1, msg_2]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp5 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
list_hidden = 'hidden (' + display_list([msg_3, msg_2, msg_1]) + ')'
|
2017-01-19 21:38:16 +01:00
|
|
|
comp6 = str(err) == msg_error.format('option', 'val3', prop, list_hidden)
|
2016-11-16 22:31:42 +01:00
|
|
|
assert comp1 or comp2 or comp3 or comp4 or comp5 or comp6
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
config.string
|
|
|
|
except Exception, err:
|
|
|
|
pass
|
|
|
|
|
2017-01-19 21:38:16 +01:00
|
|
|
assert str(err) == msg_error.format('option', 'string', properties, display_list(['disabled', 'hidden']))
|
2016-09-14 20:17:25 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
config.string3
|
|
|
|
except Exception, err:
|
|
|
|
pass
|
|
|
|
|
2017-01-19 21:38:16 +01:00
|
|
|
assert str(err) == msg_error.format('option', 'string3', prop, 'hidden')
|