o
    ^Zh}                     @   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   L/var/www/auris/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outZ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   
r@   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   Zones
isinstanceZmemmapmodegcZcollectr   r   r   )
r7   Zmonkeypatchr   rB   rA   bcZrecorded_warningsdZexception_msgr   r   r   'test_memory_numpy_check_mmap_mode_async]   s,   


rI   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   Zcall_and_shelverC   getr4   r	   KeyError)r7   r'   r   Resultr   resultr   r   r   test_call_and_shelve_async   s0   




rQ   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#   rM   )r<   counterr   r   r   r=      s   z*test_memorized_func_call_async.<locals>.ffrR   )ignorer   r
   zf has not been called properlyz0Metadata are not returned by MemorizedFunc.call.)r   callrC   dict)r   r=   r?   rR   r<   metar   r   r   test_memorized_func_call_async   s   rW   )r"   rE   r2   ZpytestZjoblib.memoryr   r   r   r   r   Zjoblib.test.commonr   r   Zjoblib.testingr	   Ztest_memoryr   r   r   markr;   r@   rI   rQ   rW   r   r   r   r   <module>   s(    
,
&
