U
    bey(                     @   s   d Z ddlZddlZddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ G d	d
 d
eejZej G dd deZdS )z) Test collection for the RetryingClient.     N)mock   )ClientTestMixin
MockSocket)RetryingClient)Client)MemcacheUnknownErrorMemcacheClientErrorc                   @   s   e Zd Zdd Zdd ZdS )TestRetryingClientPassthroughc                 K   s4   t d|}tt|}tjtt|d|d|_|S )N	localhostsockZside_effect)r   	r   r   listr   ZMock	functoolspartialsetattr_connectselfmock_socket_valueskwargsbase_clientr    r   c/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pymemcache/test/test_client_retry.pymake_base_client   s    
z.TestRetryingClientPassthrough.make_base_clientc                 K   s$   | j f d|i|}t|dd}|S )Nr   r   attemptsr   r   r   r   r   r   clientr   r   r   make_client   s    z)TestRetryingClientPassthrough.make_clientN)__name__
__module____qualname__r   r!   r   r   r   r   r
      s   r
   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/S )0TestRetryingClientc                 K   s4   t d|}tt|}tjtt|d|d|_|S )z9Creates a regular mock client to wrap in the RetryClient.r   r   r   )r   r   r   r   r   r   r   *   s    
z#TestRetryingClient.make_base_clientc                 K   s   | j |d}t|f|}|S )zt
        Creates a RetryingClient that will respond with the given values,
        configured using kwargs.
        )r   r   r   r   r   r   r!   6   s    zTestRetryingClient.make_clientc              	   C   s2   |  g }t| tt t  W 5 Q R X d S N)r   r   pytestraises	TypeError)r   r   r   r   r   test_constructor_defaultC   s    
z+TestRetryingClient.test_constructor_defaultc              	   C   sJ   |  g }t|dd}|jdks$ttt t|dd W 5 Q R X d S )Nr   r   r   )r   r   Z	_attemptsAssertionErrorr'   r(   
ValueErrorr   r   rcr   r   r   test_constructor_attemptsJ   s
    
