Commits

Anonymous committed b3cad54

Bump to 1.0.2
Refecactoring out the "inspector" code that generates the string.

Comments (0)

Files changed (2)

     else:
         return ""
 
-def dict_compare(d_expected, d_received, reporter=None):
+def structure_inspector(d_expected, d_received):
+    msg = ""
+    if type(d_expected) == type(d_received):
+        msg += reportNotFoundKeysIn(d_expected,d_received,"Not In Received: ")
+        msg += reportNotFoundKeysIn(d_received,d_expected,"Not In Expected: ")
+        # report keys with different values
+        differentKeysLabelShown = False
+        if isinstance(d_expected, (list, tuple)):
+            d_expected = listToDict(d_expected)
+            d_received = listToDict(d_received)
+        for expected_key in d_expected.keys():
+            if expected_key in d_received:
+                if d_expected[expected_key] != d_received[expected_key]:
+                    if not differentKeysLabelShown:
+                        msg += "Different values in"+os.linesep
+                    msg += "'%s':  %s != %s " % (   repr(expected_key),
+                                                    repr(d_expected[expected_key]),
+                                                    repr(d_received[expected_key])) + os.linesep
+    else:
+        msg += ( "Not same type: "
+                 + repr(d_expected)+ repr(type(d_expected)) + " != "
+                 + repr(d_received)+ repr(type(d_received)) )
+    return msg
+
+def dict_compare(d_expected, d_received, reporter=None, inspector=structure_inspector):
     if cmp(d_expected,d_received)==0:
         return True
     if reporter != None:
-        msg = ""
-        if type(d_expected) == type(d_received):
-            msg += reportNotFoundKeysIn(d_expected,d_received,"Not In Received: ")
-            msg += reportNotFoundKeysIn(d_received,d_expected,"Not In Expected: ")
-            # report keys with different values
-            differentKeysLabelShown = False
-            if isinstance(d_expected, (list, tuple)):
-                d_expected = listToDict(d_expected)
-                d_received = listToDict(d_received)
-            for expected_key in d_expected.keys():
-                if expected_key in d_received:
-                    if d_expected[expected_key] != d_received[expected_key]:
-                        if not differentKeysLabelShown:
-                            msg += "Different values in"+os.linesep
-                        msg += "'%s':  %s != %s " % (   repr(expected_key),
-                                                        repr(d_expected[expected_key]),
-                                                        repr(d_received[expected_key])) + os.linesep
-        else:
-            msg += ( "Not same type: "
-                     + repr(d_expected)+ repr(type(d_expected)) + " != "
-                     + repr(d_received)+ repr(type(d_received)) )
+        msg = inspector(d_expected, d_received)
         reporter(msg)
                     
     return False
     from setuptools import setup, find_packages
 
 setup(name='dict_compare',
-      version='1.0.1',
+      version='1.0.2',
       maintainer='Agustin Villena, Marijn Vriens',
       maintainer_email="marijn+dictcompare@metronomo.cl",
       license='BSD',