remove pickle dump/load support
This commit is contained in:
@ -14,7 +14,6 @@ from tiramisu.storage import delete_session
|
||||
from .test_state import _diff_opts, _diff_conf
|
||||
|
||||
from py.test import raises
|
||||
from pickle import dumps, loads
|
||||
|
||||
|
||||
def return_true(value, param=None, suffix=None):
|
||||
@ -1311,36 +1310,6 @@ def test_masterslaves_callback_samegroup_dyndescription():
|
||||
#assert cfg.getowner(st3val2) == owners.default
|
||||
|
||||
|
||||
def test_state_config():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
dod1 = DynOptionDescription('dod1', '', [a, b], callback=return_list)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od1 = OptionDescription('od1', '', [dod1])
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2, st3])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='c29090938')
|
||||
except ValueError:
|
||||
cfg = Config(od2, session_id='c29090938')
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
|
||||
try:
|
||||
delete_session('config', 'c29090938')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_invalid_conflict_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
|
@ -2,21 +2,13 @@
|
||||
#do_autopath()
|
||||
#
|
||||
from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
|
||||
IntOption, IPOption, NetmaskOption, StrOption, OptionDescription, \
|
||||
DynOptionDescription, MasterSlaves
|
||||
from tiramisu.config import Config, GroupConfig, MetaConfig
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.storage import delete_session
|
||||
from tiramisu.error import ConfigError
|
||||
from pickle import dumps, loads
|
||||
OptionDescription, DynOptionDescription
|
||||
from tiramisu.config import Config
|
||||
from pickle import dumps
|
||||
from py.test import raises
|
||||
import sys
|
||||
|
||||
|
||||
def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def _get_slots(opt):
|
||||
slots = set()
|
||||
for subclass in opt.__class__.__mro__:
|
||||
@ -221,34 +213,7 @@ def test_diff_opt():
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_diff_optdesc():
|
||||
u = UnicodeOption('u', '')
|
||||
b = BoolOption('b', '')
|
||||
od = OptionDescription('od', '', [b], requires=[{'option': u, 'expected': u'u', 'action': 'disabled', 'inverse': True}])
|
||||
o = OptionDescription('o', '', [u, od])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_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)
|
||||
raises(NotImplementedError, "dumps(o1)")
|
||||
|
||||
|
||||
def test_diff_information_config():
|
||||
@ -258,328 +223,10 @@ def test_diff_information_config():
|
||||
b.impl_set_information('info2', 'oh')
|
||||
o = OptionDescription('o', '', [b])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
try:
|
||||
cfg = Config(o1, persistent=True, session_id='c29090938')
|
||||
except ValueError:
|
||||
cfg = Config(o1, session_id='c29090938')
|
||||
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'
|
||||
try:
|
||||
delete_session('config', 'c29090938')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_diff_opt_multi():
|
||||
b = BoolOption('b', '', multi=True)
|
||||
o = OptionDescription('o', '', [b])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opt(o1, q)
|
||||
_diff_opt(o1.o, q.o)
|
||||
_diff_opt(o1.o.b, q.o.b)
|
||||
raises(NotImplementedError, "dumps(Config(o1))")
|
||||
|
||||
|
||||
def test_only_optiondescription():
|
||||
b = BoolOption('b', '')
|
||||
b
|
||||
raises(SystemError, "a = dumps(b)")
|
||||
|
||||
|
||||
def test_diff_opt_cache():
|
||||
b = BoolOption('b', '')
|
||||
u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
u.impl_add_consistency('not_equal', b)
|
||||
s = SymLinkOption('s', u)
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
o1.impl_build_cache_option()
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_diff_opt_callback():
|
||||
b = BoolOption('b', '', callback=return_value)
|
||||
b2 = BoolOption('b2', '', callback=return_value, callback_params={'': ('yes',)})
|
||||
b3 = BoolOption('b3', '', callback=return_value, callback_params={'': ('yes', (b, False)), 'value': ('no',)})
|
||||
b4 = BoolOption("b4", "", callback=return_value, callback_params={'': ((None,),), 'value': ('string',)})
|
||||
o = OptionDescription('o', '', [b, b2, b3, b4])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
o1.impl_build_cache_option()
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_no_state_attr():
|
||||
# all _state_xxx attributes should be deleted
|
||||
b = BoolOption('b', '')
|
||||
u = UnicodeOption('u', '', requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
||||
s = SymLinkOption('s', u)
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_no_state(q)
|
||||
_no_state(q.o)
|
||||
_no_state(q.o.b)
|
||||
_no_state(q.o.u)
|
||||
_no_state(q.o.s)
|
||||
|
||||
|
||||
def test_state_config():
|
||||
val1 = BoolOption('val1', "")
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
try:
|
||||
cfg = Config(maconfig, persistent=True, session_id='c29090931')
|
||||
except ValueError:
|
||||
cfg = Config(maconfig, session_id='c29090931')
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', 'c29090931')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_config2():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
dod1 = OptionDescription('dod1', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od1 = OptionDescription('od1', '', [dod1])
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st3 = StrOption('st3', "", multi=True, callback=return_value, callback_params={'': ((st2, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2, st3])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = OptionDescription('st', '', [stm])
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='c29090939')
|
||||
except ValueError:
|
||||
cfg = Config(od2, session_id='c29090939')
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', 'c29090939')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_diff_opt_value():
|
||||
b = BoolOption('b', '')
|
||||
u = UnicodeOption('u', '', properties=('force_store_value',))
|
||||
s = SymLinkOption('s', u)
|
||||
o = OptionDescription('o', '', [b, u, s])
|
||||
o1 = OptionDescription('o1', '', [o])
|
||||
try:
|
||||
cfg = Config(o1, persistent=True, session_id='c29090941')
|
||||
except ValueError:
|
||||
cfg = Config(o1, session_id='c29090941')
|
||||
cfg._impl_test = True
|
||||
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', 'c29090941')
|
||||
except ValueError:
|
||||
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='c29090940')
|
||||
except ValueError:
|
||||
cfg = Config(o1, session_id='c29090940')
|
||||
cfg._impl_test = True
|
||||
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', 'c29090940')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_properties():
|
||||
val1 = BoolOption('val1', "")
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
try:
|
||||
cfg = Config(maconfig, persistent=True, session_id='c29090932')
|
||||
except ValueError:
|
||||
cfg = Config(maconfig, session_id='c29090932')
|
||||
cfg._impl_test = True
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_settings()[val1].append('test')
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', 'c29090932')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_values():
|
||||
val1 = BoolOption('val1', "")
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
try:
|
||||
cfg = Config(maconfig, persistent=True, session_id='c29090933')
|
||||
except ValueError:
|
||||
cfg = Config(maconfig, session_id='c29090933')
|
||||
cfg._impl_test = True
|
||||
cfg.val1 = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_conf(cfg, q)
|
||||
q.val1 = False
|
||||
assert cfg.val1 is True
|
||||
assert q.val1 is False
|
||||
try:
|
||||
delete_session('config', 'c29090933')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_values_owner():
|
||||
val1 = BoolOption('val1', "")
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
try:
|
||||
cfg = Config(maconfig, persistent=True, session_id='c29090934')
|
||||
except ValueError:
|
||||
cfg = Config(maconfig, session_id='c29090934')
|
||||
cfg._impl_test = True
|
||||
owners.addowner('newowner')
|
||||
cfg.cfgimpl_get_settings().setowner(owners.newowner)
|
||||
cfg.val1 = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_conf(cfg, q)
|
||||
q.val1 = False
|
||||
nval1 = q.cfgimpl_get_description().val1
|
||||
assert q.getowner(nval1) == owners.newowner
|
||||
try:
|
||||
delete_session('config', 'c29090934')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_metaconfig():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='c29090935')
|
||||
except ValueError:
|
||||
conf1 = Config(od2, session_id='c29090935')
|
||||
conf1._impl_test = True
|
||||
conf2 = Config(od2, session_id='c29090936')
|
||||
conf2._impl_test = True
|
||||
meta = MetaConfig([conf1, conf2], session_id='c29090937')
|
||||
meta._impl_test = True
|
||||
raises(ConfigError, "dumps(meta)")
|
||||
try:
|
||||
delete_session('config', 'c29090935')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_groupconfig():
|
||||
i1 = IntOption('i1', '')
|
||||
od1 = OptionDescription('od1', '', [i1])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='c29090938')
|
||||
except ValueError:
|
||||
conf1 = Config(od2, session_id='c29090938')
|
||||
conf1._impl_test = True
|
||||
conf2 = Config(od2, session_id='c29090939')
|
||||
conf2._impl_test = True
|
||||
meta = GroupConfig([conf1, conf2], session_id='c29090940')
|
||||
meta._impl_test = True
|
||||
a = dumps(meta)
|
||||
q = loads(a)
|
||||
_diff_conf(meta, q)
|
||||
try:
|
||||
delete_session('config', 'c29090938')
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
#def test_state_unkown_setting_owner():
|
||||
# """load an unknow _owner, should create it"""
|
||||
# assert not 'supernewuser' in owners.__dict__
|
||||
# val = """ccopy_reg
|
||||
#_reconstructor
|
||||
#p0
|
||||
#(ctiramisu.setting
|
||||
#Settings
|
||||
#p1
|
||||
#c__builtin__
|
||||
#object
|
||||
#p2
|
||||
#Ntp3
|
||||
#Rp4
|
||||
#(dp5
|
||||
#S'_owner'
|
||||
#p6
|
||||
#S'supernewuser'
|
||||
#p7
|
||||
#sS'_p_'
|
||||
#p8
|
||||
#g0
|
||||
#(ctiramisu.storage.dictionary.setting
|
||||
#Properties
|
||||
#p9
|
||||
#g2
|
||||
#Ntp10
|
||||
#Rp11
|
||||
#(dp12
|
||||
#S'_cache'
|
||||
#p13
|
||||
#(dp14
|
||||
#sS'_permissives'
|
||||
#p15
|
||||
#(dp16
|
||||
#sS'_properties'
|
||||
#p17
|
||||
#(dp18
|
||||
#sbsb.
|
||||
#."""
|
||||
# if sys.version_info[0] >= 3: # pragma: optional cover
|
||||
# val = bytes(val, "UTF-8")
|
||||
# loads(val)
|
||||
# assert 'supernewuser' in owners.__dict__
|
||||
raises(NotImplementedError, "a = dumps(b)")
|
||||
|
Reference in New Issue
Block a user