Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_binascii.cpython-34.pyo

�
f f�*�@sdZddlmZddlZddlZddlZdddddd	d
gZddd
ddddgZeeddgZGdd�dej	�Z
Gdd�de
�ZGdd�de
�ZGdd�de
�Z
dd�Zedkre�ndS)zTest the binascii C module.�)�supportN�
b2a_base64�b2a_hex�b2a_hqx�b2a_qp�b2a_uu�hexlify�rlecode_hqx�
a2b_base64�a2b_hex�a2b_hqx�a2b_qp�a2b_uu�	unhexlify�
rledecode_hqx�crc32�crc_hqxc@s�eZdZeZdZeeed��7Zed7Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�BinASCIITests.The quick brown fox jumps over the lazy dog.
�s
Hello world.
cCs|j|j�|_dS)N)�	type2test�rawdata�data)�self�r�7/opt/alt/python34/lib64/python3.4/test/test_binascii.py�setUpszBinASCIITest.setUpcCs6|jttjt��|jttjt��dS)N)�
assertTrue�
issubclass�binascii�Error�	ExceptionZ
Incomplete)rrrr�test_exceptionsszBinASCIITest.test_exceptionscCsMxFtD]>}|jttt|�d��|jttt|��qWdS)N�__call__)�
all_functionsr�hasattr�getattrr�assertRaises�	TypeError)r�namerrr�test_functions!s
zBinASCIITest.test_functionscCsxd}|jd|�}x#ttt�D]\}}tt|�}tt|�}y.||j|��}||j|��}WnAtk
r�}	z!|jdj	|||	��WYdd}	~	XnX|dkr�|\}}
n|j
||dj	||||��|j|t�|j|t�|j
t|�d�q)W|jtj|d�t�|jtj|�t�dS)N�-z{}/{} conversion raises {!r}rz{}/{} conversion: {!r} != {!r}�r)r�zip�
a2b_functions�
b2a_functionsr%rrr �fail�format�assertEqual�assertIsInstance�bytesZ
assertLess�maxr�intr)r�MAX_ALL�raw�fa�fb�a2b�b2a�a�res�err�_rrr�test_returned_value's&/z BinASCIITest.test_returned_valuecCs�d}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt�}x6|D].}|j|�}tj|�}||7}q~W|j	||j�dS)N�9r)
�range�lenrrrr�appendr3r
r1)r�
MAX_BASE64�lines�i�br<r=�linerrr�test_base64valid>s" 	
zBinASCIITest.test_base64validc
sFd}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt��d}x0td�D]"}||kr��j|�q�q�W�fdd�}t�}x?t	||�D].}	|j|	�}tj
|�}||7}q�W|j||j�|jtj
|j���d�dS)NrArs@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/rcs��}t|�t|�}t�}xr|r�|r�t|�t|�|krn|d|dd�}}n|d|dd�}}|j|�q(W|||S)Nr�)rC�	bytearrayrD)rIZnoiseZratior=�c)�fillersrr�addnoise\s	z1BinASCIITest.test_base64invalid.<locals>.addnoise�)rBrCrrrrrrDrL�mapr
r1)
rrErFrGrHr<ZvalidrOr=rIr)rNr�test_base64invalidMs&" 		zBinASCIITest.test_base64invalidcCs�d}g}x_tdt|j�|�D]B}|j|j|||��}tj|�}|j|�q(Wt�}x6|D].}|j|�}tj	|�}||7}q~W|j
||j�|j
tj	d�dd�|j
tj	d�dd�|j
tj	d�dd�|jtjtj	d	�|jtjtj	d
�|jtjtjdd�|j
tjd
�d�dS)Nr*rss�s�� s�s�s!!!!�.�!�xs!>   
)
rBrCrrrrrrDr3rr1r&r)rZMAX_UUrFrGrHr<r=rIrrr�test_uurs&" 	
zBinASCIITest.test_uucCs�tj|jd�d�}tj|jd�|�}|j|d�|jttj�|jttj|jd��x7dD]/}|jtj|jd�|�|d
@�qWdS)
NsTest the CRC-32 ofrs
 this string.i�7rPrK�4�E#�xV4i�����)rrKrYrZr[r\)rrrr1r&r')r�crcrrr�test_crc_hqx�s
