tiramisu/tests/test_config_api.py

459 lines
20 KiB
Python
Raw Normal View History

"configuration objects global API"
2019-12-24 15:24:20 +01:00
import pytest
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()
2019-06-21 23:04:04 +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
2019-12-24 15:24:20 +01:00
from tiramisu.error import PropertiesOptionError, ValueWarning
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions
2019-12-24 15:24:20 +01:00
import warnings
2018-10-31 08:00:19 +01:00
def teardown_function(function):
2019-12-24 15:24:20 +01:00
# 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__)
def make_description():
2013-04-03 12:20:26 +02:00
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
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',))
objspaceoption = ChoiceOption('objspace', 'Object space',
('std', 'thunk'), 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
2014-02-01 17:25:31 +01:00
booloption2 = BoolOption('bool', 'Test boolean option', default=False)
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)
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])
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
2014-02-01 16:49:16 +01:00
intoption, boolop, floatoption2])
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
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_od_not_list():
2018-04-12 23:04:33 +02:00
b = BoolOption('bool', '', multi=True)
2019-12-24 15:24:20 +01:00
with pytest.raises(AssertionError):
OptionDescription('od', '', b)
2018-04-12 23:04:33 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_str():
descr = make_description()
2019-12-24 15:24:20 +01:00
c = await Config(descr)
c # does not crash
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_make_dict(config_type):
"serialization of the whole config to a dict"
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
BoolOption("b", "", default=False, properties=('hidden',))]),
IntOption("int", "", default=42)])
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.property.read_write()
await cfg.permissive.add('hidden')
cfg = await get_config(cfg, config_type)
d = await cfg.value.dict()
assert d == {"s1.a": False, "int": 42}
2019-12-24 15:24:20 +01:00
await cfg.option('int').value.set(43)
await cfg.option('s1.a').value.set(True)
d = await cfg.value.dict()
assert d == {"s1.a": True, "int": 43}
2019-12-24 15:24:20 +01:00
d2 = await cfg.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43}
2019-06-21 23:04:04 +02:00
if config_type == 'tiramisu':
2019-12-25 20:44:56 +01:00
assert await cfg.forcepermissive.value.dict() == {"s1.a": True, "s1.b": False, "int": 43}
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_make_dict_with_disabled(config_type):
2014-03-12 14:57:36 +01:00
descr = 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)])
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {"s1.a": False, "int": 42}
2019-06-21 23:04:04 +02:00
if config_type == 'tiramisu':
2019-12-24 15:24:20 +01:00
assert await cfg.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
assert await cfg.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
2018-04-11 16:36:15 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_make_dict_with_disabled_in_callback(config_type):
descr = 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',)),
2014-03-12 14:57:36 +01:00
IntOption("int", "", default=42)])
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
d = await cfg.value.dict()
2014-03-12 14:57:36 +01:00
assert d == {"s1.a": False, "int": 42}
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_make_dict_fullpath(config_type):
2017-01-06 21:01:24 +01:00
descr = OptionDescription("root", "", [
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)])
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
2019-06-21 23:04:04 +02:00
if config_type == 'tiramisu':
# FIXME
2019-12-24 15:24:20 +01:00
assert await cfg.option('opt').value.dict() == {"s1.a": False, "int": 42}
assert await cfg.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
2019-06-21 23:04:04 +02:00
if config_type == 'tiramisu':
# FIXME
2019-12-24 15:24:20 +01:00
assert await cfg.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
2017-01-06 21:01:24 +01:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_find_in_config():
2012-10-11 16:16:43 +02:00
"finds option in config"
descr = make_description()
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.property.read_only()
await cfg.permissive.add('hidden')
ret = list(await cfg.option.find('dummy'))
2016-10-01 20:15:08 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
2017-02-03 23:39:24 +01:00
#
2019-12-24 15:24:20 +01:00
ret_find = await cfg.option.find('dummy', first=True)
ret = await ret_find.option.get()
_is_same_opt(ret, await cfg.option('gc.dummy').option.get())
2017-02-03 23:39:24 +01:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option.find('float'))
2016-10-01 20:15:08 +02:00
assert len(ret) == 2
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.float').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.option('float').option.get())
2018-03-19 08:33:53 +01:00
#
2019-12-24 15:24:20 +01:00
ret = await cfg.option.find('bool', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.gc2.bool').option.get())
ret = await cfg.option.find('bool', value=True, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('bool').option.get())
ret = await cfg.option.find('dummy', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.dummy').option.get())
ret = await cfg.option.find('float', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.float').option.get())
2018-04-10 12:33:51 +02:00
#FIXME cannot find an option without name
2019-12-24 15:24:20 +01:00
#ret = await cfg.find(bytype=ChoiceOption)
2018-03-19 08:33:53 +01:00
#assert len(ret) == 2
2019-12-24 15:24:20 +01:00
#_is_same_opt(ret[0], await cfg.unwrap_from_path('gc.name'))
#_is_same_opt(ret[1], await cfg.unwrap_from_path('objspace'))
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
#_is_same_opt(await cfg.find_first(bytype=ChoiceOption), await cfg.unwrap_from_path('gc.name'))
#ret = await cfg.find(byvalue='ref')
2018-03-19 08:33:53 +01:00
#assert len(ret) == 1
2019-12-24 15:24:20 +01:00
#_is_same_opt(ret[0], await cfg.unwrap_from_path('gc.name'))
#_is_same_opt(await cfg.find_first(byvalue='ref'), await cfg.unwrap_from_path('gc.name'))
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option.find('prop'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option.find('prop', value=None))
2018-10-07 10:55:52 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option.find('prop'))
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
#
2019-12-24 15:24:20 +01:00
await cfg.property.read_write()
with pytest.raises(AttributeError):
ret = await cfg.option.find('prop')
assert await ret.option.get()
ret = list(await cfg.unrestraint.option.find(name='prop'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 2
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.forcepermissive.option.find('prop'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = await cfg.forcepermissive.option.find('prop', first=True)
_is_same_opt(await ret.option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
# combinaison of filters
2019-12-24 15:24:20 +01:00
ret = list(await cfg.unrestraint.option.find('prop', type=BoolOption))
2018-04-12 23:04:33 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
ret = await cfg.unrestraint.option.find('prop', type=BoolOption, first=True)
_is_same_opt(await ret.option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option.find('dummy', value=False))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = await cfg.option.find('dummy', value=False, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.dummy').option.get())
#subcfgig
ret = list(await cfg.option('gc').find('dummy'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option('gc').find('float'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.float').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.option('gc').find('bool'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.gc2.bool').option.get())
ret = await cfg.option('gc').find('bool', value=False, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.gc2.bool').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
with pytest.raises(AttributeError):
ret = await cfg.option('gc').find('bool', value=True, first=True)
assert await ret.option.get()
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
with pytest.raises(AttributeError):
ret = await cfg.option('gc').find('wantref')
await ret.option.get()
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
ret = list(await cfg.unrestraint.option('gc').find('prop'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 2
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
await cfg.property.read_only()
ret = list(await cfg.option('gc').find('prop'))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
2018-04-10 12:33:51 +02:00
# not OptionDescription
2019-12-24 15:24:20 +01:00
with pytest.raises(AttributeError):
await cfg.option.find('gc', first=True)
with pytest.raises(AttributeError):
await cfg.option.find('gc2', first=True)
2018-03-19 08:33:53 +01:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_find_multi():
2019-12-08 09:09:48 +01:00
b = BoolOption('bool', '', multi=True, properties=('notunique',))
2018-04-10 12:33:51 +02:00
o = OptionDescription('od', '', [b])
2019-12-24 15:24:20 +01:00
cfg = await Config(o)
2018-04-10 12:33:51 +02:00
#
2019-12-24 15:24:20 +01:00
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False])
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False, False])
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False, False, True])
ret = list(await cfg.option.find('bool', value=True))
2018-04-10 12:33:51 +02:00
assert len(ret) == 1
2019-12-24 15:24:20 +01:00
_is_same_opt(await ret[0].option.get(), b)
ret = await cfg.option.find('bool', value=True, first=True)
_is_same_opt(await ret.option.get(), b)
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_does_not_find_in_config():
descr = make_description()
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
with pytest.raises(AttributeError):
list(await cfg.option.find('IDontExist'))
2013-09-30 21:21:47 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_filename(config_type):
a = FilenameOption('a', '')
2013-09-30 21:21:47 +02:00
o = OptionDescription('o', '', [a])
2019-12-24 15:24:20 +01:00
cfg = await Config(o)
# FIXME cfg = await get_config(cfg, config_type)
await cfg.option('a').value.set('/')
await cfg.option('a').value.set('/tmp')
await cfg.option('a').value.set('/tmp/')
await cfg.option('a').value.set('/tmp/text.txt')
await cfg.option('a').value.set('tmp')
await cfg.option('a').value.set('tmp/')
await cfg.option('a').value.set('tmp/text.txt')
with pytest.raises(ValueError):
await cfg.option('a').value.set('/tmp/with space.txt')
with pytest.raises(ValueError):
await cfg.option('a').value.set('/tmp/with$.txt')
@pytest.mark.asyncio
async def test_invalid_option():
2015-07-24 17:54:10 +02:00
ChoiceOption('a', '', ('1', '2'))
2019-12-24 15:24:20 +01:00
with pytest.raises(TypeError):
ChoiceOption('a', '', [1, 2])
with pytest.raises(TypeError):
ChoiceOption('a', '', 1)
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), 3)
2015-07-24 17:54:10 +02:00
FloatOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
FloatOption('a', '', 'string')
2019-12-08 09:09:48 +01:00
StrOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
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)
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
SymLinkOption('a', 'string')
2015-07-24 17:54:10 +02:00
IPOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
IPOption('a', '', 1)
with pytest.raises(ValueError):
IPOption('a', '', 'string')
2015-07-24 17:54:10 +02:00
PortOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
PortOption('a', '', 'string')
with pytest.raises(ValueError):
PortOption('a', '', '11:12:13', allow_range=True)
with pytest.raises(ValueError):
PortOption('a', '', 11111111111111111111)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)
2015-07-24 17:54:10 +02:00
NetworkOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
NetworkOption('a', '', 'string')
2015-07-24 17:54:10 +02:00
NetmaskOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
NetmaskOption('a', '', 'string')
2015-07-24 17:54:10 +02:00
BroadcastOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
BroadcastOption('a', '', 'string')
2015-07-24 17:54:10 +02:00
DomainnameOption('a', '')
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
DomainnameOption('a', '', 'string')
with pytest.raises(ValueError):
DomainnameOption('a', '', type='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', allow_ip='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', allow_without_dot='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', 1)
#
ChoiceOption('a', '', (1,), multi=True, default_multi=1)
2019-12-24 15:24:20 +01:00
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), default_multi=1)
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)
with pytest.raises(ValueError):
FloatOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
StrOption('a', '', multi=True, default_multi=1)
with pytest.raises(ValueError):
IPOption('a', '', multi=True, default_multi=1)
with pytest.raises(ValueError):
IPOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi=11111111111111111111)
with pytest.raises(ValueError):
NetworkOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
NetmaskOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
BroadcastOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', multi=True, default_multi=1)
@pytest.mark.asyncio
async def test_help():
2018-08-15 08:35:22 +02:00
stro = StrOption('s', '', multi=True)
od1 = OptionDescription('o', '', [stro])
od2 = OptionDescription('o', '', [od1])
2019-12-24 15:24:20 +01:00
cfg = await Config(od2)
2018-10-07 10:55:52 +02:00
cfg.help(_display=False)
cfg.config.help(_display=False)
cfg.option.help(_display=False)
2019-12-24 15:24:20 +01:00
cfg.option('o').help(_display=False)
2018-10-07 10:55:52 +02:00
cfg.option('o.s').help(_display=False)
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_config_reset():
descr = make_description()
2019-12-24 15:24:20 +01:00
cfg = await Config(descr)
await cfg.owner.set('test')
assert await cfg.owner.get() == 'test'
assert not await cfg.option('gc.gc2.bool').value.get()
assert not await cfg.option('boolop').property.get()
assert not await cfg.option('boolop').permissive.get()
assert not await cfg.option('wantref').information.get('info', None)
#
2019-12-24 15:24:20 +01:00
await cfg.option('gc.gc2.bool').value.set(True)
await cfg.option('boolop').property.add('test')
await cfg.option('float').permissive.set(frozenset(['test']))
await cfg.option('wantref').information.set('info', 'info')
assert await cfg.option('gc.gc2.bool').value.get()
assert await cfg.option('boolop').property.get()
assert await cfg.option('float').permissive.get()
assert await cfg.option('wantref').information.get('info', None)
#
2019-12-24 15:24:20 +01:00
assert await cfg.owner.get() == 'test'
await cfg.config.reset()
assert await cfg.owner.get() == 'test'
assert not await cfg.option('gc.gc2.bool').value.get()
assert not await cfg.option('boolop').property.get()
assert not await cfg.option('float').permissive.get()
assert not await cfg.option('wantref').information.get('info', None)