a
    h}                     @   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                    sd   t |dd}|| } tdD ]@}tdD ]2}| |I dH }||ksHJ 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   Y/var/www/html/assistant/venv/lib/python3.9/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 ]}dD ]`}t| jd||d}tj| jdd ||}|d	I d H  |jd
d t }|d	I d H }q2t |d	 ksJ |	|d	I d H }||ksJ t |d	 ks*J q*d|_
t| jdd}||d	I d H  d S )Nc                    s   t dI d H   d | S N皙?r
   asynciosleepappend)nr   r   r   f#   s    
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outZevaledr   r%   r   test_memory_integration_async   s0    
r9   c                     sd   t    fdd} td dd}|| }tdD ].}t }|dI d H  t |d ks0J q0d S )Nc                    s   t dI d H   d | S r   r    )xr%   r   r   ffP   s    
z test_no_memory_async.<locals>.ffr   r      r
   )r.   r   r   r   r   )r;   r   ggr   r7   r   r%   r   test_no_memory_asyncL   s    
r>   c           
         s   t | jddd}| dd }td}||I dH }||I dH }t|tjsVJ |jdksdJ t|tjstJ |jdksJ ~~t	  t
| t||}||I dH }t|dksJ d	}	|	|d v sJ t|tjsJ |jdksJ 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   r/   r   r   Zones
isinstanceZmemmapmodegcZcollectr   r   r   )
r5   Zmonkeypatchr   r@   r?   bcZrecorded_warningsdZexception_msgr   r   r   'test_memory_numpy_check_mmap_mode_async]   s*    


rG   c              	      s   d	dd}t t|| jt|t| jdd|td d|fttttfD ]\}}tdD ]2}|	dI d H }t
||s~J | dks\J q\|  tt |  W d    n1 s0    Y  |  qLd 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   r/   r   r   r   r   r   r   Zcall_and_shelverA   getr2   r	   KeyError)r5   r&   r   Resultr   resultr   r   r   test_call_and_shelve_async   s*    


&rO   c                    s   dd }| j |dgd}i }|d|I d H dks4J |d|I d H dksLJ |d|I d H \}}|dksrJ dt|tsJ dd S )	Nc                    s,   t dI d H  || dd || < ||  S )Nr   r   r
   )r!   r"   rK   )r:   counterr   r   r   r;      s    z*test_memorized_func_call_async.<locals>.ffrP   )ignorer   r
   zf has not been called properlyz0Metadata are not returned by MemorizedFunc.call.)r   callrA   dict)r   r;   r=   rP   r:   metar   r   r   test_memorized_func_call_async   s    rU   )r!   rC   r0   ZpytestZjoblib.memoryr   r   r   r   r   Zjoblib.test.commonr   r   Zjoblib.testingr	   Ztest_memoryr   r   r   markr9   r>   rG   rO   rU   r   r   r   r   <module>   s&   
,
&
