X-Git-Url: http://git.labs.libre-entreprise.org/?p=tiramisu.git;a=blobdiff_plain;f=test%2Ftest_dereference.py;h=a1e7652f7f717335ca46ab0791dfdde76b94751b;hp=4ea124082c8e033fbe05cb59639a2744f85b027b;hb=c8bc3093c7f5ed74c86eb8fad522a9f20283bacb;hpb=313b03b2462106fe54b603d2f46395823e8fd4a7 diff --git a/test/test_dereference.py b/test/test_dereference.py index 4ea1240..a1e7652 100644 --- a/test/test_dereference.py +++ b/test/test_dereference.py @@ -1,12 +1,15 @@ # coding: utf-8 -import autopath -#from py.test import raises +from .autopath import do_autopath +do_autopath() -from tiramisu.config import Config -from tiramisu.option import BoolOption, OptionDescription +from tiramisu.config import Config, GroupConfig, MetaConfig +from tiramisu.option import BoolOption, IntOption, StrOption, OptionDescription, submulti import weakref +IS_DEREFABLE = True + + def test_deref_storage(): b = BoolOption('b', '') o = OptionDescription('od', '', [b]) @@ -44,43 +47,48 @@ def test_deref_config(): def test_deref_option(): + global IS_DEREFABLE b = BoolOption('b', '') o = OptionDescription('od', '', [b]) w = weakref.ref(b) del(b) - assert w() is not None + try: + assert w() is not None + except AssertionError: + IS_DEREFABLE = False + return del(o) - #FIXME - #assert w() is None + assert w() is None def test_deref_optiondescription(): + if not IS_DEREFABLE: + return b = BoolOption('b', '') o = OptionDescription('od', '', [b]) w = weakref.ref(o) del(b) assert w() is not None del(o) - #FIXME - #assert w() is None + assert w() is None -#def test_deref_option_cache(): -# FIXME quand c'est un dico, il faut garder la reference -# mais la comme c'est dans la base, forcement c'est dereference -# b = BoolOption('b', '') -# o = OptionDescription('od', '', [b]) -# o.impl_build_cache_option() -# w = weakref.ref(b) -# del(b) -# assert w() is not None -# del(o) -# #FIXME l'objet n'est plus en mémoire mais par contre reste dans la base -# #Voir comment supprimer (et quand) -# #assert w() is None +def test_deref_option_cache(): + if not IS_DEREFABLE: + return + b = BoolOption('b', '') + o = OptionDescription('od', '', [b]) + o.impl_build_cache_option() + w = weakref.ref(b) + del(b) + assert w() is not None + del(o) + assert w() is None def test_deref_optiondescription_cache(): + if not IS_DEREFABLE: + return b = BoolOption('b', '') o = OptionDescription('od', '', [b]) o.impl_build_cache_option() @@ -88,26 +96,27 @@ def test_deref_optiondescription_cache(): del(b) assert w() is not None del(o) - #FIXME - #assert w() is None + 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) -# #FIXME meme chose -# #assert w() is None +def test_deref_option_config(): + if not IS_DEREFABLE: + return + 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 -#FIXME rien a voir mais si je fais un config.impl_get_path_by_opt() ca me retourne la methode ! def test_deref_optiondescription_config(): + if not IS_DEREFABLE: + return b = BoolOption('b', '') o = OptionDescription('od', '', [b]) c = Config(o) @@ -117,5 +126,56 @@ def test_deref_optiondescription_config(): del(o) assert w() is not None del(c) - #FIXME - #assert w() is None + assert w() is None + + +def test_deref_groupconfig(): + if not IS_DEREFABLE: + return + i1 = IntOption('i1', '') + od1 = OptionDescription('od1', '', [i1]) + od2 = OptionDescription('od2', '', [od1]) + conf1 = Config(od2, 'conf1') + conf2 = Config(od2, 'conf2') + 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(): + if not IS_DEREFABLE: + return + i1 = IntOption('i1', '') + od1 = OptionDescription('od1', '', [i1]) + od2 = OptionDescription('od2', '', [od1]) + conf1 = Config(od2, 'conf1') + conf2 = Config(od2, 'conf2') + meta = MetaConfig([conf1, conf2]) + w = weakref.ref(conf1) + del(conf1) + assert w() is not None + del(meta) + assert w() is None + + +def test_deref_submulti(): + if not IS_DEREFABLE: + return + 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