[python-hdf5storage] 125/152: Fixed tests to work with how dicts are read back as structured np.ndarrays if python metadata isn't stored.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 0.1
in repository python-hdf5storage.

commit 917d99ba6f2065f4a3e10c04938c29f942b54fb8
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Fri Feb 14 18:28:13 2014 -0500

    Fixed tests to work with how dicts are read back as structured np.ndarrays if python metadata isn't stored.
---
 tests/asserts.py             | 67 ++++++++++++++++++++++++--------------------
 tests/test_write_readback.py |  1 +
 2 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/tests/asserts.py b/tests/asserts.py
index bdbafe1..891e26b 100644
--- a/tests/asserts.py
+++ b/tests/asserts.py
@@ -66,24 +66,27 @@ def assert_equal(a, b):
 
 def assert_equal_none_format(a, b):
     # Compares a and b for equality. b is always the original. If they
-    # are dictionaries, they must have the same set of keys, after which
-    # they values must all be# compared. If they are a collection type
-    # (list, tuple, set, frozenset, or deque), then the compairison must
-    # be made with b converted to an object array. If the original is
-    # not a numpy type (isn't or doesn't inherit from np.generic or
-    # np.ndarray), then it is a matter of converting it to the
-    # appropriate numpy type. Otherwise, both are supposed to be numpy
-    # types. For object arrays, each element must be iterated over to be
-    # compared. Then, if it isn't a string type, then they must have the
-    # same dtype, shape, and all elements. If it is an empty string,
-    # then it would have been stored as just a null byte (recurse to do
-    # that comparison). If it is a bytes_ type, the dtype, shape, and
+    # are dictionaries, a must be a structured ndarray and they must
+    # have the same set of keys, after which they values must all be
+    # compared. If they are a collection type (list, tuple, set,
+    # frozenset, or deque), then the compairison must be made with b
+    # converted to an object array. If the original is not a numpy type
+    # (isn't or doesn't inherit from np.generic or np.ndarray), then it
+    # is a matter of converting it to the appropriate numpy
+    # type. Otherwise, both are supposed to be numpy types. For object
+    # arrays, each element must be iterated over to be compared. Then,
+    # if it isn't a string type, then they must have the same dtype,
+    # shape, and all elements. If it is an empty string, then it would
+    # have been stored as just a null byte (recurse to do that
+    # comparison). If it is a bytes_ type, the dtype, shape, and
     # elements must all be the same. If it is string_ type, we must
     # convert to uint32 and then everything can be compared.
     if type(b) == dict:
-        assert set(a.keys()) == set(b.keys())
+        assert type(a) == np.ndarray
+        assert a.dtype.names is not None
+        assert set(a.dtype.names) == set(b.keys())
         for k in b:
-            assert_equal_none_format(a[k], b[k])
+            assert_equal_none_format(a[k][0], b[k])
     elif type(b) in (list, tuple, set, frozenset, collections.deque):
         assert_equal_none_format(a, np.object_(list(b)))
     elif not isinstance(b, (np.generic, np.ndarray)):
@@ -124,28 +127,30 @@ def assert_equal_none_format(a, b):
 
 def assert_equal_matlab_format(a, b):
     # Compares a and b for equality. b is always the original. If they
-    # are dictionaries, they must have the same set of keys, after which
-    # they values must all be# compared. If they are a collection type
-    # (list, tuple, set, frozenset, or deque), then the compairison must
-    # be made with b converted to an object array. If the original is
-    # not a numpy type (isn't or doesn't inherit from np.generic or
-    # np.ndarray), then it is a matter of converting it to the
-    # appropriate numpy type. Otherwise, both are supposed to be numpy
-    # types. For object arrays, each element must be iterated over to be
-    # compared. Then, if it isn't a string type, then they must have the
-    # same dtype, shape, and all elements. All strings are converted to
-    # numpy.str_ on read. If it is empty, it has shape (1, 0). A
-    # numpy.str_ has all of its strings per row compacted together. A
-    # numpy.bytes_ string has to have the same thing done, but then it
-    # needs to be converted up to UTF-32 and to numpy.str_ through
-    # uint32.
+    # are dictionaries, a must be a structured ndarray and they must
+    # have the same set of keys, after which they values must all be
+    # compared. If they are a collection type (list, tuple, set,
+    # frozenset, or deque), then the compairison must be made with b
+    # converted to an object array. If the original is not a numpy type
+    # (isn't or doesn't inherit from np.generic or np.ndarray), then it
+    # is a matter of converting it to the appropriate numpy
+    # type. Otherwise, both are supposed to be numpy types. For object
+    # arrays, each element must be iterated over to be compared. Then,
+    # if it isn't a string type, then they must have the same dtype,
+    # shape, and all elements. All strings are converted to numpy.str_
+    # on read. If it is empty, it has shape (1, 0). A numpy.str_ has all
+    # of its strings per row compacted together. A numpy.bytes_ string
+    # has to have the same thing done, but then it needs to be converted
+    # up to UTF-32 and to numpy.str_ through uint32.
     #
     # In all cases, we expect things to be at least two dimensional
     # arrays.
     if type(b) == dict:
-        assert set(a.keys()) == set(b.keys())
+        assert type(a) == np.ndarray
+        assert a.dtype.names is not None
+        assert set(a.dtype.names) == set(b.keys())
         for k in b:
-            assert_equal_matlab_format(a[k], b[k])
+            assert_equal_matlab_format(a[k][0], b[k])
     elif type(b) in (list, tuple, set, frozenset, collections.deque):
         assert_equal_matlab_format(a, np.object_(list(b)))
     elif not isinstance(b, (np.generic, np.ndarray)):
diff --git a/tests/test_write_readback.py b/tests/test_write_readback.py
index 5b99bbc..f0a6cf2 100644
--- a/tests/test_write_readback.py
+++ b/tests/test_write_readback.py
@@ -174,6 +174,7 @@ class TestPythonMatlabFormat(object):
                 self.dict_value_subarray_dimensions, \
                 self.max_dict_value_subarray_axis_length), \
                 dtype=random.choice(self.dtypes))
+        return data
 
     def random_name(self):
         # Makes a random POSIX path of a random depth.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git



More information about the debian-science-commits mailing list