Your IP : 216.73.216.60


Current Path : /opt/alt/python36/lib64/python3.6/test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/__pycache__/test_secrets.cpython-36.opt-1.pyc

3

� f�@sfdZddlZddlZddlZGdd�dej�ZGdd�dej�ZGdd�dej�Zed	krbej	�dS)
z�Test the secrets module.

As most of the functions in secrets are thin wrappers around functions
defined elsewhere, we don't need to test them exhaustively.
�Nc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Compare_Digest_Testsz%Test secrets.compare_digest function.cCsRxLdD]D}|d}|d}|jtj||��|jtj|jd�|jd���qWdS)N�a�bcd�xyz123�dzutf-8)rrr)�
assertTrue�secrets�compare_digest�encode)�self�sr�b�r�6/opt/alt/python36/lib64/python3.6/test/test_secrets.py�
test_equals

zCompare_Digest_Tests.test_equalcCs~|jtjdd��|jtjdd��xTdD]L}|dd	}|dd
}|jtj||��|jtj|jd�|jd���q*WdS)
N�abcZabcdsabcsabcd�x�mn�a1b2c3r�q�kzutf-8)rrr)ZassertFalserr	r
)rrrr
rrr�test_unequals
z!Compare_Digest_Tests.test_unequalcCs6d}|jd�}|jttj||�|jttj||�dS)NZabcdezutf-8)r
�assertRaises�	TypeErrorrr	)rrr
rrr�test_bad_types$s
z#Compare_Digest_Tests.test_bad_typescCs,|jtjdd�t�|jtjdd�t�dS)NrZxyz)�assertIsInstancerr	�bool)rrrr�	test_bool-szCompare_Digest_Tests.test_boolN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrs

	rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Random_Testsz*Test wrappers around SystemRandom methods.cCs^d}xTdD]L}xFtd�D]:}tj|�}|jd|ko@d|kn|||f�qWq
WdS)	Nzrandbits(%d) returned %d����r�)r#r$r%)�rangerZrandbitsr)r�errmsgZnumbits�i�nrrr�
test_randbits6s


zRandom_Tests.test_randbitscCs<dddddddg}x$td�D]}|jtj|�|k�qWdS)	N�r'���� �@�
)r(rrZchoice)r�itemsr*rrr�test_choice>szRandom_Tests.test_choicecCsNx(tdd�D]}|jtj|�t|��qW|jttjd�|jttjd�dS)Nr'r3rr-���)r(ZassertInrZ	randbelowr�
ValueError)rr*rrr�test_randbelowDszRandom_Tests.test_randbelowN)rrr r!r,r5r8rrrrr"3sr"c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Token_TestszTest token functions.cCs�x�tjtjtjfD]�}|j|d��j|j}y
|�Wn"tk
rV|jd|�YnXy|d�Wn"tk
r�|jd|�YnXWdQRXqWtj}|j	t
tjd��|�|j	t
tjd��d|�dS)N)�funcz$%s cannot be called with no argumentz%s cannot be called with Noner')r�token_bytes�	token_hex�
token_urlsafe�subTestrrZfailZDEFAULT_ENTROPY�assertEqual�len)rr:�name�sizerrr�test_token_defaultsOs

"zToken_Tests.test_token_defaultscCsRxLdD]D}|j|d��.|jtj|�t�|jttj|��|�WdQRXqWdS)Nr-r/�r)r+)r-r/rDr)r>rrr;�bytesr?r@)rr+rrr�test_token_bytesas
zToken_Tests.test_token_bytescCslxfd	D]^}|j|d��Htj|�}|j|t�|jt|�d|�|jtdd�|D���WdQRXqWdS)
Nr-r$��Z)r+r'css|]}|tjkVqdS)N)�stringZ	hexdigits)�.0�crrr�	<genexpr>osz-Token_Tests.test_token_hex.<locals>.<genexpr>)r-r$rGrH)	r>rr<r�strr?r@r�all)rr+rrrr�test_token_hexhs

zToken_Tests.test_token_hexc
sltjtjd�xVd	D]N}|j|d��8tj|�}|j|t�|jt	�fdd�|D���WdQRXqWdS)
Nz-_r-���L)r+c3s|]}|�kVqdS)Nr)rJrK)�legalrrrLxsz1Token_Tests.test_token_urlsafe.<locals>.<genexpr>)r-rPrQrR)
rIZ
ascii_lettersZdigitsr>rr=rrMrrN)rr+rr)rSr�test_token_urlsafeqs

zToken_Tests.test_token_urlsafeN)rrr r!rCrFrOrTrrrrr9Ls
	r9�__main__)
r!rZunittestrIZTestCaserr"r9r�mainrrrr�<module>s$/