summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-02-08 21:00:22 +0000
committerEric Wieser <wieser.eric@gmail.com>2020-02-08 21:00:22 +0000
commit2d1e8f38e973f88aeb29dc51caa0f57ab86efc67 (patch)
tree94eed4a75dbab0e73a11ea5935cdabc643d9cceb /numpy/core/tests
parent9531e5e1ba37b95f4d3b7f355c2869cab2e139d5 (diff)
downloadnumpy-2d1e8f38e973f88aeb29dc51caa0f57ab86efc67.tar.gz
BUG, MAINT: Stop using the error-prone deprecated Py_UNICODE apis
These APIs work with either UCS2 or UCS4, depending on the value of `Py_UNICODE_WIDE`. After python 3.3, there's a better way to handle this type of thing, which means we no longer have to care about this. Fixes gh-3258 Fixes gh-15363
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_multiarray.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index ad38911cb..13244f3ba 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -7854,6 +7854,34 @@ class TestBytestringArrayNonzero:
assert_(a)
+class TestUnicodeEncoding:
+ """
+ Tests for encoding related bugs, such as UCS2 vs UCS4, round-tripping
+ issues, etc
+ """
+ def test_round_trip(self):
+ """ Tests that GETITEM, SETITEM, and PyArray_Scalar roundtrip """
+ # gh-15363
+ arr = np.zeros(shape=(), dtype="U1")
+ for i in range(1, sys.maxunicode + 1):
+ expected = chr(i)
+ arr[()] = expected
+ assert arr[()] == expected
+ assert arr.item() == expected
+
+ def test_assign_scalar(self):
+ # gh-3258
+ l = np.array(['aa', 'bb'])
+ l[:] = np.unicode_('cc')
+ assert_equal(l, ['cc', 'cc'])
+
+ def test_fill_scalar(self):
+ # gh-7227
+ l = np.array(['aa', 'bb'])
+ l.fill(np.unicode_('cc'))
+ assert_equal(l, ['cc', 'cc'])
+
+
class TestUnicodeArrayNonzero:
def test_empty_ustring_array_is_falsey(self):