B
    u9a…½  ã               @   s¦  d Z ddlZddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddl
mZ e
 
d¡jZG dd„ de
j
ƒZG dd	„ d	e
j
ƒZd
ZG dd„ dejƒZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd Z(d!Z)d"Z*G d#d$„ d$ejƒZ+G d%d&„ d&ƒZ,G d'd(„ d(e,ƒZ-G d)d*„ d*e-ejƒZ.G d+d,„ d,e,ƒZ/G d-d.„ d.e/ƒZ0G d/d0„ d0ƒZ1G d1d2„ d2e0ƒZ2G d3d4„ d4e0ƒZ3G d5d6„ d6e2ejƒZ4G d7d8„ d8e3ejƒZ5G d9d:„ d:e2ejƒZ6G d;d<„ d<e3ejƒZ7G d=d>„ d>e2ejƒZ8G d?d@„ d@e3ejƒZ9G dAdB„ dBe2ejƒZ:G dCdD„ dDe3ejƒZ;G dEdF„ dFe2ejƒZ<G dGdH„ dHe3ejƒZ=G dIdJ„ dJe/ƒZ>G dKdL„ dLe>ejƒZ?G dMdN„ dNe>ejƒZ@eAdOkr¢e B¡  dS )Pz(Test the arraymodule.
   Roger E. Masse
é    N)Úsupport)Ú_array_reconstructorÚuc               @   s   e Zd ZdS )ÚArraySubclassN)Ú__name__Ú
__module__Ú__qualname__© r	   r	   ú /usr/lib/python3.7/test_array.pyr      s   r   c               @   s   e Zd Zddd„ZdS )ÚArraySubclassWithKwargsNc             C   s   t j  | ¡ d S )N)ÚarrayÚ__init__)ÚselfÚtypecodeÚnewargr	   r	   r
   r      s    z ArraySubclassWithKwargs.__init__)N)r   r   r   r   r	   r	   r	   r
   r      s   r   ZubBhHiIlLfdqQc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚMiscTestc             C   sD   |   ttj¡ | j ttjdd |   ttjd¡ |   ttjd¡ d S )Né*   )ZspamZxxÚx)ÚassertRaisesÚ	TypeErrorr   Ú
ValueError)r   r	   r	   r
   Útest_bad_constructor   s    zMiscTest.test_bad_constructorc             C   sj   t   d¡}||d d …< |  t|ƒd¡ |  t|| ƒd¡ |  t|d ƒd¡ ||7 }|  t|ƒd¡ d S )NÚBr   é   )r   ÚassertEqualÚlen)r   Úar	   r	   r
   Ú
test_empty%   s    
zMiscTest.test_emptyN)r   r   r   r   r   r	   r	   r	   r
   r      s   r   éÿÿÿÿé   é   r   é   é   é   é   é   é	   é
   é   é   é   é   é   é   é   é   é   é   é   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚArrayReconstructorTestc             C   s°   |   ttdddd¡ |   tttddd¡ |   tttjddd¡ |   tttjddd¡ |   tttjddd¡ |   tttjdtd¡ |   tttjddd¡ |   tttjddd	¡ d S )
NÚ Úbr   ó    ú?é   Údr-   ó   a)r   r   Úarray_reconstructorÚstrr   r   ÚUNKNOWN_FORMAT)r   r	   r	   r
   Ú
test_errorN   s     z!ArrayReconstructorTest.test_errorc             C   s„  ddddgt ddddd	gfd
dddgtddddgfdddgtdddddgfdddgtdddddgfdddgtddddgfdddgtddddgfddgtdddddgfddgtdddddgfddgtddddgfddgt	ddddgfdgt
d ddddgfdgtd!ddddgfdgtd"dddgfdgtd#dddgfdgt
d d$d%dd&gfdgtd!d$d%dd&gfdgtd"d'd%dgfdgtd#d'd%dgfd(gtd)d*td+ƒtd,ƒd-gfd(gtd.d*td+ƒtd,ƒd-gfd/gtd0d1td+ƒtd,ƒd-gfd/gtd2d1td+ƒtd,ƒd-gff}x|D ]ˆ}|\}}}}tj|f|žŽ }xd|D ]\}yt ||¡}	W n tk
rH   wY nX ttj|||ƒ}
| j|	|
d3 |	|
|¡d4 qW qôW d S )5Nr   ÚHÚIÚLz=BBBBé€   é   r   éÿ   r5   ÚhÚiÚlz=bbbi€ÿÿÿz<HHHHi €  iÿ  iÿÿ  z>HHHHz<hhhi €ÿÿz>hhhz<IIIIl        iÿÿÿl   ÿÿ z>IIIIz<iiii   €z>iiiz<QQQQz>QQQQz<qqqz>qqql            l   ÿÿÿÿ l   ÿÿÿÿ lûÿÿÿ         Úfz<ffffg   @ àoAÚinfz-infg       €z>ffffr9   z<ddddgÿ?Cz>ddddz{0!r} != {1!r}; testcase={2!r})Úmsg)ÚUNSIGNED_INT8ÚSIGNED_INT8ÚUNSIGNED_INT16_LEÚUNSIGNED_INT16_BEÚSIGNED_INT16_LEÚSIGNED_INT16_BEÚUNSIGNED_INT32_LEÚUNSIGNED_INT32_BEÚSIGNED_INT32_LEÚSIGNED_INT32_BEÚUNSIGNED_INT64_LEÚUNSIGNED_INT64_BEÚSIGNED_INT64_LEÚSIGNED_INT64_BEÚIEEE_754_FLOAT_LEÚfloatÚIEEE_754_FLOAT_BEÚIEEE_754_DOUBLE_LEÚIEEE_754_DOUBLE_BEÚstructÚpackr   ÚOverflowErrorr;   r   Úformat)r   Ú	testcasesÚtestcaseZvalid_typecodesÚmformat_codeZ
struct_fmtÚvaluesZarraystrr   r   r5   r	   r	   r
   Útest_numbers`   sp    















z#ArrayReconstructorTest.test_numbersc          	   C   sv   d}t dftdftdftdff}xP|D ]H}|\}}t d|¡}ttjd|| |¡ƒ}| j||d |||¡d q&W d S )	Nu   Bonne JournÃ©e ð ŒŠð ‡z	UTF-16-LEz	UTF-16-BEz	UTF-32-LEz	UTF-32-BEr   z{0!r} != {1!r}; testcase={2!r})rJ   )	ÚUTF16_LEÚUTF16_BEÚUTF32_LEÚUTF32_BEr   r;   Úencoder   ra   )r   Zteststrrb   rc   rd   Úencodingr   r5   r	   r	   r
   Útest_unicodeŸ   s    

z#ArrayReconstructorTest.test_unicodeN)r   r   r   r>   rf   rm   r	   r	   r	   r
   r3   L   s   ?r3   c               @   sØ  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/e0 1e2e3d[ƒd\¡d]d^„ ƒZ4d_d`„ Z5dadb„ Z6e7j8dcdd„ ƒZ9e7j8dedf„ ƒZ:dgdh„ Z;e7j8didj„ ƒZ<dkdl„ Z=dmS )nÚBaseTestc             C   s   |   ||¡ d S )N)r   )r   Úentry1Úentry2r	   r	   r
   ÚassertEntryEqual¹   s    zBaseTest.assertEntryEqualc             C   s   t t  | j¡d tt ƒ  S )Nr   )Ú	typecodesÚindexr   r   )r   r	   r	   r
   Úbadtypecode¼   s    zBaseTest.badtypecodec             C   sD   t   | j¡}|  |j| j¡ |  |j| j¡ |  tt j | jd ¡ d S )N)r   r   r   ZassertGreaterEqualÚitemsizeÚminitemsizer   r   )r   r   r	   r	   r
   Útest_constructorÀ   s    zBaseTest.test_constructorc             C   sV   t   | j¡}| | jd ¡ |  t|ƒd¡ t   | j| j¡}|  t|ƒt| jƒ¡ d S )Nr   r   )r   r   ÚappendÚexampler   r   )r   r   r	   r	   r
   Útest_lenÆ   s
    zBaseTest.test_lenc             C   s|   t   | j| j¡}|  t|jd¡ | ¡ }|  |t¡ |  t	|ƒd¡ |  |d t
