tiramisu/tests/test_dereference.py

230 lines
5.2 KiB
Python
Raw Normal View History

# 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
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):
return value
def test_deref_value():
2014-04-14 23:00:37 +02:00
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
def test_deref_setting():
2014-04-14 23:00:37 +02:00
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
def test_deref_config():
2014-04-14 23:00:37 +02:00
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
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
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
def test_deref_option_cache():
2014-04-14 23:00:37 +02:00
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
def test_deref_optiondescription_cache():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
o._build_cache()
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
def test_deref_option_config():
2014-04-14 23:00:37 +02:00
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
2014-01-25 10:15:25 +01:00
def test_deref_optiondescription_config():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
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
assert w() is None
2013-09-30 16:22:08 +02:00
def test_deref_validator():
a = StrOption('a', '', default='yes')
2019-10-27 11:09:15 +01:00
b = StrOption('b', '', validators=[Calculation(funcname, Params(ParamOption(a)))], default='val')
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
assert y() is None
assert z() is None
def test_deref_callback():
a = StrOption('a', "", 'val')
2019-09-28 16:32:48 +02:00
b = StrOption('b', "", Calculation(funcname, Params((ParamOption(a),))))
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
assert y() is None
assert z() is None
def test_deref_symlink():
a = BoolOption("a", "", default=False)
b = SymLinkOption("b", a)
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
assert y() is None
assert z() is None
def test_deref_dyn():
a = StrOption('a', '', ['val1', 'val2'], multi=True)
b = StrOption('b', '')
dod = DynOptionDescription('dod', '', [b], suffixes=Calculation(funcname, Params((ParamOption(a),))))
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
assert y() is None
assert z() is None