o
    \i}                     @   s   d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	 d dl
mZmZ d dlmZ ddlmZmZ dd Zejj d	d
 Zejj dd Zeejj dd Zejj dd Zejj dd ZdS )    N)AsyncMemorizedFuncAsyncNotMemorizedFuncMemorizedResultMemoryNotMemorizedResult)np
with_numpy)raises   )corrupt_single_cache_itemmonkeypatch_cached_func_warnc                    sf   t |dd}|| } tdD ] }tdD ]}| |I dH }||ks%J t||d ks/J qqdS )z<Similar to check_identity_lazy_async for coroutine functionsr   locationverbose      Nr
   )r   cacherangelen)funcaccumulatorr   memoryi_value r   ~/var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/joblib/test/test_memory_async.pycheck_identity_lazy_async   s   
r   c           	         s
  t    fdd}t| | jI d H  dD ]X}dD ]0}t| jd||d}tj| jdd ||}|d	I d H  |jd
d t }|d	I d H }qt |d	 ksUJ |	|d	I d H }||ksdJ t |d	 ksnJ qd|_
t| jdd}||d	I d H  d S )Nc                        t dI d H   d | S N皙?r
   asynciosleepappend)nr   r   r   f#      
z(test_memory_integration_async.<locals>.f)FT)rN
   )r   r   	mmap_modecompressT)ignore_errorsr
   F)warn__main__r   r   )listr   strpathr   shutilrmtreer   clearr   eval
__module__)	tmpdirr'   r,   r+   r   gcurrent_accumulatoroutevaledr   r&   r   test_memory_integration_async   s2   
r<   c                     sf   t    fdd} td dd}|| }tdD ]}t }|dI d H  t |d ks0J qd S )Nc                    r   r   r!   )xr&   r   r   ffP   r(   z test_no_memory_async.<locals>.ffr   r      r
   )r0   r   r   r   r   )r>   r   ggr   r9   r   r&   r   test_no_memory_asyncL   s   
rA   c           
         s   t | jddd}| dd }td}||I dH }||I dH }t|tjs,J |jdks3J t|tjs;J |jdksBJ ~~t	  t
| t||}||I dH }t|dks`J d	}	|	|d v sjJ t|tjsrJ |jdksyJ dS )
z8Check that mmap_mode is respected even at the first callr)   r   )r   r+   r   c                    s
   | d S )Nr   r   )ar   r   r   twiced   s   z6test_memory_numpy_check_mmap_mode_async.<locals>.twicer   Nr
   zException while loading results)r   r1   r   r   ones
isinstancememmapmodegccollectr   r   r   )
r7   monkeypatchr   rC   rB   bcrecorded_warningsdexception_msgr   r   r   'test_memory_numpy_check_mmap_mode_async]   s,   


rP   c              	      s   d	dd}t t|| jt|t| jdd|td d|fttttfD ]B\}}tdD ]}|	dI d H }t
||s@J | dksHJ q/|  tt |  W d    n1 s`w   Y  |  q'd S )
Nr
   c                    s   t dI d H  | d | S )Nr    r   )r"   r#   )r=   yr   r   r   r'      s   z%test_call_and_shelve_async.<locals>.fr   r   )r   r      )r
   )zipr   r1   r   r   r   r   r   r   call_and_shelverE   getr4   r	   KeyError)r7   r'   r   Resultr   resultr   r   r   test_call_and_shelve_async   s0   




rY   c                    s   dd }| j |dgd}i }|d|I d H dksJ |d|I d H dks'J |d|I d H \}}|dks:J dt|tsCJ dd S )	Nc                    s.   t dI d H  || dd || < ||  S )Nr    r   r
   )r"   r#   rU   )r=   counterr   r   r   r>      s   z*test_memorized_func_call_async.<locals>.ffrZ   )ignorer   r
   zf has not been called properlyz0Metadata are not returned by MemorizedFunc.call.)r   callrE   dict)r   r>   r@   rZ   r=   metar   r   r   test_memorized_func_call_async   s   r_   )r"   rH   r2   pytestjoblib.memoryr   r   r   r   r   joblib.test.commonr   r   joblib.testingr	   test_memoryr   r   r   markr<   rA   rP   rY   r_   r   r   r   r   <module>   s(    
,
&
