diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-20 20:22:59 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-20 20:22:59 +0000 |
commit | c90f2faa40029995bb7f3d4000dc63dabf057592 (patch) | |
tree | 78c593bc370eeb658650bf9033b6903cc0c15b1a /numpy/testing/utils.py | |
parent | f30e6c284e6430068c8301206c7e811f5127141b (diff) | |
download | numpy-c90f2faa40029995bb7f3d4000dc63dabf057592.tar.gz |
Added dict and list support to assert_equal when they contain arrays.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 19acd2654..3ccbac8c1 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -65,6 +65,18 @@ def assert_equal(actual,desired,err_msg='',verbose=1): """ Raise an assertion if two items are not equal. I think this should be part of unittest.py """ + if isinstance(desired, dict): + assert isinstance(actual, dict),`type(actual)` + assert_equal(len(actual),len(desired),err_msg,verbose) + for k,i in desired.items(): + assert actual.has_key(k),`k` + assert_equal(actual[k], desired[k], 'key=%r\n%s' % (k,err_msg), verbose) + return + if isinstance(desired, list) and isinstance(actual, list): + assert_equal(len(actual),len(desired),err_msg,verbose) + for k in range(len(desired)): + assert_equal(actual[k], desired[k], 'item=%r\n%s' % (k,err_msg), verbose) + return from numpy.core import ArrayType if isinstance(actual, ArrayType) or isinstance(desired, ArrayType): return assert_array_equal(actual, desired, err_msg) @@ -79,7 +91,7 @@ def assert_equal(actual,desired,err_msg='',verbose=1): + 'DESIRED: ' + repr(desired) \ + '\nACTUAL: ' + repr(actual) assert desired == actual, msg - + return def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1): """ Raise an assertion if two items are not |