¡ |  |d t
¡ |  |d t	|ƒ¡ d S )Nr   r    r   r   )r   r   ry   r   r   Úbuffer_infoZassertIsInstanceÚtupler   r   Úint)r   r   Zbir	   r	   r
   Útest_buffer_infoÎ   s    zBaseTest.test_buffer_infoc             C   s   | j dkrd}n| j}t | j |¡}|  t|jd¡ |jdkrŒt | j |¡}| ¡  |jdkrl|  ||¡ n|  ||¡ | ¡  |  ||¡ d S )Nr   u   ô€„€r   )r   r    r!   r%   r   )	r   ry   r   r   r   Úbyteswapru   r   ÚassertNotEqual)r   ry   r   r5   r	   r	   r
   Útest_byteswapØ   s    


zBaseTest.test_byteswapc             C   sF   dd l }t | j| j¡}|  |¡}|  t|ƒt|ƒ¡ |  ||¡ d S )Nr   )Úcopyr   r   ry   r€   Úidr   )r   r‚   r   r5   r	   r	   r
   Ú	test_copyé   s
    
zBaseTest.test_copyc             C   sF   dd l }t | j| j¡}| |¡}|  t|ƒt|ƒ¡ |  ||¡ d S )Nr   )r‚   r   r   ry   Zdeepcopyr€   rƒ   r   )r   r‚   r   r5   r	   r	   r
   Útest_deepcopyð   s
    
zBaseTest.test_deepcopyc             C   sj   t   | j| j¡}x(tdƒD ]}|  | |¡d t j ¡ qW x*tdtjƒD ]}|  | |¡d t¡ qHW d S )Nr   r   )	r   r   ry   ÚrangeÚassertIsÚ__reduce_ex__ÚpickleÚHIGHEST_PROTOCOLr;   )r   r   Úprotocolr	   r	   r
   Útest_reduce_ex÷   s
    zBaseTest.test_reduce_exc             C   sÈ   xÂt tjd ƒD ]°}t | j| j¡}t t ||¡¡}|  t	|ƒt	|ƒ¡ |  
||¡ t| j| jƒ}d|_t t ||¡¡}|  t	|ƒt	|ƒ¡ |  
||¡ |  
|j|j¡ |  
t|ƒt|ƒ¡ qW d S )Nr   r'   )r†   r‰   rŠ   r   r   ry   ÚloadsÚdumpsr€   rƒ   r   r   r   Útype)r   r‹   r   r5   r	   r	   r
   Útest_pickleþ   s    zBaseTest.test_picklec             C   sÀ   xºt tjd ƒD ]¨}t | j¡}t t ||¡¡}|  t|ƒt|ƒ¡ |  	||¡ t
| jƒ}d|_t t ||¡¡}|  t|ƒt|ƒ¡ |  	||¡ |  	|j|j¡ |  	t|ƒt|ƒ¡ qW d S )Nr   r'   )r†   r‰   rŠ   r   r   r   rŽ   r€   rƒ   r   r   r   r   )r   r‹   r   r5   r	   r	   r
   Útest_pickle_for_empty_array  s    
z$BaseTest.test_pickle_for_empty_arrayc       
      C   s²  t   | j| j¡}t|ƒ}|d d d… }x„ttjd ƒD ]p}t|ƒ}t ||f|¡}t 	|¡\}}| 
|¡ |  t|ƒt|ƒ¡ |  t|ƒ|| ¡ t|ƒ t ||f|¡}t 	|¡\}}| 
|¡ |  t|ƒt|ƒ¡ |  t|ƒ|dd … | ¡ x tdt|ƒƒD ]}	t|ƒ qW t ||f|¡}t 	|¡\}}| 
|¡ |  t|ƒt|ƒ¡ |  t|ƒ|¡ |  tt|¡ t ||f|¡}t 	|¡\}}| 
|¡ |  t|ƒg ¡ q8W d S )Nr   r   )r   r   ry   Úlistr†   r‰   rŠ   ÚiterrŽ   r   Úfromlistr   r   Únextr   r   ÚStopIteration)
r   ZorigÚdataZdata2ÚprotoZitorigr9   Úitr   rF   r	   r	   r
   Útest_iterator_pickle  s8    



