2012-07-13 09:42:14 +02:00
|
|
|
"configuration objects global API"
|
2023-04-15 16:12:35 +02:00
|
|
|
from pytest import raises
|
2018-03-19 08:33:53 +01:00
|
|
|
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2023-04-15 16:12:35 +02:00
|
|
|
from .config import config_type, get_config, value_list, global_owner
|
2015-07-24 17:54:10 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
2019-12-08 09:09:48 +01:00
|
|
|
BoolOption, FilenameOption, SymLinkOption, IPOption, \
|
2014-02-06 22:17:20 +01:00
|
|
|
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
|
2018-08-15 08:35:22 +02:00
|
|
|
DomainnameOption, OptionDescription
|
2023-04-27 11:44:52 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError, ValueWarning, ConfigError
|
2019-12-24 15:24:20 +01:00
|
|
|
import warnings
|
2018-10-31 08:00:19 +01:00
|
|
|
|
|
|
|
|
2020-01-22 20:46:18 +01:00
|
|
|
#def teardown_function(function):
|
|
|
|
# # test_od_not_list emit a warnings because of doesn't create a Config
|
|
|
|
# with warnings.catch_warnings(record=True) as w:
|
|
|
|
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
2013-04-20 21:58:52 +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)
|
2018-04-10 12:33:51 +02:00
|
|
|
prop = BoolOption('prop', 'prop 1', properties=('disabled',))
|
2018-04-12 23:04:33 +02:00
|
|
|
prop2 = StrOption('prop', 'prop 2', properties=('hidden',))
|
2012-07-13 09:42:14 +02:00
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
2013-04-20 21:58:52 +02:00
|
|
|
('std', 'thunk'), 'std')
|
2012-07-13 09:42:14 +02:00
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
2014-02-01 17:25:31 +01:00
|
|
|
booloption2 = BoolOption('bool', 'Test boolean option', default=False)
|
2012-07-13 09:42:14 +02:00
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
2014-02-01 16:49:16 +01:00
|
|
|
floatoption2 = FloatOption('float', 'Test float option', default=2.3)
|
2012-07-13 09:42:14 +02:00
|
|
|
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', 'Tests', default=False)
|
|
|
|
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
2014-02-01 17:25:31 +01:00
|
|
|
gcgroup2 = OptionDescription('gc2', '', [booloption2, prop])
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcgroup2, gcoption, gcdummy, floatoption, prop2])
|
2012-07-13 09:42:14 +02:00
|
|
|
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
2013-04-20 21:58:52 +02:00
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
2014-02-01 16:49:16 +01:00
|
|
|
intoption, boolop, floatoption2])
|
2012-07-13 09:42:14 +02:00
|
|
|
return descr
|
|
|
|
|
|
|
|
|
2016-10-01 20:15:08 +02:00
|
|
|
def _is_same_opt(opt1, opt2):
|
|
|
|
if "id" in dir(opt1):
|
|
|
|
assert opt1.id == opt2.id
|
|
|
|
else:
|
|
|
|
assert opt1 == opt2
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_od_not_list():
|
2018-04-12 23:04:33 +02:00
|
|
|
b = BoolOption('bool', '', multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(AssertionError):
|
2019-12-24 15:24:20 +01:00
|
|
|
OptionDescription('od', '', b)
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2018-04-12 23:04:33 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_str():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg # does not crash
|
|
|
|
# assert not list_sessions()
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_make_dict(config_type):
|
2012-07-13 09:42:14 +02:00
|
|
|
"serialization of the whole config to a dict"
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription("opt", "", [
|
2012-07-13 09:42:14 +02:00
|
|
|
OptionDescription("s1", "", [
|
2014-03-31 22:34:57 +02:00
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('hidden',))]),
|
2012-07-13 09:42:14 +02:00
|
|
|
IntOption("int", "", default=42)])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
d = cfg.value.dict()
|
|
|
|
assert d == {"s1.a": False, "int": 42}
|
|
|
|
cfg.option('int').value.set(43)
|
|
|
|
cfg.option('s1.a').value.set(True)
|
|
|
|
d = cfg.value.dict()
|
|
|
|
assert d == {"s1.a": True, "int": 43}
|
|
|
|
if config_type == 'tiramisu':
|
|
|
|
assert cfg.forcepermissive.value.dict() == {"s1.a": True, "s1.b": False, "int": 43}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_dict_sub(config_type):
|
|
|
|
"serialization part of config to a dict"
|
|
|
|
od1 = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('hidden',))]),
|
|
|
|
IntOption("int", "", default=42)])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
cfg = get_config(cfg, config_type)
|
2023-04-27 11:34:35 +02:00
|
|
|
assert cfg.option('s1').value.dict() == {'s1.a': False}
|
2023-04-15 16:12:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_make_dict_not_value(config_type):
|
|
|
|
"serialization part of config to a dict"
|
|
|
|
od1 = OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('hidden',))]),
|
|
|
|
IntOption("int", "", default=42)])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
cfg = get_config(cfg, config_type)
|
2023-04-27 11:44:52 +02:00
|
|
|
with raises(ConfigError):
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg.option('s1.a').value.dict()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_dict_with_disabled(config_type):
|
|
|
|
od1 = OptionDescription("opt", "", [
|
2014-03-12 14:57:36 +01:00
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('disabled',))]),
|
2015-11-29 23:03:08 +01:00
|
|
|
OptionDescription("s2", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False)], properties=('disabled',)),
|
|
|
|
IntOption("int", "", default=42)])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {"s1.a": False, "int": 42}
|
|
|
|
if config_type == 'tiramisu':
|
|
|
|
assert cfg.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
|
|
|
|
assert cfg.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_make_dict_with_disabled_in_callback(config_type):
|
|
|
|
od1 = OptionDescription("opt", "", [
|
2015-11-29 23:03:08 +01:00
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('disabled',))]),
|
|
|
|
OptionDescription("s2", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False)], properties=('disabled',)),
|
2014-03-12 14:57:36 +01:00
|
|
|
IntOption("int", "", default=42)])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
d = cfg.value.dict()
|
|
|
|
assert d == {"s1.a": False, "int": 42}
|
|
|
|
# assert not list_sessions()
|
2012-07-13 09:42:14 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_make_dict_fullpath(config_type):
|
|
|
|
od1 = OptionDescription("root", "", [
|
2017-01-06 21:01:24 +01:00
|
|
|
OptionDescription("opt", "", [
|
|
|
|
OptionDescription("s1", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False, properties=('disabled',))]),
|
|
|
|
OptionDescription("s2", "", [
|
|
|
|
BoolOption("a", "", default=False),
|
|
|
|
BoolOption("b", "", default=False)], properties=('disabled',)),
|
|
|
|
IntOption("int", "", default=42)]),
|
|
|
|
IntOption("introot", "", default=42)])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
2023-04-27 11:34:35 +02:00
|
|
|
assert cfg.option('opt').value.dict() == {"opt.s1.a": False, "opt.int": 42}
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_in_config():
|
2012-10-11 16:16:43 +02:00
|
|
|
"finds option in config"
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_only()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
ret = list(cfg.option.find('dummy'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret_find = cfg.option.find('dummy', first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
ret = ret_find.get()
|
|
|
|
_is_same_opt(ret, cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.option.find('float'))
|
|
|
|
assert len(ret) == 2
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.float').get())
|
|
|
|
_is_same_opt(ret[1].get(), cfg.option('float').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = cfg.option.find('bool', first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.option.find('bool', value=True, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('bool').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.option.find('dummy', first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.option.find('float', first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('gc.float').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = list(cfg.option.find('prop'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.option.find('prop', value=None))
|
|
|
|
assert len(ret) == 1
|
|
|
|
ret = list(cfg.option.find('prop'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
cfg.property.read_write()
|
|
|
|
with raises(AttributeError):
|
|
|
|
ret = cfg.option.find('prop')
|
2023-05-16 22:50:38 +02:00
|
|
|
assert ret.get()
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = list(cfg.unrestraint.option.find(name='prop'))
|
|
|
|
assert len(ret) == 2
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get())
|
|
|
|
_is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.forcepermissive.option.find('prop'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.forcepermissive.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = cfg.forcepermissive.option.find('prop', first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.forcepermissive.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
# combinaison of filters
|
|
|
|
ret = list(cfg.unrestraint.option.find('prop', type=BoolOption))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.unrestraint.option.find('prop', type=BoolOption, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.unrestraint.option('gc.gc2.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.option.find('dummy', value=False))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = cfg.option.find('dummy', value=False, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#subcfgig
|
|
|
|
ret = list(cfg.option('gc').find('dummy'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.dummy').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.option('gc').find('float'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.float').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.option('gc.gc2').find('bool'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.gc2.bool').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.option('gc').find('bool', value=False, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), cfg.option('gc.gc2.bool').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
with raises(AttributeError):
|
|
|
|
ret = cfg.option('gc').find('bool', value=True, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
assert ret.get()
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
with raises(AttributeError):
|
|
|
|
ret = cfg.option('gc').find('wantref')
|
2023-05-16 22:50:38 +02:00
|
|
|
ret.get()
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
ret = list(cfg.unrestraint.option('gc').find('prop'))
|
|
|
|
assert len(ret) == 2
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.unrestraint.option('gc.gc2.prop').get())
|
|
|
|
_is_same_opt(ret[1].get(), cfg.forcepermissive.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
#
|
|
|
|
cfg.property.read_only()
|
|
|
|
ret = list(cfg.option('gc').find('prop'))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), cfg.option('gc.prop').get())
|
2023-04-15 16:12:35 +02:00
|
|
|
# not OptionDescription
|
|
|
|
with raises(AttributeError):
|
|
|
|
cfg.option.find('gc', first=True)
|
|
|
|
with raises(AttributeError):
|
|
|
|
cfg.option.find('gc2', first=True)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_multi():
|
2019-12-08 09:09:48 +01:00
|
|
|
b = BoolOption('bool', '', multi=True, properties=('notunique',))
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('od', '', [b])
|
|
|
|
cfg = Config(od1)
|
|
|
|
#
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True))
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True, first=True))
|
|
|
|
cfg.option('bool').value.set([False])
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True))
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True, first=True))
|
|
|
|
cfg.option('bool').value.set([False, False])
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True))
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('bool', value=True, first=True))
|
|
|
|
cfg.option('bool').value.set([False, False, True])
|
|
|
|
ret = list(cfg.option.find('bool', value=True))
|
|
|
|
assert len(ret) == 1
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret[0].get(), b)
|
2023-04-15 16:12:35 +02:00
|
|
|
ret = cfg.option.find('bool', value=True, first=True)
|
2023-05-16 22:50:38 +02:00
|
|
|
_is_same_opt(ret.get(), b)
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_does_not_find_in_config():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
with raises(AttributeError):
|
|
|
|
list(cfg.option.find('IDontExist'))
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_filename(config_type):
|
2013-10-01 08:19:10 +02:00
|
|
|
a = FilenameOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('o', '', [a])
|
|
|
|
cfg = Config(od1)
|
|
|
|
# FIXME cfg = get_config(cfg, config_type)
|
|
|
|
cfg.option('a').value.set('/')
|
|
|
|
cfg.option('a').value.set('/tmp')
|
|
|
|
cfg.option('a').value.set('/tmp/')
|
|
|
|
cfg.option('a').value.set('/tmp/text.txt')
|
|
|
|
cfg.option('a').value.set('/tmp/with space.txt')
|
|
|
|
cfg.option('a').value.set('/tmp/with$.txt')
|
|
|
|
with raises(ValueError):
|
|
|
|
cfg.option('a').value.set('not starts with /')
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_option():
|
2015-07-24 17:54:10 +02:00
|
|
|
ChoiceOption('a', '', ('1', '2'))
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(TypeError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ChoiceOption('a', '', [1, 2])
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(TypeError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ChoiceOption('a', '', 1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ChoiceOption('a', '', (1,), 3)
|
2015-07-24 17:54:10 +02:00
|
|
|
FloatOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
FloatOption('a', '', 'string')
|
2019-12-08 09:09:48 +01:00
|
|
|
StrOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
StrOption('a', '', 1)
|
2019-12-08 09:09:48 +01:00
|
|
|
u = StrOption('a', '')
|
2015-07-24 17:54:10 +02:00
|
|
|
SymLinkOption('a', u)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
SymLinkOption('a', 'string')
|
2015-07-24 17:54:10 +02:00
|
|
|
IPOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IPOption('a', '', 1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IPOption('a', '', 'string')
|
2015-07-24 17:54:10 +02:00
|
|
|
PortOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', 'string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', '11:12:13', allow_range=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', 11111111111111111111)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2022-10-01 19:43:49 +02:00
|
|
|
PortOption('a', '', 'tcp:80')
|
2015-07-24 17:54:10 +02:00
|
|
|
NetworkOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
NetworkOption('a', '', 'string')
|
2015-07-24 17:54:10 +02:00
|
|
|
NetmaskOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
NetmaskOption('a', '', 'string')
|
2015-07-24 17:54:10 +02:00
|
|
|
BroadcastOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
BroadcastOption('a', '', 'string')
|
2015-07-24 17:54:10 +02:00
|
|
|
DomainnameOption('a', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', 'string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', type='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', allow_ip='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', allow_without_dot='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', 1)
|
2015-09-17 19:14:56 +02:00
|
|
|
#
|
|
|
|
ChoiceOption('a', '', (1,), multi=True, default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ChoiceOption('a', '', (1,), default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
FloatOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
StrOption('a', '', multi=True, default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IPOption('a', '', multi=True, default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IPOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
PortOption('a', '', multi=True, default_multi=11111111111111111111)
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
NetworkOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
NetmaskOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
BroadcastOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', multi=True, default_multi='string')
|
2023-04-15 16:12:35 +02:00
|
|
|
with raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
DomainnameOption('a', '', multi=True, default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2019-12-24 15:24:20 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_help():
|
2018-08-15 08:35:22 +02:00
|
|
|
stro = StrOption('s', '', multi=True)
|
|
|
|
od1 = OptionDescription('o', '', [stro])
|
|
|
|
od2 = OptionDescription('o', '', [od1])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od2)
|
|
|
|
cfg.help(_display=False)
|
|
|
|
cfg.config.help(_display=False)
|
|
|
|
cfg.option.help(_display=False)
|
|
|
|
cfg.option('o').help(_display=False)
|
|
|
|
cfg.option('o.s').help(_display=False)
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_config_reset():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.owner.set('test')
|
|
|
|
assert cfg.owner.get() == 'test'
|
|
|
|
assert not cfg.option('gc.gc2.bool').value.get()
|
|
|
|
assert not cfg.option('boolop').property.get()
|
|
|
|
assert not cfg.option('boolop').permissive.get()
|
|
|
|
assert not cfg.option('wantref').information.get('info', None)
|
|
|
|
#
|
|
|
|
cfg.option('gc.gc2.bool').value.set(True)
|
|
|
|
cfg.option('boolop').property.add('test')
|
|
|
|
cfg.option('float').permissive.set(frozenset(['test']))
|
|
|
|
cfg.option('wantref').information.set('info', 'info')
|
|
|
|
assert cfg.option('gc.gc2.bool').value.get()
|
|
|
|
assert cfg.option('boolop').property.get()
|
|
|
|
assert cfg.option('float').permissive.get()
|
|
|
|
assert cfg.option('wantref').information.get('info', None)
|
|
|
|
#
|
|
|
|
assert cfg.owner.get() == 'test'
|
|
|
|
cfg.config.reset()
|
|
|
|
assert cfg.owner.get() == 'test'
|
|
|
|
assert not cfg.option('gc.gc2.bool').value.get()
|
|
|
|
assert not cfg.option('boolop').property.get()
|
|
|
|
assert not cfg.option('float').permissive.get()
|
|
|
|
assert not cfg.option('wantref').information.get('info', None)
|
|
|
|
# assert not list_sessions()
|