[python-hdf5storage] 73/152: Added write readback tests for numpy.object_ type.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:35 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 f261dbf899273945c21099df33615b19131abe88
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sat Feb 1 23:52:12 2014 -0500
Added write readback tests for numpy.object_ type.
---
tests/test_write_readback.py | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/tests/test_write_readback.py b/tests/test_write_readback.py
index 7988b2c..036bea8 100644
--- a/tests/test_write_readback.py
+++ b/tests/test_write_readback.py
@@ -67,6 +67,13 @@ class TestPythonMatlabFormat(object):
for x in np.nditer(data, op_flags=['readwrite']):
x[...] = np.str_(self.random_str_ascii(length))
return data
+ elif dtype == 'object':
+ data = np.zeros(shape=shape, dtype='object')
+ for index, x in np.ndenumerate(data):
+ data[index] = self.random_numpy( \
+ shape=self.random_numpy_shape(2, 8), \
+ dtype=random.choice(self.dtypes))
+ return data
else:
nbytes = np.ndarray(shape=(1,), dtype=dtype).nbytes
bts = np.random.bytes(nbytes * np.prod(shape))
@@ -84,6 +91,10 @@ class TestPythonMatlabFormat(object):
else:
return self.random_numpy(tuple(), dtype)[()]
+ def random_numpy_shape(self, dimensions, max_length):
+ return tuple([random.randint(1, max_length) for x in range(0,
+ dimensions)])
+
def random_name(self):
depth = random.randint(1, 5)
path = '/'
@@ -102,7 +113,7 @@ class TestPythonMatlabFormat(object):
hdf5storage.write(data, name=name, filename=self.filename,
options=options)
out = hdf5storage.read(name=name, filename=self.filename,
- options=options)
+ options=options)
except:
raise
finally:
@@ -116,8 +127,17 @@ class TestPythonMatlabFormat(object):
def assert_equal_numpy(self, a, b):
assert type(a) == type(b)
assert a.dtype == b.dtype
- npt.assert_equal(a, b)
-
+ if a.dtype.name != 'object':
+ npt.assert_equal(a, b)
+ else:
+ assert a.shape == b.shape
+ for index, x in np.ndenumerate(a):
+ assert type(a[index]) == type(b[index])
+ if isinstance(b[index], (np.generic, np.ndarray)):
+ self.assert_equal_numpy(a[index], b[index])
+ else:
+ assert a[index] == b[index]
+
def test_None(self):
data = None
out = self.write_readback(data, self.random_name(),
@@ -215,7 +235,7 @@ class TestPythonMatlabFormat(object):
self.assert_equal_numpy(out, data)
def check_numpy_array(self, dtype):
- shape = (random.randint(1, 12), random.randint(1, 12))
+ shape = self.random_numpy_shape(2, 12)
data = self.random_numpy(shape, dtype)
out = self.write_readback(data, self.random_name(),
self.options)
@@ -232,7 +252,9 @@ class TestPythonMatlabFormat(object):
yield self.check_numpy_scalar, dt
def test_numpy_array(self):
- for dt in self.dtypes:
+ dtypes = self.dtypes.copy()
+ dtypes.append('object')
+ for dt in dtypes:
yield self.check_numpy_array, dt
def test_numpy_empty(self):
--
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