Your IP : 216.73.216.85


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_secrets.cpython-38.opt-1.pyc

U

i�f�@sfdZddlZddlZddlZGdd�dej�ZGdd�dej�ZGdd�dej�Zed	krbe�	�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.c	CsNdD]D}|d}|d}|�t�||��|�t�|�d�|�d���qdS)N)�aZbcdZxyz123�d�utf-8)�
assertTrue�secrets�compare_digest�encode��self�sr�b�r�6/opt/alt/python38/lib64/python3.8/test/test_secrets.py�
test_equals
zCompare_Digest_Tests.test_equalc	Csz|�t�dd��|�t�dd��dD]L}|dd}|dd}|�t�||��|�t�|�d	�|�d	���q(dS)
N�abcZabcdsabcsabcd)�xZmnZa1b2c3r�q�kr)ZassertFalserrr	r
rrr�test_unequalsz!Compare_Digest_Tests.test_unequalcCs6d}|�d�}|�ttj||�|�ttj||�dS)NZabcder)r	�assertRaises�	TypeErrorrr)rrr
rrr�test_bad_types$s
z#Compare_Digest_Tests.test_bad_typescCs,|�t�dd�t�|�t�dd�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.cCsVd}dD]H}td�D]:}t�|�}|�d|ko<d|kn|||f�qqdS)Nzrandbits(%d) returned %d)����r�)�rangerZrandbitsr)r�errmsgZnumbits�i�nrrr�
test_randbits6s

zRandom_Tests.test_randbitscCs8dddddddg}td�D]}|�t�|�|k�qdS)	N�r%���� �@�
)r&rrZchoice)r�itemsr(rrr�test_choice>szRandom_Tests.test_choicecCsJtdd�D]}|�t�|�t|��q
|�ttjd�|�ttjd�dS)Nr%r1r���)r&ZassertInrZ	randbelowr�
ValueError)rr(rrr�test_randbelowDszRandom_Tests.test_randbelowN)rrrrr*r3r6rrrrr 3sr c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Token_TestszTest token functions.c
Cs�tjtjtjfD]�}|j|d��j|j}z
|�Wn"tk
rT|�d|�YnXz|d�Wn"tk
r�|�d|�YnXW5QRXqtj}|�	t
t�d��|�|�	t
t�d��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)rr8�name�sizerrr�test_token_defaultsOs �
 zToken_Tests.test_token_defaultsc
CsNdD]D}|j|d��.|�t�|�t�|�tt�|��|�W5QRXqdS)N)r+r-�r�r))r<rrr9�bytesr=r>)rr)rrr�test_token_bytesaszToken_Tests.test_token_bytesc
CshdD]^}|j|d��Ht�|�}|�|t�|�t|�d|�|�tdd�|D���W5QRXqdS)N)r+r"��ZrCr%css|]}|tjkVqdS�N)�stringZ	hexdigits��.0�crrr�	<genexpr>osz-Token_Tests.test_token_hex.<locals>.<genexpr>)	r<rr:r�strr=r>r�all�rr)rrrr�test_token_hexhs
zToken_Tests.test_token_hexc
shtjtjd�dD]N}|j|d��8t�|�}|�|t�|�t	�fdd�|D���W5QRXqdS)Nz-_)r+���LrCc3s|]}|�kVqdSrHrrJ�ZlegalrrrMxsz1Token_Tests.test_token_urlsafe.<locals>.<genexpr>)
rIZ
ascii_lettersZdigitsr<rr;rrNrrOrPrrUr�test_token_urlsafeqs
zToken_Tests.test_token_urlsafeN)rrrrrArErQrVrrrrr7Ls
	r7�__main__)
rrZunittestrIZTestCaserr r7r�mainrrrr�<module>s$/