Skip to content

Commit

Permalink
compare pickled version of SGObject instances not just ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Mar 19, 2012
1 parent 5efddaa commit 7329de6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions testsuite/python_modular/tester.py 100644 → 100755
@@ -1,8 +1,10 @@
#!/usr/bin/env python
import pickle
import os
import filecmp
import numpy

from modshogun import SGObject
from generator import setup_tests, get_fname, blacklist, get_test_mod, run_test

def typecheck(a, b):
Expand All @@ -19,9 +21,11 @@ def compare(a, b, tolerance):

if type(a) == numpy.ndarray:
if tolerance:
return max(a - b) < tolerance
return numpy.max(numpy.abs(a - b)) < tolerance
else:
return numpy.all(a == b)
elif isinstance(a, SGObject):
return pickle.dumps(a) == pickle.dumps(b)
elif type(a) in (tuple,list):
if len(a) != len(b): return False
for obj1, obj2 in zip(a,b):
Expand All @@ -41,6 +45,12 @@ def compare_dbg(a, b):
else:
print "Numpy Array mismatch"
print a-b
elif isinstance(a, SGObject):
if pickle.dumps(a) == pickle.dumps(b):
return True
print "a", pickle.dumps(a)
print "b", pickle.dumps(b)
return False
elif type(a) in (tuple,list):
if len(a) != len(b):
print "Length mismatch (len(a)=%d vs len(b)=%d)" % (len(a), len(b))
Expand Down Expand Up @@ -82,7 +92,9 @@ def tester(tests, cmp_method, tolerance):
print "%-60s OK" % setting_str
else:
print "%-60s ERROR" % setting_str
except:
except Exception, e:
print e

import pdb
pdb.set_trace()
except Exception, e:
Expand Down

0 comments on commit 7329de6

Please sign in to comment.