[Numpy-svn] r8215 - trunk/numpy/ma/tests

numpy-svn@scip... numpy-svn@scip...
Sat Feb 20 20:51:05 CST 2010


Author: ptvirtan
Date: 2010-02-20 20:51:05 -0600 (Sat, 20 Feb 2010)
New Revision: 8215

Modified:
   trunk/numpy/ma/tests/test_core.py
   trunk/numpy/ma/tests/test_mrecords.py
Log:
3K: ma: solve some bytes vs. str issues in tests

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2010-02-21 02:50:49 UTC (rev 8214)
+++ trunk/numpy/ma/tests/test_core.py	2010-02-21 02:51:05 UTC (rev 8215)
@@ -17,6 +17,8 @@
 import numpy.ma.core
 from numpy.ma.core import *
 
+from numpy.compat import asbytes, asbytes_nested
+
 pi = np.pi
 
 import sys
@@ -1292,7 +1294,7 @@
         assert_equal(fval, default_fill_value(0))
         #
         fval = _check_fill_value(0, "|S3")
-        assert_equal(fval, "0")
+        assert_equal(fval, asbytes("0"))
         fval = _check_fill_value(None, "|S3")
         assert_equal(fval, default_fill_value("|S3"))
         #
@@ -1346,7 +1348,7 @@
         "Tests the behavior of fill_value during conversion"
         # We had a tailored comment to make sure special attributes are properly
         # dealt with
-        a = array(['3', '4', '5'])
+        a = array(asbytes_nested(['3', '4', '5']))
         a._optinfo.update({'comment':"updated!"})
         #
         b = array(a, dtype=int)
@@ -1376,14 +1378,14 @@
         mtype = [('f', float), ('s', '|S3')]
         x = array([(1, 'a'), (2, 'b'), (pi, 'pi')], dtype=mtype)
         x.fill_value = 999
-        assert_equal(x.fill_value.item(), [999., '999'])
+        assert_equal(x.fill_value.item(), [999., asbytes('999')])
         assert_equal(x['f'].fill_value, 999)
-        assert_equal(x['s'].fill_value, '999')
+        assert_equal(x['s'].fill_value, asbytes('999'))
         #
         x.fill_value = (9, '???')
-        assert_equal(x.fill_value.item(), (9, '???'))
+        assert_equal(x.fill_value.item(), (9, asbytes('???')))
         assert_equal(x['f'].fill_value, 9)
-        assert_equal(x['s'].fill_value, '???')
+        assert_equal(x['s'].fill_value, asbytes('???'))
         #
         x = array([1, 2, 3.1])
         x.fill_value = 999
@@ -2374,7 +2376,9 @@
                   dtype=[('a', int), ('b', float), ('c', '|S8')])
         x[-1] = masked
         assert_equal(x.tolist(),
-                     [(1, 1.1, 'one'), (2, 2.2, 'two'), (None, None, None)])
+                     [(1, 1.1, asbytes('one')),
+                      (2, 2.2, asbytes('two')),
+                      (None, None, None)])
         # ... on structured array w/ masked fields
         a = array([(1, 2,), (3, 4)], mask=[(0, 1), (0, 0)],
                   dtype=[('a', int), ('b', int)])
@@ -3215,7 +3219,8 @@
         assert_equal(base_b._data, [pi, 2.2, 3.3, 4.4, 5.5])
 
         assert_equal(base_c.dtype, '|S8')
-        assert_equal(base_c._data, ['pi', 'two', 'three', 'four', 'five'])
+        assert_equal(base_c._data,
+                     asbytes_nested(['pi', 'two', 'three', 'four', 'five']))
 
     def test_set_record_slice(self):
         base = self.data['base']
@@ -3229,7 +3234,8 @@
         assert_equal(base_b._data, [pi, pi, pi, 4.4, 5.5])
 
         assert_equal(base_c.dtype, '|S8')
-        assert_equal(base_c._data, ['pi', 'pi', 'pi', 'four', 'five'])
+        assert_equal(base_c._data,
+                     asbytes_nested(['pi', 'pi', 'pi', 'four', 'five']))
 
     def test_mask_element(self):
         "Check record access"

