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
|
2018-10-31 08:00:19 +01:00
|
|
|
from tiramisu.storage import list_sessions
|
|
|
|
|
|
|
|
|
|
|
|
def teardown_function(function):
|
|
|
|
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
2013-08-27 21:36:52 +02:00
|
|
|
|
|
|
|
|
2014-11-10 09:13:44 +01:00
|
|
|
IS_DEREFABLE = True
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_storage():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2018-09-08 20:17:20 +02:00
|
|
|
w = weakref.ref(c._config_bag.context.cfgimpl_get_values()._p_)
|
2014-04-14 23:00:37 +02:00
|
|
|
del(c)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_value():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2018-09-08 20:17:20 +02:00
|
|
|
w = weakref.ref(c._config_bag.context.cfgimpl_get_values())
|
2014-04-14 23:00:37 +02:00
|
|
|
del(c)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_setting():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2018-09-08 20:17:20 +02:00
|
|
|
w = weakref.ref(c._config_bag.context.cfgimpl_get_settings())
|
2014-04-14 23:00:37 +02:00
|
|
|
del(c)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_config():
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2014-04-14 23:00:37 +02:00
|
|
|
w = weakref.ref(c)
|
|
|
|
del(c)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_option():
|
2014-11-10 09:13:44 +01:00
|
|
|
global IS_DEREFABLE
|
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:
|
|
|
|
IS_DEREFABLE = False
|
|
|
|
return
|
2014-04-14 23:00:37 +02:00
|
|
|
del(o)
|
|
|
|
assert w() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_optiondescription():
|
2014-11-10 09:13:44 +01:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
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
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_option_cache():
|
2014-11-10 09:13:44 +01:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
await 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
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_optiondescription_cache():
|
2016-10-01 20:15:08 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
2013-08-27 21:36:52 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
await 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
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_option_config():
|
2014-11-10 09:13:44 +01:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
2014-04-14 23:00:37 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2014-04-14 23:00:37 +02:00
|
|
|
w = weakref.ref(b)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
|
|
|
del(c)
|
|
|
|
assert w() is None
|
2013-08-27 21:36:52 +02:00
|
|
|
|
2014-01-25 10:15:25 +01:00
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_optiondescription_config():
|
2016-10-01 20:15:08 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
2013-08-27 21:36:52 +02:00
|
|
|
b = BoolOption('b', '')
|
|
|
|
o = OptionDescription('od', '', [b])
|
2019-12-24 15:24:20 +01:00
|
|
|
c = await Config(o)
|
2013-08-27 21:36:52 +02:00
|
|
|
w = weakref.ref(o)
|
|
|
|
del(b)
|
|
|
|
assert w() is not None
|
|
|
|
del(o)
|
|
|
|
assert w() is not None
|
|
|
|
del(c)
|
2014-04-15 21:48:31 +02:00
|
|
|
assert w() is None
|
2013-09-30 16:22:08 +02:00
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_validator():
|
2017-09-21 21:23:03 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
|
|
|
a = StrOption('a', '', default='yes')
|
2019-10-27 11:09:15 +01:00
|
|
|
b = StrOption('b', '', validators=[Calculation(funcname, Params(ParamOption(a)))], default='val')
|
2017-09-21 21:23:03 +02:00
|
|
|
od = OptionDescription('root', '', [a, b])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(od)
|
2017-09-21 21:23:03 +02:00
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(od)
|
|
|
|
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(od)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(cfg)
|
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_callback():
|
2017-09-21 21:23:03 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
|
|
|
a = StrOption('a', "", 'val')
|
2019-09-28 16:32:48 +02:00
|
|
|
b = StrOption('b', "", Calculation(funcname, Params((ParamOption(a),))))
|
2017-09-21 21:23:03 +02:00
|
|
|
od = OptionDescription('root', '', [a, b])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(od)
|
2017-09-21 21:23:03 +02:00
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(od)
|
|
|
|
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(od)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(cfg)
|
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_symlink():
|
2017-09-21 21:23:03 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
|
|
|
a = BoolOption("a", "", default=False)
|
|
|
|
b = SymLinkOption("b", a)
|
|
|
|
od = OptionDescription('root', '', [a, b])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(od)
|
2017-09-21 21:23:03 +02:00
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(od)
|
|
|
|
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(od)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(cfg)
|
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|
|
|
|
|
|
|
|
|
2019-12-24 15:24:20 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_deref_dyn():
|
2017-09-21 21:23:03 +02:00
|
|
|
if not IS_DEREFABLE:
|
|
|
|
return
|
|
|
|
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),))))
|
2017-09-21 21:23:03 +02:00
|
|
|
od = OptionDescription('od', '', [dod, a])
|
2019-12-24 15:24:20 +01:00
|
|
|
cfg = await Config(od)
|
2017-09-21 21:23:03 +02:00
|
|
|
w = weakref.ref(a)
|
|
|
|
x = weakref.ref(b)
|
|
|
|
y = weakref.ref(od)
|
|
|
|
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(od)
|
|
|
|
del(dod)
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
assert w() is not None
|
|
|
|
assert x() is not None
|
|
|
|
del(cfg)
|
|
|
|
assert y() is None
|
|
|
|
assert z() is None
|