This commit is contained in:
2017-11-20 17:01:36 +01:00
parent 5d1be8a11a
commit 119ca85041
11 changed files with 1141 additions and 1199 deletions

View File

@ -220,16 +220,12 @@ def _autocheck_set_value(api, path, **kwargs):
submulti_ = api.unrestraint.option(path).option.issubmulti()
ismaster = api.unrestraint.option(path).option.ismaster()
isslave = api.unrestraint.option(path).option.isslave()
# empty_value = _getdefault(api, path, multi, isslave, submulti_)
if not multi:
first_value = FIRST_VALUE
# second_value = SECOND_VALUE
elif submulti_ is False:
first_value = LIST_FIRST_VALUE
# second_value = LIST_SECOND_VALUE
else:
first_value = SUBLIST_FIRST_VALUE
# second_value = SUBLIST_SECOND_VALUE
# for slave should have an index and good length
# for master must append, not set
@ -509,7 +505,7 @@ def _getproperties(multi, isslave, kwargs):
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
return default_props, tuple(properties)
return default_props, frozenset(properties)
def _check_default_properties(api, path, kwargs, props_permissive, props):
@ -540,17 +536,6 @@ def _autocheck_property(api, path, **kwargs):
multi = api.unrestraint.option(path).option.ismulti()
isslave = api.unrestraint.option(path).option.isslave()
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isslave:
default_props = ['empty']
properties.append('empty')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
if extra_properties:
properties.extend(extra_properties)
default_props.extend(extra_properties)
default_props, properties = _getproperties(multi, isslave, kwargs)
_check_default_properties(api, path, kwargs, default_props, default_props)
@ -863,7 +848,7 @@ def autocheck_permissive(api, path, **kwargs):
def check_all(cfg, path, meta, multi, default, default_multi, **kwargs):
def check_all(cfg, path, meta, multi, default, default_multi, require, consistency, **kwargs):
if DISPLAY:
text = u' {} launch tests for {}'.format(ICON, path)
if multi is True:
@ -882,22 +867,37 @@ def check_all(cfg, path, meta, multi, default, default_multi, **kwargs):
if api.unrestraint.option(path).option.isslave():
master_path = path.rsplit('.', 1)[0] + '.master'
api.option(master_path).value.set(LIST_SECOND_VALUE)
for func in autocheck_registers:
api = getapi(cfg.duplicate())
if DISPLAY:
print(u' {} {}'.format(ICON, func.__name__))
try:
func(api, path, **kwargs)
except Exception as err:
msg = u'error in function {} for {}'.format(func.__name__, path)
if multi is True:
msg += u' as a multi'
elif multi is submulti:
msg += u' as a submulti'
if multi is True:
msg += u' with default value'
print(u'{}: {}'.format(msg, kwargs))
raise err
if not require:
requires = [False]
else:
requires = [False, True]
for req in requires:
for func in autocheck_registers:
api = getapi(cfg.duplicate())
#FIXME devrait etre dans la config ca ...
api.read_write()
ckwargs = copy(kwargs)
if req:
api.option('extraoptrequire').value.set('value')
if 'permissive' in ckwargs and not 'permissive_od' in ckwargs or \
'propertyerror' in ckwargs and not 'propertyerror_od' in ckwargs:
for to_del in ['permissive', 'propertyerror', 'extra_properties']:
if to_del in ckwargs:
del ckwargs[to_del]
if DISPLAY:
print(u' {} {}'.format(ICON, func.__name__))
try:
func(api, path, **ckwargs)
except Exception as err:
msg = u'error in function {} for {}'.format(func.__name__, path)
if multi is True:
msg += u' as a multi'
elif multi is submulti:
msg += u' as a submulti'
if multi is True:
msg += u' with default value'
print(u'{}: {}'.format(msg, ckwargs))
raise err
def check_deref(weakrefs):
@ -907,23 +907,32 @@ def check_deref(weakrefs):
assert wrf() is None
def make_conf(options, meta, multi, default, default_multi):
def make_conf(options, meta, multi, default, default_multi, require, consistency):
weakrefs = []
dyn = []
goptions = []
def make_option(path, option_infos):
#FIXME
option_type = 'str'
option_properties = []
option_requires = []
isslave = False
if option_infos is not None:
for prop in PROPERTIES:
if option_infos.get(prop, False) is True:
option_properties.append(prop)
if not require:
option_properties.append(prop)
else:
option_requires.append({'option': goptions[0], 'expected': None,
'action': prop})
isslave = option_infos.get('slave', False)
args = [path, "{}'s option".format(path)]
kwargs = {}
if option_properties != []:
kwargs['properties'] = tuple(option_properties)
if multi:
if option_requires != []:
kwargs['requires'] = option_requires
if multi and path is not 'extraoptrequire':
kwargs['multi'] = multi
if default and not submulti:
if multi is False:
@ -933,7 +942,7 @@ def make_conf(options, meta, multi, default, default_multi):
else:
value = SUBLIST_EMPTY_VALUE
kwargs['default'] = value
if default_multi:
if default_multi and path is not 'extraoptrequire':
if multi is not submulti:
value = SECOND_VALUE
else:
@ -942,6 +951,12 @@ def make_conf(options, meta, multi, default, default_multi):
tiramisu_option = OPTIONS_TYPE[option_type]['option']
obj = tiramisu_option(*args, **kwargs)
if not 'extraopt' in path and consistency:
if require:
gopt = goptions[1]
else:
gopt = goptions[0]
obj.impl_add_consistency('not_equal', gopt, warnings_only=True)
weakrefs.append(weakref.ref(obj))
return obj
@ -961,6 +976,7 @@ def make_conf(options, meta, multi, default, default_multi):
if infos.get('dyn', False) is True:
optiondescription = DynOptionDescription
kwargs['callback'] = return_list
dyn.append(path)
options = []
if 'options' in collected:
options.extend(collected['options'])
@ -978,7 +994,22 @@ def make_conf(options, meta, multi, default, default_multi):
return obj
collect_options = {}
for path, option in options.items():
if require or consistency:
noptions = OrderedDict()
if require:
noptions['extraoptrequire'] = {}
if consistency:
subpath = list(options.keys())[0]
if '.' in subpath:
subpath = subpath.rsplit('.', 1)[0] + '.'
else:
subpath = ''
noptions[subpath + 'extraoptconsistency'] = {}
noptions.update(options)
else:
noptions = options
for path, option in noptions.items():
if option is None:
continue
local_collect_options = collect_options
@ -987,8 +1018,9 @@ def make_conf(options, meta, multi, default, default_multi):
local_collect_options = local_collect_options[optiondescription]
local_collect_options['properties'].update(option.get(optiondescription, {}))
option_name = path.split('.')[-1]
path = '.'.join(path.split('.')[:-1])
local_collect_options.setdefault('options', []).append(make_option(option_name, option.get(option_name)))
obj = make_option(option_name, option.get(option_name))
goptions.append(obj)
local_collect_options.setdefault('options', []).append(obj)
rootod = make_optiondescriptions('root', collect_options)
if rootod is None:
@ -998,7 +1030,8 @@ def make_conf(options, meta, multi, default, default_multi):
if meta:
cfg = MetaConfig([cfg], session_id='metatest')
weakrefs.append(weakref.ref(cfg))
return cfg, weakrefs
del goptions
return cfg, weakrefs, dyn
DICT_PATHS = [
@ -1091,24 +1124,35 @@ def test_options(paths):
return kwargs
lpaths = list(paths.keys())
for meta in (False, True):
for default_multi in (False, True):
for default in (False, True):
for multi in (False, True, submulti):
if multi is False and default_multi:
continue
cfg, weakrefs = make_conf(paths, meta, multi, default, default_multi)
if cfg is None:
continue
if len(lpaths) == 9:
check_all(cfg, lpaths[3], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
check_all(cfg, lpaths[4], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
check_all(cfg, lpaths[5], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
check_all(cfg, lpaths[6], meta, multi, default, default_multi, **get_kwargs(lpaths[0]))
check_all(cfg, lpaths[7], meta, multi, default, default_multi, **get_kwargs(lpaths[1]))
check_all(cfg, lpaths[8], meta, multi, default, default_multi, **get_kwargs(lpaths[2]))
else:
for lpath in lpaths:
check_all(cfg, lpath, meta, multi, default, default_multi, **get_kwargs(lpath))
del cfg
check_deref(weakrefs)
meta = False
#for meta in (False, True):
for consistency in (False, True):
for require in (False, True):
for default_multi in (False, True):
for default in (False, True):
for multi in (False, True, submulti):
if multi is submulti and consistency:
continue
if multi is False and default_multi:
continue
cfg, weakrefs, dyn = make_conf(paths, meta, multi, default, default_multi, require, consistency)
if cfg is None:
continue
if dyn:
cnt = 0
idx = 0
for index, lpath in enumerate(lpaths):
if paths[lpath]:
cnt += 1
else:
check_all(cfg, lpaths[index], meta, multi, default,
default_multi, require, consistency, **get_kwargs(lpaths[idx]))
idx += 1
if idx == cnt:
idx = 0
else:
for lpath in lpaths:
check_all(cfg, lpath, meta, multi, default,
default_multi, require, consistency, **get_kwargs(lpath))
del cfg
check_deref(weakrefs)