diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:47:14 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:47:14 +0000 |
commit | b47f2caba51e6e5b4e96fb16089db8e5abfcdc1b (patch) | |
tree | 378545c320650db0481c00efe821512699a00f62 | |
parent | ae00919e25ec6613685915ef658bb257d3835a2c (diff) | |
download | numpy-b47f2caba51e6e5b4e96fb16089db8e5abfcdc1b.tar.gz |
3K: core: fix a few str vs bytes issues in tests
-rw-r--r-- | numpy/core/tests/test_numerictypes.py | 5 | ||||
-rw-r--r-- | numpy/core/tests/test_records.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 23 |
3 files changed, 20 insertions, 14 deletions
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py index bc633ebc1..44878b117 100644 --- a/numpy/core/tests/test_numerictypes.py +++ b/numpy/core/tests/test_numerictypes.py @@ -308,7 +308,10 @@ class read_values_nested(object): 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): diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index 546729df6..5e159f348 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -11,17 +11,17 @@ class TestFromrecords(TestCase): 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]) diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 7a434c31b..afe93914d 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -6,7 +6,7 @@ import copy 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 @@ class TestRegression(TestCase): 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 @@ class TestRegression(TestCase): 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 @@ class TestRegression(TestCase): 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 @@ class TestRegression(TestCase): 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 @@ class TestRegression(TestCase): 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) |