some tests
This commit is contained in:
@ -19,7 +19,6 @@
|
||||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
from copy import copy
|
||||
from itertools import chain
|
||||
|
||||
|
||||
from ..i18n import _
|
||||
@ -39,8 +38,7 @@ class CacheOptionDescription(BaseOption):
|
||||
_consistencies=None,
|
||||
_consistencies_id=0,
|
||||
cache_option=None,
|
||||
force_store_values=None,
|
||||
_dependencies=None):
|
||||
force_store_values=None):
|
||||
"""validate duplicate option and set option has readonly option
|
||||
"""
|
||||
# cache_option is None only when we start to build cache
|
||||
@ -52,7 +50,6 @@ class CacheOptionDescription(BaseOption):
|
||||
_consistencies = {}
|
||||
cache_option = []
|
||||
force_store_values = []
|
||||
_dependencies = []
|
||||
else:
|
||||
init = False
|
||||
|
||||
@ -70,8 +67,7 @@ class CacheOptionDescription(BaseOption):
|
||||
_consistencies,
|
||||
_consistencies_id,
|
||||
cache_option,
|
||||
force_store_values,
|
||||
_dependencies)
|
||||
force_store_values)
|
||||
else:
|
||||
option._set_readonly()
|
||||
is_multi = option.impl_is_multi()
|
||||
@ -91,7 +87,7 @@ class CacheOptionDescription(BaseOption):
|
||||
is_masterslaves = option.impl_is_master_slaves()
|
||||
if not is_masterslaves:
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must be a master/slaves').format(
|
||||
'must be a masterslaves').format(
|
||||
option.impl_getname()))
|
||||
masterslaves = option.impl_get_master_slaves()
|
||||
for weak_opt in all_cons_opts:
|
||||
@ -103,7 +99,7 @@ class CacheOptionDescription(BaseOption):
|
||||
option.impl_getname(), opt.impl_getname()))
|
||||
elif masterslaves != opt.impl_get_master_slaves():
|
||||
raise ConfigError(_('malformed consistency option "{0}" '
|
||||
'must be in same master/slaves for "{1}"').format(
|
||||
'must be in same masterslaves as "{1}"').format(
|
||||
option.impl_getname(), opt.impl_getname()))
|
||||
_consistencies.setdefault(weak_opt,
|
||||
[]).append((_consistencies_id,
|
||||
@ -123,7 +119,7 @@ class CacheOptionDescription(BaseOption):
|
||||
#if option in require is a multi:
|
||||
# * option in require must be a master or a slave
|
||||
# * current option must be a slave (and only a slave)
|
||||
# * option in require and current option must be in same master/slaves
|
||||
# * option in require and current option must be in same masterslaves
|
||||
for require_opt, values in require[0]:
|
||||
if require_opt.impl_is_multi():
|
||||
if is_slave is None:
|
||||
@ -132,8 +128,8 @@ class CacheOptionDescription(BaseOption):
|
||||
masterslaves = option.impl_get_master_slaves()
|
||||
if is_slave and require_opt.impl_is_master_slaves():
|
||||
if masterslaves != require_opt.impl_get_master_slaves():
|
||||
raise ValueError(_('malformed requirements option {0} '
|
||||
'must be in same master/slaves for {1}').format(
|
||||
raise ValueError(_('malformed requirements option "{0}" '
|
||||
'must be in same masterslaves for "{1}"').format(
|
||||
require_opt.impl_getname(), option.impl_getname()))
|
||||
else:
|
||||
raise ValueError(_('malformed requirements option "{0}" '
|
||||
@ -149,14 +145,12 @@ class CacheOptionDescription(BaseOption):
|
||||
self._cache_consistencies = {}
|
||||
for weak_opt, cons in _consistencies.items():
|
||||
opt = weak_opt()
|
||||
if opt not in cache_option: # pragma: optional cover
|
||||
if opt not in cache_option:
|
||||
raise ConfigError(_('consistency with option {0} '
|
||||
'which is not in Config').format(
|
||||
opt.impl_getname()))
|
||||
self._cache_consistencies[opt] = tuple(cons)
|
||||
self._cache_force_store_values = force_store_values
|
||||
if _dependencies:
|
||||
self._dependencies = tuple(_dependencies)
|
||||
self._set_readonly()
|
||||
|
||||
def impl_already_build_caches(self):
|
||||
@ -171,11 +165,11 @@ class CacheOptionDescription(BaseOption):
|
||||
for subpath, option in self._cache_force_store_values:
|
||||
if option.impl_is_master_slaves('slave'):
|
||||
# problem with index
|
||||
raise ConfigError(_('a slave ({0}) cannot have '
|
||||
'force_store_value property').format(subpath))
|
||||
raise ConfigError(_('the slave "{0}" cannot have '
|
||||
'"force_store_value" property').format(option.impl_get_display_name()))
|
||||
if option.issubdyn():
|
||||
raise ConfigError(_('a dynoption ({0}) cannot have '
|
||||
'force_store_value property').format(subpath))
|
||||
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(config=context, option=option)
|
||||
value = values.getvalue(subpath,
|
||||
@ -231,15 +225,8 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
config_bag):
|
||||
dynopt = option.getsubdyn()
|
||||
rootpath = self.impl_get_path_by_opt(dynopt)
|
||||
if rootpath == '':
|
||||
ori_index = 0
|
||||
else:
|
||||
ori_index = len(rootpath) + 1
|
||||
subpaths = option.impl_getpath(config_bag.config)[ori_index:].split('.')[:-1]
|
||||
if subpaths != ['']:
|
||||
subpaths = [rootpath] + subpaths
|
||||
else:
|
||||
subpaths = [rootpath]
|
||||
ori_index = len(rootpath) + 1
|
||||
subpaths = [rootpath] + option.impl_getpath(config_bag.config)[ori_index:].split('.')[:-1]
|
||||
for suffix in dynopt._impl_get_suffixes(config_bag):
|
||||
subpath = '.'.join([subp + suffix for subp in subpaths])
|
||||
if isinstance(option, OnlyOption):
|
||||
@ -260,13 +247,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
option):
|
||||
if isinstance(option,
|
||||
bytype):
|
||||
if byname is None:
|
||||
if option.issubdyn():
|
||||
for doption in self.build_dynoptions(option, config_bag):
|
||||
dpath = doption.impl_getname(config_bag.config)
|
||||
yield (dpath, doption)
|
||||
else:
|
||||
yield (path, option)
|
||||
return _filter_by_name(path, option)
|
||||
|
||||
def _filter_by_name(path,
|
||||
option):
|
||||
@ -276,22 +257,14 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
for doption in self.build_dynoptions(option, config_bag):
|
||||
if byname == doption.impl_getname():
|
||||
dpath = doption.impl_getpath(config_bag.config)
|
||||
yield (dpath, doption)
|
||||
break
|
||||
else:
|
||||
if byname == name:
|
||||
yield (path, option)
|
||||
return (dpath, doption)
|
||||
elif byname == name:
|
||||
return (path, option)
|
||||
|
||||
def _filter(path, option):
|
||||
generators = []
|
||||
if bytype is not None:
|
||||
generators.append(_filter_by_type(path, option))
|
||||
if byname is not None:
|
||||
generators.append(_filter_by_name(path, option))
|
||||
if len(generators) == 1:
|
||||
return generators[0]
|
||||
else:
|
||||
return chain(*generators)
|
||||
return _filter_by_type(path, option)
|
||||
return _filter_by_name(path, option)
|
||||
|
||||
opts, paths = self._cache_paths
|
||||
for index, option in enumerate(opts):
|
||||
@ -300,16 +273,9 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
path = paths[index]
|
||||
if _subpath is not None and not path.startswith(_subpath + '.'):
|
||||
continue
|
||||
if bytype == byname is None:
|
||||
if option.issubdyn():
|
||||
for doption in self.build_dynoptions(option, config_bag):
|
||||
dpath = doption.impl_getpath(config_bag.config)
|
||||
yield (dpath, doption)
|
||||
else:
|
||||
yield (dpath, option)
|
||||
else:
|
||||
for ret in _filter(path, option):
|
||||
yield ret
|
||||
ret = _filter(path, option)
|
||||
if ret:
|
||||
yield ret
|
||||
|
||||
def impl_getchild(self,
|
||||
name,
|
||||
@ -331,18 +297,10 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
|
||||
def impl_get_opt_by_path(self,
|
||||
path):
|
||||
if getattr(self, '_cache_paths', None) is None:
|
||||
raise ConfigError(_('use impl_get_opt_by_path only with root optiondescription'))
|
||||
if path not in self._cache_paths[1]:
|
||||
raise AttributeError(_('no option for path "{}"').format(path))
|
||||
return self._cache_paths[0][self._cache_paths[1].index(path)]
|
||||
|
||||
def impl_get_path_by_opt(self,
|
||||
opt):
|
||||
if getattr(self, '_cache_paths', None) is None:
|
||||
raise ConfigError(_('use impl_get_path_by_opt only with root OptionDescription'))
|
||||
if opt not in self._cache_paths[0]:
|
||||
raise AttributeError(_('no option "{}" found').format(opt))
|
||||
return self._cache_paths[1][self._cache_paths[0].index(opt)]
|
||||
|
||||
def impl_getchildren(self,
|
||||
@ -351,7 +309,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||
subpath = None
|
||||
for child in self._impl_st_getchildren():
|
||||
if dyn and child.impl_is_dynoptiondescription():
|
||||
if config_bag.config is None:
|
||||
if config_bag.config is None: # pragma: no cover
|
||||
raise ConfigError(_('need context'))
|
||||
if subpath is None:
|
||||
if config_bag.config.cfgimpl_get_description() == self:
|
||||
@ -437,7 +395,7 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
valid_child.sort()
|
||||
old = None
|
||||
for child in valid_child:
|
||||
if child == old: # pragma: optional cover
|
||||
if child == old:
|
||||
raise ConflictError(_('duplicate option name: '
|
||||
'"{0}"').format(child))
|
||||
if dynopt_names:
|
||||
@ -471,7 +429,7 @@ class OptionDescription(OptionDescriptionWalk):
|
||||
:param group_type: an instance of `GroupType` or `MasterGroupType`
|
||||
that lives in `setting.groups`
|
||||
"""
|
||||
if self._group_type != groups.default: # pragma: optional cover
|
||||
if self._group_type != groups.default:
|
||||
raise TypeError(_('cannot change group_type if already set '
|
||||
'(old {0}, new {1})').format(self._group_type,
|
||||
group_type))
|
||||
|
Reference in New Issue
Block a user