2013-07-03 21:56:19 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-08-22 12:17:10 +02:00
|
|
|
|
2013-08-24 21:26:10 +02:00
|
|
|
"""theses tests are much more to test that config, option description, vs...
|
2013-08-22 12:17:10 +02:00
|
|
|
**it's there** and answers via attribute access"""
|
2018-03-19 08:33:53 +01:00
|
|
|
import weakref
|
|
|
|
|
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
|
2013-08-22 12:17:10 +02:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
2024-07-04 19:55:49 +02:00
|
|
|
from tiramisu import Config, Calculation, Params, ParamSelfInformation, calc_value
|
2014-10-25 22:58:46 +02:00
|
|
|
from tiramisu.i18n import _
|
2019-12-08 09:09:48 +01:00
|
|
|
from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \
|
2024-07-05 19:35:39 +02:00
|
|
|
BoolOption, StrOption, SymLinkOption, OptionDescription, undefined, \
|
|
|
|
DomainnameOption, EmailOption, URLOption, RegexpOption, IPOption, \
|
|
|
|
PortOption, NetworkOption, NetmaskOption, BroadcastOption, UsernameOption, \
|
|
|
|
GroupnameOption, DateOption, FilenameOption, PasswordOption, MACOption, \
|
|
|
|
PermissionsOption
|
2023-04-27 11:44:52 +02:00
|
|
|
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError
|
2018-10-31 08:00:19 +01: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-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)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
2013-04-03 12:20:26 +02:00
|
|
|
stroption = StrOption('str', 'Test string option', default="abc", properties=('mandatory', ))
|
2014-03-31 22:34:57 +02:00
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True, properties=('hidden',))
|
2024-06-20 12:56:27 +02:00
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False, informations={'info': 'default value'})
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False)
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
2013-04-20 21:58:52 +02:00
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
2012-07-13 09:42:14 +02:00
|
|
|
return descr
|
|
|
|
|
2013-04-20 21:58:52 +02:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_base_config(config_type):
|
2018-03-19 08:33:53 +01:00
|
|
|
"""making a :class:`tiramisu.config.Config()` object
|
|
|
|
and a :class:`tiramisu.option.OptionDescription()` object
|
|
|
|
"""
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.config.type() == 'config'
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2013-04-20 21:58:52 +02:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_base_config_name():
|
2015-11-24 10:58:19 +01:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(od1)
|
|
|
|
#raises(ValueError, "Config(descr, session_id='unvalid name')")
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_path():
|
2019-02-24 20:23:16 +01:00
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('tiramisu', '', [gcdummy])
|
|
|
|
cfg = Config(od1)
|
|
|
|
base = OptionDescription('config', '', [od1])
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
with Config(base):
|
|
|
|
pass
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_config_force_permissive():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.permissive.add('hidden')
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('boolop').value.get()
|
|
|
|
assert cfg.forcepermissive.option('boolop').value.get() is True
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_config_in_a_tree():
|
2019-06-21 23:04:04 +02:00
|
|
|
# FIXME
|
|
|
|
config_type = 'tiramisu'
|
2013-08-22 12:17:10 +02:00
|
|
|
"how options are organized into a tree, see :ref:`tree`"
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
#
|
|
|
|
cfg.option('bool').value.set(False)
|
|
|
|
#
|
|
|
|
assert cfg.option('gc.name').value.get() == 'ref'
|
|
|
|
cfg.option('gc.name').value.set('framework')
|
|
|
|
assert cfg.option('gc.name').value.get() == 'framework'
|
|
|
|
#
|
|
|
|
assert cfg.option('objspace').value.get() == 'std'
|
|
|
|
cfg.option('objspace').value.set('thunk')
|
|
|
|
assert cfg.option('objspace').value.get() == 'thunk'
|
|
|
|
#
|
|
|
|
assert cfg.option('gc.float').value.get() == 2.3
|
|
|
|
cfg.option('gc.float').value.set(3.4)
|
|
|
|
assert cfg.option('gc.float').value.get() == 3.4
|
|
|
|
#
|
|
|
|
assert cfg.option('int').value.get() == 0
|
|
|
|
cfg.option('int').value.set(123)
|
|
|
|
assert cfg.option('int').value.get() == 123
|
|
|
|
#
|
|
|
|
assert cfg.option('wantref').value.get() is False
|
|
|
|
cfg.option('wantref').value.set(True)
|
|
|
|
assert cfg.option('wantref').value.get() is True
|
|
|
|
#
|
|
|
|
assert cfg.option('str').value.get() == 'abc'
|
|
|
|
cfg.option('str').value.set('def')
|
|
|
|
assert cfg.option('str').value.get() == 'def'
|
|
|
|
#
|
|
|
|
with pytest.raises(AttributeError):
|
|
|
|
cfg.option('gc.foo').value.get()
|
|
|
|
##
|
|
|
|
cfg = Config(od1)
|
|
|
|
assert cfg.option('bool').value.get() is True
|
|
|
|
assert cfg.option('gc.name').value.get() == 'ref'
|
|
|
|
assert cfg.option('wantframework').value.get() is False
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_not_valid_properties():
|
2019-12-24 15:24:20 +01:00
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
stroption = StrOption('str', 'Test string option', default='abc', properties='mandatory')
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2024-07-05 19:35:39 +02:00
|
|
|
def test_information_load():
|
|
|
|
ChoiceOption('a', '', ('a', 'b'), informations={'info': 'value'})
|
|
|
|
BoolOption('a', '', informations={'info': 'value'})
|
|
|
|
IntOption('a', '', informations={'info': 'value'})
|
|
|
|
FloatOption('a', '', informations={'info': 'value'})
|
|
|
|
StrOption('a', '', informations={'info': 'value'})
|
|
|
|
RegexpOption('a', '', informations={'info': 'value'})
|
|
|
|
IPOption('a', '', informations={'info': 'value'})
|
|
|
|
PortOption('a', '', informations={'info': 'value'})
|
|
|
|
NetworkOption('a', '', informations={'info': 'value'})
|
|
|
|
NetmaskOption('a', '', informations={'info': 'value'})
|
|
|
|
BroadcastOption('a', '', informations={'info': 'value'})
|
|
|
|
DomainnameOption('a', '', informations={'info': 'value'})
|
|
|
|
EmailOption('a', '', informations={'info': 'value'})
|
|
|
|
URLOption('a', '', informations={'info': 'value'})
|
|
|
|
UsernameOption('a', '', informations={'info': 'value'})
|
|
|
|
GroupnameOption('a', '', informations={'info': 'value'})
|
|
|
|
DateOption('a', '', informations={'info': 'value'})
|
|
|
|
FilenameOption('a', '', informations={'info': 'value'})
|
|
|
|
PasswordOption('a', '', informations={'info': 'value'})
|
|
|
|
MACOption('a', '', informations={'info': 'value'})
|
|
|
|
PermissionsOption('a', '', informations={'info': 'value'})
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_information_config():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
#
|
|
|
|
assert list(cfg.information.list()) == ['doc']
|
|
|
|
cfg.information.set('info', string)
|
|
|
|
assert cfg.information.get('info') == string
|
|
|
|
assert set(cfg.information.list()) == {'doc', 'info'}
|
|
|
|
#
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.information.get('noinfo')
|
|
|
|
assert cfg.information.get('noinfo', 'default') == 'default'
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.information.remove('info')
|
2023-04-15 16:12:35 +02:00
|
|
|
with pytest.raises(ValueError):
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.information.remove('info')
|
2023-04-15 16:12:35 +02:00
|
|
|
with pytest.raises(ValueError):
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.information.remove('noinfo')
|
2023-04-15 16:12:35 +02:00
|
|
|
assert list(cfg.information.list()) == ['doc']
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2023-05-11 15:44:48 +02:00
|
|
|
def test_information_config_list():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
cfg.information.set('info', string)
|
|
|
|
#
|
|
|
|
assert cfg.information.exportation() == {None: {'info': string}}
|
|
|
|
assert set(cfg.information.list()) == {'info', 'doc'}
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_information_exportation():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
cfg.information.set('info', string)
|
|
|
|
#
|
|
|
|
assert cfg.information.exportation() == {None: {'info': string}}
|
|
|
|
|
|
|
|
|
|
|
|
def test_information_importation():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
assert cfg.information.exportation() == {}
|
|
|
|
#
|
|
|
|
cfg.information.importation({None: {'info': string}})
|
|
|
|
assert cfg.information.exportation() == {None: {'info': string}}
|
|
|
|
|
|
|
|
|
|
|
|
def test_information_option():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
#
|
|
|
|
assert list(cfg.option('gc.name').information.list()) == ['doc']
|
|
|
|
cfg.option('gc.name').information.set('info', string)
|
|
|
|
assert cfg.option('gc.name').information.get('info') == string
|
|
|
|
assert set(cfg.option('gc.name').information.list()) == {'doc', 'info'}
|
|
|
|
#
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('gc.name').information.get('noinfo')
|
|
|
|
assert cfg.option('gc.name').information.get('noinfo', 'default') == 'default'
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.option('gc.name').information.remove('info')
|
2023-04-15 16:12:35 +02:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('gc.name').information.get('info')
|
|
|
|
with pytest.raises(ValueError):
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.option('gc.name').information.remove('noinfo')
|
2023-04-15 16:12:35 +02:00
|
|
|
assert list(cfg.option('gc.name').information.list()) == ['doc']
|
|
|
|
#
|
|
|
|
assert cfg.option('wantref').information.get('info') == 'default value'
|
|
|
|
cfg.option('wantref').information.set('info', 'default value')
|
|
|
|
assert cfg.option('wantref').information.get('info') == 'default value'
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.option('wantref').information.remove('info')
|
2023-04-15 16:12:35 +02:00
|
|
|
assert cfg.option('wantref').information.get('info') == 'default value'
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2023-05-11 15:44:48 +02:00
|
|
|
def test_information_option_2():
|
2024-06-20 12:56:27 +02:00
|
|
|
i1 = IntOption('test1', '', informations={'info': 'value'})
|
2023-05-11 15:44:48 +02:00
|
|
|
od1 = OptionDescription('test', '', [i1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
# it's tuples
|
|
|
|
assert set(cfg.option('test1').information.list()) == {'info', 'doc'}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2024-07-04 19:55:49 +02:00
|
|
|
def test_information_option_symlink():
|
|
|
|
i1 = IntOption('test1', '', Calculation(calc_value, Params(ParamSelfInformation('info'))), informations={'info': 'value'})
|
|
|
|
i2 = SymLinkOption('test2', i1)
|
|
|
|
od1 = OptionDescription('test', '', [i2, i1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
# it's tuples
|
|
|
|
assert set(cfg.option('test1').information.list()) == {'info', 'doc'}
|
|
|
|
assert set(cfg.option('test2').information.list()) == {'info', 'doc'}
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_information_optiondescription():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
|
|
|
string = 'some informations'
|
|
|
|
#
|
|
|
|
assert list(cfg.option('gc').information.list()) == ['doc']
|
|
|
|
cfg.option('gc').information.set('info', string)
|
|
|
|
assert cfg.option('gc').information.get('info') == string
|
|
|
|
assert set(cfg.option('gc').information.list()) == {'doc', 'info'}
|
|
|
|
#
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('gc').information.get('noinfo')
|
|
|
|
assert cfg.option('gc').information.get('noinfo', 'default') == 'default'
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.option('gc').information.remove('info')
|
2023-04-15 16:12:35 +02:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('gc').information.get('info')
|
|
|
|
with pytest.raises(ValueError):
|
2024-06-20 12:56:27 +02:00
|
|
|
cfg.option('gc').information.remove('noinfo')
|
2023-04-15 16:12:35 +02:00
|
|
|
assert list(cfg.option('gc').information.list()) == ['doc']
|
|
|
|
# assert not list_sessions()
|
2023-01-24 07:46:44 +01:00
|
|
|
|
|
|
|
|
2020-01-22 20:46:18 +01:00
|
|
|
def compare(val1, val2):
|
2023-04-15 16:12:35 +02:00
|
|
|
assert val1 == val2
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_modified_values():
|
2013-08-24 22:54:02 +02:00
|
|
|
g1 = IntOption('g1', '', 1)
|
|
|
|
g2 = StrOption('g2', '', 'héhé')
|
2019-12-08 09:09:48 +01:00
|
|
|
g3 = StrOption('g3', '', 'héhé')
|
2013-08-24 22:54:02 +02:00
|
|
|
g4 = BoolOption('g4', '', True)
|
|
|
|
g5 = StrOption('g5', '')
|
2017-03-17 21:27:42 +01:00
|
|
|
g6 = StrOption('g6', '', multi=True)
|
|
|
|
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [d1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
compare(cfg.value.exportation(), {})
|
2023-05-16 22:50:38 +02:00
|
|
|
assert not cfg.option('od.g5').ismulti()
|
|
|
|
assert not cfg.option('od.g5').issubmulti()
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg.option('od.g5').value.set('yes')
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}})
|
|
|
|
cfg.option('od.g4').value.set(False)
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g4': {None: [False, 'user']}})
|
2023-11-18 21:12:13 +01:00
|
|
|
cfg.option('od.g4').value.set(True)
|
2023-04-15 16:12:35 +02:00
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g4': {None: [True, 'user']}})
|
|
|
|
cfg.option('od.g4').value.reset()
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}})
|
2023-05-16 22:50:38 +02:00
|
|
|
assert cfg.option('od.g6').ismulti()
|
2023-11-18 21:12:13 +01:00
|
|
|
cfg.option('od.g6').value.set([None])
|
2023-04-15 16:12:35 +02:00
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g6': {None: [[None], 'user']}})
|
|
|
|
cfg.option('od.g6').value.set([])
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g6': {None: [[], 'user']}})
|
|
|
|
cfg.option('od.g6').value.set(['3'])
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g6': {None: [['3'], 'user']}})
|
|
|
|
cfg.option('od.g6').value.set([])
|
|
|
|
compare(cfg.value.exportation(), {'od.g5': {None: ['yes', 'user']}, 'od.g6': {None: [[], 'user']}})
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_modified_values_not_modif(config_type):
|
2018-07-22 11:51:48 +02:00
|
|
|
g1 = StrOption('g1', '', multi=True)
|
|
|
|
d1 = OptionDescription('od', '', [g1])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('root', '', [d1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('od.g1').value.get() == []
|
|
|
|
value = cfg.option('od.g1').value.get()
|
|
|
|
value.append('val')
|
|
|
|
assert cfg.option('od.g1').value.get() == []
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_duplicated_option():
|
2013-08-28 11:33:43 +02:00
|
|
|
g1 = IntOption('g1', '', 1)
|
2015-07-24 17:54:10 +02:00
|
|
|
g1
|
2013-08-28 11:33:43 +02:00
|
|
|
#in same OptionDescription
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ConflictError):
|
2019-12-24 15:24:20 +01:00
|
|
|
d1 = OptionDescription('od', '', [g1, g1])
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2013-11-23 23:34:17 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_duplicated_option_diff_od():
|
2013-11-23 23:34:17 +01:00
|
|
|
g1 = IntOption('g1', '', 1)
|
2013-08-28 11:33:43 +02:00
|
|
|
d1 = OptionDescription('od1', '', [g1])
|
|
|
|
#in different OptionDescription
|
2014-02-16 23:37:27 +01:00
|
|
|
d2 = OptionDescription('od2', '', [g1, d1])
|
2015-07-24 17:54:10 +02:00
|
|
|
d2
|
2020-01-22 20:46:18 +01:00
|
|
|
with pytest.raises(ConflictError):
|
2023-04-15 16:12:35 +02:00
|
|
|
Config(d2)
|
2013-09-27 09:52:18 +02:00
|
|
|
|
2013-12-09 15:43:45 +01:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_cannot_assign_value_to_option_description():
|
|
|
|
od1 = make_description()
|
|
|
|
cfg = Config(od1)
|
2023-04-27 11:44:52 +02:00
|
|
|
with pytest.raises(ConfigError):
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg.option('gc').value.set(3)
|
|
|
|
# assert not list_sessions()
|
2013-12-09 17:59:39 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_config_multi(config_type):
|
2013-12-09 17:59:39 +01:00
|
|
|
i1 = IntOption('test1', '', multi=True)
|
|
|
|
i2 = IntOption('test2', '', multi=True, default_multi=1)
|
|
|
|
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('test', '', [i1, i2, i3])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('test1').value.get() == []
|
|
|
|
assert cfg.option('test2').value.get() == []
|
2023-11-18 21:12:13 +01:00
|
|
|
cfg.option('test2').value.set([1])
|
2023-04-15 16:12:35 +02:00
|
|
|
assert cfg.option('test2').value.get() == [1]
|
|
|
|
assert cfg.option('test3').value.get() == [2]
|
2023-11-18 21:12:13 +01:00
|
|
|
cfg.option('test3').value.set([2, 1])
|
2023-04-15 16:12:35 +02:00
|
|
|
assert cfg.option('test3').value.get() == [2, 1]
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_prefix_error():
|
2019-02-25 20:30:20 +01:00
|
|
|
i1 = IntOption('test1', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('test', '', [i1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg.option('test1').value.set(1)
|
|
|
|
try:
|
|
|
|
cfg.option('test1').value.set('yes')
|
|
|
|
except Exception as err:
|
|
|
|
assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('yes', _('integer'), 'test1')
|
|
|
|
try:
|
|
|
|
cfg.option('test1').value.set('yes')
|
|
|
|
except Exception as err:
|
|
|
|
err.prefix = ''
|
|
|
|
assert str(err) == _('invalid value')
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_validation():
|
2019-06-21 23:04:04 +02:00
|
|
|
# FIXME
|
|
|
|
config_type = 'tiramisu'
|
2013-12-09 18:56:29 +01:00
|
|
|
i1 = IntOption('test1', '')
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('test', '', [i1])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg.property.read_write()
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
cfg.option('test1').value.set(1)
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('test1').value.set('yes')
|
|
|
|
assert cfg.option('test1').value.get() == 1
|
|
|
|
cfg.property.remove('validator')
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
cfg.option('test1').value.set('yes')
|
|
|
|
assert cfg.option('test1').value.get() == 'yes'
|
|
|
|
cfg.property.add('validator')
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
cfg.option('test1').value.get()
|
|
|
|
cfg.option('test1').value.reset()
|
|
|
|
assert cfg.option('test1').value.get() is None
|
|
|
|
# assert not list_sessions()
|
|
|
|
|
2015-11-24 10:58:19 +01:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
#def test_subconfig():
|
|
|
|
# i = IntOption('i', '')
|
|
|
|
# o = OptionDescription('val', '', [i])
|
|
|
|
# od1 = OptionDescription('val', '', [o])
|
|
|
|
# cfg = Config(od1)
|
|
|
|
# cfg
|
|
|
|
# with pytest.raises(TypeError):
|
|
|
|
# SubConfig(i, weakref.ref(cfg))
|
|
|
|
# assert not list_sessions()
|
2015-11-24 10:58:19 +01:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
|
|
|
|
def test_config_subconfig():
|
2016-09-22 08:27:18 +02:00
|
|
|
i1 = IntOption('i1', '')
|
|
|
|
i2 = IntOption('i2', '', default=1)
|
|
|
|
i3 = IntOption('i3', '')
|
|
|
|
i4 = IntOption('i4', '', default=2)
|
|
|
|
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
|
|
|
od2 = OptionDescription('od2', '', [od1])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od2)
|
|
|
|
with pytest.raises(ConfigError):
|
|
|
|
cfg2 = Config(od1)
|
|
|
|
# assert not list_sessions()
|
2019-02-24 20:23:16 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_config_od_name(config_type):
|
2019-02-24 20:23:16 +01:00
|
|
|
i = IntOption('i', '')
|
|
|
|
s = SymLinkOption('s', i)
|
|
|
|
o = OptionDescription('val', '', [i, s])
|
|
|
|
o2 = OptionDescription('val', '', [o])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o2)
|
|
|
|
cfg = get_config(cfg, config_type)
|
2023-05-16 22:50:38 +02:00
|
|
|
assert cfg.option('val.i').name() == 'i'
|
|
|
|
assert cfg.option('val.s').name() == 's'
|
|
|
|
assert cfg.option('val.s').type() == _('integer')
|
|
|
|
assert cfg.option('val').type() == 'optiondescription'
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2019-02-24 20:23:16 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_config_od_type(config_type):
|
2019-02-24 20:23:16 +01:00
|
|
|
i = IntOption('i', '')
|
|
|
|
o = OptionDescription('val', '', [i])
|
|
|
|
o2 = OptionDescription('val', '', [o])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o2)
|
|
|
|
cfg = get_config(cfg, config_type)
|
2023-05-16 22:50:38 +02:00
|
|
|
assert cfg.option('val').type() == 'optiondescription'
|
|
|
|
assert cfg.option('val.i').type() == _('integer')
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2019-02-24 20:23:16 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_config_default(config_type):
|
2019-02-24 20:23:16 +01:00
|
|
|
i = IntOption('i', '', 8)
|
|
|
|
o = OptionDescription('val', '', [i])
|
|
|
|
o2 = OptionDescription('val', '', [o])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o2)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('val.i').value.default() == 8
|
|
|
|
cfg.option('val.i').value.set(9)
|
|
|
|
assert cfg.option('val.i').value.get() == 9
|
|
|
|
assert cfg.option('val.i').value.default() == 8
|
|
|
|
# assert not list_sessions()
|