Modified: trunk/numpy/ma/tests/test_mrecords.py
===================================================================
--- trunk/numpy/ma/tests/test_mrecords.py	2010-02-21 02:50:49 UTC (rev 8214)
+++ trunk/numpy/ma/tests/test_mrecords.py	2010-02-21 02:51:05 UTC (rev 8215)
@@ -14,7 +14,7 @@
 from numpy.core.records import fromrecords as recfromrecords, \
                                fromarrays as recfromarrays
 
-from numpy.compat import asbytes
+from numpy.compat import asbytes, asbytes_nested
 
 import numpy.ma.testutils
 from numpy.ma.testutils import *
@@ -68,7 +68,7 @@
         mbase_first = mbase[0]
         assert isinstance(mbase_first, mrecarray)
         assert_equal(mbase_first.dtype, mbase.dtype)
-        assert_equal(mbase_first.tolist(), (1,1.1,'one'))
+        assert_equal(mbase_first.tolist(), (1,1.1,asbytes('one')))
         # Used to be mask, now it's recordmask
         assert_equal(mbase_first.recordmask, nomask)
         assert_equal(mbase_first._mask.item(), (False, False, False))
@@ -222,7 +222,8 @@
         assert_equal(mbase.a._mask, [0,0,0,0,1])
         assert_equal(mbase.b._data, [5.,5.,3.3,4.4,5.5])
         assert_equal(mbase.b._mask, [0,0,0,0,1])
-        assert_equal(mbase.c._data, ['5','5','three','four','five'])
+        assert_equal(mbase.c._data,
+                     asbytes_nested(['5','5','three','four','five']))
         assert_equal(mbase.b._mask, [0,0,0,0,1])
         #
         mbase = base.view(mrecarray).copy()
@@ -231,7 +232,8 @@
         assert_equal(mbase.a._mask, [1,1,0,0,1])
         assert_equal(mbase.b._data, [1.1,2.2,3.3,4.4,5.5])
         assert_equal(mbase.b._mask, [1,1,0,0,1])
-        assert_equal(mbase.c._data, ['one','two','three','four','five'])
+        assert_equal(mbase.c._data,
+                     asbytes_nested(['one','two','three','four','five']))
         assert_equal(mbase.b._mask, [1,1,0,0,1])
     #
     def test_setslices_hardmask(self):
@@ -243,7 +245,8 @@
             mbase[-2:] = (5,5,5)
             assert_equal(mbase.a._data, [1,2,3,5,5])
             assert_equal(mbase.b._data, [1.1,2.2,3.3,5,5.5])
-            assert_equal(mbase.c._data, ['one','two','three','5','five'])
+            assert_equal(mbase.c._data,
+                         asbytes_nested(['one','two','three','5','five']))
             assert_equal(mbase.a._mask, [0,1,0,0,1])
             assert_equal(mbase.b._mask, mbase.a._mask)
             assert_equal(mbase.b._mask, mbase.c._mask)
@@ -315,7 +318,8 @@
                           fill_value=(99999,99999.,'N/A'))
         #
         assert_equal(mrec.tolist(),
-                     [(1,1.1,None),(2,2.2,'two'),(None,None,'three')])
+                     [(1,1.1,None),(2,2.2,asbytes('two')),
+                      (None,None,asbytes('three'))])
 
 
     #
@@ -329,7 +333,7 @@
         "Test that 'exotic' formats are processed properly"
         easy = mrecarray(1, dtype=[('i',int), ('s','|S8'), ('f',float)])
         easy[0] = masked
-        assert_equal(easy.filled(1).item(), (1,'1',1.))
+        assert_equal(easy.filled(1).item(), (1,asbytes('1'),1.))
         #
         solo = mrecarray(1, dtype=[('f0', '<f8', (2, 2))])
         solo[0] = masked
@@ -465,13 +469,13 @@
 
     def test_fromtextfile(self):
         "Tests reading from a text file."
-        fcontent = """#
+        fcontent = asbytes("""#
 'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
 'strings',1,1.0,'mixed column',,1
 'with embedded "double quotes"',2,2.0,1.0,,1
 'strings',3,3.0E5,3,,1
 'strings',4,-1e-10,,,1
-"""
+""")
         import os
         import tempfile
         (tmp_fd,tmp_fl) = tempfile.mkstemp()



More information about the Numpy-svn mailing list