2013-08-27 21:36:52 +02:00
|
|
|
# coding: utf-8
|
2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
do_autopath()
|
2018-10-31 08:00:19 +01:00
|
|
|
import weakref
|
2019-12-24 15:24:20 +01:00
|
|
|
import pytest
|
2013-08-27 21:36:52 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
|
|
|
|
SymLinkOption, OptionDescription, DynOptionDescription, submulti, \
|
2019-09-28 16:32:48 +02:00
|
|
|
Config, GroupConfig, MetaConfig, Params, ParamOption, Calculation
|
2014-11-10 09:13:44 +01:00
|
|
|
|
2015-07-24 17:54:10 +02:00
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
def funcname(*args, **kwargs):
|
2017-09-21 21:23:03 +02:00
|
|
|
return value
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_value():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(cfg._config_bag.context.get_values())
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2014-04-14 23:00:37 +02:00
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_setting():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(cfg._config_bag.context.get_settings())
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2014-04-14 23:00:37 +02:00
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_config():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(cfg)
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2014-04-14 23:00:37 +02:00
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_option():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
w = weakref.ref(b)
|
|
|
|
del(b)
|
2014-11-10 09:13:44 +01:00
|
|
|
try:
|
|
|
|
assert w() is not None
|
|
|
|
except AssertionError:
|
|
|
|
return
|
2014-04-14 23:00:37 +02:00
|
|
|
del(o)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_optiondescription():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
|
|
|
w = weakref.ref(o)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_option_cache():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
o._build_cache()
|
2014-04-14 23:00:37 +02:00
|
|
|
w = weakref.ref(b)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is None
|
2013-08-27 21:36:52 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_optiondescription_cache():
|
2013-08-27 21:36:52 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
o._build_cache()
|
2013-08-27 21:36:52 +02:00
|
|
|
w = weakref.ref(o)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
2014-04-14 23:00:37 +02:00
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_option_config():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(b)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2014-04-14 23:00:37 +02:00
|
|
|
assert w() is None
|
2013-08-27 21:36:52 +02:00
|
|
|
|
2014-01-25 10:15:25 +01:00
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_optiondescription_config():
|
2013-08-27 21:36:52 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2023-04-15 16:12:35 +02:00
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(o)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2014-04-15 21:48:31 +02:00
|
|
|
assert w() is None
|
2013-09-30 16:22:08 +02:00
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_validator():
|
2017-09-21 21:23:03 +02:00
|
|
|
a = StrOption('a', '', default='yes')
|
2019-10-27 11:09:15 +01:00
|
|
|
b = StrOption('b', '', validators=[Calculation(funcname, Params(ParamOption(a)))], default='val')
|
2023-04-15 16:12:35 +02:00
|
|
|
o = OptionDescription('root', '', [a, b])
|
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(o)
|
|
|
|
z = weakref.ref(cfg)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(a)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2017-09-21 21:23:03 +02:00
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_callback():
|
2017-09-21 21:23:03 +02:00
|
|
|
a = StrOption('a', "", 'val')
|
2019-09-28 16:32:48 +02:00
|
|
|
b = StrOption('b', "", Calculation(funcname, Params((ParamOption(a),))))
|
2023-04-15 16:12:35 +02:00
|
|
|
o = OptionDescription('root', '', [a, b])
|
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(o)
|
|
|
|
z = weakref.ref(cfg)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(a)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2017-09-21 21:23:03 +02:00
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_symlink():
|
2017-09-21 21:23:03 +02:00
|
|
|
a = BoolOption("a", "", default=False)
|
|
|
|
b = SymLinkOption("b", a)
|
2023-04-15 16:12:35 +02:00
|
|
|
o = OptionDescription('root', '', [a, b])
|
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(o)
|
|
|
|
z = weakref.ref(cfg)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(a)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2017-09-21 21:23:03 +02:00
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2023-04-15 16:12:35 +02:00
|
|
|
def test_deref_dyn():
|
2017-09-21 21:23:03 +02:00
|
|
|
a = StrOption('a', '', ['val1', 'val2'], multi=True)
|
|
|
|
b = StrOption('b', '')
|
2019-10-15 17:45:21 +02:00
|
|
|
dod = DynOptionDescription('dod', '', [b], suffixes=Calculation(funcname, Params((ParamOption(a),))))
|
2023-04-15 16:12:35 +02:00
|
|
|
o = OptionDescription('od', '', [dod, a])
|
|
|
|
cfg = Config(o)
|
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(o)
|
|
|
|
z = weakref.ref(cfg)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(a)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(o)
|
|
|
|
del(dod)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
2020-01-22 20:46:18 +01:00
|
|
|
del cfg
|
2017-09-21 21:23:03 +02:00
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|