coverage
This commit is contained in:
@ -49,7 +49,8 @@ class BroadcastOption(Option):
|
||||
current_opt,
|
||||
opts,
|
||||
vals,
|
||||
warnings_only):
|
||||
warnings_only,
|
||||
context):
|
||||
if len(vals) != 3:
|
||||
raise ConfigError(_('invalid len for vals'))
|
||||
if None in vals:
|
||||
|
@ -85,7 +85,6 @@ class ChoiceOption(Option):
|
||||
current_opt=undefined):
|
||||
if current_opt is undefined:
|
||||
current_opt = self
|
||||
#FIXME cache? but in context...
|
||||
values = self._choice_values
|
||||
if isinstance(values, FunctionType):
|
||||
if option_bag is undefined:
|
||||
|
@ -101,7 +101,10 @@ class IPOption(Option):
|
||||
current_opt,
|
||||
opts,
|
||||
vals,
|
||||
warnings_only):
|
||||
warnings_only,
|
||||
context):
|
||||
if len(vals) != 3 and context is undefined:
|
||||
raise ConfigError(_('ip_network needs an IP, a network and a netmask'))
|
||||
if len(vals) != 3 or None in vals:
|
||||
return
|
||||
ip, network, netmask = vals
|
||||
@ -117,4 +120,5 @@ class IPOption(Option):
|
||||
opts[2]._cons_ip_netmask(current_opt,
|
||||
(opts[2], opts[0]),
|
||||
(netmask, ip),
|
||||
warnings_only)
|
||||
warnings_only,
|
||||
context)
|
||||
|
@ -50,9 +50,12 @@ class NetmaskOption(Option):
|
||||
current_opt,
|
||||
opts,
|
||||
vals,
|
||||
warnings_only):
|
||||
warnings_only,
|
||||
context):
|
||||
#opts must be (netmask, network) options
|
||||
if len(vals) != 2 or None in vals:
|
||||
if context is undefined and len(vals) != 2:
|
||||
raise ConfigError(_('network_netmask needs a network and a netmask'))
|
||||
if None in vals or len(vals) != 2:
|
||||
return
|
||||
return self.__cons_netmask(current_opt,
|
||||
opts,
|
||||
@ -66,9 +69,12 @@ class NetmaskOption(Option):
|
||||
current_opt,
|
||||
opts,
|
||||
vals,
|
||||
warnings_only):
|
||||
warnings_only,
|
||||
context):
|
||||
#opts must be (netmask, ip) options
|
||||
if len(vals) != 2 or None in vals:
|
||||
if context is undefined and len(vals) != 2:
|
||||
raise ConfigError(_('ip_netmask needs an IP and a netmask'))
|
||||
if None in vals or len(vals) != 2:
|
||||
return
|
||||
self.__cons_netmask(current_opt,
|
||||
opts,
|
||||
@ -86,8 +92,6 @@ class NetmaskOption(Option):
|
||||
make_net,
|
||||
warnings_only,
|
||||
typ):
|
||||
if len(opts) != 2:
|
||||
raise ConfigError(_('invalid len for opts'))
|
||||
msg = None
|
||||
try:
|
||||
ip = IP('{0}/{1}'.format(val_ipnetwork, val_netmask), make_net=make_net)
|
||||
@ -99,7 +103,7 @@ class NetmaskOption(Option):
|
||||
msg = _('this is a network with netmask "{0}" ("{1}")')
|
||||
else:
|
||||
msg = _('this is a network with {2} "{0}" ("{1}")')
|
||||
if ip.broadcast() == val_ip:
|
||||
elif ip.broadcast() == val_ip:
|
||||
if current_opt == opts[1]:
|
||||
msg = _('this is a broadcast with netmask "{0}" ("{1}")')
|
||||
else:
|
||||
|
@ -207,8 +207,9 @@ class Option(OnlyOption):
|
||||
return
|
||||
|
||||
def _is_not_unique(value):
|
||||
#FIXME pourquoi la longueur doit etre egal ?
|
||||
if check_error and self.impl_is_unique() and len(set(value)) != len(value):
|
||||
# if set(value) has not same length than value
|
||||
if check_error and self.impl_is_unique() and \
|
||||
len(set(value)) != len(value):
|
||||
for idx, val in enumerate(value):
|
||||
if val in value[idx+1:]:
|
||||
raise ValueError(_('invalid value "{}", this value is already in "{}"'
|
||||
@ -243,7 +244,6 @@ class Option(OnlyOption):
|
||||
if isinstance(_value, list): # pragma: no cover
|
||||
raise ValueError(_('which must not be a list').format(_value,
|
||||
self.impl_get_display_name()))
|
||||
#FIXME a revoir ...
|
||||
if _value is not None:
|
||||
if check_error:
|
||||
# option validation
|
||||
@ -271,8 +271,6 @@ class Option(OnlyOption):
|
||||
self.__class__.__name__, 0)
|
||||
else:
|
||||
raise err
|
||||
#if is_multi is None:
|
||||
# is_multi = self.impl_is_multi()
|
||||
try:
|
||||
val = value
|
||||
if not self.impl_is_multi():
|
||||
@ -332,8 +330,6 @@ class Option(OnlyOption):
|
||||
return False
|
||||
|
||||
def impl_is_master_slaves(self, type_='both'):
|
||||
"""FIXME
|
||||
"""
|
||||
master_slaves = self.impl_get_master_slaves()
|
||||
if master_slaves is not None:
|
||||
if type_ in ('both', 'master') and \
|
||||
@ -654,7 +650,8 @@ class Option(OnlyOption):
|
||||
getattr(self, func)(current_opt,
|
||||
all_cons_opts,
|
||||
values,
|
||||
warnings_only)
|
||||
warnings_only,
|
||||
context)
|
||||
except ValueError as err:
|
||||
if warnings_only:
|
||||
msg = _('attention, "{0}" could be an invalid {1} for "{2}", {3}'
|
||||
@ -672,7 +669,8 @@ class Option(OnlyOption):
|
||||
current_opt,
|
||||
opts,
|
||||
vals,
|
||||
warnings_only):
|
||||
warnings_only,
|
||||
context):
|
||||
equal = []
|
||||
is_current = False
|
||||
for idx_inf, val_inf in enumerate(vals):
|
||||
|
@ -74,6 +74,15 @@ class CacheOptionDescription(BaseOption):
|
||||
if not option.impl_is_symlinkoption():
|
||||
properties = option.impl_getproperties()
|
||||
if 'force_store_value' in properties:
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
# problem with index
|
||||
raise ConfigError(_('the slave "{0}" cannot have '
|
||||
'"force_store_value" property').format(
|
||||
option.impl_get_display_name()))
|
||||
if option.issubdyn():
|
||||
raise ConfigError(_('the dynoption "{0}" cannot have '
|
||||
'"force_store_value" property').format(
|
||||
option.impl_get_display_name()))
|
||||
force_store_values.append((subpath, option))
|
||||
if 'force_default_on_freeze' in properties and \
|
||||
'frozen' not in properties and \
|
||||
@ -163,15 +172,6 @@ class CacheOptionDescription(BaseOption):
|
||||
value_setted = False
|
||||
values = context.cfgimpl_get_values()
|
||||
for subpath, option in self._cache_force_store_values:
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
# problem with index
|
||||
raise ConfigError(_('the slave "{0}" cannot have '
|
||||
'"force_store_value" property').format(
|
||||
option.impl_get_display_name()))
|
||||
if option.issubdyn():
|
||||
raise ConfigError(_('the dynoption "{0}" cannot have '
|
||||
'"force_store_value" property').format(
|
||||
option.impl_get_display_name()))
|
||||
if not values._p_.hasvalue(subpath):
|
||||
config_bag = ConfigBag(context=context)
|
||||
option_bag = OptionBag()
|
||||
@ -429,12 +429,6 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
def impl_getdoc(self):
|
||||
return self.impl_get_information('doc')
|
||||
|
||||
def impl_validate(self,
|
||||
*args,
|
||||
**kwargs):
|
||||
"""usefull for OptionDescription"""
|
||||
pass
|
||||
|
||||
# ____________________________________________________________
|
||||
def impl_set_group_type(self,
|
||||
group_type):
|
||||
@ -444,8 +438,8 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
that lives in `setting.groups`
|
||||
"""
|
||||
if self._group_type != groups.default:
|
||||
raise TypeError(_('cannot change group_type if already set '
|
||||
'(old {0}, new {1})').format(self._group_type,
|
||||
raise ValueError(_('cannot change group_type if already set '
|
||||
'(old {0}, new {1})').format(self._group_type,
|
||||
group_type))
|
||||
if not isinstance(group_type, groups.GroupType):
|
||||
raise ValueError(_('group_type: {0}'
|
||||
|
@ -785,6 +785,9 @@ class Settings(object):
|
||||
def setowner(self,
|
||||
owner):
|
||||
":param owner: sets the default value for owner at the Config level"
|
||||
if owner in forbidden_owners:
|
||||
raise ValueError(_('set owner "{0}" is forbidden').format(str(owner)))
|
||||
|
||||
self._owner = owner
|
||||
|
||||
def getowner(self):
|
||||
|
@ -19,7 +19,7 @@ from time import time
|
||||
from .cache.dictionary import Cache as DictCache
|
||||
|
||||
|
||||
def _display_classname(obj):
|
||||
def _display_classname(obj): # pragma: no cover
|
||||
return(obj.__class__.__name__.lower())
|
||||
|
||||
DEBUG = False
|
||||
@ -38,12 +38,12 @@ class Cache(DictCache):
|
||||
if slave, add index
|
||||
"""
|
||||
if 'cache' in props or 'cache' in self_props:
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
|
||||
_display_classname(self),
|
||||
id(self)))
|
||||
self._setcache(path, index, val, time())
|
||||
elif DEBUG:
|
||||
elif DEBUG: # pragma: no cover
|
||||
print('not setcache {} with index {} and value {} and props {} and {} in {} ({})'.format(path,
|
||||
index,
|
||||
val,
|
||||
@ -60,7 +60,7 @@ class Cache(DictCache):
|
||||
self_props,
|
||||
type_):
|
||||
no_cache = False, None
|
||||
if 'cache' in props:
|
||||
if 'cache' in props or type_ == 'context_props':
|
||||
indexed = self._getcache(path, index)
|
||||
if indexed is None:
|
||||
return no_cache
|
||||
@ -79,22 +79,22 @@ class Cache(DictCache):
|
||||
'expire' in self_props):
|
||||
ntime = int(time())
|
||||
if timestamp + expires_time >= ntime:
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache in cache (1)', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
else:
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache expired value for path {} < {}'.format(
|
||||
timestamp + expires_time, ntime))
|
||||
# if expired, remove from cache
|
||||
#self.delcache(path)
|
||||
else:
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache in cache (2)', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
return True, value
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache {} with index {} not in {} cache'.format(path, index,
|
||||
_display_classname(self)))
|
||||
return no_cache
|
||||
@ -102,14 +102,14 @@ class Cache(DictCache):
|
||||
def delcache(self, path):
|
||||
"""remove cache for a specified path
|
||||
"""
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('delcache', path, _display_classname(self), id(self))
|
||||
if path in self._cache:
|
||||
self._delcache(path)
|
||||
|
||||
def reset_all_cache(self):
|
||||
"empty the cache"
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('reset_all_cache', _display_classname(self), id(self))
|
||||
self._reset_all_cache()
|
||||
|
||||
@ -118,6 +118,6 @@ class Cache(DictCache):
|
||||
please only use it in test purpose
|
||||
example: {'path1': {'index1': ('value1', 'time1')}, 'path2': {'index2': ('value2', 'time2', )}}
|
||||
"""
|
||||
if DEBUG:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('get_chached {} for {} ({})'.format(self._cache, _display_classname(self), id(self)))
|
||||
return self._get_cached()
|
||||
|
@ -109,19 +109,11 @@ class Values(object):
|
||||
owners.default,
|
||||
index=_index,
|
||||
with_value=True)
|
||||
|
||||
if owner != owners.default:
|
||||
if owner != owners.default and not ('frozen' in option_bag.properties and \
|
||||
'force_default_on_freeze' in option_bag.properties):
|
||||
# if a value is store in storage, check if not frozen + force_default_on_freeze
|
||||
# if frozen + force_default_on_freeze => force default value
|
||||
if not ('frozen' in option_bag.properties and \
|
||||
'force_default_on_freeze' in option_bag.properties):
|
||||
if index is not None and not is_slave:
|
||||
if len(value) > index:
|
||||
return value[index]
|
||||
#value is smaller than expected
|
||||
#so return default value
|
||||
else:
|
||||
return value
|
||||
return value
|
||||
return self.getdefaultvalue(option_bag)
|
||||
|
||||
def getdefaultvalue(self,
|
||||
@ -415,7 +407,7 @@ class Values(object):
|
||||
raise ConfigError(_("can't set owner for the symlinkoption \"{}\""
|
||||
"").format(opt.impl_get_display_name()))
|
||||
if owner in forbidden_owners:
|
||||
raise ConfigError(_('set owner "{0}" is forbidden').format(str(owner)))
|
||||
raise ValueError(_('set owner "{0}" is forbidden').format(str(owner)))
|
||||
|
||||
if not self._p_.hasvalue(option_bag.path):
|
||||
raise ConfigError(_('no value for {0} cannot change owner to {1}'
|
||||
|
Reference in New Issue
Block a user