[Numpy-svn] r8202 - trunk/numpy/core/tests

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 20:47:14 CST 2010


Author: ptvirtan
Date: 2010-02-20 20:47:14 -0600 (Sat, 20 Feb 2010)
New Revision: 8202

Modified:
   trunk/numpy/core/tests/test_numerictypes.py
   trunk/numpy/core/tests/test_records.py
   trunk/numpy/core/tests/test_regression.py
Log:
3K: core: fix a few str vs bytes issues in tests

Modified: trunk/numpy/core/tests/test_numerictypes.py
===================================================================
--- trunk/numpy/core/tests/test_numerictypes.py	2010-02-21 02:46:46 UTC (rev 8201)
+++ trunk/numpy/core/tests/test_numerictypes.py	2010-02-21 02:47:14 UTC (rev 8202)
@@ -308,7 +308,10 @@
         h = np.array(self._buffer, dtype=self._descr)
         self.assert_(h.dtype['Info']['value'].name == 'complex128')
         self.assert_(h.dtype['Info']['y2'].name == 'float64')
-        self.assert_(h.dtype['info']['Name'].name == 'unicode256')
+        if sys.version_info[0] >= 3:
+            self.assert_(h.dtype['info']['Name'].name == 'str256')
+        else:
+            self.assert_(h.dtype['info']['Name'].name == 'unicode256')
         self.assert_(h.dtype['info']['Value'].name == 'complex128')
 
     def test_nested2_descriptor(self):

Modified: trunk/numpy/core/tests/test_records.py
===================================================================
--- trunk/numpy/core/tests/test_records.py	2010-02-21 02:46:46 UTC (rev 8201)
+++ trunk/numpy/core/tests/test_records.py	2010-02-21 02:47:14 UTC (rev 8202)
@@ -11,17 +11,17 @@
 
     def test_method_array(self):
         r = np.rec.array(asbytes('abcdefg') * 100, formats='i2,a3,i4', shape=3, byteorder='big')
-        assert_equal(r[1].item(), (25444, 'efg', 1633837924))
+        assert_equal(r[1].item(), (25444, asbytes('efg'), 1633837924))
 
     def test_method_array2(self):
         r = np.rec.array([(1, 11, 'a'), (2, 22, 'b'), (3, 33, 'c'), (4, 44, 'd'), (5, 55, 'ex'),
                      (6, 66, 'f'), (7, 77, 'g')], formats='u1,f4,a1')
-        assert_equal(r[1].item(), (2, 22.0, 'b'))
+        assert_equal(r[1].item(), (2, 22.0, asbytes('b')))
 
     def test_recarray_slices(self):
         r = np.rec.array([(1, 11, 'a'), (2, 22, 'b'), (3, 33, 'c'), (4, 44, 'd'), (5, 55, 'ex'),
                      (6, 66, 'f'), (7, 77, 'g')], formats='u1,f4,a1')
-        assert_equal(r[1::2][1].item(), (4, 44.0, 'd'))
+        assert_equal(r[1::2][1].item(), (4, 44.0, asbytes('d')))
 
     def test_recarray_fromarrays(self):
         x1 = np.array([1, 2, 3, 4])

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2010-02-21 02:46:46 UTC (rev 8201)
+++ trunk/numpy/core/tests/test_regression.py	2010-02-21 02:47:14 UTC (rev 8202)
@@ -6,7 +6,7 @@
 from os import path
 from numpy.testing import *
 from numpy.testing.utils import _assert_valid_refcount
-from numpy.compat import asbytes, asunicode
+from numpy.compat import asbytes, asunicode, asbytes_nested
 import numpy as np
 
 if sys.version_info[0] >= 3:
@@ -284,9 +284,9 @@
     def test_chararray_rstrip(self,level=rlevel):
         """Ticket #222"""
         x = np.chararray((1,),5)
-        x[0] = 'a   '
+        x[0] = asbytes('a   ')
         x = x.rstrip()
-        assert_equal(x[0], 'a')
+        assert_equal(x[0], asbytes('a'))
 
     def test_object_array_shape(self,level=rlevel):
         """Ticket #239"""
@@ -438,7 +438,7 @@
 
     def test_numeric_carray_compare(self, level=rlevel):
         """Ticket #341"""
-        assert_equal(np.array([ 'X' ], 'c'),'X')
+        assert_equal(np.array(['X'], 'c'), asbytes('X'))
 
     def test_string_array_size(self, level=rlevel):
         """Ticket #342"""
@@ -988,7 +988,7 @@
 
     def test_char_array_creation(self, level=rlevel):
         a = np.array('123', dtype='c')
-        b = np.array(['1','2','3'])
+        b = np.array(asbytes_nested(['1','2','3']))
         assert_equal(a,b)
 
     def test_unaligned_unicode_access(self, level=rlevel) :
@@ -997,7 +997,10 @@
             msg = 'unicode offset: %d chars'%i
             t = np.dtype([('a','S%d'%i),('b','U2')])
             x = np.array([(asbytes('a'),u'b')], dtype=t)
-            assert_equal(str(x), "[('a', u'b')]", err_msg=msg)
+            if sys.version_info[0] >= 3:
+                assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
+            else:
+                assert_equal(str(x), "[('a', u'b')]", err_msg=msg)
 
     def test_sign_for_complex_nan(self, level=rlevel):
         """Ticket 794."""
@@ -1146,13 +1149,13 @@
     def test_object_array_to_fixed_string(self):
         """Ticket #1235."""
         a = np.array(['abcdefgh', 'ijklmnop'], dtype=np.object_)
-        b = np.array(a, dtype=(np.string_, 8))
+        b = np.array(a, dtype=(np.str_, 8))
         assert_equal(a, b)
-        c = np.array(a, dtype=(np.string_, 5))
+        c = np.array(a, dtype=(np.str_, 5))
         assert_equal(c, np.array(['abcde', 'ijklm']))
-        d = np.array(a, dtype=(np.string_, 12))
+        d = np.array(a, dtype=(np.str_, 12))
         assert_equal(a, d)
-        e = np.empty((2, ), dtype=(np.string_, 8))
+        e = np.empty((2, ), dtype=(np.str_, 8))
         e[:] = a[:]
         assert_equal(a, e)
 



More information about the Numpy-svn mailing list