summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-02-20 18:05:41 +0000
committerPauli Virtanen <pav@iki.fi>2010-02-20 18:05:41 +0000
commit87cf71e97cc256fb6e86c921c0c5d6c54a037910 (patch)
tree76d1c362dbf20dc6b8a2c1324ea07fe7fbd4a474
parent69ba79ac12c615102cd1a6b8947d3ad736f6e936 (diff)
downloadnumpy-87cf71e97cc256fb6e86c921c0c5d6c54a037910.tar.gz
3K: BUG: core: fix some tests for Py3
-rw-r--r--numpy/compat/py3k.py4
-rw-r--r--numpy/core/tests/test_multiarray.py14
2 files changed, 10 insertions, 8 deletions
diff --git a/numpy/compat/py3k.py b/numpy/compat/py3k.py
index a75bfebfd..931044787 100644
--- a/numpy/compat/py3k.py
+++ b/numpy/compat/py3k.py
@@ -3,7 +3,7 @@ Python 3 compatibility tools.
"""
-__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception']
+__all__ = ['bytes', 'asbytes', 'isfileobj', 'getexception', 'strchar']
import sys
@@ -16,9 +16,11 @@ if sys.version_info[0] >= 3:
return s.encode('iso-8859-1')
def isfileobj(f):
return isinstance(f, io.IOBase)
+ strchar = 'U'
else:
bytes = str
asbytes = str
+ strchar = 'S'
def isfileobj(f):
return isinstance(f, file)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 71a8c49d1..d4a0244ca 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -6,7 +6,7 @@ from numpy.testing import *
from numpy.core import *
from numpy.core.multiarray_tests import test_neighborhood_iterator, test_neighborhood_iterator_oob
-from numpy.compat import asbytes, getexception
+from numpy.compat import asbytes, getexception, strchar
from test_print import in_foreign_locale
@@ -414,7 +414,7 @@ class TestMethods(TestCase):
strtype = '>i2'
else:
strtype = '<i2'
- mydtype = [('name', 'S5'),('col2',strtype)]
+ mydtype = [('name', strchar + '5'),('col2',strtype)]
r = np.array([('a', 1),('b', 255), ('c', 3), ('d', 258)],
dtype= mydtype)
r.sort(order='col2')
@@ -1063,13 +1063,13 @@ class TestRecord(TestCase):
assert_raises(TypeError, np.dtype, [(('b', asbytes('a')), int)])
dt = np.dtype([((asbytes('a'), 'b'), int)])
- assert_raises(KeyError, dt.__getitem__, asbytes('a'))
+ assert_raises(ValueError, dt.__getitem__, asbytes('a'))
x = np.array([(1,), (2,), (3,)], dtype=dt)
- assert_raises(KeyError, x.__getitem__, asbytes('a'))
+ assert_raises(ValueError, x.__getitem__, asbytes('a'))
y = x[0]
- assert_raises(KeyError, y.__getitem__, asbytes('a'))
+ assert_raises(IndexError, y.__getitem__, asbytes('a'))
else:
def test_unicode_field_titles(self):
# Unicode field titles are added to field dict on Py2
@@ -1087,8 +1087,8 @@ class TestRecord(TestCase):
def test_unicode_field_names(self):
# Unicode field names are not allowed on Py2
title = unicode('b')
- assert_raises(TypeError, np.dtype, [(title, int)])
- assert_raises(TypeError, np.dtype, [(('a', title), int)])
+ assert_raises(ValueError, np.dtype, [(title, int)])
+ assert_raises(ValueError, np.dtype, [(('a', title), int)])
class TestView(TestCase):
def test_basic(self):