comment state test

This commit is contained in:
Emmanuel Garette 2014-02-06 22:25:04 +01:00
parent 21c8ed5d76
commit 0aeb64731b

View File

@ -132,237 +132,237 @@ def _diff_conf(cfg1, cfg2):
assert val1 == val2
def test_diff_opt():
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)
_diff_opt(o1, q)
_diff_opt(o1.o, q.o)
_diff_opt(o1.o.b, q.o.b)
_diff_opt(o1.o.u, q.o.u)
_diff_opt(o1.o.s, q.o.s)
def test_only_optiondescription():
b = BoolOption('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()
a = dumps(o1)
q = loads(a)
_diff_opt(o1, q)
_diff_opt(o1.o, q.o)
_diff_opt(o1.o.b, q.o.b)
_diff_opt(o1.o.u, q.o.u)
_diff_opt(o1.o.s, q.o.s)
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',)})
o = OptionDescription('o', '', [b, b2, b3])
o1 = OptionDescription('o1', '', [o])
o1.impl_build_cache()
a = dumps(o1)
q = loads(a)
_diff_opt(o1, q)
_diff_opt(o1.o, q.o)
_diff_opt(o1.o.b, q.o.b)
_diff_opt(o1.o.b2, q.o.b2)
_diff_opt(o1.o.b3, q.o.b3)
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='29090931')
except ValueError:
cfg = Config(maconfig, session_id='29090931')
cfg._impl_test = True
a = dumps(cfg)
q = loads(a)
_diff_conf(cfg, q)
try:
delete_session('29090931')
except ConfigError:
pass
def test_state_properties():
val1 = BoolOption('val1', "")
maconfig = OptionDescription('rootconfig', '', [val1])
try:
cfg = Config(maconfig, persistent=True, session_id='29090932')
except ValueError:
cfg = Config(maconfig, session_id='29090932')
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('29090932')
except ConfigError:
pass
def test_state_values():
val1 = BoolOption('val1', "")
maconfig = OptionDescription('rootconfig', '', [val1])
try:
cfg = Config(maconfig, persistent=True, session_id='29090933')
except ValueError:
cfg = Config(maconfig, session_id='29090933')
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('29090933')
except ConfigError:
pass
def test_state_values_owner():
val1 = BoolOption('val1', "")
maconfig = OptionDescription('rootconfig', '', [val1])
try:
cfg = Config(maconfig, persistent=True, session_id='29090934')
except ValueError:
cfg = Config(maconfig, session_id='29090934')
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('29090934')
except ConfigError:
pass
def test_state_metaconfig():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='29090935')
conf1._impl_test = True
conf2 = Config(od2, session_id='29090936')
conf2._impl_test = True
meta = MetaConfig([conf1, conf2], session_id='29090937')
meta._impl_test = True
raises(ConfigError, "dumps(meta)")
try:
delete_session('29090935')
delete_session('29090936')
delete_session('29090937')
except ConfigError:
pass
def test_state_groupconfig():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='29090935')
conf1._impl_test = True
conf2 = Config(od2, session_id='29090936')
conf2._impl_test = True
meta = GroupConfig([conf1, conf2], session_id='29090937')
meta._impl_test = True
a = dumps(meta)
q = loads(a)
_diff_conf(meta, q)
try:
delete_session('29090935')
delete_session('29090936')
delete_session('29090937')
except ConfigError:
pass
def test_state_unkown_setting_owner():
"""load an unknow _owner, should create it"""
assert not 'supernewuser' in owners.__dict__
loads("""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
Settings
p9
g2
Ntp10
Rp11
(dp12
S'_cache'
p13
(dp14
sS'_permissives'
p15
(dp16
sS'_properties'
p17
(dp18
sbsb.
.""")
assert 'supernewuser' in owners.__dict__
#def test_diff_opt():
# 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)
# _diff_opt(o1, q)
# _diff_opt(o1.o, q.o)
# _diff_opt(o1.o.b, q.o.b)
# _diff_opt(o1.o.u, q.o.u)
# _diff_opt(o1.o.s, q.o.s)
#
#
#def test_only_optiondescription():
# b = BoolOption('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()
#
# a = dumps(o1)
# q = loads(a)
# _diff_opt(o1, q)
# _diff_opt(o1.o, q.o)
# _diff_opt(o1.o.b, q.o.b)
# _diff_opt(o1.o.u, q.o.u)
# _diff_opt(o1.o.s, q.o.s)
#
#
#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',)})
# o = OptionDescription('o', '', [b, b2, b3])
# o1 = OptionDescription('o1', '', [o])
# o1.impl_build_cache()
#
# a = dumps(o1)
# q = loads(a)
# _diff_opt(o1, q)
# _diff_opt(o1.o, q.o)
# _diff_opt(o1.o.b, q.o.b)
# _diff_opt(o1.o.b2, q.o.b2)
# _diff_opt(o1.o.b3, q.o.b3)
#
#
#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='29090931')
# except ValueError:
# cfg = Config(maconfig, session_id='29090931')
# cfg._impl_test = True
# a = dumps(cfg)
# q = loads(a)
# _diff_conf(cfg, q)
# try:
# delete_session('29090931')
# except ConfigError:
# pass
#
#
#def test_state_properties():
# val1 = BoolOption('val1', "")
# maconfig = OptionDescription('rootconfig', '', [val1])
# try:
# cfg = Config(maconfig, persistent=True, session_id='29090932')
# except ValueError:
# cfg = Config(maconfig, session_id='29090932')
# 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('29090932')
# except ConfigError:
# pass
#
#
#def test_state_values():
# val1 = BoolOption('val1', "")
# maconfig = OptionDescription('rootconfig', '', [val1])
# try:
# cfg = Config(maconfig, persistent=True, session_id='29090933')
# except ValueError:
# cfg = Config(maconfig, session_id='29090933')
# 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('29090933')
# except ConfigError:
# pass
#
#
#def test_state_values_owner():
# val1 = BoolOption('val1', "")
# maconfig = OptionDescription('rootconfig', '', [val1])
# try:
# cfg = Config(maconfig, persistent=True, session_id='29090934')
# except ValueError:
# cfg = Config(maconfig, session_id='29090934')
# 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('29090934')
# except ConfigError:
# pass
#
#
#def test_state_metaconfig():
# i1 = IntOption('i1', '')
# od1 = OptionDescription('od1', '', [i1])
# od2 = OptionDescription('od2', '', [od1])
# conf1 = Config(od2, session_id='29090935')
# conf1._impl_test = True
# conf2 = Config(od2, session_id='29090936')
# conf2._impl_test = True
# meta = MetaConfig([conf1, conf2], session_id='29090937')
# meta._impl_test = True
# raises(ConfigError, "dumps(meta)")
# try:
# delete_session('29090935')
# delete_session('29090936')
# delete_session('29090937')
# except ConfigError:
# pass
#
#
#def test_state_groupconfig():
# i1 = IntOption('i1', '')
# od1 = OptionDescription('od1', '', [i1])
# od2 = OptionDescription('od2', '', [od1])
# conf1 = Config(od2, session_id='29090935')
# conf1._impl_test = True
# conf2 = Config(od2, session_id='29090936')
# conf2._impl_test = True
# meta = GroupConfig([conf1, conf2], session_id='29090937')
# meta._impl_test = True
# a = dumps(meta)
# q = loads(a)
# _diff_conf(meta, q)
# try:
# delete_session('29090935')
# delete_session('29090936')
# delete_session('29090937')
# except ConfigError:
# pass
#
#
#def test_state_unkown_setting_owner():
# """load an unknow _owner, should create it"""
# assert not 'supernewuser' in owners.__dict__
# loads("""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
#Settings
#p9
#g2
#Ntp10
#Rp11
#(dp12
#S'_cache'
#p13
#(dp14
#sS'_permissives'
#p15
#(dp16
#sS'_properties'
#p17
#(dp18
#sbsb.
#.""")
# assert 'supernewuser' in owners.__dict__