1414import operator
1515import struct
1616import sys
17- import warnings
1817
1918import array
2019from array import _array_reconstructor as array_reconstructor
2120
22- with warnings .catch_warnings ():
23- warnings .simplefilter ('ignore' , DeprecationWarning )
24- sizeof_wchar = array .array ('u' ).itemsize
25-
2621
2722class ArraySubclass (array .array ):
2823 pass
@@ -32,7 +27,7 @@ def __init__(self, typecode, newarg=None):
3227 array .array .__init__ (self )
3328
3429typecodes = (
35- 'u' , ' w' , 'b' , 'B' , 'h' , 'H' , 'i' , 'I' , 'l' , 'L' ,
30+ 'w' , 'b' , 'B' , 'h' , 'H' , 'i' , 'I' , 'l' , 'L' ,
3631 'f' , 'd' , 'q' , 'Q' , 'e' , 'Zf' , 'Zd' )
3732
3833
@@ -135,14 +130,6 @@ def test_typecodes(self):
135130
136131class ArrayReconstructorTest (unittest .TestCase ):
137132
138- def setUp (self ):
139- self .enterContext (warnings .catch_warnings ())
140- warnings .filterwarnings (
141- "ignore" ,
142- message = "The 'u' type code is deprecated and "
143- "will be removed in Python 3.16" ,
144- category = DeprecationWarning )
145-
146133 def test_error (self ):
147134 self .assertRaises (TypeError , array_reconstructor ,
148135 "" , "b" , 0 , b"" )
@@ -242,12 +229,11 @@ def test_unicode(self):
242229 )
243230 for testcase in testcases :
244231 mformat_code , encoding = testcase
245- for c in 'uw' :
246- a = array .array (c , teststr )
247- b = array_reconstructor (
248- array .array , c , mformat_code , teststr .encode (encoding ))
249- self .assertEqual (a , b ,
250- msg = "{0!r} != {1!r}; testcase={2!r}" .format (a , b , testcase ))
232+ a = array .array ('w' , teststr )
233+ b = array_reconstructor (
234+ array .array , 'w' , mformat_code , teststr .encode (encoding ))
235+ self .assertEqual (a , b ,
236+ msg = "{0!r} != {1!r}; testcase={2!r}" .format (a , b , testcase ))
251237
252238
253239class BaseTest :
@@ -259,14 +245,6 @@ class BaseTest:
259245 # outside: An entry that is not in example
260246 # minitemsize: the minimum guaranteed itemsize
261247
262- def setUp (self ):
263- self .enterContext (warnings .catch_warnings ())
264- warnings .filterwarnings (
265- "ignore" ,
266- message = "The 'u' type code is deprecated and "
267- "will be removed in Python 3.16" ,
268- category = DeprecationWarning )
269-
270248 def assertEntryEqual (self , entry1 , entry2 ):
271249 self .assertEqual (entry1 , entry2 )
272250
@@ -299,7 +277,7 @@ def test_buffer_info(self):
299277 self .assertEqual (bi [1 ], len (a ))
300278
301279 def test_byteswap (self ):
302- if self .typecode in ( 'u' , 'w' ) :
280+ if self .typecode == 'w' :
303281 example = '\U00100100 '
304282 else :
305283 example = self .example
@@ -1167,7 +1145,7 @@ def test_buffer(self):
11671145 self .assertEqual (m .tobytes (), expected )
11681146 self .assertRaises (BufferError , a .frombytes , a .tobytes ())
11691147 self .assertEqual (m .tobytes (), expected )
1170- if self .typecode in ( 'u' , 'w' ) :
1148+ if self .typecode == 'w' :
11711149 self .assertRaises (BufferError , a .fromunicode , a .tounicode ())
11721150 self .assertEqual (m .tobytes (), expected )
11731151 self .assertRaises (BufferError , operator .imul , a , 2 )
@@ -1223,7 +1201,7 @@ def test_sizeof_without_buffer(self):
12231201 support .check_sizeof (self , a , basesize )
12241202
12251203 def test_initialize_with_unicode (self ):
1226- if self .typecode not in ( 'u' , 'w' ) :
1204+ if self .typecode != 'w' :
12271205 with self .assertRaises (TypeError ) as cm :
12281206 a = array .array (self .typecode , 'foo' )
12291207 self .assertIn ("cannot use a str" , str (cm .exception ))
@@ -1232,7 +1210,6 @@ def test_initialize_with_unicode(self):
12321210 self .assertIn ("cannot use a unicode array" , str (cm .exception ))
12331211 else :
12341212 a = array .array (self .typecode , "foo" )
1235- a = array .array (self .typecode , array .array ('u' , 'foo' ))
12361213 a = array .array (self .typecode , array .array ('w' , 'foo' ))
12371214
12381215 @support .cpython_only
@@ -1258,12 +1235,12 @@ def test_setitem(self):
12581235 self .assertRaises (TypeError , a .__setitem__ , 0 , self .example [:2 ])
12591236
12601237class UnicodeTest (StringTest , unittest .TestCase ):
1261- typecode = 'u '
1238+ typecode = 'w '
12621239 example = '\x01 \u263a \x00 \ufeff '
12631240 smallerexample = '\x01 \u263a \x00 \ufefe '
12641241 biggerexample = '\x01 \u263a \x01 \ufeff '
12651242 outside = str ('\x33 ' )
1266- minitemsize = sizeof_wchar
1243+ minitemsize = 4
12671244
12681245 def test_unicode (self ):
12691246 self .assertRaises (TypeError , array .array , 'b' , 'foo' )
@@ -1285,36 +1262,6 @@ def test_unicode(self):
12851262
12861263 self .assertRaises (TypeError , a .fromunicode )
12871264
1288- def test_issue17223 (self ):
1289- if self .typecode == 'u' and sizeof_wchar == 2 :
1290- # PyUnicode_FromUnicode() cannot fail with 16-bit wchar_t
1291- self .skipTest ("specific to 32-bit wchar_t" )
1292-
1293- # this used to crash
1294- # U+FFFFFFFF is an invalid code point in Unicode 6.0
1295- invalid_str = b'\xff \xff \xff \xff '
1296-
1297- a = array .array (self .typecode , invalid_str )
1298- self .assertRaises (ValueError , a .tounicode )
1299- self .assertRaises (ValueError , str , a )
1300-
1301- def test_typecode_u_deprecation (self ):
1302- with self .assertWarns (DeprecationWarning ):
1303- array .array ("u" )
1304-
1305- def test_empty_string_mem_leak_gh140474 (self ):
1306- with warnings .catch_warnings ():
1307- warnings .simplefilter ('ignore' , DeprecationWarning )
1308- for _ in range (1000 ):
1309- a = array .array ('u' , '' )
1310- self .assertEqual (len (a ), 0 )
1311- self .assertEqual (a .typecode , 'u' )
1312-
1313-
1314- class UCS4Test (UnicodeTest ):
1315- typecode = 'w'
1316- minitemsize = 4
1317-
13181265
13191266class NumberTest (BaseTest ):
13201267
0 commit comments