z,TestRetryingClient.test_constructor_attemptsc              	   C   s   |  g }t|d d}|jt ks&tt|ttgd}|jttgksLtt|tgd}|jttgksntt|ttgd}|jttfksttt	 t|dd W 5 Q R X tt	 t|tt
gd W 5 Q R X d S )N)	retry_forhaha!)r   r   
_retry_fortupler+   	ExceptionIOErrorr'   r(   r,   strr-   r   r   r   test_constructor_retry_forR   s    
z-TestRetryingClient.test_constructor_retry_forc              	   C   s   |  g }t|d d}|jt ks&tt|ttgd}|jttgksLtt|tgd}|jttgksntt|ttgd}|jttfksttt	 t|dd W 5 Q R X tt	 t|tt
gd W 5 Q R X d S )N)do_not_retry_forr1   )r   r   _do_not_retry_forr3   r+   r4   r5   r'   r(   r,   r6   r-   r   r   r    test_constructor_do_no_retry_form   s    
z3TestRetryingClient.test_constructor_do_no_retry_forc              	   C   s   |  g }t|d d d}|jt ks(t|jt ks8tt|ttgtt	gd}|jttfks`t|jtt	fksrtt
t t|ttt	gtt	gd}W 5 Q R X d S )N)r0   r8   )r   r   r2   r3   r+   r9   r4   r5   r,   r   r'   r(   r-   r   r   r   test_constructor_both_filters   s"    
z0TestRetryingClient.test_constructor_both_filtersc                 C   s*   |  g }t|}t|t|ks&td S r&   )r   r   dirr+   )r   baser    r   r   r   test_dir_passthrough   s    
z'TestRetryingClient.test_dir_passthroughc                 C   s   |  ddg}d|d< d S )N	   UNKNOWN
   STORED
   value   keyr!   r   r    r   r   r    test_retry_dict_set_is_supported   s    z3TestRetryingClient.test_retry_dict_set_is_supportedc                 C   s"   |  ddg}|d dkstd S )Nr?      VALUE key 0 5
value
END
rB   rA   )r!   r+   rD   r   r   r    test_retry_dict_get_is_supported   s    z3TestRetryingClient.test_retry_dict_get_is_supportedc              	   C   s0   |  ddg}tt |d  W 5 Q R X d S )Nr?      END
rB   )r!   r'   r(   KeyErrorrD   r   r   r   *test_retry_dict_get_not_found_is_supported   s    z=TestRetryingClient.test_retry_dict_get_not_found_is_supportedc                 C   s   |  ddg}|d= d S )Nr?   s	   DELETED
rB   rC   rD   r   r   r    test_retry_dict_del_is_supported   s    z3TestRetryingClient.test_retry_dict_del_is_supportedc                 C   s,   | j ddgdd}|d}|dks(td S )Nr?   rF      r   keyrA   r!   getr+   r   r    resultr   r   r   test_retry_get_found   s     
z'TestRetryingClient.test_retry_get_foundc                 C   s,   | j ddgdd}|d}|d ks(td S )Nr?   rH   rL   r   rM   rN   rP   r   r   r   test_retry_get_not_found   s    
z+TestRetryingClient.test_retry_get_not_foundc              	   C   s6   | j ddgdd}tt |d W 5 Q R X d S )Nr?   rL   r   rM   r!   r'   r(   r   rO   rD   r   r   r   test_retry_get_exception   s    z+TestRetryingClient.test_retry_get_exceptionc                 C   s2   | j ddgdd}|jdddd}|d	ks.td S )
Nr?   r@   rL   r   rM   valueFZnoreplyT)r!   setr+   rP   r   r   r   test_retry_set_success   s    z)TestRetryingClient.test_retry_set_successc              	   C   s>   | j dddgdd}tt |jdddd W 5 Q R X d S )	Nr?   r@   rL   r   rM   rV   FrW   )r!   r'   r(   r   rX   rD   r   r   r   test_retry_set_fail   s     z&TestRetryingClient.test_retry_set_failc              	   C   s6   | j ddgdd}tt |d W 5 Q R X d S )Nr?   rF   r   r   rM   rT   rD   r   r   r   test_no_retry   s     z TestRetryingClient.test_no_retryc                 C   s8   | j tddgdttgd}|d}|dks4td S )NWhoops.rF   rL   r   r0   rM   rA   )r!   r	   r3   rO   r+   rP   r   r   r    test_retry_for_exception_success   s    

z3TestRetryingClient.test_retry_for_exception_successc              	   C   sB   | j tddgdttgd}tt |d W 5 Q R X d S )Nr\   rF   rL   r]   rM   )r!   r   r3   r	   r'   r(   rO   rD   r   r   r   test_retry_for_exception_fail   s    
z0TestRetryingClient.test_retry_for_exception_failc                 C   s8   | j tddgdttgd}|d}|dks4td S )Nr\   rF   rL   r   r8   rM   rA   )r!   r	   r3   r   rO   r+   rP   r   r   r   'test_do_not_retry_for_exception_success   s    

z:TestRetryingClient.test_do_not_retry_for_exception_successc              	   C   sB   | j tddgdttgd}tt |d W 5 Q R X d S )Nr\   rF   rL   r`   rM   )r!   r	   r3   r'   r(   rO   rD   r   r   r   $test_do_not_retry_for_exception_fail   s    
z7TestRetryingClient.test_do_not_retry_for_exception_failc              	   C   sh   | j tddtddgdttgttgd}|d}|dksDttt |d W 5 Q R X d S )Nr\   rF   rL   )r   r0   r8   rM   rA   )r!   r	   r   r3   rO   r+   r'   r(   rP   r   r   r   test_both_exception_filters
  s    
z.TestRetryingClient.test_both_exception_filtersN)r"   r#   r$   r   r!   r*   r/   r7   r:   r;   r>   rE   rG   rJ   rK   rR   rS   rU   rY   rZ   r[   r^   r_   ra   rb   rc   r   r   r   r   r%   (   s.   

r%   )__doc__r   Zunittestr   r'   Ztest_clientr   r   Zpymemcache.client.retryingr   Zpymemcache.client.baser   Zpymemcache.exceptionsr   r	   ZTestCaser
   markunitobjectr%   r   r   r   r   <module>   s   