zBaseTest.test_iterator_picklec             C   sž   t   | j| j¡}|  t|ƒt| jƒ¡ t|ƒ}t|ƒ}x|D ]}t|ƒ q<W | | j¡ |  t|ƒg ¡ |  t|ƒ| jg¡ |  t|ƒt| jƒ| jg ¡ d S )N)	r   r   ry   r   r’   r“   r•   rx   Úoutside)r   r   ZexhitZempitr   r	   r	   r
   Útest_exhausted_iteratorA  s    
z BaseTest.test_exhausted_iteratorc          
   C   sr  t   | j| j¡}| d| jd ¡ |  t|ƒdt| jƒ ¡ |  |d |d ¡ |  t|j¡ |  t|jd ¡ |  t|jdd ¡ t   | j| j¡}| d| jd ¡ |  |t   | j| jd d… | jd d…  | jdd …  ¡¡ t   | j| j¡}| d| jd ¡ |  |t   | j| jd d… | j ¡¡ t   | j| j¡}| d| jd ¡ |  |t   | j| j| jd d…  ¡¡ d S )Nr   r   r   iüÿÿiè  )r   r   ry   Úinsertr   r   r   r   )r   r   r	   r	   r
   Útest_insertM  s0    . zBaseTest.test_insertc          	   C   sþ   t   | jd| j ¡}|  t|j¡ t tj¡ t	tjdƒ}z¢| |¡ | 
¡  t   | j¡}t	tjdƒ}|  t|j¡ | |t| jƒ¡ |  |t   | j| j¡¡ |  ||¡ |  t|j|t| jƒd ¡ |  ||¡ | 
¡  W d |jsì| 
¡  t tj¡ X d S )Nr    ÚwbÚrbr   )r   r   ry   r   r   Ztofiler   ÚunlinkÚTESTFNÚopenÚcloseÚfromfiler   r   r€   ÚEOFErrorÚclosed)r   r   rH   r5   r	   r	   r
   Útest_tofromfilen  s&    
zBaseTest.test_tofromfilec          	   C   sP   t   | j¡}ttjdƒ}z|  t|j|t| j	ƒ¡ W d | 
¡  t tj¡ X d S )NrŸ   )r   r   r£   r   r¢   r   ÚOSErrorr¥   r   ry   r¤   r¡   )r   r   rH   r	   r	   r
   Útest_fromfile_ioerror„  s    zBaseTest.test_fromfile_ioerrorc          	   C   sÌ   t   | jd| j ¡}ttjdƒ}zŠ| |¡ | ¡  t   | j¡}ttjdƒ}| |t	| jƒ¡ |  
|t   | j| j¡¡ |  ||¡ | |t	| jƒ¡ |  
||¡ | ¡  W d |jsº| ¡  t tj¡ X d S )Nr    rŸ   r    )r   r   ry   r£   r   r¢   Úwriter¤   r¥   r   r   r€   r§   r¡   )r   r   rH   r5   r	   r	   r
   Útest_filewrite  s     
zBaseTest.test_filewritec             C   s~   t   | jd| j ¡}t   | j¡}|  t|jd¡ |  t|j¡ |  t|jd¡ |  t|jd g¡ | | ¡ ¡ |  ||¡ d S )Nr    r   )r   r   ry   r   r   Útolistr”   r   )r   r   r5   r	   r	   r
   Útest_tofromlist¢  s    zBaseTest.test_tofromlistc          	   C   sÊ   d}t jdd }t jddtd t | jd| j ¡}t | j¡}|  t|j	d¡ |  t|j
¡ |  t|j
d¡ | 
| 	¡ ¡ |  ||¡ |jdkr¬|  t|j
d	¡ |d7 }W d Q R X |  t|ƒ|¡ d S )
Nr    T)ÚrecordÚalwaysz!(to|from)string\(\) is deprecated)ÚmessageÚcategoryr   r   r   )ÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningr   r   ry   r   r   ZtostringZ
fromstringr   ru   r   r   )r   Znb_warningsÚrr   r5   r	   r	   r
   Útest_tofromstring¬  s     
zBaseTest.test_tofromstringc             C   s¨   t   | jd| j ¡}t   | j¡}|  t|jd¡ |  t|j¡ |  t|jd¡ | | ¡ ¡ t   | jt| ¡ ƒ¡}|  ||¡ |  ||¡ |j	dkr¤|  t
|jd¡ d S )Nr    r   r   ó   x)r   r   ry   r   r   ÚtobytesÚ	frombytesÚ	bytearrayr   ru   r   )r   r   r5   Úcr	   r	   r
   Útest_tofrombytesÀ  s    
zBaseTest.test_tofrombytesc             C   s.   t   | j| j¡}t   | j|¡}|  ||¡ d S )N)r   r   ry   r   )r   r   r5   r	   r	   r
   Útest_fromarrayÍ  s    zBaseTest.test_fromarrayc             C   sV   t   | jd| j ¡}|  |tt|ƒdt j iƒ¡ t   | j¡}|  t|ƒd| j ¡ d S )Nr    r   zarray('%s'))r   r   ry   r   ÚevalÚrepr)r   r   r	   r	   r
   Ú	test_reprÒ  s    zBaseTest.test_reprc             C   s    t   | jd| j ¡}t|ƒ d S )Nr    )r   r   ry   r<   )r   r   r	   r	   r
   Útest_strÙ  s    zBaseTest.test_strc             C   sì  t   | j| j¡}|  |dkd¡ |  |dkd¡ |  ||kd¡ |  ||kd¡ |  ||k d¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ t   | j| j¡}t   | j| j¡}|  |d| kd¡ |  |d| kd¡ |  |d| k d¡ |  |d| kd¡ |  |d| kd¡ |  |d| kd¡ |  ||kd¡ |  ||kd¡ |  ||k d¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ |  ||k d¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ d S )Nr   FTr    )r   r   ry   r‡   ÚsmallerexampleÚbiggerexample)r   r   ZalZabr	   r	   r
   Útest_cmpÝ  s:    zBaseTest.test_cmpc             C   s„   t   | j| j¡t   | j| jd d d… ¡ }|  |t   | j| j| jd d d…  ¡¡ t   |  ¡ ¡}|  t|j|¡ |  t|jd¡ d S )Nr   Úbad)r   r   ry   r   rt   r   r   Ú__add__)r   r   r5   r	   r	   r
   Útest_add  s    "zBaseTest.test_addc          
   C   sÖ   t   | j| jd d d… ¡}|}|t   | jd| j ¡7 }|  ||¡ |  |t   | j| jd d d… d| j  ¡¡ t   | j| j¡}||7 }|  |t   | j| j| j ¡¡ t   |  ¡ ¡}|  t|j|¡ |  t|j	d¡ d S )Nr   r    rÇ   )
