coverage
This commit is contained in:
parent
fe379abb42
commit
722779ebf7
|
@ -165,6 +165,9 @@ def test_information_config():
|
||||||
assert config.impl_get_information('info') == string
|
assert config.impl_get_information('info') == string
|
||||||
raises(ValueError, "config.impl_get_information('noinfo')")
|
raises(ValueError, "config.impl_get_information('noinfo')")
|
||||||
assert config.impl_get_information('noinfo', 'default') == 'default'
|
assert config.impl_get_information('noinfo', 'default') == 'default'
|
||||||
|
config.impl_del_information('info')
|
||||||
|
raises(ValueError, "config.impl_get_information('info')")
|
||||||
|
raises(ValueError, "config.impl_del_information('noinfo')")
|
||||||
|
|
||||||
|
|
||||||
def test_config_impl_get_path_by_opt():
|
def test_config_impl_get_path_by_opt():
|
||||||
|
|
|
@ -162,6 +162,10 @@ def test_find_in_config():
|
||||||
ret = conf.find(byname='dummy')
|
ret = conf.find(byname='dummy')
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||||
|
#
|
||||||
|
ret = conf.find_first(byname='dummy')
|
||||||
|
_is_same_opt(ret, conf.unwrap_from_path('gc.dummy'))
|
||||||
|
#
|
||||||
ret = conf.find(byname='float')
|
ret = conf.find(byname='float')
|
||||||
assert len(ret) == 2
|
assert len(ret) == 2
|
||||||
_is_same_opt(ret[0], conf.unwrap_from_path('gc.float'))
|
_is_same_opt(ret[0], conf.unwrap_from_path('gc.float'))
|
||||||
|
|
|
@ -61,8 +61,8 @@ def test_duplicate_force_store_value():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
conf2 = Config(descr)
|
conf2 = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||||
assert conf2.cfgimpl_get_values()._p_.get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||||
conf.creole.general.wantref = True
|
conf.creole.general.wantref = True
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'creole.general.wantref': ('user', True)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('user', True)}
|
||||||
assert conf2.cfgimpl_get_values()._p_.get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
assert conf2.cfgimpl_get_values().get_modified_values() == {'creole.general.wantref': ('forced', False)}
|
||||||
|
|
|
@ -646,6 +646,7 @@ def test_find_dyndescription_context():
|
||||||
assert isinstance(cfg.find_first(byname='stval1', type_='option'), DynSymLinkOption)
|
assert isinstance(cfg.find_first(byname='stval1', type_='option'), DynSymLinkOption)
|
||||||
assert cfg.find(bytype=StrOption, type_='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
|
assert cfg.find(bytype=StrOption, type_='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
|
||||||
opts = cfg.find(byvalue='yes')
|
opts = cfg.find(byvalue='yes')
|
||||||
|
raises(AttributeError, "cfg.find(byname='strnotexists')")
|
||||||
assert len(opts) == 1
|
assert len(opts) == 1
|
||||||
assert isinstance(opts[0], DynSymLinkOption)
|
assert isinstance(opts[0], DynSymLinkOption)
|
||||||
assert opts[0].impl_getname() == 'stval1'
|
assert opts[0].impl_getname() == 'stval1'
|
||||||
|
|
|
@ -170,15 +170,15 @@ def test_freeze_get_multi():
|
||||||
def test_force_store_value():
|
def test_force_store_value():
|
||||||
descr = make_description_freeze()
|
descr = make_description_freeze()
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('forced', False),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', (False,))}
|
'wantref3': ('forced', (False,))}
|
||||||
conf.wantref = True
|
conf.wantref = True
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('user', True),
|
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('user', True),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', (False,))}
|
'wantref3': ('forced', (False,))}
|
||||||
del(conf.wantref)
|
del(conf.wantref)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'wantref': ('forced', False),
|
assert conf.cfgimpl_get_values().get_modified_values() == {'wantref': ('forced', False),
|
||||||
'wantref2': ('forced', False),
|
'wantref2': ('forced', False),
|
||||||
'wantref3': ('forced', (False,))}
|
'wantref3': ('forced', (False,))}
|
||||||
|
|
||||||
|
@ -206,28 +206,28 @@ def test_force_store_value_masterslaves():
|
||||||
descr = OptionDescription("int", "", [b, c])
|
descr = OptionDescription("int", "", [b, c])
|
||||||
descr.impl_set_group_type(groups.master)
|
descr.impl_set_group_type(groups.master)
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', ())}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', ())}
|
||||||
|
|
||||||
|
|
||||||
def test_force_store_value_callback():
|
def test_force_store_value_callback():
|
||||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
||||||
descr = OptionDescription("int", "", [b])
|
descr = OptionDescription("int", "", [b])
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', 1)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 1)}
|
||||||
|
|
||||||
|
|
||||||
def test_force_store_value_callback_params():
|
def test_force_store_value_callback_params():
|
||||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
||||||
descr = OptionDescription("int", "", [b])
|
descr = OptionDescription("int", "", [b])
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', 2)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||||
|
|
||||||
|
|
||||||
def test_force_store_value_callback_params_2():
|
def test_force_store_value_callback_params_2():
|
||||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
||||||
descr = OptionDescription("int", "", [b])
|
descr = OptionDescription("int", "", [b])
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', 2)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||||
|
|
||||||
|
|
||||||
def test_force_store_value_callback_params_with_opt():
|
def test_force_store_value_callback_params_with_opt():
|
||||||
|
@ -235,4 +235,4 @@ def test_force_store_value_callback_params_with_opt():
|
||||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
||||||
descr = OptionDescription("int", "", [a, b])
|
descr = OptionDescription("int", "", [a, b])
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
assert conf.cfgimpl_get_values()._p_.get_modified_values() == {'int': ('forced', 2)}
|
assert conf.cfgimpl_get_values().get_modified_values() == {'int': ('forced', 2)}
|
||||||
|
|
|
@ -14,38 +14,6 @@ def a_func():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
#def test_option_comparison():
|
|
||||||
# "compare :class:`tiramisu.option.BoolOption`"
|
|
||||||
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
|
||||||
# dummy2 = BoolOption('dummy2', 'doc dummy')
|
|
||||||
# dummy3 = BoolOption('dummy1', 'doc dummy')
|
|
||||||
# assert dummy1 != dummy2
|
|
||||||
# assert dummy1 == dummy3
|
|
||||||
|
|
||||||
|
|
||||||
#def test_option_comparison_obj():
|
|
||||||
# "compare :class:`tiramisu.option.IntOption`"
|
|
||||||
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
|
||||||
# dummy2 = IntOption('dummy1', 'doc dummy')
|
|
||||||
# assert dummy1 != dummy2
|
|
||||||
|
|
||||||
|
|
||||||
#def test_option_comparison_advanced():
|
|
||||||
# dummy1 = BoolOption('dummy1', 'doc dummy')
|
|
||||||
# dummy2 = BoolOption('dummy1', 'doc dummy')
|
|
||||||
# dummy3 = BoolOption('dummy1', 'doc dummy', None)
|
|
||||||
# dummy4 = BoolOption('dummy1', 'doc dummy', True)
|
|
||||||
# dummy5 = BoolOption('dummy1', 'doc dummy', multi=True)
|
|
||||||
# dummy6 = BoolOption('dummy1', 'doc dummy', properties=tuple())
|
|
||||||
# dummy7 = BoolOption('dummy1', 'doc dummy', properties=tuple('new',))
|
|
||||||
# assert dummy1 == dummy2
|
|
||||||
# assert dummy1 == dummy3
|
|
||||||
# assert dummy1 != dummy4
|
|
||||||
# assert dummy1 != dummy5
|
|
||||||
# assert dummy1 == dummy6
|
|
||||||
# assert dummy1 != dummy7
|
|
||||||
|
|
||||||
|
|
||||||
def test_option_valid_name():
|
def test_option_valid_name():
|
||||||
IntOption('test', '')
|
IntOption('test', '')
|
||||||
raises(ValueError, 'IntOption(1, "")')
|
raises(ValueError, 'IntOption(1, "")')
|
||||||
|
@ -62,61 +30,61 @@ def test_option_with_callback():
|
||||||
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
|
||||||
|
|
||||||
|
|
||||||
#def test_option_get_information():
|
def test_option_get_information():
|
||||||
# description = "it's ok"
|
description = "it's ok"
|
||||||
# string = 'some informations'
|
string = 'some informations'
|
||||||
# i = IntOption('test', description)
|
i = IntOption('test', description)
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
# i.impl_set_information('info', string)
|
i.impl_set_information('info', string)
|
||||||
|
assert i.impl_get_information('info') == string
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||||
|
assert i.impl_get_information('doc') == description
|
||||||
|
assert i.impl_getdoc() == description
|
||||||
|
|
||||||
|
|
||||||
|
def test_option_get_information_config():
|
||||||
|
description = "it's ok"
|
||||||
|
string = 'some informations'
|
||||||
|
string
|
||||||
|
i = IntOption('test', description)
|
||||||
|
od = OptionDescription('od', '', [i])
|
||||||
|
Config(od)
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
raises(AttributeError, "i.impl_set_information('info', string)")
|
||||||
# assert i.impl_get_information('info') == string
|
# assert i.impl_get_information('info') == string
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
# assert i.impl_get_information('noinfo', 'default') == 'default'
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||||
# assert i.impl_get_information('doc') == description
|
assert i.impl_get_information('doc') == description
|
||||||
# assert i.impl_getdoc() == description
|
assert i.impl_getdoc() == description
|
||||||
#
|
|
||||||
#
|
|
||||||
#def test_option_get_information_config():
|
def test_option_get_information_config2():
|
||||||
# description = "it's ok"
|
description = "it's ok"
|
||||||
# string = 'some informations'
|
string = 'some informations'
|
||||||
# string
|
i = IntOption('test', description)
|
||||||
# i = IntOption('test', description)
|
i.impl_set_information('info', string)
|
||||||
# od = OptionDescription('od', '', [i])
|
od = OptionDescription('od', '', [i])
|
||||||
# Config(od)
|
Config(od)
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
# raises(AttributeError, "i.impl_set_information('info', string)")
|
raises(AttributeError, "i.impl_set_information('info', 'hello')")
|
||||||
## assert i.impl_get_information('info') == string
|
assert i.impl_get_information('info') == string
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
# assert i.impl_get_information('noinfo', 'default') == 'default'
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||||
# assert i.impl_get_information('doc') == description
|
assert i.impl_get_information('doc') == description
|
||||||
# assert i.impl_getdoc() == description
|
assert i.impl_getdoc() == description
|
||||||
#
|
|
||||||
#
|
|
||||||
#def test_option_get_information_config2():
|
def test_optiondescription_get_information():
|
||||||
# description = "it's ok"
|
description = "it's ok"
|
||||||
# string = 'some informations'
|
string = 'some informations'
|
||||||
# i = IntOption('test', description)
|
o = OptionDescription('test', description, [])
|
||||||
# i.impl_set_information('info', string)
|
o.impl_set_information('info', string)
|
||||||
# od = OptionDescription('od', '', [i])
|
assert o.impl_get_information('info') == string
|
||||||
# Config(od)
|
raises(ValueError, "o.impl_get_information('noinfo')")
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
assert o.impl_get_information('noinfo', 'default') == 'default'
|
||||||
# raises(AttributeError, "i.impl_set_information('info', 'hello')")
|
assert o.impl_get_information('doc') == description
|
||||||
# assert i.impl_get_information('info') == string
|
assert o.impl_getdoc() == description
|
||||||
# raises(ValueError, "i.impl_get_information('noinfo')")
|
|
||||||
# assert i.impl_get_information('noinfo', 'default') == 'default'
|
|
||||||
# assert i.impl_get_information('doc') == description
|
|
||||||
# assert i.impl_getdoc() == description
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#def test_optiondescription_get_information():
|
|
||||||
# description = "it's ok"
|
|
||||||
# string = 'some informations'
|
|
||||||
# o = OptionDescription('test', description, [])
|
|
||||||
# o.impl_set_information('info', string)
|
|
||||||
# assert o.impl_get_information('info') == string
|
|
||||||
# raises(ValueError, "o.impl_get_information('noinfo')")
|
|
||||||
# assert o.impl_get_information('noinfo', 'default') == 'default'
|
|
||||||
# assert o.impl_get_information('doc') == description
|
|
||||||
# assert o.impl_getdoc() == description
|
|
||||||
|
|
||||||
|
|
||||||
def test_option_multi():
|
def test_option_multi():
|
||||||
|
|
|
@ -647,3 +647,19 @@ def test_multi_master_default_slave():
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||||
cfg.cfgimpl_reset_cache()
|
cfg.cfgimpl_reset_cache()
|
||||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.1']
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.1']
|
||||||
|
|
||||||
|
|
||||||
|
def test_groups_with_master_get_modified_value():
|
||||||
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||||
|
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
assert cfg.cfgimpl_get_values().get_modified_values() == {}
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||||
|
cfg.cfgimpl_reset_cache()
|
||||||
|
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',))}
|
||||||
|
cfg.ip_admin_eth0.netmask_admin_eth0 = ['255.255.255.255']
|
||||||
|
assert cfg.cfgimpl_get_values().get_modified_values() == {'ip_admin_eth0.ip_admin_eth0': ('user', ('192.168.1.1',)), 'ip_admin_eth0.netmask_admin_eth0': ({'0': 'user'}, {'0': '255.255.255.255'})}
|
||||||
|
|
|
@ -29,6 +29,8 @@ def display_list(lst, separator='and'):
|
||||||
ret = lst[0]
|
ret = lst[0]
|
||||||
if isinstance(ret, unicode):
|
if isinstance(ret, unicode):
|
||||||
ret = ret.encode('utf8')
|
ret = ret.encode('utf8')
|
||||||
|
if not isinstance(ret, str):
|
||||||
|
ret = str(ret)
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
lst_ = []
|
lst_ = []
|
||||||
|
@ -41,6 +43,8 @@ def display_list(lst, separator='and'):
|
||||||
last = lst[-1]
|
last = lst[-1]
|
||||||
if isinstance(last, unicode):
|
if isinstance(last, unicode):
|
||||||
last = last.encode('utf8')
|
last = last.encode('utf8')
|
||||||
|
if not isinstance(last, str):
|
||||||
|
last = str(last)
|
||||||
return ', '.join(lst_) + _(' {} ').format(separator) + last
|
return ', '.join(lst_) + _(' {} ').format(separator) + last
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
""
|
""
|
||||||
# Copyright (C) 2014 Team tiramisu (see AUTHORS for all contributors)
|
# Copyright (C) 2014-2017 Team tiramisu (see AUTHORS for all contributors)
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,7 +23,7 @@ from ...setting import undefined
|
||||||
from ...error import ConfigError
|
from ...error import ConfigError
|
||||||
static_tuple = tuple()
|
static_tuple = tuple()
|
||||||
static_set = frozenset()
|
static_set = frozenset()
|
||||||
if sys.version_info[0] >= 3: # pragma: optional cover
|
if sys.version_info[0] >= 3: # pragma: no cover
|
||||||
xrange = range
|
xrange = range
|
||||||
|
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ class StorageBase(object):
|
||||||
self._opt = opt
|
self._opt = opt
|
||||||
|
|
||||||
def _is_string(self, infos):
|
def _is_string(self, infos):
|
||||||
if sys.version_info[0] >= 3: # pragma: optional cover
|
if sys.version_info[0] >= 3: # pragma: no cover
|
||||||
return isinstance(infos, str)
|
return isinstance(infos, str)
|
||||||
else:
|
else:
|
||||||
return isinstance(infos, str) or isinstance(infos, unicode)
|
return isinstance(infos, str) or isinstance(infos, unicode)
|
||||||
|
@ -424,7 +424,7 @@ class StorageOptionDescription(StorageBase):
|
||||||
raise AttributeError(_('no option {0} found').format(opt))
|
raise AttributeError(_('no option {0} found').format(opt))
|
||||||
return self._cache_paths[1][self._cache_paths[0].index(opt)]
|
return self._cache_paths[1][self._cache_paths[0].index(opt)]
|
||||||
|
|
||||||
def impl_get_group_type(self): # pragma: optional cover
|
def impl_get_group_type(self):
|
||||||
return self._group_type
|
return self._group_type
|
||||||
|
|
||||||
def impl_build_cache_option(self, _currpath=None, cache_path=None,
|
def impl_build_cache_option(self, _currpath=None, cache_path=None,
|
||||||
|
@ -467,7 +467,7 @@ class StorageOptionDescription(StorageBase):
|
||||||
if dynopt == subopt:
|
if dynopt == subopt:
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found:
|
if not found: # pragma: no cover
|
||||||
raise ConfigError(_('cannot find dynpath'))
|
raise ConfigError(_('cannot find dynpath'))
|
||||||
subpath = subpath + suffix
|
subpath = subpath + suffix
|
||||||
for slength in xrange(length, len(spath)):
|
for slength in xrange(length, len(spath)):
|
||||||
|
@ -523,7 +523,7 @@ class StorageOptionDescription(StorageBase):
|
||||||
return _filter_by_name(path, option)
|
return _filter_by_name(path, option)
|
||||||
|
|
||||||
opts, paths = self._cache_paths
|
opts, paths = self._cache_paths
|
||||||
for index in range(0, len(paths)):
|
for index in xrange(0, len(paths)):
|
||||||
option = opts[index]
|
option = opts[index]
|
||||||
if option.impl_is_optiondescription():
|
if option.impl_is_optiondescription():
|
||||||
continue
|
continue
|
||||||
|
@ -556,7 +556,7 @@ class StorageOptionDescription(StorageBase):
|
||||||
def _getattr(self, name, suffix=undefined, context=undefined, dyn=True):
|
def _getattr(self, name, suffix=undefined, context=undefined, dyn=True):
|
||||||
error = False
|
error = False
|
||||||
if suffix is not undefined:
|
if suffix is not undefined:
|
||||||
if undefined in [suffix, context]: # pragma: optional cover
|
if undefined in [suffix, context]: # pragma: no cover
|
||||||
raise ConfigError(_("suffix and context needed if "
|
raise ConfigError(_("suffix and context needed if "
|
||||||
"it's a dyn option"))
|
"it's a dyn option"))
|
||||||
if name.endswith(suffix):
|
if name.endswith(suffix):
|
||||||
|
|
|
@ -35,9 +35,6 @@ class Values(Cache):
|
||||||
def getsession(self):
|
def getsession(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def delsession(self, session):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _setvalue_info(self, nb, idx, value, values, index, vidx):
|
def _setvalue_info(self, nb, idx, value, values, index, vidx):
|
||||||
lst = list(self._values[nb])
|
lst = list(self._values[nb])
|
||||||
if idx is None:
|
if idx is None:
|
||||||
|
@ -82,8 +79,6 @@ class Values(Cache):
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = tuple(value)
|
value = tuple(value)
|
||||||
vidx = self._setvalue_info(2, idx, value, values, index, vidx)
|
vidx = self._setvalue_info(2, idx, value, values, index, vidx)
|
||||||
if isinstance(value, list):
|
|
||||||
value = tuple(value)
|
|
||||||
self._setvalue_info(3, idx, owner, values, index, vidx)
|
self._setvalue_info(3, idx, owner, values, index, vidx)
|
||||||
self._values = tuple(values)
|
self._values = tuple(values)
|
||||||
|
|
||||||
|
@ -183,32 +178,20 @@ class Values(Cache):
|
||||||
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
|
||||||
"""
|
"""
|
||||||
if path in self._values[0]:
|
if path in self._values[0]:
|
||||||
idx = self._values[0].index(path)
|
path_idx = self._values[0].index(path)
|
||||||
if isinstance(self._values[1][idx], tuple):
|
indexes = self._values[1][path_idx]
|
||||||
if index is None:
|
if indexes is None:
|
||||||
raise ValueError('index is mandatory')
|
if index is not None: # pragma: no cover
|
||||||
elif index is not None:
|
raise ValueError('index is forbidden')
|
||||||
raise ValueError('index is forbidden')
|
value = self._values[nb][path_idx]
|
||||||
|
|
||||||
if self._values[1][idx] is None:
|
|
||||||
if index is None:
|
|
||||||
value = self._values[nb][idx]
|
|
||||||
else:
|
|
||||||
value = self._values[nb][idx][index]
|
|
||||||
else:
|
else:
|
||||||
if index is not None:
|
if index is None: # pragma: no cover
|
||||||
if index in self._values[1][idx]:
|
raise ValueError('index is mandatory')
|
||||||
subidx = self._values[1][idx].index(index)
|
if index in indexes:
|
||||||
value = self._values[nb][idx][subidx]
|
subidx = indexes.index(index)
|
||||||
else:
|
value = self._values[nb][path_idx][subidx]
|
||||||
value = undefined
|
|
||||||
else:
|
else:
|
||||||
value = []
|
value = undefined
|
||||||
for i in xrange(0, max(self._values[1][idx])):
|
|
||||||
if i in self._values[1][idx]:
|
|
||||||
value.append(self._values[nb][idx][self._values[1][idx].index(i)])
|
|
||||||
else:
|
|
||||||
value.append(undefined)
|
|
||||||
else:
|
else:
|
||||||
value = undefined
|
value = undefined
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
|
|
|
@ -19,7 +19,7 @@ from ..setting import owners
|
||||||
|
|
||||||
|
|
||||||
class SerializeObject(object):
|
class SerializeObject(object):
|
||||||
def __getstate__(self):
|
def __getstate__(self): # pragma: no cover
|
||||||
ret = {}
|
ret = {}
|
||||||
for key in dir(self):
|
for key in dir(self):
|
||||||
if not key.startswith('__'):
|
if not key.startswith('__'):
|
||||||
|
@ -53,7 +53,7 @@ class Cache(object):
|
||||||
str_owner = []
|
str_owner = []
|
||||||
_value.append(value[2])
|
_value.append(value[2])
|
||||||
for owner in value[3]:
|
for owner in value[3]:
|
||||||
if isinstance(owner, list):
|
if isinstance(owner, list): # pragma: no cover
|
||||||
str_owners = []
|
str_owners = []
|
||||||
for subowner in owner:
|
for subowner in owner:
|
||||||
str_owners.append(str(subowner))
|
str_owners.append(str(subowner))
|
||||||
|
@ -64,7 +64,7 @@ class Cache(object):
|
||||||
states[slot] = _value
|
states[slot] = _value
|
||||||
else:
|
else:
|
||||||
states[slot] = value
|
states[slot] = value
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
pass
|
pass
|
||||||
return states
|
return states
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class Cache(object):
|
||||||
def convert_owner(owner):
|
def convert_owner(owner):
|
||||||
try:
|
try:
|
||||||
owner = getattr(owners, owner)
|
owner = getattr(owners, owner)
|
||||||
except AttributeError:
|
except AttributeError: # pragma: no cover
|
||||||
owners.addowner(owner)
|
owners.addowner(owner)
|
||||||
owner = getattr(owners, owner)
|
owner = getattr(owners, owner)
|
||||||
return owner
|
return owner
|
||||||
|
@ -86,7 +86,7 @@ class Cache(object):
|
||||||
_value.append(value[2])
|
_value.append(value[2])
|
||||||
obj_owner = []
|
obj_owner = []
|
||||||
for owner in value[3]:
|
for owner in value[3]:
|
||||||
if isinstance(owner, list):
|
if isinstance(owner, list): # pragma: no cover
|
||||||
obj_owners = []
|
obj_owners = []
|
||||||
for subowner in owner:
|
for subowner in owner:
|
||||||
obj_owners.append(convert_owner(subowner))
|
obj_owners.append(convert_owner(subowner))
|
||||||
|
@ -104,7 +104,7 @@ class Cache(object):
|
||||||
value, created = self._cache[path][index]
|
value, created = self._cache[path][index]
|
||||||
if created is None or exp <= created:
|
if created is None or exp <= created:
|
||||||
return True, value
|
return True, value
|
||||||
return False, None
|
return False, None # pragma: no cover
|
||||||
|
|
||||||
def hascache(self, path, index):
|
def hascache(self, path, index):
|
||||||
""" path is in the cache
|
""" path is in the cache
|
||||||
|
|
Loading…
Reference in New Issue