[python-hdf5storage] 02/12: Changed tests to work after fixing bug where str was written like numpy.bytes_ instead of like numpy.str_ and added test for writing and reading back unicode characters.

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


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

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

commit dc3657b1dd8fa2191d31d5c06159a4a670ada157
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Fri Mar 7 16:29:55 2014 -0500

    Changed tests to work after fixing bug where str was written like numpy.bytes_ instead of like numpy.str_ and added test for writing and reading back unicode characters.
---
 tests/asserts.py             | 17 +++++++++++++----
 tests/test_write_readback.py | 21 ++++++++++++++++++++-
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/tests/asserts.py b/tests/asserts.py
index cb414c0..6033d7b 100644
--- a/tests/asserts.py
+++ b/tests/asserts.py
@@ -97,20 +97,29 @@ def assert_equal_none_format(a, b):
             assert a.dtype == np.float64([]).dtype
             assert a.shape == (0, )
         elif (sys.hexversion >= 0x03000000 \
-                and isinstance(b, (bytes, str, bytearray))) \
+                and isinstance(b, (bytes, bytearray))) \
                 or (sys.hexversion < 0x03000000 \
-                and isinstance(b, (bytes, unicode, bytearray))):
+                and isinstance(b, (bytes, bytearray))):
             assert a == np.bytes_(b)
+        elif (sys.hexversion >= 0x03000000 \
+                and isinstance(b, str)) \
+                or (sys.hexversion < 0x03000000 \
+                and isinstance(b, unicode)):
+            assert_equal_none_format(a, np.unicode_(b))
         else:
             assert_equal_none_format(a, np.array(b)[()])
     else:
         if b.dtype.name != 'object':
             if b.dtype.char in ('U', 'S'):
-                if b.shape == tuple() and len(b) == 0:
+                if b.dtype.char == 'S' and b.shape == tuple() \
+                        and len(b) == 0:
                     assert_equal(a, \
                         np.zeros(shape=tuple(), dtype=b.dtype.char))
                 elif b.dtype.char == 'U':
-                    c = np.atleast_1d(b).view(np.uint32)
+                    if b.shape == tuple() and len(b) == 0:
+                        c = np.uint32(())
+                    else:
+                        c = np.atleast_1d(b).view(np.uint32)
                     assert a.dtype == c.dtype
                     assert a.shape == c.shape
                     npt.assert_equal(a, c)
diff --git a/tests/test_write_readback.py b/tests/test_write_readback.py
index 3b46425..877fba3 100644
--- a/tests/test_write_readback.py
+++ b/tests/test_write_readback.py
@@ -89,6 +89,18 @@ class TestPythonMatlabFormat(object):
             return u''.join([random.choice(ltrs) for i in \
                 range(0, length)])
 
+    def random_str_some_unicode(self, length):
+        # Makes a random ASCII+limited unicode str of the specified
+        # length.
+        if sys.hexversion >= 0x03000000:
+            ltrs = '\u03c0\u03c9\xe9'
+            return ''.join([random.choice(ltrs) for i in \
+                range(0, length)])
+        else:
+            ltrs = u'\u03c0\u03c9\xe9'
+            return u''.join([random.choice(ltrs) for i in \
+                range(0, length)])
+
     def random_bytes(self, length):
         # Makes a random sequence of bytes of the specified length from
         # the ASCII set.
@@ -325,13 +337,20 @@ class TestPythonMatlabFormat(object):
                                   self.options)
         self.assert_equal(out, data)
 
-    def test_str(self):
+    def test_str_ascii(self):
         data = self.random_str_ascii(random.randint(1,
                                      self.max_string_length))
         out = self.write_readback(data, self.random_name(),
                                   self.options)
         self.assert_equal(out, data)
 
+    def test_str_unicode(self):
+        data = self.random_str_some_unicode(random.randint(1,
+                                            self.max_string_length))
+        out = self.write_readback(data, self.random_name(),
+                                  self.options)
+        self.assert_equal(out, data)
+
     def test_str_empty(self):
         data = ''
         out = self.write_readback(data, self.random_name(),

-- 
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