Skip to content

Commit

Permalink
Merge pull request numpy#15374 from sethtroisi/cleanup_usc4
Browse files Browse the repository at this point in the history
TST: Simplify unicode test
  • Loading branch information
mattip authored Jan 21, 2020
2 parents 19b96a1 + 05a220d commit 3040041
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions numpy/core/tests/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from numpy.compat import unicode
from numpy.testing import assert_, assert_equal, assert_array_equal

# Python 3.3+ uses a flexible string representation
ucs4 = False

def buffer_length(arr):
if isinstance(arr, unicode):
arr = str(arr)
Expand Down Expand Up @@ -63,10 +60,7 @@ def content_check(self, ua, ua_scalar, nbytes):
# Encode to ascii and double check
assert_(ua_scalar.encode('ascii') == b'')
# Check buffer lengths for scalars
if ucs4:
assert_(buffer_length(ua_scalar) == 0)
else:
assert_(buffer_length(ua_scalar) == 0)
assert_(buffer_length(ua_scalar) == 0)

def test_zeros0D(self):
# Check creation of 0-dimensional objects
Expand Down Expand Up @@ -116,17 +110,14 @@ def content_check(self, ua, ua_scalar, nbytes):
assert_(ua_scalar.encode('utf-8') ==
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
assert_(buffer_length(ua_scalar) == 4*self.ulen)
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
assert_(buffer_length(ua_scalar) == 2*self.ulen)
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
assert_(buffer_length(ua_scalar) == 2*self.ulen)

def test_values0D(self):
# Check creation of 0-dimensional objects with values
Expand Down Expand Up @@ -201,17 +192,14 @@ def content_check(self, ua, ua_scalar, nbytes):
assert_(ua_scalar.encode('utf-8') ==
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
assert_(buffer_length(ua_scalar) == 4*self.ulen)
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
assert_(buffer_length(ua_scalar) == 2*self.ulen)
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
assert_(buffer_length(ua_scalar) == 2*self.ulen)

def test_values0D(self):
# Check assignment of 0-dimensional objects with values
Expand Down

0 comments on commit 3040041

Please sign in to comment.