r   r   ry   r‡   r   rt   r   r   rÈ   Ú__iadd__)r   r   r5   r	   r	   r
   Ú	test_iadd  s    &zBaseTest.test_iaddc             C   s   dt   | j| j¡ }|  |t   | jd| j ¡¡ t   | j| j¡d }|  |t   | j| jd ¡¡ dt   | j| j¡ }|  |t   | j¡¡ dt   | j| j¡ }|  |t   | j¡¡ dt   | j| jd d… ¡ }|  |t   | j|d gd ¡¡ |  t|jd¡ d S )Nr"   r   r   r   rÇ   )r   r   ry   r   r   r   Ú__mul__)r   r   r	   r	   r
   Útest_mul#  s*    zBaseTest.test_mulc             C   sü   t   | j| j¡}|}|d9 }|  ||¡ |  |t   | jd| j ¡¡ |d9 }|  ||¡ |  |t   | j¡¡ |d9 }|  ||¡ |  |t   | j¡¡ |d9 }|  ||¡ |  |t   | j¡¡ t   | j| j¡}|d9 }|  |t   | j¡¡ |  t|jd¡ d S )Nr"   r   iè  r   rÇ   )r   r   ry   r‡   r   r   r   Ú__imul__)r   r   r5   r	   r	   r
   Ú	test_imulD  s(    zBaseTest.test_imulc             C   sê   t   | j| j¡}|  |d | jd ¡ |  |d | jd ¡ |  |d | jd ¡ |  |d | jd ¡ |  |t| jƒd  | jd ¡ |  |t| jƒ  | jd ¡ |  t|j¡ |  t|jt| jƒ¡ |  t|jt| jƒ d ¡ d S )Nr   r   r   )	r   r   ry   rq   r   r   r   Ú__getitem__Ú
IndexError)r   r   r	   r	   r
   Útest_getitema  s     zBaseTest.test_getitemc             C   s¨  t   | j| j¡}|d |d< |  |d |d ¡ t   | j| j¡}|d |d< |  |d |d ¡ t   | j| j¡}|d |d< |  |d |d ¡ t   | j| j¡}|d |d< |  |d |d ¡ t   | j| j¡}|d |t| jƒd < |  |d |d ¡ t   | j| j¡}|d |t| jƒ < |  |d |d ¡ |  t|j¡ |  t|jd ¡ |  t|jdd ¡ |  t|jt| jƒ| jd ¡ |  t|jt| jƒ d | jd ¡ d S )Nr   r   r   )	r   r   ry   rq   r   r   r   Ú__setitem__rÑ   )r   r   r	   r	   r
   Útest_setitemm  s:    zBaseTest.test_setitemc          	   C   s>  t   | j| j¡}|d= |  |t   | j| jdd … ¡¡ t   | j| j¡}|d= |  |t   | j| jd d… ¡¡ t   | j| j¡}|t| jƒd = |  |t   | j| jd d… ¡¡ t   | j| j¡}|t| jƒ = |  |t   | j| jdd … ¡¡ |  t|j¡ |  t|jd ¡ |  t|jt| jƒ¡ |  t|jt| jƒ d ¡ d S )Nr   r   r   )	r   r   ry   r   r   r   r   Ú__delitem__rÑ   )r   r   r	   r	   r
   Útest_delitem”  s0    zBaseTest.test_delitemc          	   C   s  t   | j| j¡}|  |d d … |¡ |  |dd … t   | j| jdd … ¡¡ |  |d d… t   | j| jd d… ¡¡ |  |d d… t   | j| jd d… ¡¡ |  |dd … t   | j| jdd … ¡¡ |  |dd… t   | j¡¡ |  |dd… t   | j¡¡ |  |dd … t   | j¡¡ |  |dd … |¡ |  |d d… |¡ |  |d d… t   | j¡¡ |  |dd… |¡ |  |dd… t   | j¡¡ d S )Nr   r   r    iè  iüÿÿiÐ  )r   r   ry   r   )r   r   r	   r	   r
   Útest_getslice¶  s@    








zBaseTest.test_getslicec             C   sŠ   t   | j| j¡}dd ddddtjdddd	f}xX|D ]P}xJ|D ]B}x<|dd … D ],}|  t||||… ƒt|ƒ|||… ¡ qNW q<W q2W d S )
Nr   r   r   r0   éd   r   éþÿÿÿiáÿÿÿiœÿÿÿ)r   r   ry   ÚsysÚmaxsizer   r’   )r   r   ÚindicesÚstartÚstopÚstepr	   r	   r
   Útest_extended_getsliceè  s    

zBaseTest.test_extended_getslicec          
   C   s:  t   | j| j¡}||d d…< |  |t   | j| j| jdd …  ¡¡ t   | j| j¡}||d d…< |  |t   | j| j| jdd …  ¡¡ t   | j| j¡}||dd …< |  |t   | j| jd d… | j ¡¡ t   | j| j¡}||dd …< |  |t   | j| jd d… | j ¡¡ t   | j| j¡}||dd…< |  |t   | j| jd d… | j | jdd …  ¡¡ t   | j| j¡}||dd …< |  |t   | jd| j ¡¡ t   | j| j¡}||dd …< |  |t   | j| j¡¡ t   | j| j¡}||d d…< |  |t   | j| j¡¡ t   | j| j¡}||d d…< |  |t   | jd| j ¡¡ t   | j| j¡}||dd…< |  |t   | j| jd d… | j | jdd …  ¡¡ t   | j| j¡}||dd…< |  |t   | jd| j ¡¡ t   | j| j¡}|  t|jtddƒd ¡ |  t|jtddƒd ¡ t   |  ¡ ¡}|  t|jtddƒ|¡ |  t|jtddƒ|¡ d S )Nr   r   iè  r    iüÿÿr   iÐ  )	r   r   ry   r   r   r   rÓ   Úslicert   )r   r   r5   r	   r	   r
   Útest_setsliceô  s~        &.zBaseTest.test_setslicec             C   sê   dd ddddt jdddd	f}xÈ|D ]À}xº|D ]²}x¬|dd … D ]œ}t | j| j¡}t|ƒ}||||… }| ¡  |||||…< t | j|¡||||…< |  |t | j|¡¡ ||||…= ||||…= |  |t | j|¡¡ q>W q,W q"W d S )
Nr   r   r   r0   rØ   r   rÙ   iáÿÿÿiœÿÿÿ)rÚ   rÛ   r   r   ry   r’   Úreverser   )r   rÜ   rÝ   rÞ   rß   r   rA   r—   r	   r	   r
   Útest_extended_set_del_sliceM  s    

z$BaseTest.test_extended_set_del_slicec             C   sr   d| j  }t | j|¡}|  t|j¡ x$|D ]}|  | |¡| |¡¡ q,W |  t|jd ¡ |  t|j| j¡ d S )Nr    )	ry   r   r   r   r   rs   r   r   r›   )r   ry   r   r   r	   r	   r
   Ú
test_indexa  s    

zBaseTest.test_indexc             C   sv   d| j  }t | j|¡}|  t|j¡ x$|D ]}|  | |¡| |¡¡ q,W |  | | j¡d¡ |  | d ¡d¡ d S )Nr    r   )ry   r   r   r   r   Úcountr   r›   )r   ry   r   r   r	   r	   r
   Ú
test_countj  s    

zBaseTest.test_countc             C   s¤   xl| j D ]b}d| j  }t | j|¡}| |¡}|d |… ||d d …  }| |¡ |  |t | j|¡¡ qW t | j| j ¡}|  t|j| j¡ |  t|jd ¡ d S )Nr    r   )	ry   r   r   rs   Úremover   r   r   r›   )r   r   ry   r   ÚposZexample2r	   r	   r
   Útest_removes  s    


zBaseTest.test_removec          
   C   sh  t   | j¡}|  t|j¡ t   | jd| j ¡}|  t|jdd¡ |  t|jd ¡ |  t|jt|ƒ¡ |  t|jt|ƒ d ¡ |  | d¡| jd ¡ |  	|t   | j| jdd … | j ¡¡ |  | d¡| jd ¡ |  	|t   | j| jdd… | jdd …  | j ¡¡ |  | d¡| jd ¡ |  | ¡ | jd ¡ |  	|t   | j| jdd … | jd d…  ¡¡ d S )Nr    r   r   r   r   r   )
r   r   r   rÑ   Úpopry   r   r   rq   r   )r   r   r	   r	   r
   Útest_pop  s(     .zBaseTest.test_popc          
   C   sN   t   | j| j¡}|  t|jd¡ | ¡  |  |t   | j| jd d d… ¡¡ d S )Nr   r   )r   r   ry   r   r   rã   r   )r   r   r	   r	   r
   Útest_reverseœ  s    zBaseTest.test_reversec             C   s  t   | j| j¡}|  t|j¡ | t   | j| jd d d… ¡¡ |  |t   | j| j| jd d d…  ¡¡ t   | j| j¡}| |¡ |  |t   | j| j| j ¡¡ t   |  ¡ ¡}|  t|j|¡ t   | j| j¡}| | jd d d… ¡ |  |t   | j| j| jd d d…  ¡¡ d S )Nr   )r   r   ry   r   r   Úextendr   rt   )r   r   r5   r	   r	   r
   Útest_extend¥  s$     "
zBaseTest.test_extendc             C   sŠ   t   | jt| jƒ¡}t   | j| j¡}|  ||¡ |  tt j | jd¡ G dd„ dƒ}|  tt j | j|ƒ ¡ dd„ }|  tt j | j|ƒ ¡ d S )Nr'   c               @   s   e Zd Zdd„ ZdS )z;BaseTest.test_constructor_with_iterable_argument.<locals>.Ac             S   s   t ‚d S )N)ÚUnicodeError)r   r	   r	   r
   Ú__iter__É  s    zDBaseTest.test_constructor_with_iterable_argument.<locals>.A.__iter__N)r   r   r   rñ   r	   r	   r	   r
   ÚAÈ  s   rò   c               s   s   t ‚d V  d S )N)rð   r	   r	   r	   r
   r   Î  s    z;BaseTest.test_constructor_with_iterable_argument.<locals>.B)r   r   r“   ry   r   r   r   rð   )r   r   r5   rò   r   r	   r	   r
   Ú'test_constructor_with_iterable_argument¿  s    z0BaseTest.test_constructor_with_iterable_argumentc             C   sX   ydd l }W n tk
r*   |  d¡ Y nX t | j¡}t|ƒg}| |¡ | ¡  d S )Nr   zgc module not available)ÚgcÚImportErrorÚskipTestr   r   r“   rx   Zcollect)r   rô   r   rG   r	   r	   r
   Útest_coveritertraverseÓ  s    

zBaseTest.test_coveritertraversec             C   s  t   | j| j¡}t|ƒ}| ¡ }|  | ¡ |¡ |  | ¡ d |d ¡ |  t|j|d ¡ |  | ¡ |¡ |  t|j	|dd… ¡ |  | ¡ |¡ |  t|j
|d ¡ |  | ¡ |¡ |  t|jd¡ |  | ¡ |¡ |  t|j| ¡ ¡ |  | ¡ |¡ |  t|j| ¡ ¡ |  | ¡ |¡ | jdkrP|  t|j| ¡ ¡ |  | ¡ |¡ |  ttj|d¡ |  | ¡ |¡ |  ttj|d¡ |  | ¡ |¡ |  ttj|tddƒ|¡ |  | ¡ |¡ |  ttj|d¡ |  | ¡ |¡ |  ttj|tddƒ¡ |  | ¡ |¡ d S )Nr   r   r   r    )r   r   ry   Ú
memoryviewrº   r   r   ÚBufferErrorrx   rî   rè   rë   r”   r­   r»   ÚfromunicodeÚ	tounicodeÚoperatorÚimulÚsetitemrá   Údelitem)r   r   ÚmZexpectedr	   r	   r
   Útest_bufferÝ  s<    zBaseTest.test_bufferc             C   sD   t   | j| j¡}t |¡}|  | ¡ | ¡ ¡ d }|  tt	|¡ d S )N)
r   r   ry   ÚweakrefÚproxyr   rº   r   ÚReferenceErrorr   )r   ÚsÚpr	   r	   r
   Útest_weakref   s
    
zBaseTest.test_weakrefÚgetrefcountztest needs sys.getrefcount()c             C   sd   x t dƒD ]}t dt dƒ¡}q
W t d¡}x t dƒD ]}t dt dƒ¡}q6W |  |t d¡¡ d S )Nr'   r   é@   )r†   r   rÚ   r  r   )r   rF   r5   Zrcr	   r	   r
   Útest_bug_782369  s    
zBaseTest.test_bug_782369c             C   s   t ddd d S )Nr5   r   )r   )r   )r   r	   r	   r
   Útest_subclass_with_kwargs  s    z"BaseTest.test_subclass_with_kwargsc             C   s&   t   dd¡}|  t|ƒ|j d¡ d S )Nr?   s   1234r!   )r   r   r   ru   )r   r   r	   r	   r
   Útest_create_from_bytes  s    zBaseTest.test_create_from_bytesc             C   sB   t   | j| j¡}t d¡}| ¡ d |j }t | ||| ¡ d S )NÚPn2Pir   )r   r   ry   r   Úcalcvobjsizer{   ru   Úcheck_sizeof)r   r   ÚbasesizeÚbuffer_sizer	   r	   r
   Útest_sizeof_with_buffer  s    
z BaseTest.test_sizeof_with_bufferc             C   s(   t   | j¡}t d¡}t | ||¡ d S )Nr  )r   r   r   r  r  )r   r   r  r	   r	   r
   Útest_sizeof_without_buffer"  s    
z#BaseTest.test_sizeof_without_bufferc          	   C   s¨   | j dkr€|  t¡}t | j d¡}W d Q R X |  dt|jƒ¡ |  t¡}t | j t dd¡¡}W d Q R X |  dt|jƒ¡ n$t | j d¡}t | j t dd¡¡}d S )Nr   Úfoozcannot use a strzcannot use a unicode array)r   r   r   r   ZassertInr<   Z	exception)r   Úcmr   r	   r	   r
   Útest_initialize_with_unicode(  s    
 z%BaseTest.test_initialize_with_unicodec             C   s*   ddl m} t dd¡}|  t||¡ d S )Nr   )Úgetbuffer_with_null_viewr   r6   )Z	_testcapir  r   r   rù   )r   r  r   r	   r	   r
   Útest_obsolete_write_lock4  s    z!BaseTest.test_obsolete_write_lockc             C   s0   t  | ttj| jf¡ t  | ttj| jf¡ d S )N)r   Zcheck_free_after_iteratingr“   r   r   Úreversed)r   r	   r	   r
   Útest_free_after_iterating:  s    
z"BaseTest.test_free_after_iteratingN)>r   r   r   rq   rt   rw   rz   r~   r   r„   r…   rŒ   r   r‘   rš   rœ   rž   r¨   rª   r¬   r®   r¸   r¾   r¿   rÂ   rÃ   rÆ   rÉ   rË   rÍ   rÏ   rÒ   rÔ   rÖ   r×   rà   râ   rä   rå   rç   rê   rì   rí   rï   ró   r÷   r  r  ÚunittestZ
skipUnlessÚhasattrrÚ   r
  r  r  r   Zcpython_onlyr  r  r  r  r  r	   r	   r	   r
   rn   °   sl   	
%!
$!'"2Y			
#	rn   c                   s   e Zd Z‡ fdd„Z‡  ZS )Ú
StringTestc                s:   t ƒ  ¡  t | j| j¡}|  t|jd| jd d… ¡ d S )Nr   r    )ÚsuperrÔ   r   r   ry   r   r   rÓ   )r   r   )Ú	__class__r	   r
   rÔ   B  s    
zStringTest.test_setitem)r   r   r   rÔ   Ú__classcell__r	   r	   )r  r
   r  @  s   r  c               @   s8   e Zd ZdZdZdZdZedƒZdZ	dd„ Z
d	d
„ ZdS )ÚUnicodeTestr   u   â˜º ï»¿u   â˜º ï»¾u   â˜ºï»¿Ú3r    c             C   sš   |   ttjdd¡ t dd¡}| d¡ | d¡ | d¡ | d¡ | ¡ }|  |d¡ |  |jt¡ d	}t d|¡}|  t|ƒd
¡ |   t|j¡ d S )Nr5   r  r   u   Â Ã‚áˆ´ú r4   u	   abcÃ¿áˆ´u   Â Ã‚áˆ´ abcÃ¿áˆ´u    ="'a\bÂ€Ã¿ áˆ´u+   array('u', '\x00="\'a\\b\x80Ã¿\x00\x01áˆ´'))	r   r   r   rú   rû   r   ru   Úsizeof_wcharrÁ   )r   r   r  r	   r	   r
   rm   O  s    



zUnicodeTest.test_unicodec             C   sD   t dkrd}n
|  d¡ t d|¡}|  t|j¡ |  tt|¡ d S )Nr!   s   ÿÿÿÿzspecific to 32-bit wchar_tr   )r$  rö   r   r   r   rû   r<   )r   Zinvalid_strr   r	   r	   r
   Útest_issue17223c  s    
