@@ -31,7 +31,10 @@ class ArraySubclassWithKwargs(array.array):
3131 def __init__ (self , typecode , newarg = None ):
3232 array .array .__init__ (self )
3333
34- typecodes = 'uwbBhHiIlLfdqQFDe'
34+ typecodes = (
35+ 'u' , 'w' , 'b' , 'B' , 'h' , 'H' , 'i' , 'I' , 'l' , 'L' ,
36+ 'f' , 'd' , 'q' , 'Q' , 'F' , 'D' , 'e' , 'Zf' , 'Zd' )
37+
3538
3639class MiscTest (unittest .TestCase ):
3740
@@ -42,8 +45,9 @@ def test_array_is_sequence(self):
4245 def test_bad_constructor (self ):
4346 self .assertRaises (TypeError , array .array )
4447 self .assertRaises (TypeError , array .array , spam = 42 )
45- self .assertRaises (TypeError , array .array , 'xx' )
48+ self .assertRaises (ValueError , array .array , 'xx' )
4649 self .assertRaises (ValueError , array .array , 'x' )
50+ self .assertRaises (ValueError , array .array , 'Z' )
4751
4852 @support .cpython_only
4953 def test_disallow_instantiation (self ):
@@ -85,6 +89,12 @@ def __index__(self):
8589 with self .assertRaises (TypeError ):
8690 a .fromlist (lst )
8791
92+ def test_typecodes (self ):
93+ self .assertIsInstance (array .typecodes , tuple )
94+ for typecode in array .typecodes :
95+ self .assertIsInstance (typecode , str )
96+ self .assertGreaterEqual (len (typecode ), 1 )
97+
8898
8999# Machine format codes.
90100#
@@ -208,6 +218,14 @@ def test_numbers(self):
208218 [9006104071832581.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
209219 (['D' ], IEEE_754_DOUBLE_COMPLEX_BE , '>DDDD' ,
210220 [9006104071832581.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
221+ (['Zf' ], IEEE_754_FLOAT_COMPLEX_LE , '<ZfZfZfZf' ,
222+ [16711938.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
223+ (['Zf' ], IEEE_754_FLOAT_COMPLEX_BE , '>ZfZfZfZf' ,
224+ [16711938.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
225+ (['Zd' ], IEEE_754_DOUBLE_COMPLEX_LE , '<ZdZdZdZd' ,
226+ [9006104071832581.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
227+ (['Zd' ], IEEE_754_DOUBLE_COMPLEX_BE , '>ZdZdZdZd' ,
228+ [9006104071832581.0j , float ('inf' ), complex ('1-infj' ), - 0.0 ]),
211229 )
212230 for testcase in testcases :
213231 valid_typecodes , mformat_code , struct_fmt , values = testcase
@@ -1237,6 +1255,9 @@ def test_free_after_iterating(self):
12371255 support .check_free_after_iterating (self , reversed , array .array ,
12381256 (self .typecode ,))
12391257
1258+ def test_known_typecode (self ):
1259+ self .assertIn (self .typecode , array .typecodes )
1260+
12401261class StringTest (BaseTest ):
12411262
12421263 def test_setitem (self ):
@@ -1576,7 +1597,7 @@ def test_nan(self):
15761597 def test_byteswap (self ):
15771598 a = array .array (self .typecode , self .example )
15781599 self .assertRaises (TypeError , a .byteswap , 42 )
1579- if a .itemsize in (1 , 2 , 4 , 8 ):
1600+ if a .itemsize in (1 , 2 , 4 , 8 , 16 ):
15801601 b = array .array (self .typecode , self .example )
15811602 b .byteswap ()
15821603 if a .itemsize == 1 :
@@ -1631,6 +1652,14 @@ class ComplexDoubleTest(CFPTest, unittest.TestCase):
16311652 typecode = 'D'
16321653 minitemsize = 16
16331654
1655+ class ComplexZfFloatTest (CFPTest , unittest .TestCase ):
1656+ typecode = 'Zf'
1657+ minitemsize = 8
1658+
1659+ class ComplexZdDoubleTest (CFPTest , unittest .TestCase ):
1660+ typecode = 'Zd'
1661+ minitemsize = 16
1662+
16341663
16351664class LargeArrayTest (unittest .TestCase ):
16361665 typecode = 'b'
0 commit comments