[Python-checkins] r81348 - python/branches/py3k-cdecimal/Lib/test/decimal_extended_tests/deccheck.py

stefan.krah python-checkins at python.org
Wed May 19 17:26:45 CEST 2010


Author: stefan.krah
Date: Wed May 19 17:26:45 2010
New Revision: 81348

Log:
Changes in the hash function will be implemented once
the new unified hash is committed. For now, skip known
differences.



Modified:
   python/branches/py3k-cdecimal/Lib/test/decimal_extended_tests/deccheck.py

Modified: python/branches/py3k-cdecimal/Lib/test/decimal_extended_tests/deccheck.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/decimal_extended_tests/deccheck.py	(original)
+++ python/branches/py3k-cdecimal/Lib/test/decimal_extended_tests/deccheck.py	Wed May 19 17:26:45 2010
@@ -341,6 +341,18 @@
     def __init__(self):
         pass
 
+    if py_minor >= 2:
+        def __hash__(self, result, operands):
+            c = operands[0]
+            if c.mpd.is_infinite():
+                # Hashing infinities changed in 3.2
+                return True
+            # If a Decimal instance is exactly representable as a float
+            # then (in 3.2) its hash matches that of the float.
+            f = float(c.dec)
+            if Decimal.from_float(f) == c.dec:
+                return True
+
     def default(self, result, operands):
         return False
 
@@ -349,9 +361,9 @@
 def cdec_known_disagreement(result, funcname, operands):
     return getattr(dhandler_cdec, funcname, dhandler_cdec.default)(result, operands)
 
-#dhandler_obj = dHandlerObj()
-#def obj_known_disagreement(result, funcname, operands):
-#    return getattr(dhandler_obj, funcname, dhandler_obj.default)(result, operands)
+dhandler_obj = dHandlerObj()
+def obj_known_disagreement(result, funcname, operands):
+    return getattr(dhandler_obj, funcname, dhandler_obj.default)(result, operands)
 
 
 
@@ -360,8 +372,8 @@
        result[0] and result[1] as well as the context flags have the same
        values."""
     if result[0] != result[1] or not context.assert_eq_status():
-        #if obj_known_disagreement(result, funcname, operands):
-        #    return # skip known disagreements
+        if obj_known_disagreement(result, funcname, operands):
+            return # skip known disagreements
         raise CdecException(result, funcname, operands)
 
 


More information about the Python-checkins mailing list