Commit 53475de1 authored by Arnaud Fontaine's avatar Arnaud Fontaine

simulation: Variation Equivalence Tester tested property name should not be hardcoded.

Instead, define default values if not set (same as previously hardcoded
ones) and get the value(s) define on the Tester instead as we may want
to check only variation_category_list and not variation_property_dict
for example...

Followup of: "simulation: improve equivalence testers explanations messages".
parent 2dff3124
...@@ -37,14 +37,17 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -37,14 +37,17 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
consistency between delivery movement and simulation movement consistency between delivery movement and simulation movement
for a specific property. for a specific property.
""" """
meta_type = 'ERP5 Dict Equivalence Tester' meta_type = 'ERP5 Variation Divergence Tester'
portal_type = 'Dict Equivalence Tester' portal_type = 'Variation Divergence Tester'
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
tested_property = ('variation_category_list',
'variation_property_dict')
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject , PropertySheet.XMLObject
...@@ -59,8 +62,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -59,8 +62,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
If prevision_movement and decision_movement don't match, it returns a If prevision_movement and decision_movement don't match, it returns a
list : (prevision_value, decision_value, message, mapping) list : (prevision_value, decision_value, message, mapping)
""" """
for tested_property in ('variation_category_list', for tested_property_index, tested_property in enumerate(self.getTestedPropertyList()):
'variation_property_dict'):
if getattr(decision_movement, 'isPropertyRecorded', if getattr(decision_movement, 'isPropertyRecorded',
lambda x:False)(tested_property): lambda x:False)(tested_property):
decision_value = decision_movement.getRecordedProperty(tested_property) decision_value = decision_movement.getRecordedProperty(tested_property)
...@@ -79,15 +81,12 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -79,15 +81,12 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
# should not happen # should not happen
raise AttributeError, 'prevision and decision values of this divergence tester should be list, tuple or dict.' raise AttributeError, 'prevision and decision values of this divergence tester should be list, tuple or dict.'
if not result: if not result:
property_name = tested_property
try: try:
# Get the property label to display to user
property_title_index = self.getTestedPropertyList().index(tested_property)
# XXX We should use "getTranslatedTestedPropertyTitleList", but it seems to # XXX We should use "getTranslatedTestedPropertyTitleList", but it seems to
# not exist for accessors having multiple possible values # not exist for accessors having multiple possible values
property_name = self.getTestedPropertyTitleList()[property_title_index] property_name = self.getTestedPropertyTitleList()[tested_property_index]
pass except IndexError:
except (ValueError, IndexError): property_name = tested_property
return ( return (
prevision_value, decision_value, prevision_value, decision_value,
'The value of ${property_name} is different between decision and prevision.', 'The value of ${property_name} is different between decision and prevision.',
...@@ -108,8 +107,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -108,8 +107,7 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
the recorded properties instead of the native ones. the recorded properties instead of the native ones.
""" """
value_list = [] value_list = []
for tested_property in ('variation_category_list', for tested_property in self.getTestedPropertyList():
'variation_property_dict'):
if movement.isPropertyRecorded(tested_property): if movement.isPropertyRecorded(tested_property):
value_list.append(movement.getRecordedProperty(tested_property)) value_list.append(movement.getRecordedProperty(tested_property))
else: else:
...@@ -130,5 +128,4 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -130,5 +128,4 @@ class VariationEquivalenceTester(Predicate, EquivalenceTesterMixin):
""" """
get = self._getTestedPropertyValue get = self._getTestedPropertyValue
return {tested_property: get(prevision_movement, tested_property) return {tested_property: get(prevision_movement, tested_property)
for tested_property in ('variation_category_list', for tested_property in self.getTestedPropertyList()}
'variation_property_dict')}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment