tiramisu/test/test_dereference.py

355 lines
8.0 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()
2013-09-30 16:22:08 +02:00
from tiramisu.config import Config, GroupConfig, MetaConfig
from tiramisu.option import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
SymLinkOption, OptionDescription, DynOptionDescription, submulti
import weakref
2014-11-10 09:13:44 +01:00
IS_DEREFABLE = True
2015-07-24 17:54:10 +02:00
def funcname(value):
return value
2014-04-14 23:00:37 +02:00
def test_deref_storage():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c.cfgimpl_get_values()._p_)
del(c)
assert w() is None
def test_deref_value():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c.cfgimpl_get_values())
del(c)
assert w() is None
def test_deref_setting():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c.cfgimpl_get_settings())
del(c)
assert w() is None
def test_deref_config():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c)
del(c)
assert w() is None
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
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
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])
o._build_cache_option()
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():
2016-10-01 20:15:08 +02:00
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
o._build_cache_option()
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-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])
c = Config(o)
w = weakref.ref(b)
del(b)
assert w() is not None
del(o)
assert w() is not None
del(c)
assert w() is None
2014-01-25 10:15:25 +01:00
def test_deref_optiondescription_config():
2016-10-01 20:15:08 +02:00
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(o)
del(b)
assert w() is not None
del(o)
assert w() is not None
del(c)
assert w() is None
2013-09-30 16:22:08 +02:00
def test_deref_groupconfig():
2016-10-01 20:15:08 +02:00
if not IS_DEREFABLE:
return
2013-09-30 16:22:08 +02:00
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, 'conf1')
conf2 = Config(od2, 'conf2')
2013-09-30 16:22:08 +02:00
meta = GroupConfig([conf1, conf2])
w = weakref.ref(conf1)
del(conf1)
assert w() is not None
del(meta)
assert w() is None
def test_deref_metaconfig():
2016-10-01 20:15:08 +02:00
if not IS_DEREFABLE:
return
2013-09-30 16:22:08 +02:00
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, 'conf1')
conf2 = Config(od2, 'conf2')
2013-09-30 16:22:08 +02:00
meta = MetaConfig([conf1, conf2])
w = weakref.ref(conf1)
del(conf1)
assert w() is not None
del(meta)
assert w() is None
2014-04-25 22:57:08 +02:00
def test_deref_submulti():
2016-10-01 20:15:08 +02:00
if not IS_DEREFABLE:
return
2014-04-25 22:57:08 +02:00
multi = StrOption('multi', '', multi=submulti)
od = OptionDescription('od', '', [multi])
cfg = Config(od)
cfg.cfgimpl_get_settings().remove('cache')
w = weakref.ref(cfg.multi)
assert w() is None
cfg.multi.append([])
w = weakref.ref(cfg.multi)
assert w() is None
m = cfg.multi
w = weakref.ref(m)
z = weakref.ref(w()[0])
del(m)
assert w() is None
assert z() is None
def test_deref_consistency():
if not IS_DEREFABLE:
return
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
cfg = Config(od)
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 y() is not None
assert z() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert y() is not None
assert z() is not None
del(od)
assert w() is not None
assert x() is not None
assert y() is not None
assert z() is not None
del(cfg)
assert y() is None
assert z() is None
#assert w() is None
#assert x() is None
def test_deref_validator():
if not IS_DEREFABLE:
return
a = StrOption('a', '', default='yes')
b = StrOption('b', '', validator=funcname, validator_params={'': ((a, False),)}, default='val')
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
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
#assert w() is None
#assert x() is None
def test_deref_callback():
if not IS_DEREFABLE:
return
a = StrOption('a', "", 'val')
b = StrOption('b', "", callback=funcname, callback_params={'': ((a, False),)})
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
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
#assert w() is None
#assert x() is None
def test_deref_symlink():
if not IS_DEREFABLE:
return
a = BoolOption("a", "", default=False)
b = SymLinkOption("b", a)
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
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 w() is None
#assert x() is None
assert y() is None
assert z() is None
def test_deref_dyn():
if not IS_DEREFABLE:
return
a = StrOption('a', '', ['val1', 'val2'], multi=True)
b = StrOption('b', '')
dod = DynOptionDescription('dod', '', [b], callback=funcname, callback_params={'': ((a, False),)})
od = OptionDescription('od', '', [dod, a])
cfg = Config(od)
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 w() is None
#assert x() is None
assert y() is None
assert z() is None