refactor check
This commit is contained in:
parent
7d032a72b2
commit
8ed035c7ff
|
@ -305,6 +305,7 @@ class SpaceAnnotator(object):
|
||||||
self.convert_helps()
|
self.convert_helps()
|
||||||
if hasattr(self.space, 'constraints'):
|
if hasattr(self.space, 'constraints'):
|
||||||
del self.space.constraints.index
|
del self.space.constraints.index
|
||||||
|
del self.space.constraints.namespace
|
||||||
if vars(self.space.constraints):
|
if vars(self.space.constraints):
|
||||||
raise Exception('constraints again?')
|
raise Exception('constraints again?')
|
||||||
del self.space.constraints
|
del self.space.constraints
|
||||||
|
@ -766,75 +767,47 @@ class SpaceAnnotator(object):
|
||||||
values = param.text
|
values = param.text
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def filter_check(self): # pylint: disable=C0111
|
def check_check(self):
|
||||||
# valid param in check
|
|
||||||
if not hasattr(self.space, 'constraints') or not hasattr(self.space.constraints, 'check'):
|
|
||||||
return
|
|
||||||
space = self.space.constraints.check
|
|
||||||
remove_indexes = []
|
remove_indexes = []
|
||||||
for check_idx, check in enumerate(space):
|
functions = dir(self.eosfunc)
|
||||||
namespace = check.namespace
|
functions.extend(['valid_enum', 'valid_in_network', 'valid_differ'])
|
||||||
|
for check_idx, check in enumerate(self.space.constraints.check):
|
||||||
|
if not check.name in functions:
|
||||||
|
raise CreoleDictConsistencyError(_('cannot find check function {}').format(check.name))
|
||||||
if hasattr(check, 'param'):
|
if hasattr(check, 'param'):
|
||||||
param_option_indexes = []
|
param_option_indexes = []
|
||||||
for idx, param in enumerate(check.param):
|
for idx, param in enumerate(check.param):
|
||||||
if param.type not in TYPE_PARAM_CHECK:
|
if param.type not in TYPE_PARAM_CHECK:
|
||||||
raise CreoleDictConsistencyError(_('cannot use {} type as a param in check for {}').format(param.type, check.target))
|
raise CreoleDictConsistencyError(_('cannot use {} type as a param in check for {}').format(param.type, check.target))
|
||||||
if param.type == 'variable':
|
if param.type == 'variable' and not self.paths.path_is_defined(param.text):
|
||||||
try:
|
|
||||||
param.text = self.paths.get_variable_path(param.text, namespace)
|
|
||||||
except CreoleDictConsistencyError as err:
|
|
||||||
if param.optional is True:
|
if param.optional is True:
|
||||||
param_option_indexes.append(idx)
|
param_option_indexes.append(idx)
|
||||||
else:
|
else:
|
||||||
raise err
|
raise CreoleDictConsistencyError(_(f'unknown param {param.text} in check'))
|
||||||
param_option_indexes = list(set(param_option_indexes))
|
param_option_indexes = list(set(param_option_indexes))
|
||||||
param_option_indexes.sort(reverse=True)
|
param_option_indexes.sort(reverse=True)
|
||||||
for idx in param_option_indexes:
|
for idx in param_option_indexes:
|
||||||
check.param.pop(idx)
|
check.param.pop(idx)
|
||||||
if not HIGH_COMPATIBILITY and check.param == []:
|
if check.param == []:
|
||||||
remove_indexes.append(check_idx)
|
remove_indexes.append(check_idx)
|
||||||
remove_indexes.sort(reverse=True)
|
remove_indexes.sort(reverse=True)
|
||||||
for idx in remove_indexes:
|
for idx in remove_indexes:
|
||||||
del space[idx]
|
del self.space.constraints.check[idx]
|
||||||
variables = {}
|
|
||||||
for index, check in enumerate(space):
|
def check_replace_text(self):
|
||||||
|
for check_idx, check in enumerate(self.space.constraints.check):
|
||||||
|
if hasattr(check, 'param'):
|
||||||
namespace = check.namespace
|
namespace = check.namespace
|
||||||
if HIGH_COMPATIBILITY:
|
for idx, param in enumerate(check.param):
|
||||||
if not self.paths.path_is_defined(check.target):
|
if param.type == 'variable':
|
||||||
continue
|
param.text = self.paths.get_variable_path(param.text, namespace)
|
||||||
check.is_in_leadership = self.paths.get_leader(check.target) != None
|
check.is_in_leadership = self.paths.get_leader(check.target) != None
|
||||||
# let's replace the target by the path
|
# let's replace the target by the path
|
||||||
check.target = self.paths.get_variable_path(check.target, namespace)
|
check.target = self.paths.get_variable_path(check.target, namespace)
|
||||||
if check.target not in variables:
|
|
||||||
variables[check.target] = []
|
def check_valid_enum(self):
|
||||||
variables[check.target].append((index, check))
|
|
||||||
# remove check already set for a variable
|
|
||||||
remove_indexes = []
|
remove_indexes = []
|
||||||
for checks in variables.values():
|
for idx, check in enumerate(self.space.constraints.check):
|
||||||
names = {}
|
|
||||||
for idx, check in checks:
|
|
||||||
if HIGH_COMPATIBILITY and check.name == 'valid_enum':
|
|
||||||
redefine = True
|
|
||||||
else:
|
|
||||||
redefine = False
|
|
||||||
#redefine = bool(check.redefine)
|
|
||||||
if redefine and check.name in names:
|
|
||||||
remove_indexes.append(names[check.name])
|
|
||||||
del names[check.name]
|
|
||||||
names[check.name] = idx
|
|
||||||
del check.index
|
|
||||||
remove_indexes.sort(reverse=True)
|
|
||||||
for idx in remove_indexes:
|
|
||||||
del space[idx]
|
|
||||||
remove_indexes = []
|
|
||||||
functions = dir(self.eosfunc)
|
|
||||||
functions.extend(['valid_enum', 'valid_in_network', 'valid_differ'])
|
|
||||||
for idx, check in enumerate(space):
|
|
||||||
if not check.name in functions:
|
|
||||||
raise CreoleDictConsistencyError(_('cannot find check function {}').format(check.name))
|
|
||||||
#is_probe = not check.name in self.eosfunc.func_on_zephir_context
|
|
||||||
#if is_probe:
|
|
||||||
# raise CreoleDictConsistencyError(_('cannot have a check with probe function ({})').format(check.name))
|
|
||||||
if check.name == 'valid_enum':
|
if check.name == 'valid_enum':
|
||||||
proposed_value_type = False
|
proposed_value_type = False
|
||||||
remove_params = []
|
remove_params = []
|
||||||
|
@ -856,30 +829,30 @@ class SpaceAnnotator(object):
|
||||||
'for valid_enum for variable {}'
|
'for valid_enum for variable {}'
|
||||||
'').format(check.target))
|
'').format(check.target))
|
||||||
param = check.param[0]
|
param = check.param[0]
|
||||||
|
if check.target in self.valid_enums:
|
||||||
|
raise CreoleDictConsistencyError(_('valid_enum already set for {}'
|
||||||
|
'').format(check.target))
|
||||||
if proposed_value_type:
|
if proposed_value_type:
|
||||||
if param.type == 'variable':
|
if param.type == 'variable':
|
||||||
try:
|
try:
|
||||||
values = self.load_params_in_validenum(param)
|
values = self.load_params_in_validenum(param)
|
||||||
except NameError as err:
|
except NameError as err:
|
||||||
raise CreoleDictConsistencyError(_('cannot load value for variable {}: {}').format(check.target, err))
|
raise CreoleDictConsistencyError(_('cannot load value for variable {}: {}').format(check.target, err))
|
||||||
add_value = True
|
add_default_value = not check.is_in_leadership
|
||||||
if HIGH_COMPATIBILITY and check.is_in_leadership:
|
if add_default_value and values:
|
||||||
add_value = False
|
|
||||||
if add_value and values:
|
|
||||||
self.force_value[check.target] = values[0]
|
self.force_value[check.target] = values[0]
|
||||||
else:
|
else:
|
||||||
if check.target in self.valid_enums:
|
|
||||||
raise CreoleDictConsistencyError(_('valid_enum already set for {}'
|
|
||||||
'').format(check.target))
|
|
||||||
values = self.load_params_in_validenum(param)
|
values = self.load_params_in_validenum(param)
|
||||||
self.valid_enums[check.target] = {'type': param.type,
|
self.valid_enums[check.target] = {'type': param.type,
|
||||||
'values': values}
|
'values': values}
|
||||||
remove_indexes.append(idx)
|
remove_indexes.append(idx)
|
||||||
remove_indexes.sort(reverse=True)
|
remove_indexes.sort(reverse=True)
|
||||||
for idx in remove_indexes:
|
for idx in remove_indexes:
|
||||||
del space[idx]
|
del self.space.constraints.check[idx]
|
||||||
|
|
||||||
|
def check_change_warning(self):
|
||||||
#convert level to "warnings_only" and hidden to "transitive"
|
#convert level to "warnings_only" and hidden to "transitive"
|
||||||
for check in space:
|
for check in self.space.constraints.check:
|
||||||
if check.level == 'warning':
|
if check.level == 'warning':
|
||||||
check.warnings_only = True
|
check.warnings_only = True
|
||||||
else:
|
else:
|
||||||
|
@ -891,6 +864,14 @@ class SpaceAnnotator(object):
|
||||||
check.transitive = False
|
check.transitive = False
|
||||||
param.hidden = None
|
param.hidden = None
|
||||||
|
|
||||||
|
def filter_check(self): # pylint: disable=C0111
|
||||||
|
# valid param in check
|
||||||
|
if not hasattr(self.space, 'constraints') or not hasattr(self.space.constraints, 'check'):
|
||||||
|
return
|
||||||
|
self.check_check()
|
||||||
|
self.check_replace_text()
|
||||||
|
self.check_valid_enum()
|
||||||
|
self.check_change_warning()
|
||||||
if not self.space.constraints.check:
|
if not self.space.constraints.check:
|
||||||
del self.space.constraints.check
|
del self.space.constraints.check
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,8 @@ class CreoleObjSpace:
|
||||||
self.xmlreflector = XMLReflector()
|
self.xmlreflector = XMLReflector()
|
||||||
self.xmlreflector.parse_dtd(dtdfilename)
|
self.xmlreflector.parse_dtd(dtdfilename)
|
||||||
self.redefine_variables = None
|
self.redefine_variables = None
|
||||||
|
self.check_removed = None
|
||||||
|
self.condition_removed = None
|
||||||
|
|
||||||
# ['variable', 'separator', 'family']
|
# ['variable', 'separator', 'family']
|
||||||
self.forced_text_elts = set()
|
self.forced_text_elts = set()
|
||||||
|
@ -155,6 +157,8 @@ class CreoleObjSpace:
|
||||||
"""
|
"""
|
||||||
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
for xmlfile, document in self.xmlreflector.load_xml_from_folders(xmlfolders):
|
||||||
self.redefine_variables = []
|
self.redefine_variables = []
|
||||||
|
self.check_removed = []
|
||||||
|
self.condition_removed = []
|
||||||
self.xml_parse_document(document,
|
self.xml_parse_document(document,
|
||||||
self.space,
|
self.space,
|
||||||
namespace,
|
namespace,
|
||||||
|
@ -477,13 +481,18 @@ class CreoleObjSpace:
|
||||||
self.remove_check(variableobj.name)
|
self.remove_check(variableobj.name)
|
||||||
if child.attrib.get('remove_condition', False):
|
if child.attrib.get('remove_condition', False):
|
||||||
self.remove_condition(variableobj.name)
|
self.remove_condition(variableobj.name)
|
||||||
if child.tag in ['fill', 'check']:
|
if child.tag == 'fill':
|
||||||
# if variable is a redefine in current dictionary
|
# if variable is a redefine in current dictionary
|
||||||
# XXX not working with variable not in variable and in leader/followers
|
# XXX not working with variable not in variable and in leader/followers
|
||||||
variableobj.redefine = child.attrib['target'] in self.redefine_variables
|
variableobj.redefine = child.attrib['target'] in self.redefine_variables
|
||||||
if not hasattr(variableobj, 'index'):
|
if not hasattr(variableobj, 'index'):
|
||||||
variableobj.index = self.index
|
variableobj.index = self.index
|
||||||
if child.tag in ['fill', 'condition', 'check']:
|
if child.tag == 'check' and child.attrib['target'] in self.redefine_variables and child.attrib['target'] not in self.check_removed:
|
||||||
|
self.remove_check(child.attrib['target'])
|
||||||
|
self.check_removed.append(child.attrib['target'])
|
||||||
|
if child.tag == 'condition' and child.attrib['source'] in self.redefine_variables and child.attrib['source'] not in self.check_removed:
|
||||||
|
self.remove_condition(child.attrib['source'])
|
||||||
|
self.condition_removed.append(child.attrib['source'])
|
||||||
variableobj.namespace = namespace
|
variableobj.namespace = namespace
|
||||||
|
|
||||||
def fill_variableobj_path_attribute(self,
|
def fill_variableobj_path_attribute(self,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
<check name="valid_not_equal" warnings_only="False">
|
<check name="valid_not_equal" warnings_only="False">
|
||||||
<param type="variable">rougail.general.int2</param>
|
<param type="variable">rougail.general.int2</param>
|
||||||
</check>
|
</check>
|
||||||
<check name="valid_not_equal" warnings_only="False"/>
|
|
||||||
<property>normal</property>
|
<property>normal</property>
|
||||||
</variable>
|
</variable>
|
||||||
<variable doc="No change" multi="False" name="int2" type="number">
|
<variable doc="No change" multi="False" name="int2" type="number">
|
||||||
|
|
|
@ -25,12 +25,6 @@
|
||||||
<value type="string">non</value>
|
<value type="string">non</value>
|
||||||
</variable>
|
</variable>
|
||||||
<variable doc="No change" multi="False" name="mode_conteneur_actif3" type="string">
|
<variable doc="No change" multi="False" name="mode_conteneur_actif3" type="string">
|
||||||
<check name="valid_not_equal" warnings_only="False">
|
|
||||||
<param type="variable">rougail.general.mode_conteneur_actif1</param>
|
|
||||||
</check>
|
|
||||||
<check name="valid_not_equal" warnings_only="False">
|
|
||||||
<param type="variable">rougail.general.mode_conteneur_actif2</param>
|
|
||||||
</check>
|
|
||||||
<check name="valid_not_equal" warnings_only="False">
|
<check name="valid_not_equal" warnings_only="False">
|
||||||
<param type="variable">rougail.general.mode_conteneur_actif1</param>
|
<param type="variable">rougail.general.mode_conteneur_actif1</param>
|
||||||
</check>
|
</check>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<variables>
|
<variables>
|
||||||
<family name="general">
|
<family name="general">
|
||||||
<variable name="mode_conteneur_actif3" redefine="True" remove_check="True">
|
<variable name="mode_conteneur_actif3" redefine="True">
|
||||||
<value>oui</value>
|
<value>oui</value>
|
||||||
</variable>
|
</variable>
|
||||||
</family>
|
</family>
|
||||||
|
|
|
@ -29,7 +29,7 @@ for test in listdir(dico_dirs):
|
||||||
excludes = set([])
|
excludes = set([])
|
||||||
test_ok -= excludes
|
test_ok -= excludes
|
||||||
test_raise -= excludes
|
test_raise -= excludes
|
||||||
#test_ok = ['11multi_disabled_if_in_filelist']
|
#test_ok = ['10check_valid_differ_removecheck']
|
||||||
#test_raise = []
|
#test_raise = []
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue