From a9919e438bfb5d7fac275c03296a82b36c8011fe Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 27 Apr 2018 14:20:12 +0200 Subject: [PATCH] remove cache when import data --- test/test_cache.py | 36 ++++++++++++++++++++++++++++++++++++ tiramisu/api.py | 7 +++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/test/test_cache.py b/test/test_cache.py index 7ef490e..286aba8 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -60,6 +60,42 @@ def test_cache(): assert 'u2' in settings._p_.get_cached() +def test_cache_importation(): + od1 = make_description() + api = getapi(Config(od1)) + api.option('u2').value.set(1) + export = api.value.exportation() + assert api.option.make_dict() == {'u1': [], 'u2': 1, 'u3': []} + api.option('u2').value.set(2) + assert api.option.make_dict() == {'u1': [], 'u2': 2, 'u3': []} + api.value.importation(export) + assert api.option.make_dict() == {'u1': [], 'u2': 1, 'u3': []} + + +def test_cache_importation_property(): + od1 = make_description() + api = getapi(Config(od1)) + api.option('u2').property.add('prop') + export = api.property.exportation() + assert api.option('u2').property.get() == {'prop'} + api.option('u2').property.add('prop2') + assert api.option('u2').property.get() == {'prop', 'prop2'} + api.property.importation(export) + assert api.option('u2').property.get() == {'prop'} + + +def test_cache_importation_permissive(): + od1 = make_description() + api = getapi(Config(od1)) + api.option('u2').permissive.set(frozenset(['prop'])) + export = api.permissive.exportation() + assert api.option('u2').permissive.get() == {'prop'} + api.option('u2').permissive.set(frozenset(['prop', 'prop2'])) + assert api.option('u2').permissive.get() == {'prop', 'prop2'} + api.permissive.importation(export) + assert api.option('u2').permissive.get() == {'prop'} + + #def test_get_cache(): # # force a value in cache, try if reget corrupted value # od1 = make_description() diff --git a/tiramisu/api.py b/tiramisu/api.py index bc4c0ac..1ca9718 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -773,7 +773,8 @@ class TiramisuContextValue(TiramisuContext): @count def importation(self, values): """import values""" - return self.config_bag.config.cfgimpl_get_values()._p_.importation(values) + self.config_bag.config.cfgimpl_get_values()._p_.importation(values) + self.config_bag.config.cfgimpl_reset_cache(None, None, None) class TiramisuContextOwner(TiramisuContext): @@ -855,7 +856,8 @@ class TiramisuContextProperty(TiramisuContext): @count def importation(self, properties): """import configuration properties""" - return self.config_bag.config.cfgimpl_get_settings()._p_.importation(properties) + self.config_bag.config.cfgimpl_get_settings()._p_.importation(properties) + self.config_bag.config.cfgimpl_reset_cache(None, None, None) class TiramisuContextPermissive(TiramisuContext): @@ -880,6 +882,7 @@ class TiramisuContextPermissive(TiramisuContext): def importation(self, permissives): """import configuration permissives""" self.config_bag.config.cfgimpl_get_settings()._pp_.importation(permissives) + self.config_bag.config.cfgimpl_reset_cache(None, None, None)