2012-07-13 09:42:14 +02:00
|
|
|
"config.set() or config.setoption() or option.setoption()"
|
|
|
|
import autopath
|
|
|
|
from py.test import raises
|
|
|
|
|
2013-04-03 12:20:26 +02:00
|
|
|
from tiramisu.setting import owners
|
2013-04-17 21:50:31 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
StrOption, OptionDescription, SymLinkOption
|
|
|
|
from tiramisu.error import ConflictOptionError, PropertiesOptionError
|
|
|
|
|
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-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values().getowner(s) == owners.user
|
2012-11-12 12:06:58 +01:00
|
|
|
config.unwrap_from_path("string").reset(config)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == 'string'
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values().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 = []
|
|
|
|
config.unwrap_from_path("string").reset(config)
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == ["string"]
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = ["eggs", "spam", "foo"]
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values().getowner(s) == 'user'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = []
|
2012-11-12 12:06:58 +01:00
|
|
|
config.unwrap_from_path("string").reset(config)
|
|
|
|
# assert config.string == ["string"]
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_values().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)
|
|
|
|
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"
|
|
|
|
# FIXME
|
|
|
|
config.string[0] = 'changetest'
|
|
|
|
# assert config.string[0] == 'changetest'
|
|
|
|
# assert config.string[
|
|
|
|
|
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-02-08 11:50:22 +01:00
|
|
|
assert config._cfgimpl_values.getowner(s) == 'default'
|
2012-07-13 09:42:14 +02:00
|
|
|
config.string = ["foo", "bar"]
|
|
|
|
assert config.string == ["foo", "bar"]
|
2013-02-08 11:50:22 +01:00
|
|
|
assert config._cfgimpl_values.getowner(s) == 'user'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
#def test_attribute_access_with_multi2():
|
|
|
|
# s = StrOption("string", "", default="string", multi=True)
|
|
|
|
# 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_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-04-03 12:20:26 +02:00
|
|
|
requires=[('int', 1, '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', 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-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', 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",
|
2012-07-13 09:42:14 +02:00
|
|
|
requires=[('int', 1, 'hide', 'inverted')], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s, intoption, stroption])
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', stroption)
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = 1
|
2013-04-03 12:20:26 +02:00
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', 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)
|
|
|
|
descr = OptionDescription("options", "", [intoption])
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=[('int', 1, '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', 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-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', 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_apply_requires_from_config():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
descr = OptionDescription("options", "", [intoption])
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=[('int', 1, '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', 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')
|
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', 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)
|
|
|
|
descr = OptionDescription("options", "", [intoption])
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=[('int', 1, '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('disabled', 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')
|
|
|
|
assert config.cfgimpl_get_settings().has_property('disabled', 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)
|
|
|
|
descr = OptionDescription("options", "", [intoption])
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=[('int', 1, '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('disabled', 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-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('disabled', 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():
|
|
|
|
s = StrOption("string", "", default=["string"], multi=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
2012-11-12 12:06:58 +01:00
|
|
|
stroption = StrOption('str', 'Test string option', default=["abc"],
|
2013-04-03 12:20:26 +02:00
|
|
|
requires=[('int', [1, 1], '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()
|
|
|
|
setting.read_write()
|
|
|
|
assert not config.cfgimpl_get_settings().has_property('hidden', stroption)
|
2012-07-13 09:42:14 +02:00
|
|
|
config.int = [1, 1]
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
2013-04-03 12:20:26 +02:00
|
|
|
assert config.cfgimpl_get_settings().has_property('hidden', 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_bool():
|
|
|
|
s = BoolOption("bool", "", default=[False], multi=True)
|
|
|
|
descr = OptionDescription("options", "", [s])
|
|
|
|
config = Config(descr)
|
2013-04-17 21:50:31 +02:00
|
|
|
assert descr.bool.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)
|
2013-04-17 21:50:31 +02:00
|
|
|
assert descr.bool.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-11 11:30:58 +02:00
|
|
|
#def test_setoption_from_option():
|
|
|
|
# "a setoption directly from the option is **not** a good practice"
|
|
|
|
# booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
# descr = OptionDescription('descr', '', [booloption])
|
|
|
|
# cfg = Config(descr)
|
|
|
|
# booloption.setoption(cfg, False)
|
|
|
|
# assert cfg.bool == False
|
2013-04-17 21:50:31 +02:00
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
def test_dwim_set():
|
|
|
|
descr = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("sub", "", [
|
|
|
|
BoolOption("b1", ""),
|
2013-04-03 12:20:26 +02:00
|
|
|
ChoiceOption("c1", "", ('a', 'b', 'c'), 'a'),
|
2012-07-13 09:42:14 +02:00
|
|
|
BoolOption("d1", ""),
|
|
|
|
]),
|
|
|
|
BoolOption("b2", ""),
|
|
|
|
BoolOption("d1", ""),
|
|
|
|
])
|
|
|
|
c = Config(descr)
|
|
|
|
c.set(b1=False, c1='b')
|
|
|
|
assert not c.sub.b1
|
|
|
|
assert c.sub.c1 == 'b'
|
|
|
|
# new config, because you cannot change values once they are set
|
|
|
|
c = Config(descr)
|
|
|
|
c.set(b2=False, **{'sub.c1': 'c'})
|
|
|
|
assert not c.b2
|
|
|
|
assert c.sub.c1 == 'c'
|
2013-04-17 21:50:31 +02:00
|
|
|
raises(ConflictOptionError, "c.set(d1=True)")
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(AttributeError, "c.set(unknown='foo')")
|
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_more_set():
|
|
|
|
descr = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False)]),
|
|
|
|
IntOption("int", "", default=42)])
|
|
|
|
d = {'s1.a': True, 'int': 23}
|
|
|
|
config = Config(descr)
|
|
|
|
config.set(**d)
|
|
|
|
assert config.s1.a
|
|
|
|
assert config.int == 23
|
|
|
|
|
2013-04-17 21:50:31 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def test_set_with_hidden_option():
|
2013-04-03 12:20:26 +02:00
|
|
|
boolopt = BoolOption("a", "", default=False, properties=(('hidden'),))
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [boolopt]),
|
|
|
|
IntOption("int", "", default=42)])
|
|
|
|
d = {'s1.a': True, 'int': 23}
|
|
|
|
config = Config(descr)
|
2013-04-03 12:20:26 +02:00
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
2012-08-13 12:49:58 +02:00
|
|
|
raises(PropertiesOptionError, "config.set(**d)")
|
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_set_with_unknown_option():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
|
|
|
descr = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [boolopt]),
|
|
|
|
IntOption("int", "", default=42)])
|
|
|
|
d = {'s1.a': True, 'int': 23}
|
|
|
|
config = Config(descr)
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(AttributeError, "config.set(**d)")
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_set_symlink_option():
|
|
|
|
boolopt = BoolOption("b", "", default=False)
|
2012-12-03 15:48:04 +01:00
|
|
|
linkopt = SymLinkOption("c", "s1.b", opt=boolopt)
|
2012-11-12 12:06:58 +01:00
|
|
|
descr = OptionDescription("opt", "",
|
2012-07-13 09:42:14 +02:00
|
|
|
[linkopt, OptionDescription("s1", "", [boolopt])])
|
|
|
|
config = Config(descr)
|
|
|
|
setattr(config, "s1.b", True)
|
|
|
|
setattr(config, "s1.b", False)
|
2013-04-17 21:50:31 +02:00
|
|
|
assert config.s1.b is False
|
|
|
|
assert config.c is False
|
2012-07-13 09:42:14 +02:00
|
|
|
config.c = True
|
2013-04-17 21:50:31 +02:00
|
|
|
assert config.s1.b is True
|
|
|
|
assert config.c is True
|
2012-07-13 09:42:14 +02:00
|
|
|
config.c = False
|
2013-04-17 21:50:31 +02:00
|
|
|
assert config.s1.b is False
|
|
|
|
assert config.c is False
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2013-02-07 16:20:21 +01:00
|
|
|
##____________________________________________________________
|
|
|
|
#def test_config_impl_values():
|
|
|
|
# descr = make_description()
|
|
|
|
# config = Config(descr)
|
|
|
|
# config.bool = False
|
|
|
|
## gcdummy.setoption(config, True, "user")
|
|
|
|
## config.setoption("gc.dummy", True, "user")
|
|
|
|
# #config.gc.dummy = True
|
|
|
|
## config.setoption("bool", False, "user")
|
|
|
|
# config.set(dummy=False)
|
|
|
|
# assert config.gc._cfgimpl_context._cfgimpl_values.values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
|
|
|
# ## acces to the option object
|
|
|
|
## config.gc._cfgimpl_descr.dummy.setoption(config, True, "user")
|
|
|
|
# assert config.gc.dummy == False
|
|
|
|
## config.set(dummy=True)
|
|
|
|
## assert config.gc.dummy == True
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
#____________________________________________________________
|
2013-04-11 11:30:58 +02:00
|
|
|
#def test_accepts_multiple_changes_from_option():
|
|
|
|
# s = StrOption("string", "", default="string")
|
|
|
|
# descr = OptionDescription("options", "", [s])
|
|
|
|
# config = Config(descr)
|
|
|
|
# config.string = "egg"
|
|
|
|
# assert s.getdefault() == "string"
|
|
|
|
# assert config.string == "egg"
|
|
|
|
# s.setoption(config, 'blah')
|
|
|
|
# assert s.getdefault() == "string"
|
|
|
|
# assert config.string == "blah"
|
|
|
|
# s.setoption(config, '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-11 11:30:58 +02:00
|
|
|
config.setoption("string", s, 'blah')
|
|
|
|
config.setoption("string", s, "oh")
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.string == "oh"
|
2013-04-17 21:50:31 +02:00
|
|
|
config.set(string2='blah')
|
2012-07-13 09:42:14 +02:00
|
|
|
assert config.bip.string2 == '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-03 12:20:26 +02:00
|
|
|
setting = c.cfgimpl_get_settings()
|
|
|
|
setting.read_write()
|
2013-04-14 12:01:32 +02:00
|
|
|
raises(AttributeError, "c.find(byname='b1')")
|