From 11d23bc8d8b510fb5c27c1f6eb9f76fdb4c91d14 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 1 Nov 2015 10:35:17 +0100 Subject: [PATCH] unserialise information and requires attribute --- test/test_state.py | 56 +++++++++++++++++++++++++++ tiramisu/option/baseoption.py | 1 - tiramisu/storage/dictionary/option.py | 5 ++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/test/test_state.py b/test/test_state.py index 52fb69b..f652658 100644 --- a/test/test_state.py +++ b/test/test_state.py @@ -188,6 +188,41 @@ def test_diff_opt(): _diff_opts(o1, q) +def test_diff_information(): + b = BoolOption('b', '') + b.impl_set_information('doc', 'oh') + b.impl_set_information('doc1', 'oh') + b.impl_set_information('doc2', 'oh') + o = OptionDescription('o', '', [b]) + o1 = OptionDescription('o1', '', [o]) + + a = dumps(o1) + q = loads(a) + _diff_opts(o1, q) + + +def test_diff_information_config(): + b = BoolOption('b', '') + b.impl_set_information('info', 'oh') + b.impl_set_information('info1', 'oh') + b.impl_set_information('info2', 'oh') + o = OptionDescription('o', '', [b]) + o1 = OptionDescription('o1', '', [o]) + try: + cfg = Config(o1, persistent=True, session_id='29090938') + except ValueError: + cfg = Config(o1, session_id='29090938') + cfg._impl_test = True + cfg.impl_set_information('info', 'oh') + + a = dumps(cfg) + q = loads(a) + _diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description()) + _diff_conf(cfg, q) + assert cfg.impl_get_information('info') == 'oh' + assert q.impl_get_information('info') == 'oh' + + def test_diff_opt_multi(): b = BoolOption('b', '', multi=True) o = OptionDescription('o', '', [b]) @@ -300,6 +335,27 @@ def test_state_config2(): pass +def test_diff_opt_config(): + b = BoolOption('b', '') + u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) + u.impl_set_information('info', 'oh') + u.impl_set_information('info1', 'oh') + u.impl_set_information('info2', 'oh') + s = SymLinkOption('s', u) + o = OptionDescription('o', '', [b, u, s]) + o1 = OptionDescription('o1', '', [o]) + try: + cfg = Config(o1, persistent=True, session_id='29090940') + except ValueError: + cfg = Config(o1, session_id='29090940') + cfg._impl_test = True + + a = dumps(cfg) + q = loads(a) + _diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description()) + _diff_conf(cfg, q) + + def test_state_properties(): val1 = BoolOption('val1', "") maconfig = OptionDescription('rootconfig', '', [val1]) diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 410980c..155bc31 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -258,7 +258,6 @@ class BaseOption(Base): :param descr: the parent :class:`tiramisu.option.OptionDescription` """ - #super(BaseOption, self)._impl_getstate() self._stated = True for func in dir(self): if func.startswith('_impl_convert_'): diff --git a/tiramisu/storage/dictionary/option.py b/tiramisu/storage/dictionary/option.py index 6717832..ec24567 100644 --- a/tiramisu/storage/dictionary/option.py +++ b/tiramisu/storage/dictionary/option.py @@ -246,12 +246,13 @@ class StorageBase(object): def _impl_setopt(self, opt): self._opt = opt - def _impl_convert_informations(self, descr, load=False): + def _impl_convert_zinformations(self, descr, load=False): if not load: infos = self._informations if isinstance(infos, tuple): self._state_informations = {} - for key, value in infos: + for idx, key in enumerate(infos[0]): + value = infos[1][idx] self._state_informations[key] = value elif isinstance(infos, str) or isinstance(infos, unicode): self._state_informations = {'doc': infos}