diff --git a/tests/test_duplicate_config.py b/tests/test_duplicate_config.py index c71be44..a517d22 100644 --- a/tests/test_duplicate_config.py +++ b/tests/test_duplicate_config.py @@ -59,6 +59,16 @@ async def test_copy(): assert not await list_sessions() +@pytest.mark.asyncio +async def test_copy_information(): + od = make_description() + async with await Config(od) as cfg: + await cfg.information.set('key', 'value') + async with await cfg.config.copy() as ncfg: + assert await ncfg.information.get('key') == 'value' + assert not await list_sessions() + + @pytest.mark.asyncio async def test_copy_force_store_value(): od = make_description() diff --git a/tiramisu/config.py b/tiramisu/config.py index e6cabd5..d80b4bf 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -654,6 +654,9 @@ class _CommonConfig(SubConfig): duplicated_settings = duplicated_config.cfgimpl_get_settings() await duplicated_values._p_.importation(connection, await self.cfgimpl_get_values()._p_.exportation(connection)) + await duplicated_values._p_.importation_informations(connection, + await self.cfgimpl_get_values()._p_.exportation_informations(connection), + ) properties = await self.cfgimpl_get_settings()._p_.exportation(connection) await duplicated_settings._p_.importation(connection, properties) diff --git a/tiramisu/storage/dictionary/value.py b/tiramisu/storage/dictionary/value.py index 60eff23..c0f5b0b 100644 --- a/tiramisu/storage/dictionary/value.py +++ b/tiramisu/storage/dictionary/value.py @@ -293,6 +293,18 @@ class Values: connection): self._storage.set_informations({}) + async def exportation_informations(self, + connection, + ): + return deepcopy(self._storage.get_informations()) + + async def importation_informations(self, + connection, + informations, + ): + #deepcopy(informations) + return self._storage.set_informations(informations) + async def exportation(self, connection): return deepcopy(self._storage.get_values()) diff --git a/tiramisu/storage/postgres/value.py b/tiramisu/storage/postgres/value.py index 810a84a..a474b6b 100644 --- a/tiramisu/storage/postgres/value.py +++ b/tiramisu/storage/postgres/value.py @@ -231,6 +231,24 @@ class Values: await connection.execute("DELETE FROM information WHERE session_id = $1", self._storage.database_id) + async def exportation_informations(self, + connection, + ): + informations = {} + for path, key, value in await connection.fetch("SELECT path, key, value FROM information WHERE session_id = $1", self._storage.database_id): + path = self._storage.load_path(path) + informations.setdefault(path, {})[key] = loads(value) + return informations + + async def importation_informations(self, + connection, + informations, + ): + for path, path_infos in informations.items(): + for key, value in path_infos.items(): + await connection.execute("INSERT INTO information(key, value, session_id, path) VALUES " + "($1, $2, $3, $4)", key, dumps(value), self._storage.database_id, path) + async def exportation(self, connection): # log.debug('exportation')