zBinASCIITest.test_crc_hqxcCsZtj|jd��}tj|jd�|�}|j|d�|jttj�dS)NsTest the CRC-32 ofs
 this string.ij�])rrrr1r&r')rr]rrr�
test_crc32�szBinASCIITest.test_crc32cCsntj|j�}tj|j|��}tj|j|��\}}tj|�}|j||j�dS)N)	rr	rrrrrr1r)rZrler<rHr?r=rrr�test_hqx�s
zBinASCIITest.test_hqxcCs�d}tj|j|��}tj|j|��}|j||�|jtjtj|dd��|jtjtj|dd�d�|jtj|j|��|�|jtj|j|��|�dS)Ns {sworldishelloi0rK�qr\r\)	rrrrr1r&rrr)r�s�t�urrr�test_hex�s#'"zBinASCIITest.test_hexc
Cs�tjdddd�ytjdidd6�Wntk
rEYnX|jd�|jtjd�d�|jtjd�d	�|jtjd
�d
�|jttjdd�|jtjd
�d�|jtjd�d�|jtjddd�ddd�|jtjd�d�|jtjddd�d�|jtjd�d�|jtjddd�d�|jtjd�d�|jtjd�d�|jtjd �d �dS)!NrrP�headerFrKz/binascii.a2b_qp(**{1:1}) didn't raise TypeErrors= s==�=s=AXZfooZbars=00
=00s
s�
�
�s
=FF
=FF
=FF�0�Ks�
�
�s=
=FF
=FF
=FFs
s=00
Z	quotetabsTs	foo	bar	
sfoo	bar=09
s
foo=09bar=09
�.s=2Es.
s=2E
sa.
)rr
r'r/r1r&r)rrrr�test_qp�s2

zBinASCIITest.test_qpcCs�|jd�}x�tD]�}|dkr>tj|d�qntt|�}y||�Wqtk
r�}z!|jdj|||��WYdd}~XqXqWdS)NrPrrz{}({!r}) raises {!r})rr#rrr%r r/r0)r�empty�func�fr>rrr�test_empty_string�s
zBinASCIITest.test_empty_stringcCs�x�tt�tt�dhBD]g}y |jttt|�d�Wqtk
r�}z|jdj	||��WYdd}~XqXqW|jttj
dd�dS)Nr�testz{}("test") raises {!r}r)�setr#r-r&r'r%rr r/r0r)rrmr>rrr�test_unicode_b2a�s$ 0zBinASCIITest.test_unicode_b2acCspd}|jd|�}xPttt�D]?\}}|dkrGq)ntt|�}tt|�}y@||j|��}||�}|jd�}||�}	WnAtk
r�}
z!|j	dj
|||
��WYdd}
~
XnX|dkr|	\}	}|\}}n|j|	|dj
|||	|��|j|	|�|j|	t
�|jt|d�q)WdS)Nr*r�asciiz{}/{} conversion raises {!r}rz{}/{} conversion: {!r} != {!r}�€)rr,r-r.r%rr�decoder r/r0r1r2r3r&�
ValueError)rr6r7r8r9r:r;r<Z
binary_resr=r>r?rrr�test_unicode_a2b�s,/zBinASCIITest.test_unicode_a2bN)�__name__�
__module__�__qualname__r3rrrBrr!r)r@rJrRrXr^r_r`rerkrorrrwrrrrrs&
%

!
rc@seZdZdd�ZdS)�ArrayBinASCIITestcCstjdt|��S)N�B)�array�list)rrbrrrrszArrayBinASCIITest.type2testN)rxryrzrrrrrr{sr{c@seZdZeZdS)�BytearrayBinASCIITestN)rxryrzrLrrrrrrsrc@seZdZeZdS)�MemoryviewBinASCIITestN)rxryrz�
memoryviewrrrrrr�sr�cCstjtttt�dS)N)rZrun_unittestrr{rr�rrrr�	test_mains	r��__main__)�__doc__rprZunittestrr}r.r-r#ZTestCaserr{rr�r�rxrrrr�<module>s �