add test test/test_dereference.py + memoryleaks in optiondescription's cache
This commit is contained in:
parent
d75cef9c0f
commit
3be005e82e
7 changed files with 123 additions and 9 deletions
111
test/test_dereference.py
Normal file
111
test/test_dereference.py
Normal file
|
@ -0,0 +1,111 @@
|
|||
# coding: utf-8
|
||||
import autopath
|
||||
#from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import BoolOption, OptionDescription
|
||||
import weakref
|
||||
|
||||
|
||||
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():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
w = weakref.ref(b)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_optiondescription():
|
||||
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():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
o.impl_build_cache()
|
||||
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.impl_build_cache()
|
||||
w = weakref.ref(o)
|
||||
del(b)
|
||||
assert w() is not None
|
||||
del(o)
|
||||
assert w() is None
|
||||
|
||||
|
||||
def test_deref_option_config():
|
||||
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
|
||||
|
||||
|
||||
def test_deref_optiondescription_config():
|
||||
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
|
|
@ -1,3 +1,4 @@
|
|||
# coding: utf-8
|
||||
import autopath
|
||||
#from py.test import raises
|
||||
|
||||
|
@ -79,3 +80,5 @@ def test_create_persistent_retrieve():
|
|||
delete_session('test_persistent')
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.b is None
|
||||
|
||||
#recup d'un coté de et l'autre
|
||||
|
|
|
@ -99,7 +99,7 @@ class Option(BaseInformation):
|
|||
__slots__ = ('_name', '_requires', '_multi', '_validator',
|
||||
'_default_multi', '_default', '_properties', '_callback',
|
||||
'_multitype', '_master_slaves', '_consistencies', '_empty',
|
||||
'_calc_properties')
|
||||
'_calc_properties', '__weakref__')
|
||||
_empty = ''
|
||||
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
|
@ -714,7 +714,7 @@ class OptionDescription(BaseInformation):
|
|||
"""
|
||||
__slots__ = ('_name', '_requires', '_cache_paths', '_group_type',
|
||||
'_properties', '_children', '_consistencies',
|
||||
'_calc_properties')
|
||||
'_calc_properties', '__weakref__')
|
||||
|
||||
def __init__(self, name, doc, children, requires=None, properties=None):
|
||||
"""
|
||||
|
@ -801,8 +801,8 @@ class OptionDescription(BaseInformation):
|
|||
else:
|
||||
save = False
|
||||
if cache_path is None:
|
||||
cache_path = [self._name]
|
||||
cache_option = [self]
|
||||
cache_path = []
|
||||
cache_option = []
|
||||
for option in self.impl_getchildren():
|
||||
attr = option._name
|
||||
if attr.startswith('_cfgimpl'):
|
||||
|
@ -929,7 +929,7 @@ def validate_requires_arg(requires, name):
|
|||
:param requires: have a look at the
|
||||
:meth:`tiramisu.setting.Settings.apply_requires` method to
|
||||
know more about
|
||||
the description of the requires dictionnary
|
||||
the description of the requires dictionary
|
||||
"""
|
||||
if requires is None:
|
||||
return None, None
|
||||
|
|
|
@ -239,7 +239,7 @@ def delete_session(session_id):
|
|||
#____________________________________________________________
|
||||
class Settings(object):
|
||||
"``Config()``'s configuration options"
|
||||
__slots__ = ('context', '_owner', '_p_')
|
||||
__slots__ = ('context', '_owner', '_p_', '__weakref__')
|
||||
|
||||
def __init__(self, context, storage):
|
||||
"""
|
||||
|
|
|
@ -22,7 +22,7 @@ from tiramisu.storage.dictionary.storage import Cache
|
|||
|
||||
|
||||
class Values(Cache):
|
||||
__slots__ = ('_values',)
|
||||
__slots__ = ('_values', '__weakref__')
|
||||
|
||||
def __init__(self, storage):
|
||||
"""init plugin means create values storage
|
||||
|
|
|
@ -23,7 +23,7 @@ from tiramisu.setting import owners
|
|||
|
||||
|
||||
class Values(Cache):
|
||||
__slots__ = tuple()
|
||||
__slots__ = ('__weakref__',)
|
||||
|
||||
def __init__(self, storage):
|
||||
"""init plugin means create values storage
|
||||
|
|
|
@ -32,7 +32,7 @@ class Values(object):
|
|||
but the values are physicaly located here, in `Values`, wich is also
|
||||
responsible of a caching utility.
|
||||
"""
|
||||
__slots__ = ('context', '_p_')
|
||||
__slots__ = ('context', '_p_', '__weakref__')
|
||||
|
||||
def __init__(self, context, storage):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue