summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-02-21 02:51:05 +0000
committerPauli Virtanen <pav@iki.fi>2010-02-21 02:51:05 +0000
commitb1ab8f8657cf0165f5e9fd828857ff474d31dfdb (patch)
tree4c78fa7dcaee7e1be371ceb1aa4b36418bcdba57 /numpy
parent4b4d5e6169fda3fad6e6587be43aefd30089e164 (diff)
downloadnumpy-b1ab8f8657cf0165f5e9fd828857ff474d31dfdb.tar.gz
3K: ma: solve some bytes vs. str issues in tests
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/tests/test_core.py24
-rw-r--r--numpy/ma/tests/test_mrecords.py22
2 files changed, 28 insertions, 18 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 9418cddc8..40b7b4235 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -17,6 +17,8 @@ from numpy.ma.testutils import *
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 @@ class TestFillingValues(TestCase):
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 @@ class TestFillingValues(TestCase):
"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 @@ class TestFillingValues(TestCase):
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 @@ class TestMaskedArrayMethods(TestCase):
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 @@ class TestMaskedFields(TestCase):
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 @@ class TestMaskedFields(TestCase):
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"
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index d34a06171..87051bfad 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -14,7 +14,7 @@ from numpy import recarray
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 @@ class TestMRecords(TestCase):
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 @@ class TestMRecords(TestCase):
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 @@ class TestMRecords(TestCase):
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 @@ class TestMRecords(TestCase):
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 @@ class TestMRecords(TestCase):
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 @@ class TestMRecords(TestCase):
"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 @@ class TestMRecordsImport(TestCase):
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()