zUnicodeTest.test_issue17223N)r   r   r   r   ry   rÄ   rÅ   r<   r›   rv   rm   r%  r	   r	   r	   r
   r!  G  s   r!  c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú
NumberTestc             C   s‚  t   | jtdƒ¡}|  |d d … |¡ |  |d d d… t   | jdddg¡¡ |  |dd d… t   | jddg¡¡ |  |d d d… t   | jdddddg¡¡ |  |d d d… t   | jdddg¡¡ |  |dd d… t   | jddg¡¡ |  |d	d
… |¡ |  |d
d	d… |d d d… ¡ |  |d	d
d… t   | jdddg¡¡ |  |ddd… t   | jg ¡¡ |  |ddd… t   | jg ¡¡ d S )Nr"   r    r   r!   r   r   r   rÙ   iœÿÿÿrØ   iè  iÐ  iüÿÿi0øÿÿ)r   r   r†   r   )r   r   r	   r	   r
   Útest_extsliceq  s    &$*&$ & zNumberTest.test_extslicec             C   s  t   | jtdƒ¡}|d d d…= |  |t   | jddg¡¡ t   | jtdƒ¡}|dd d…= |  |t   | jdddg¡¡ t   | jtdƒ¡}|dd d…= |  |t   | jddddg¡¡ t   | jtdƒ¡}|d d d	…= |  |t   | jdddddd
dddg	¡¡ t   | jtdƒ¡}|dd dd> …= d S )Nr"   r    r   r   r   r!   rÙ   r'   iè  r#   r$   r%   r&   iM  )r   r   r†   r   )r   r   r	   r	   r
   Útest_delslice  s    (zNumberTest.test_delslicec             C   sX  t   | jtdƒ¡}t   | jdgd ¡|d d d…< |  |t   | jddddddddddg
