o
    HXh                     @   sj   d Z ddlZddlZddlZG dd dejZG dd dejZG dd dejZed	kr3e	  dS dS )
zTest 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                   @   0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Compare_Digest_Testsz%Test secrets.compare_digest function.c              	   C   sN   dD ]"}|d }|d }|  t|| |  t|d|d qd S )N)aZbcdZxyz123d   utf-8)
assertTruesecretscompare_digestencodeselfsr   b r   ;/opt/python-3.10.19/usr/lib/python3.10/test/test_secrets.py
test_equal   s    zCompare_Digest_Tests.test_equalc              	   C   sz   |  tdd |  tdd dD ]&}|d d }|d d }|  t|| |  t|d	|d	 qd S )
NabcZabcds   abcs   abcd)xZmnZa1b2c3r   qkr   )ZassertFalser   r	   r
   r   r   r   r   test_unequal   s    z!Compare_Digest_Tests.test_unequalc                 C   s6   d}| d}| ttj|| | ttj|| d S )NZabcder   )r
   assertRaises	TypeErrorr   r	   )r   r   r   r   r   r   test_bad_types$   s   
z#Compare_Digest_Tests.test_bad_typesc                 C   s,   |  tddt |  tddt d S )Nr   Zxyz)assertIsInstancer   r	   bool)r   r   r   r   	test_bool-   s   zCompare_Digest_Tests.test_boolN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s    
	r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Random_Testsz*Test wrappers around SystemRandom methods.c                 C   sV   d}dD ]$}t dD ]}t|}| d|  kod| k n  |||f  q
qd S )Nzrandbits(%d) returned %d)            r      )ranger   Zrandbitsr   )r   errmsgZnumbitsinr   r   r   test_randbits6   s   
.zRandom_Tests.test_randbitsc                 C   s.   g d}t dD ]}| t||v  qd S )N)   r&                @   
   )r'   r   r   choice)r   itemsr)   r   r   r   test_choice>   s   zRandom_Tests.test_choicec                 C   sJ   t ddD ]}| t|t | q| ttjd | ttjd d S )Nr&   r2   r   )r'   ZassertInr   	randbelowr   
ValueError)r   r)   r   r   r   test_randbelowD   s   zRandom_Tests.test_randbelowN)r   r   r   r    r+   r5   r9   r   r   r   r   r!   3   s
    r!   c                   @   r   )Token_TestszTest token functions.c              
   C   s   t jt jt jfD ]H}| j|d8 |j}z|  W n ty)   | d|  Y nw z|d  W n ty@   | d|  Y nw W d    n1 sKw   Y  qt j}| 	t
t d | | 	t
t d d|  d S )N)funcz$%s cannot be called with no argumentz%s cannot be called with Noner&   )r   token_bytes	token_hextoken_urlsafesubTestr   r   ZfailZDEFAULT_ENTROPYassertEquallen)r   r;   namesizer   r   r   test_token_defaultsO   s*   

zToken_Tests.test_token_defaultsc              	   C   sb   dD ],}| j |d | t|t | tt|| W d    n1 s)w   Y  qd S )N)r,   r.      r   r*   )r?   r   r   r<   bytesr@   rA   )r   r*   r   r   r   test_token_bytesa   s   zToken_Tests.test_token_bytesc              	   C   s|   dD ]9}| j |d) t|}| |t | t|d|  | tdd |D  W d    n1 s6w   Y  qd S )N)r,   r#      Z   rF   r&   c                 s   s    | ]}|t jv V  qd S N)string	hexdigits.0cr   r   r   	<genexpr>o   s    z-Token_Tests.test_token_hex.<locals>.<genexpr>)	r?   r   r=   r   strr@   rA   r   allr   r*   r   r   r   r   test_token_hexh   s   
zToken_Tests.test_token_hexc              	      s|   t jt j d  dD ]1}| j|d! t|}| |t | t	 fdd|D  W d    n1 s6w   Y  q
d S )Nz-_)r,         L   rF   c                 3   s    | ]}| v V  qd S rK   r   rN   Zlegalr   r   rQ   x   s    z1Token_Tests.test_token_urlsafe.<locals>.<genexpr>)
rL   ascii_lettersdigitsr?   r   r>   r   rR   r   rS   rT   r   rY   r   test_token_urlsafeq   s   
zToken_Tests.test_token_urlsafeN)r   r   r   r    rD   rH   rU   r\   r   r   r   r   r:   L   s    	r:   __main__)
r    r   ZunittestrL   ZTestCaser   r!   r:   r   mainr   r   r   r   <module>   s    $/