Commit 0a6c28bc authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add VariationDivergenceTester and remove DictDivergenceTester.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31390 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5c8bbf61
...@@ -33,7 +33,7 @@ from Products.ERP5.Document.Predicate import Predicate ...@@ -33,7 +33,7 @@ from Products.ERP5.Document.Predicate import Predicate
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5.mixin.divergence_tester import DivergenceTesterMixin from Products.ERP5.mixin.divergence_tester import DivergenceTesterMixin
class DictDivergenceTester(Predicate, DivergenceTesterMixin): class VariationDivergenceTester(Predicate, DivergenceTesterMixin):
""" """
The purpose of this divergence tester is to check the The purpose of this divergence tester is to check the
consistency between delivery movement and simulation movement consistency between delivery movement and simulation movement
...@@ -59,13 +59,13 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin): ...@@ -59,13 +59,13 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin):
# Declarative interfaces # Declarative interfaces
zope.interface.implements( interfaces.IDivergenceTester, ) zope.interface.implements( interfaces.IDivergenceTester, )
def _compare(self, prevision_movement, decision_movement): def _compare(self, prevision_movement, decision_movement):
""" """
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)
""" """
tested_property = self.getTestedProperty() for tested_property in ('variation_category_list',
'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)
...@@ -73,9 +73,15 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin): ...@@ -73,9 +73,15 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin):
decision_value = decision_movement.getProperty(tested_property) decision_value = decision_movement.getProperty(tested_property)
prevision_value = prevision_movement.getProperty(tested_property) prevision_value = prevision_movement.getProperty(tested_property)
# XXX do we have configurable parameter for this divergence tester ? if isinstance(prevision_value, (list, tuple)):
# like ambiguity... result = sorted(decision_value) == sorted(prevision_value)
if sorted(decision_value.items()) != sorted(prevision_value.items()): elif isinstance(prevision_value, dict):
result = sorted(decision_value.items()) == \
sorted(prevision_value.items())
else:
# should not happen
raise AttributeError, 'prevision and decision values of this divergence tester should be list, tuple or dict.'
if not result:
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.',
...@@ -91,9 +97,12 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin): ...@@ -91,9 +97,12 @@ class DictDivergenceTester(Predicate, DivergenceTesterMixin):
decision_movement -- a delivery movement (decision) decision_movement -- a delivery movement (decision)
""" """
tested_property = self.getTestedProperty() property_dict = {}
for tested_property in ('variation_category_list',
'variation_property_dict'):
prevision_value = prevision_movement.getProperty(tested_property) prevision_value = prevision_movement.getProperty(tested_property)
return {tested_property:prevision_value} property_dict[tested_property] = prevision_value
return property_dict
def accept(self, simulation_movement): def accept(self, simulation_movement):
""" """
......
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