¡¡ t   | jtdƒ¡}t   | jdgd ¡|d d d	…< |  |t   | jd
dddddddddg
¡¡ t   | jtdƒ¡}||d d d…< |  |t   | jdddd
g¡¡ t   | jtdƒ¡}|d d … }|d d … }t   | jtdƒ¡}||dd…< ||tddƒ< ||dd…< d S )Nr'   r   r"   r    r   r   r$   r&   éüÿÿÿr   r!   r#   r%   r   )r   r   r†   r   rá   )r   r   r5   r½   Zinsr	   r	   r
   Útest_assignment  s     **zNumberTest.test_assignmentc             C   sf   t   | jtdƒ¡}|  t|ƒttdƒƒ¡ t   | jdg¡}|  |d |kd¡ |  |d |kd¡ d S )Nr'   r1   r   Tr   )r   r   r†   r   r’   )r   r   r5   r	   r	   r
   Útest_iterationcontains¢  s
    z!NumberTest.test_iterationcontainsc             C   s”   t   | j|g¡}||d< |  tt j | j|d g¡ |  t|jd|d ¡ t   | j|g¡}||d< |  tt j | j|d g¡ |  t|jd|d ¡ d S )Nr   r   )r   r   r   r`   rÓ   )r   ÚlowerÚupperr   r	   r	   r
   Úcheck_overflow©  s    zNumberTest.check_overflowc             C   sT   | j }G dd„ dtjƒ}|| j ddddgdƒ}|  |d d¡ |  tt|d	d
¡ d S )Nc               @   s*   e Zd ZdgZdd„ Zdd„ Zdd„ ZdS )	z6NumberTest.test_subclassing.<locals>.ExaggeratingArrayÚoffsetc             S   s   t j  | ||¡S )N)r   Ú__new__)Úclsr   r—   r/  r	   r	   r
   r0  ¾  s    z>NumberTest.test_subclassing.<locals>.ExaggeratingArray.__new__c             S   s
   || _ d S )N)r/  )r   r   r—   r/  r	   r	   r
   r   Á  s    z?NumberTest.test_subclassing.<locals>.ExaggeratingArray.__init__c             S   s   t j  | |¡| j S )N)r   rÐ   r/  )r   rF   r	   r	   r
   rÐ   Ä  s    zBNumberTest.test_subclassing.<locals>.ExaggeratingArray.__getitem__N)r   r   r   Ú	__slots__r0  r   rÐ   r	   r	   r	   r
   ÚExaggeratingArray»  s   r3  r   r#   r$   r(   r!   r   ZcolorZblue)r   r   rq   r   ÚAttributeErrorÚsetattr)r   r   r3  r   r	   r	   r
   Útest_subclassing¹  s
    zNumberTest.test_subclassingc             C   s.   t   dtdƒ¡}t   | j|¡}|  ||¡ d S )Nr5   r'   )r   r†   r   r   )r   r   r5   r	   r	   r
   Útest_frombytearrayÌ  s    zNumberTest.test_frombytearrayN)
r   r   r   r'  r(  r*  r+  r.  r6  r7  r	   r	   r	   r
   r&  o  s   r&  c               @   s   e Zd Zdd„ ZdS )ÚIntegerNumberTestc          	   C   sX   t   | j¡}| d¡ |  t¡ | d¡ W d Q R X |  t¡ d|d< W d Q R X d S )Nr   g      E@r   )r   r   rx   r   r   )r   r   r	   r	   r
   Útest_type_errorÒ  s    
z!IntegerNumberTest.test_type_errorN)r   r   r   r9  r	   r	   r	   r
   r8  Ñ  s   r8  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚIntablec             C   s
   || _ d S )N)Ú_num)r   Znumr	   r	   r
   r   Û  s    zIntable.__init__c             C   s   | j S )N)r;  )r   r	   r	   r
   Ú__int__Ý  s    zIntable.__int__c             C   s   t t| ƒt|ƒ ƒS )N)r:  r}   )r   Úotherr	   r	   r
   Ú__sub__ß  s    zIntable.__sub__c             C   s   t t| ƒt|ƒ ƒS )N)r:  r}   )r   r=  r	   r	   r
   rÈ   á  s    zIntable.__add__N)r   r   r   r   r<  r>  rÈ   r	   r	   r	   r
   r:  Ú  s   r:  c               @   sB   e Zd ZdddddgZdddddgZdddddgZdZd	d
„ ZdS )ÚSignedNumberTestr   r   r   r   rC   é~   é+   é   c             C   sh   t   | j¡}dttd|jd d ƒƒ }ttd|jd d ƒƒd }|  ||¡ |  t|ƒt|ƒ¡ d S )Nr   r    r%   r   )r   r   r}   Úpowru   r.  r:  )r   r   r,  r-  r	   r	   r
   Útest_overflowê  s
    zSignedNumberTest.test_overflowN)r   r   r   ry   rÄ   rÅ   r›   rD  r	   r	   r	   r
   r?  ä  s
   r?  c               @   sP   e Zd ZddddddgZddddddgZddddddgZd	Zd
d„ Zdd„ ZdS )ÚUnsignedNumberTestr   r   r.   rB  r   rD   éþ   rA  éª   c             C   sL   t   | j¡}d}ttd|jd ƒƒd }|  ||¡ |  t|ƒt|ƒ¡ d S )Nr   r    r%   r   )r   r   r}   rC  ru   r.  r:  )r   r   r,  r-  r	   r	   r
   rD  ÷  s
    z UnsignedNumberTest.test_overflowc             C   s   t | jƒ}t | j| j¡}| |¡ |  |t | j| j| j ¡¡ t | j| j¡}| tt|ƒƒ¡ |  |t | j| j| jd d d…  ¡¡ d S )Nr   )Úbytesry   r   r   rî   r   r¼   r  )r   r  r   r	   r	   r
   Útest_bytes_extendþ  s    

z$UnsignedNumberTest.test_bytes_extendN)	r   r   r   ry   rÄ   rÅ   r›   rD  rI  r	   r	   r	   r
   rE  ñ  s   rE  c               @   s   e Zd ZdZdZdS )ÚByteTestr5   r   N)r   r   r   r   rv   r	   r	   r	   r
   rJ    s   rJ  c               @   s   e Zd ZdZdZdS )ÚUnsignedByteTestr   r   N)r   r   r   r   rv   r	   r	   r	   r
   rK    s   rK  c               @   s   e Zd ZdZdZdS )Ú	ShortTestrE   r    N)r   r   r   r   rv   r	   r	   r	   r
   rL    s   rL  c               @   s   e Zd ZdZdZdS )ÚUnsignedShortTestr?   r    N)r   r   r   r   rv   r	   r	   r	   r
   rM    s   rM  c               @   s   e Zd ZdZdZdS )ÚIntTestrF   r    N)r   r   r   r   rv   r	   r	   r	   r
   rN     s   rN  c               @   s   e Zd ZdZdZdS )ÚUnsignedIntTestr@   r    N)r   r   r   r   rv   r	   r	   r	   r
   rO  $  s   rO  c               @   s   e Zd ZdZdZdS )ÚLongTestrG   r!   N)r   r   r   r   rv   r	   r	   r	   r
   rP  (  s   rP  c               @   s   e Zd ZdZdZdS )ÚUnsignedLongTestrA   r!   N)r   r   r   r   rv   r	   r	   r	   r
   rQ  ,  s   rQ  c               @   s   e Zd ZdZdZdS )ÚLongLongTestÚqr%   N)r   r   r   r   rv   r	   r	   r	   r
   rR  0  s   rR  c               @   s   e Zd ZdZdZdS )ÚUnsignedLongLongTestÚQr%   N)r   r   r   r   rv   r	   r	   r	   r
   rT  4  s   rT  c               @   sR   e Zd ZdddddgZdddddgZdddddgZdZd	d
„ Zdd„ Zdd„ Z	dS )ÚFPTestg      EÀr   r   g     jø@g    _ Âg    _ Âg    _ BrB  c             C   s   |   ||¡ d S )N)ZassertAlmostEqual)r   ro   rp   r	   r	   r
   rq   >  s    zFPTest.assertEntryEqualc             C   sŒ   t   | jtdƒg¡}t   | jtdƒg¡}|  ||kd¡ |  ||kd¡ |  ||kd¡ |  ||kd¡ |  ||k d¡ |  ||kd¡ d S )NÚnanTF)r   r   rZ   r‡   )r   r   r5   r	   r	   r
   Útest_nanA  s    zFPTest.test_nanc             C   s†   t   | j| j¡}|  t|jd¡ |jdkr‚t   | j| j¡}| ¡  |jdkrZ|  ||¡ n|  | 	¡ | 	¡ ¡ | ¡  |  ||¡ d S )Nr   )r   r    r!   r%   r   )
r   r   ry   r   r   r   ru   r   r€   rº   )r   r   r5   r	   r	   r
   r   K  s    

zFPTest.test_byteswapN)
r   r   r   ry   rÄ   rÅ   r›   rq   rX  r   r	   r	   r	   r
   rV  8  s   
rV  c               @   s   e Zd ZdZdZdS )Ú	FloatTestrH   r!   N)r   r   r   r   rv   r	   r	   r	   r
   rY  [  s   rY  c               @   s   e Zd ZdZdZdd„ ZdS )Ú
DoubleTestr9   r%   c             C   sœ   ddl m} t ddgd ¡}y||d d 9 }W n tk
rF   Y nX |  d¡ t ddd	dg¡}y||d
 d   W n tk
rŒ   Y nX |  d¡ d S )Nr   )rÛ   r9   r   i   r   z6Array of size > maxsize created - MemoryError expectedgËII‹
¿@gñÔÈSû!	@r   )rÚ   rÛ   r   ÚMemoryErrorZfail)r   rÛ   r   r5   r	   r	   r
   Útest_alloc_overflowc  s    
zDoubleTest.test_alloc_overflowN)r   r   r   r   rv   r\  r	   r	   r	   r
   rZ  _  s   rZ  Ú__main__)CÚ__doc__r  Ztestr   r  r‰   rü   r^   rÚ   r³   r   r   r;   ru   r$  r   r   rr   ZTestCaser   r=   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   r[   r\   r]   rg   rh   ri   rj   r3   rn   r  r!  r&  r8  r:  r?  rE  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rT  rV  rY  rZ  r   Úmainr	   r	   r	   r
   Ú<module>   sŠ   d       (b	
#
