unserialise information and requires attribute

This commit is contained in:
Emmanuel Garette 2015-11-01 10:35:17 +01:00
parent 445516ce34
commit 11d23bc8d8
3 changed files with 59 additions and 3 deletions

View File

@ -188,6 +188,41 @@ def test_diff_opt():
_diff_opts(o1, q) _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(): def test_diff_opt_multi():
b = BoolOption('b', '', multi=True) b = BoolOption('b', '', multi=True)
o = OptionDescription('o', '', [b]) o = OptionDescription('o', '', [b])
@ -300,6 +335,27 @@ def test_state_config2():
pass 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(): def test_state_properties():
val1 = BoolOption('val1', "") val1 = BoolOption('val1', "")
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])

View File

@ -258,7 +258,6 @@ class BaseOption(Base):
:param descr: the parent :class:`tiramisu.option.OptionDescription` :param descr: the parent :class:`tiramisu.option.OptionDescription`
""" """
#super(BaseOption, self)._impl_getstate()
self._stated = True self._stated = True
for func in dir(self): for func in dir(self):
if func.startswith('_impl_convert_'): if func.startswith('_impl_convert_'):

View File

@ -246,12 +246,13 @@ class StorageBase(object):
def _impl_setopt(self, opt): def _impl_setopt(self, opt):
self._opt = opt self._opt = opt
def _impl_convert_informations(self, descr, load=False): def _impl_convert_zinformations(self, descr, load=False):
if not load: if not load:
infos = self._informations infos = self._informations
if isinstance(infos, tuple): if isinstance(infos, tuple):
self._state_informations = {} self._state_informations = {}
for key, value in infos: for idx, key in enumerate(infos[0]):
value = infos[1][idx]
self._state_informations[key] = value self._state_informations[key] = value
elif isinstance(infos, str) or isinstance(infos, unicode): elif isinstance(infos, str) or isinstance(infos, unicode):
self._state_informations = {'doc': infos} self._state_informations = {'doc': infos}