2013-08-22 12:17:10 +02:00
|
|
|
"""these tests are here to create some :class:`tiramisu.option.Option`'s
|
|
|
|
and to compare them
|
|
|
|
"""
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
|
|
|
import warnings
|
2013-05-05 21:43:19 +02:00
|
|
|
|
2018-09-12 21:05:14 +02:00
|
|
|
from tiramisu.error import APIError, ConfigError
|
2019-10-16 07:31:52 +02:00
|
|
|
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation, groups, list_sessions
|
2019-04-08 08:41:33 +02:00
|
|
|
from tiramisu.i18n import _
|
2020-01-22 20:46:18 +01:00
|
|
|
from .config import event_loop
|
2018-10-31 08:00:19 +01:00
|
|
|
|
2019-10-16 07:31:52 +02:00
|
|
|
try:
|
|
|
|
groups.family
|
|
|
|
except:
|
|
|
|
groups.family = groups.GroupType('family')
|
2018-10-31 08:00:19 +01:00
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
|
|
|
|
def a_func():
|
|
|
|
return None
|
2013-05-05 21:43:19 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_valid_name():
|
2013-12-09 17:55:52 +01:00
|
|
|
IntOption('test', '')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IntOption(1, "")
|
2019-02-11 20:28:03 +01:00
|
|
|
i = IntOption("test1", "")
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
SymLinkOption(1, i)
|
2019-02-11 20:28:03 +01:00
|
|
|
i = SymLinkOption("test1", i)
|
2021-05-18 18:52:42 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
#@pytest.mark.asyncio
|
|
|
|
#async def test_option_unvalid_name():
|
|
|
|
# with pytest.raises(ValueError):
|
|
|
|
# IntOption('test.', '')
|
|
|
|
# with pytest.raises(ValueError):
|
|
|
|
# IntOption('test.val', '')
|
|
|
|
# with pytest.raises(ValueError):
|
|
|
|
# IntOption('.test', '')
|
|
|
|
# with pytest.raises(ValueError):
|
|
|
|
# OptionDescription('.test', '', [])
|
2013-12-09 18:56:29 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_get_information():
|
2017-02-03 23:39:24 +01:00
|
|
|
description = "it's ok"
|
|
|
|
string = 'some informations'
|
|
|
|
i = IntOption('test', description)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2017-02-03 23:39:24 +01:00
|
|
|
i.impl_set_information('info', string)
|
|
|
|
assert i.impl_get_information('info') == string
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2017-02-03 23:39:24 +01:00
|
|
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
|
|
|
assert i.impl_get_information('doc') == description
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_get_information_config():
|
2017-02-03 23:39:24 +01:00
|
|
|
description = "it's ok"
|
|
|
|
string = 'some informations'
|
|
|
|
i = IntOption('test', description)
|
|
|
|
od = OptionDescription('od', '', [i])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
pass
|
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_set_information('info', string)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2017-02-03 23:39:24 +01:00
|
|
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
|
|
|
assert i.impl_get_information('doc') == description
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2017-02-03 23:39:24 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_get_information_default():
|
2019-10-16 07:42:18 +02:00
|
|
|
description = "it's ok"
|
|
|
|
string = 'some informations'
|
|
|
|
i = IntOption('test', description)
|
|
|
|
i.impl_set_information('noinfo', 'optdefault')
|
|
|
|
od = OptionDescription('od', '', [i])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
#
|
|
|
|
assert await cfg.option('test').information.get('noinfo', 'falsedefault') == 'optdefault'
|
|
|
|
#
|
|
|
|
await cfg.option('test').information.set('noinfo', 'notdefault')
|
|
|
|
assert await cfg.option('test').information.get('noinfo', 'falsedefault') == 'notdefault'
|
|
|
|
assert not await list_sessions()
|
2019-10-16 07:42:18 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_get_information_config2():
|
2017-02-03 23:39:24 +01:00
|
|
|
description = "it's ok"
|
|
|
|
string = 'some informations'
|
|
|
|
i = IntOption('test', description)
|
|
|
|
i.impl_set_information('info', string)
|
|
|
|
od = OptionDescription('od', '', [i])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
pass
|
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_set_information('info', 'hello')
|
2017-02-03 23:39:24 +01:00
|
|
|
assert i.impl_get_information('info') == string
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i.impl_get_information('noinfo')
|
2017-02-03 23:39:24 +01:00
|
|
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
|
|
|
assert i.impl_get_information('doc') == description
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2017-02-03 23:39:24 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_optiondescription_get_information():
|
2017-02-03 23:39:24 +01:00
|
|
|
description = "it's ok"
|
|
|
|
string = 'some informations'
|
|
|
|
o = OptionDescription('test', description, [])
|
|
|
|
o.impl_set_information('info', string)
|
|
|
|
assert o.impl_get_information('info') == string
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
o.impl_get_information('noinfo')
|
2017-02-03 23:39:24 +01:00
|
|
|
assert o.impl_get_information('noinfo', 'default') == 'default'
|
|
|
|
assert o.impl_get_information('doc') == description
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2013-12-09 18:56:29 +01:00
|
|
|
|
2013-12-09 17:55:52 +01:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_isoptiondescription():
|
2018-09-22 17:45:52 +02:00
|
|
|
i = IntOption('test', '')
|
|
|
|
od = OptionDescription('od', '', [i])
|
|
|
|
od = OptionDescription('od', '', [od])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
assert await cfg.option('od').option.isoptiondescription()
|
|
|
|
assert not await cfg.option('od.test').option.isoptiondescription()
|
|
|
|
assert not await list_sessions()
|
2018-09-22 17:45:52 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_double():
|
2019-03-02 21:31:21 +01:00
|
|
|
i = IntOption('test', '')
|
|
|
|
od = OptionDescription('od1', '', [i])
|
|
|
|
od = OptionDescription('od2', '', [od])
|
|
|
|
od = OptionDescription('od3', '', [od])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
assert await cfg.option('od2.od1.test').value.get() is None
|
|
|
|
assert await cfg.option('od2').option('od1').option('test').value.get() is None
|
|
|
|
assert not await list_sessions()
|
2019-03-02 21:31:21 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_multi():
|
2013-12-09 17:55:52 +01:00
|
|
|
IntOption('test', '', multi=True)
|
|
|
|
IntOption('test', '', multi=True, default_multi=1)
|
|
|
|
IntOption('test', '', default=[1], multi=True, default_multi=1)
|
2013-12-09 18:56:29 +01:00
|
|
|
#add default_multi to not multi's option
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IntOption('test', '', default_multi=1)
|
2013-12-09 18:56:29 +01:00
|
|
|
#unvalid default_multi
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
IntOption('test', '', multi=True, default_multi='yes')
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2019-09-28 16:32:48 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
#@pytest.mark.asyncio
|
|
|
|
#async def test_option_multi_legacy():
|
2019-09-28 16:32:48 +02:00
|
|
|
# #not default_multi with callback
|
2020-01-22 20:46:18 +01:00
|
|
|
# #with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
# IntOption('test', '', multi=True, default_multi=1, callback=a_func)")
|
2018-04-06 23:51:25 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_unknown_option():
|
2018-04-06 23:51:25 +02:00
|
|
|
i = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
|
|
|
od2 = OptionDescription('od', '', [od1])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od2) as cfg:
|
|
|
|
# test is an option, not an optiondescription
|
|
|
|
with pytest.raises(TypeError):
|
|
|
|
await cfg.option('od.test.unknown').value.get()
|
|
|
|
# unknown is an unknown option
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
await cfg.option('unknown').value.get()
|
|
|
|
# unknown is an unknown option
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
await cfg.option('od.unknown').value.get()
|
|
|
|
# unknown is an unknown optiondescription
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
await cfg.option('od.unknown.suboption').value.get()
|
|
|
|
assert not await list_sessions()
|
2018-04-06 23:51:25 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_optiondescription_list():
|
2018-09-29 20:05:28 +02:00
|
|
|
groups.notfamily1 = groups.GroupType('notfamily1')
|
|
|
|
i = IntOption('test', '')
|
|
|
|
i2 = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
|
|
|
od1.impl_set_group_type(groups.family)
|
|
|
|
od3 = OptionDescription('od2', '', [i2])
|
|
|
|
od3.impl_set_group_type(groups.notfamily1)
|
|
|
|
od2 = OptionDescription('od', '', [od1, od3])
|
|
|
|
od4 = OptionDescription('od', '', [od2])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od4) as cfg:
|
|
|
|
assert len(list(await cfg.option('od').list('option'))) == 0
|
|
|
|
assert len(list(await cfg.option('od').list('optiondescription'))) == 2
|
|
|
|
assert len(list(await cfg.option('od').list('optiondescription', group_type=groups.family))) == 1
|
|
|
|
assert len(list(await cfg.option('od').list('optiondescription', group_type=groups.notfamily1))) == 1
|
|
|
|
assert len(list(await cfg.option('od.od').list('option'))) == 1
|
|
|
|
assert len(list(await cfg.option('od.od2').list('option'))) == 1
|
|
|
|
try:
|
|
|
|
list(await cfg.option('od').list('unknown'))
|
|
|
|
except AssertionError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise Exception('must raise')
|
|
|
|
try:
|
|
|
|
list(await cfg.option('od').list('option', group_type='toto'))
|
|
|
|
except AssertionError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise Exception('must raise')
|
|
|
|
assert not await list_sessions()
|
2018-09-29 20:05:28 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_optiondescription_group():
|
2018-09-12 21:05:14 +02:00
|
|
|
groups.notfamily = groups.GroupType('notfamily')
|
|
|
|
i = IntOption('test', '')
|
|
|
|
i2 = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
|
|
|
od1.impl_set_group_type(groups.family)
|
|
|
|
od3 = OptionDescription('od2', '', [i2])
|
|
|
|
od3.impl_set_group_type(groups.notfamily)
|
|
|
|
od2 = OptionDescription('od', '', [od1, od3])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od2) as cfg:
|
|
|
|
assert len(list(await cfg.option.list('option'))) == 0
|
|
|
|
assert len(list(await cfg.option.list('optiondescription'))) == 2
|
|
|
|
assert len(list(await cfg.option.list('optiondescription', group_type=groups.family))) == 1
|
|
|
|
assert len(list(await cfg.option.list('optiondescription', group_type=groups.notfamily))) == 1
|
|
|
|
try:
|
|
|
|
list(await cfg.option.list('unknown'))
|
|
|
|
except AssertionError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise Exception('must raise')
|
|
|
|
try:
|
|
|
|
list(await cfg.option.list('option', group_type='toto'))
|
|
|
|
except AssertionError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise Exception('must raise')
|
|
|
|
assert not await list_sessions()
|
2018-09-12 21:05:14 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_optiondescription_group_redefined():
|
2018-09-12 21:05:14 +02:00
|
|
|
try:
|
|
|
|
groups.notfamily = groups.GroupType('notfamily')
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
i = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
|
|
|
od1.impl_set_group_type(groups.family)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ValueError):
|
2019-12-24 15:24:20 +01:00
|
|
|
od1.impl_set_group_type(groups.notfamily)
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2018-09-12 21:05:14 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_optiondescription_group_leadership():
|
2018-09-12 21:05:14 +02:00
|
|
|
i = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ConfigError):
|
2019-12-24 15:24:20 +01:00
|
|
|
od1.impl_set_group_type(groups.leadership)
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2018-09-12 21:05:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_asign_optiondescription():
|
2018-04-06 23:51:25 +02:00
|
|
|
i = IntOption('test', '')
|
|
|
|
od1 = OptionDescription('od', '', [i])
|
|
|
|
od2 = OptionDescription('od', '', [od1])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od2) as cfg:
|
|
|
|
with pytest.raises(APIError):
|
|
|
|
await cfg.option('od').value.set('test')
|
|
|
|
with pytest.raises(APIError):
|
|
|
|
await cfg.option('od').value.reset()
|
|
|
|
assert not await list_sessions()
|
2018-09-11 20:12:06 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_intoption():
|
2018-09-11 20:12:06 +02:00
|
|
|
i1 = IntOption('test1', 'description', min_number=3)
|
|
|
|
i2 = IntOption('test2', 'description', max_number=3)
|
|
|
|
od = OptionDescription('od', '', [i1, i2])
|
2020-01-22 20:46:18 +01:00
|
|
|
async with await Config(od) as cfg:
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
await cfg.option('test1').value.set(2)
|
|
|
|
await cfg.option('test1').value.set(3)
|
|
|
|
await cfg.option('test1').value.set(4)
|
|
|
|
await cfg.option('test2').value.set(2)
|
|
|
|
await cfg.option('test2').value.set(3)
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
await cfg.option('test2').value.set(4)
|
|
|
|
assert not await list_sessions()
|
2019-12-24 15:24:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_get_display_type():
|
2019-02-24 20:23:16 +01:00
|
|
|
i1 = IntOption('test1', 'description', min_number=3)
|
2019-04-08 08:41:33 +02:00
|
|
|
assert i1.get_display_type() == _('integer')
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|
2019-03-02 19:43:51 +01:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_option_not_in_config():
|
2019-03-02 19:43:51 +01:00
|
|
|
i1 = IntOption('test1', 'description', min_number=3)
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(AttributeError):
|
2019-12-24 15:24:20 +01:00
|
|
|
i1.impl_getpath()
|
2020-01-22 20:46:18 +01:00
|
|
|
assert not await list_sessions()
|