2012-07-13 09:42:14 +02:00
|
|
|
"test all types of option default values for options, add new option in a descr"
|
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
|
2014-10-26 08:51:45 +01:00
|
|
|
from tiramisu.setting import owners
|
2019-10-27 11:09:15 +01:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConfigError, LeadershipError
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
|
2023-04-15 16:12:35 +02:00
|
|
|
BoolOption, OptionDescription, Leadership, Config, undefined
|
|
|
|
from .config import config_type, get_config
|
2018-10-31 08:00:19 +01:00
|
|
|
|
|
|
|
|
2019-06-21 23:04:04 +02:00
|
|
|
owners.addowner("frozenmultifollower")
|
|
|
|
|
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
def make_description():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
|
|
|
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)
|
|
|
|
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,
|
2013-04-20 21:58:52 +02:00
|
|
|
requires=['boolop'])
|
2012-07-13 09:42:14 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
|
|
|
requires=['boolop'])
|
2012-11-12 12:06:58 +01:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('tiramisu', '', [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
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
# default values
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_default_is_none(config_type):
|
2012-07-13 09:42:14 +02:00
|
|
|
"""
|
|
|
|
Most constructors take a ``default`` argument that specifies the default
|
|
|
|
value of the option. If this argument is not supplied the default value is
|
|
|
|
assumed to be ``None``.
|
|
|
|
"""
|
|
|
|
dummy1 = BoolOption('dummy1', 'doc dummy')
|
|
|
|
dummy2 = BoolOption('dummy2', 'doc dummy')
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('group', '', [dummy1, dummy2])
|
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
# so when the default value is not set, there is actually a default value
|
|
|
|
assert cfg.option('dummy1').value.get() is None
|
|
|
|
assert cfg.option('dummy2').value.get() is None
|
|
|
|
# assert not list_sessions()
|
2013-04-20 21:58:52 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_set_defaut_value_from_option_object():
|
2012-07-13 09:42:14 +02:00
|
|
|
"""Options have an available default setting and can give it back"""
|
|
|
|
b = BoolOption("boolean", "", default=False)
|
2013-05-08 18:14:42 +02:00
|
|
|
assert b.impl_getdefault() is False
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2013-04-20 21:58:52 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_force_default_on_freeze():
|
2012-08-13 16:06:02 +02:00
|
|
|
"a frozen option wich is forced returns his default"
|
2013-04-03 12:20:26 +02:00
|
|
|
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
|
2012-08-13 16:06:02 +02:00
|
|
|
dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('group', '', [dummy1, dummy2])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = cfg_ori
|
|
|
|
# FIXME cfg = get_config(cfg_ori, config_type)
|
|
|
|
owner = cfg.owner.get()
|
|
|
|
cfg.option('dummy1').value.set(True)
|
|
|
|
cfg.option('dummy2').value.set(False)
|
|
|
|
assert cfg.option('dummy1').owner.get() == owner
|
|
|
|
assert cfg.option('dummy2').owner.get() == owner
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
cfg_ori.option('dummy1').property.add('frozen')
|
|
|
|
cfg_ori.option('dummy2').property.add('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert cfg.option('dummy1').value.get() is False
|
|
|
|
assert cfg.option('dummy2').value.get() is False
|
|
|
|
assert cfg.option('dummy1').owner.isdefault()
|
|
|
|
assert cfg.option('dummy2').owner.get() == owner
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg_ori.option('dummy2').owner.set('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('dummy1').value.reset()
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
cfg_ori.option('dummy1').property.remove('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
cfg.option('dummy1').value.reset()
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
cfg.option('dummy1').property.add('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('dummy2').owner.set('frozen')
|
|
|
|
# assert not list_sessions()
|
2013-04-20 21:58:52 +02:00
|
|
|
|
2012-07-13 09:42:14 +02:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_force_default_on_freeze_multi():
|
2013-08-28 22:50:35 +02:00
|
|
|
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
|
|
|
|
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription('group', '', [dummy1, dummy2])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = cfg_ori
|
|
|
|
# FIXME cfg = get_config(cfg_ori, config_type)
|
2023-11-18 21:12:13 +01:00
|
|
|
default = cfg.option('dummy1').value.default()[0]
|
|
|
|
cfg.option('dummy1').value.set([default, True])
|
|
|
|
default = cfg.option('dummy2').value.default()[0]
|
|
|
|
cfg.option('dummy2').value.set([default, False])
|
2023-04-15 16:12:35 +02:00
|
|
|
owner = cfg.owner.get()
|
|
|
|
assert cfg.option('dummy1').owner.get() == owner
|
|
|
|
assert cfg.option('dummy2').owner.get() == owner
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
cfg_ori.option('dummy1').property.add('frozen')
|
|
|
|
cfg_ori.option('dummy2').property.add('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert cfg.option('dummy1').value.get() == [False]
|
|
|
|
assert cfg.option('dummy2').value.get() == [True, False]
|
|
|
|
assert cfg.option('dummy1').owner.isdefault()
|
|
|
|
assert cfg.option('dummy2').owner.get() == owner
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg_ori.option('dummy2').owner.set('owner')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg.option('dummy2').value.reset()
|
|
|
|
# if config_type == 'tiramisu-api':
|
|
|
|
# cfg.send()
|
|
|
|
cfg_ori.option('dummy1').property.remove('frozen')
|
|
|
|
# cfg = get_config(cfg_ori, config_type)
|
|
|
|
cfg.option('dummy1').value.reset()
|
|
|
|
# assert not list_sessions()
|
2018-03-19 08:33:53 +01:00
|
|
|
|
|
|
|
|
2024-02-08 08:32:24 +01:00
|
|
|
#def test_force_default_on_freeze_leader():
|
|
|
|
# dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
|
|
|
|
# dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
|
|
|
# descr = Leadership("dummy1", "", [dummy1, dummy2])
|
|
|
|
# od1 = OptionDescription("root", "", [descr])
|
|
|
|
# with pytest.raises(ConfigError):
|
|
|
|
# Config(od1)
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2018-03-19 08:33:53 +01:00
|
|
|
|
|
|
|
|
2024-02-08 08:32:24 +01:00
|
|
|
#def test_force_metaconfig_on_freeze_leader():
|
|
|
|
# dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_metaconfig_on_freeze',))
|
|
|
|
# dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
|
|
|
# descr = Leadership("dummy1", "", [dummy1, dummy2])
|
|
|
|
# od1 = OptionDescription("root", "", [descr])
|
|
|
|
# with pytest.raises(ConfigError):
|
|
|
|
# Config(od1)
|
2023-04-15 16:12:35 +02:00
|
|
|
# assert not list_sessions()
|
2019-02-23 22:10:43 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_force_default_on_freeze_leader_frozen():
|
2018-04-03 15:51:45 +02:00
|
|
|
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen'))
|
|
|
|
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
2019-02-23 19:06:23 +01:00
|
|
|
descr = Leadership("dummy1", "", [dummy1, dummy2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription("root", "", [descr])
|
|
|
|
cfg = Config(od1)
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('dummy1.dummy1').property.remove('frozen')
|
|
|
|
# assert not list_sessions()
|
2018-04-03 15:51:45 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_force_metaconfig_on_freeze_leader_frozen():
|
2019-02-23 22:10:43 +01:00
|
|
|
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_metaconfig_on_freeze', 'frozen'))
|
|
|
|
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
|
|
|
|
descr = Leadership("dummy1", "", [dummy1, dummy2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription("root", "", [descr])
|
|
|
|
cfg = Config(od1)
|
|
|
|
with pytest.raises(LeadershipError):
|
|
|
|
cfg.option('dummy1.dummy1').property.remove('frozen')
|
|
|
|
# assert not list_sessions()
|
2019-02-23 22:10:43 +01:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_force_default_on_freeze_follower(config_type):
|
2019-12-08 09:09:48 +01:00
|
|
|
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('notunique',))
|
2018-03-19 08:33:53 +01:00
|
|
|
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
|
2019-02-23 19:06:23 +01:00
|
|
|
descr = Leadership("dummy1", "", [dummy1, dummy2])
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription("root", "", [descr])
|
|
|
|
cfg_ori = Config(od1)
|
|
|
|
cfg_ori.property.read_write()
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
cfg.option('dummy1.dummy1').value.set([True])
|
|
|
|
cfg.option('dummy1.dummy2', 0).value.set(False)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == False
|
|
|
|
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).owner.get() == 'user'
|
|
|
|
#
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
cfg_ori.option('dummy1.dummy2').property.add('frozen')
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == None
|
|
|
|
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).owner.isdefault()
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
with pytest.raises(PropertiesOptionError):
|
|
|
|
cfg_ori.option('dummy1.dummy2', 0).owner.set('frozenmultifollower')
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
#
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
cfg_ori.option('dummy1.dummy2').property.remove('frozen')
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
cfg.option('dummy1.dummy1').value.set([True, True])
|
|
|
|
cfg.option('dummy1.dummy2', 1).value.set(False)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == False
|
|
|
|
assert cfg.option('dummy1.dummy2', 1).value.get() == False
|
|
|
|
#
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
cfg_ori.option('dummy1.dummy2').property.add('frozen')
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == None
|
|
|
|
assert cfg.option('dummy1.dummy2', 1).value.get() == None
|
|
|
|
#
|
|
|
|
cfg.option('dummy1.dummy1').value.pop(1)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == None
|
|
|
|
#
|
|
|
|
if config_type == 'tiramisu-api':
|
|
|
|
cfg.send()
|
|
|
|
cfg_ori.option('dummy1.dummy2').property.remove('frozen')
|
|
|
|
cfg = get_config(cfg_ori, config_type)
|
|
|
|
assert cfg.option('dummy1.dummy1').value.get() == [True]
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == False
|
|
|
|
#
|
|
|
|
cfg.option('dummy1.dummy1').value.set([True, True])
|
|
|
|
assert cfg.option('dummy1.dummy2', 0).value.get() == False
|
|
|
|
assert cfg.option('dummy1.dummy2', 1).value.get() == None
|
|
|
|
# assert not list_sessions()
|
2013-08-28 22:50:35 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_overrides_changes_option_value(config_type):
|
2012-07-13 09:42:14 +02:00
|
|
|
"with config.override(), the default is changed and the value is changed"
|
2023-04-15 16:12:35 +02:00
|
|
|
od1 = OptionDescription("test", "", [
|
2012-07-13 09:42:14 +02:00
|
|
|
BoolOption("b", "", default=False)])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
cfg.option('b').value.set(True)
|
|
|
|
# assert not list_sessions()
|
2013-04-20 21:58:52 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_choice_with_no_default(config_type):
|
|
|
|
od1 = OptionDescription("test", "", [
|
2013-04-03 12:20:26 +02:00
|
|
|
ChoiceOption("backend", "", ("c", "cli"))])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('backend').value.get() is None
|
|
|
|
cfg.option('backend').value.set('c')
|
|
|
|
# assert not list_sessions()
|
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_choice_with_default(config_type):
|
|
|
|
od1 = OptionDescription("test", "", [
|
2013-04-03 12:20:26 +02:00
|
|
|
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(od1)
|
|
|
|
cfg = get_config(cfg, config_type)
|
|
|
|
assert cfg.option('backend').value.get() == 'cli'
|
|
|
|
# assert not list_sessions()
|