Commits

percious  committed ca7be4b

fixed operators so they return true unless there is a failed condition. Adding logging to the comparisons.

  • Participants
  • Parent commits 8abfedc
  • Tags 0.1

Comments (0)

Files changed (3)

 from setuptools import setup, find_packages
 import sys, os
 
-version = '0.1rc3'
+version = '0.1'
 
 setup(name='strainer',
       version=version,

File strainer/log.py

+import logging
+
+log = logging.Logger('strainer')
+
+#handler
+ch = logging.StreamHandler()
+ch.setLevel(logging.DEBUG)
+
+# create formatter
+formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
+
+# add formatter to ch
+ch.setFormatter(formatter)
+
+log.addHandler(ch)
+
+
+__all__ = ['log']

File strainer/operators.py

 from pprint import pformat, pprint
 from simplejson import loads
 from nose.tools import *
+import strainer.log as log
+
+log = log.log
 
 def remove_whitespace_nodes(node):
     new_node = copy.copy(node)
     try:
         haystack_s = normalize_to_xhtml(haystack)
     except ValidationError, e:
-        print e.message
         raise ValidationError('Could not parse haystack: %s into xml. %s'%(haystack, e.message))
     return needle_s in haystack_s
 
 
 def eq_pprint(a, b, msg=None):
     if a != b:
-        pprint(a)
-        print 'does not equal'
-        pprint(b)
-    assert a == b, msg or "%r != %r" % (a, b)
+        log.error(msg)
+        assert False
+    return True
 
 def _eq_list(ca, cb, ignore=None):
-    eq_pprint(len(ca), len(cb), "the lengths of the lists are different %s != %s" % (str(ca), str(cb)))
+    eq_pprint(len(ca), len(cb), "The lengths of the lists are different %s != %s" % (str(ca), str(cb)))
     for i, v in enumerate(ca):
         if isinstance(v, dict):
             _eq_dict(ca[i], cb[i], ignore=ignore)
             _eq_list(ca[i], cb[i], ignore=ignore)
         else:
             eq_pprint(ca[i], cb[i])
+    return True
 
 def _eq_dict(ca, cb, ignore=None):
     # assume ca and cb can be destructively modified
                 del ca[key]
             if key in cb:
                 del cb[key]
+    return True
 
     #this needs to be recursive so we can '&ignore'-out ids anywhere in a json stream
     for key in set(ca.keys() + cb.keys()):
         assert key in cb, '%s!= %s\n key "%s" not in second argument' %(ca, cb, key)
         v1 = ca[key]
         v2 = cb[key]
+        log.info('Comparing values for key: %s', key)
         if v1 == '&ignore' or v2 == '&ignore':
+            log.info('Ignored comparison for key: %s', key)
             continue
         if not isinstance(v2, basestring) and isinstance(v1, basestring):
-            eq_pprint(type(v1), type(v2), 'The types of values for "%s" do not match' % key)
+            eq_pprint(type(v1), type(v2), 'The types of values for "%s" do not match (%s vs. %s)' %(key, v1, v2))
         if isinstance(v1, list):
             _eq_list(v1, v2, ignore=ignore)
         elif isinstance(v1, dict):
             _eq_dict(v1, v2, ignore=ignore)
         else:
-            eq_pprint(v1, v2, 'value of key "%s" does not equal:\n%s\ninstead, it\'s:\n%s'%(key, ca[key], cb[key]))
-    #By this point, we've already checked all the keys and values, so don't compare again
- 
+            eq_pprint(v1, v2, 'The types of values for "%s" do not match (%s vs. %s)' %(key, v1, v2))
+    return True
 
 def eq_dict(a, b, ignore=None):
     #Make a copy as our search for ignored values is destructive
     cb = copy.deepcopy(b)
                 
     _eq_dict(ca, cb, ignore=ignore)
+    return True
 
 def eq_json(a, b):
     if isinstance(a, basestring):
         b = loads(b)
         
     eq_dict(a, b)
+    
+    return True
 
 
 __all__ = [_key for _key in locals().keys() if not _key.startswith('_')]