remove cache with a variable is calculated
This commit is contained in:
@ -573,8 +573,8 @@ def test_cache_master_callback():
|
||||
'val1': {None: (set([]), None)},
|
||||
'val1.val1': {None: (set(['empty']), None)},
|
||||
'val1.val2': {None: (set([]), None), 0: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached(cfg) == {'val1.val1': {None: ([None], None)},
|
||||
'val1.val2': {None: ([None], None), 0: (None, None)}}
|
||||
#assert cfg.cfgimpl_get_values()._p_.get_cached(cfg) == {'val1.val1': {None: ([None], None)},
|
||||
# 'val1.val2': {None: ([None], None), 0: (None, None)}}
|
||||
|
||||
|
||||
def test_cache_requires():
|
||||
@ -665,4 +665,4 @@ def test_callback_value_incr():
|
||||
assert cfg.val2 == 1
|
||||
sleep(1)
|
||||
assert cfg.val1 == 2
|
||||
#assert cfg.val2 == 2
|
||||
assert cfg.val2 == 2
|
||||
|
@ -3,13 +3,18 @@ from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.config import Config, GroupConfig, MetaConfig
|
||||
from tiramisu.option import BoolOption, IntOption, StrOption, OptionDescription, submulti
|
||||
from tiramisu.option import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
|
||||
SymLinkOption, OptionDescription, DynOptionDescription, submulti
|
||||
import weakref
|
||||
|
||||
|
||||
IS_DEREFABLE = True
|
||||
|
||||
|
||||
def funcname(value):
|
||||
return value
|
||||
|
||||
|
||||
def test_deref_storage():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
@ -78,7 +83,7 @@ def test_deref_option_cache():
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
o.impl_build_cache_option()
|
||||
o._build_cache_option()
|
||||
w = weakref.ref(b)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
@ -91,7 +96,7 @@ def test_deref_optiondescription_cache():
|
||||
return
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
o.impl_build_cache_option()
|
||||
o._build_cache_option()
|
||||
w = weakref.ref(o)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
@ -179,3 +184,171 @@ def test_deref_submulti():
|
||||
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
|
||||
|
@ -696,3 +696,21 @@ def test_multi_submulti_meta():
|
||||
multi.append()
|
||||
assert conf1.multi == [['val', None]]
|
||||
assert meta.multi == [['val']]
|
||||
|
||||
|
||||
def test_multi_submulti_meta_no_cache():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
conf1 = Config(od, session_id='conf1')
|
||||
conf1.read_write()
|
||||
conf2 = Config(od, session_id='conf2')
|
||||
conf2.read_write()
|
||||
meta = MetaConfig([conf1, conf2])
|
||||
meta.read_write()
|
||||
meta.cfgimpl_get_settings().remove('cache')
|
||||
meta.multi = [['val']]
|
||||
assert meta.multi == [['val']]
|
||||
multi = conf1.multi[0]
|
||||
multi.append()
|
||||
assert conf1.multi == [['val', None]]
|
||||
assert meta.multi == [['val']]
|
||||
|
Reference in New Issue
Block a user