CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_memory.cpython-310.pyc295 linesDownload Raw Back to __pycache__
1o

2��YiC��@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl3Z4ddlZddlm
Z
ddlZddlmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'dd	l(m)Z)m*Z*m+Z+d�dd�Z,d
d�Z-dd�Z.dd�Z/dd�Z0e)dddg�dd��Z1dd�Z2dd�Z3dd�Z4d d!�Z5d"d#�Z6d$d%�Z7d&d'�Z8d(d)�Z9gfd*d+�Z:d,d-�Z;e'e)d.dd/g�d0d1���Z<e'd2d3��Z=d4d5�Z>d6d7�Z?d8d9�Z@d:d;�ZAe)d<d=gd>d/fgd?dfg�d@dA��ZBdBdC�ZCdDdE�ZDejE�)dFddg�dGdH��ZFdIdJ�ZGdKdL�ZHdMdN�ZIdOdP�ZJdQdR�ZKdSdT�ZLdUdV�ZMdWdX�ZNdYdZ�ZOd[d\�ZPd]d^d_�d`da�ZQdbeRdceSddeSfdedf�ZTdgdh�ZUdidj�ZVd�dkdl�ZWdmdn�ZXdodp�ZYdqdr�ZZdsdt�Z[dudv�Z\dwdx�Z]dydz�Z^d�d{d|�Z_e&d}d~��Z`e&dd���Zad�d��ZbGd�d��d�e�ZcGd�d��d�e�Zde)d�dee�ef�g�d�d���Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�d��Zld�d��Zmd�d��Znd�d��Zod�d��Zpd�d�d��ZqejE�)d�d�d�d��d/d�d�d�id��g�d�d���Zrd�d��ZsGd�d��d��ZtGd�d��d��ZuGd�d��d��ZvdS)�z5Test the memory module.6�N)�Path)�FileSystemStoreBackend�StoreBackendBase)�hash)�_FUNCTION_HASHES�_STORE_BACKENDS�JobLibCollisionWarning�
MemorizedFunc�MemorizedResult�Memory�NotMemorizedFunc�NotMemorizedResult�_build_func_identifier�_store_backend_factory�
expires_after�register_store_backend)�Parallel�delayed)�np�with_multiprocessing�7with_numpy)�parametrize�raises�warns�cCs|d|S)z-A module-level function for testing purposes.����x�yrr��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\joblib/test/test_memory.py�f/sr!cCsZt|dd�}|�|�}td�D]}td�D]}||�|ksJ�t|�|dks)J�qqdS)z�Given a function and an accumulator (a list that grows every8    time the function is called), check that the function can be9    decorated by memory to be a lazy identity.10    r��location�verbose�rrN)r�cache�range�len)�func�accumulatorr#�memory�i�_rrr �check_identity_lazy6s11��r.cCsV|j��\}tj�|jd�}t|d��}|�d�Wd�dS1s$wYdS)N�12output.pkl�w�garbage)�
store_backend�	get_items�os�path�join�open�write)r+Zsingle_cache_itemZoutput_filenamer!rrr �corrupt_single_cache_itemEs13"�r9cs"g��fdd�}|�|d|��S)Ncs��|�dS�N��append)�item�Zrecordedrr �append_to_recordSsz6monkeypatch_cached_func_warn.<locals>.append_to_record�warn)�setattr)r)Zmonkeypatch_fixturer?rr>r �monkeypatch_cached_func_warnLsrBcs�t���fdd�}t|�|j�dD]M}dD]*}t|jd||d�}tj|jdd�|�|�}|d	�|jd14d�t��}|d	�}qt��|d	ksKJ�|�	|d	�|ksUJ�t��|d	ks_J�qd|_15t|jd
d�}|�|�d	�dS)z&Simple test of memory lazy evaluation.c���d�|S�Nrr;��arg�r*rr r!c�16z"test_memory_integration.<locals>.f)FT)�rN�17)r#r$�	mmap_mode�compressT��
ignore_errorsrF)r@�__main__rr"N)�listr.�strpathr�shutil�rmtreer&�clearr(�eval�18__module__)�tmpdirr!rLrKr+�g�current_accumulator�outrrGr �test_memory_integration\s.�1920r[�call_before_reducingTFcsdD]�}d}d�|�}i}ttt�|�|dd�d|�|d}d|_|d�dks*J�|jj|ks2J�t|j	d	d21�}|�22|��tt�
|d��dksKJ�t�
|d�d	}d|vsZJ�|d|}	|d	kr�t�
|	�dgksnJ�t�
|	d�gksyJ�|r��d
�tt�
|	d��dks�J�tdd��fdd�dD��n8tdd��fdd�dD��td�D]}23tt�
|	d��d
kr�nt�d�q�tt�
|	d��d
ks�J��d
�tt�
|	d��dks�J�qtt�
|	d��dks�J��d
�tt�
|	d��dks�J�qdS)N)rrz024        def f(x):25            return x26        z<ipython-input-{}-000000000000>�exec)�filename�moder!rOrrr"�joblibz
ipython-inputr%r�Zn_jobsc3��|]	}t��|�VqdSr:�r��.0r,�Zcached_frr �	<genexpr>���zHtest_parallel_call_cached_function_defined_in_jupyter.<locals>.<genexpr>)rrc3rbr:rcrdrfrr rg�rh�皙�����?�)�formatr]�compile�textwrap�dedentrV�__code__�co_filenamerrQr&r(r4�listdirrr'�time�sleep)rWr\Z27session_noZipython_cell_sourceZipython_cell_idZ	my_localsr!r+Zf_cache_relative_directoryZf_cache_directoryr-rrfr �5test_parallel_call_cached_function_defined_in_jupyter�sT28��29	�rucs^t���fdd�}tddd�}|�|�}td�D]}t��}|d�t��|dks,J�qdS)z*Test memory with location=None: no memoizecrCrDr;rErGrr �ff�rHztest_no_memory.<locals>.ffNrr"rkr)rPrr&r'r()rvr+Zggr-rYrrGr �test_no_memory�s30�rwcsRt��d31�fdd�	}t|�|j�t|jdd�}|�|�}|ddd	�dks'J�dS)z3Test memory with a function with keyword arguments.NrcrCrDr;�Zarg1Zarg2rGrr rXrHztest_memory_kwarg.<locals>.grr"�rrxrD)rPr.rQrr&)rWrXr+rrGr �test_memory_kwargs32rzcs,t���fdd��t�fdd��|j�dS)z*Test memory with a function with a lambda.crC�z*A helper function to define l as a lambda.rr;�rrGrr �helper�33z"test_memory_lambda.<locals>.helpercs�|�Sr:rr|)r}rr �<lambda>�z$test_memory_lambda.<locals>.<lambda>N)rPr.rQ)rWr)r*r}r �test_memory_lambdasr�cCs�t|jdd�}|jdd��}|}|jdd��}|}tt��}|d�|d�Wd�n1s0wYt|�dks=J�dt|dj�vsHJ�dS)	z=Check that name collisions with functions will raise warningsrr"cS�|S)z&A first function called name_collisionrr|rrr �name_collision$�z2test_memory_name_collision.<locals>.name_collisioncSr�)z'A second function called name_collisionrr|rrr r�+r�rN�	collision)rrQr&rrr(�str�message)rWr+r��a�b�warninforrr �test_memory_name_collision s34353637�r�cCs�t|jdd�}|�dd��}|�dd��}tt�� }|d�dks"J�|d�dks*J�|d�dks2J�Wd�n1s<wYt|�dksIJ�dS)	Nrr"cSr�r:rr|rrr r=�z7test_memory_warning_lambda_collisions.<locals>.<lambda>cS�|dSrDrr|rrr r>r�rrrk)rrQr&rrr()rWr+r�r�r�rrr �%test_memory_warning_lambda_collisions:s38�r�cCs�t|jdd�}td�}|�|�}td�}|�|�}tt��}|d�|d�|d�Wd�n1s4wYt|�dksAJ�dt|dj��	�vsNJ�dS)Nrr"�lambda x: xz
lambda x: x+1rrz
cannot detect)39rrQrUr&rrr(r�r��lower)rWr+Za1�b1r�rrr �'test_memory_warning_collision_detectionJs40414243�r�cs8t���fdd�}ddl}|�|d�}t|�|j�dS)z#Test memory with functools.partial.cs��d�|Sr{r;rrGrr r)`r~z!test_memory_partial.<locals>.funcrNr)rP�	functools�partialr.rQ)rWr)r��functionrrGr �test_memory_partial\s44r�cCs4t|jdd�}td�}|�|�}|d�dksJ�dS)zESmoke test memory with a function with a function defined in an eval.rr"r�rN)rrQrUr&)rWr+�m�mmrrr �test_memory_evalls45r�cCst|�}|�d�|S)zsA function with a side effect in its arguments.46 47    Return the length of its argument and append one element.48    N)r(r<)rZlen_xrrr �count_and_appendvs49r�cCs8t|jdd�}|�t�}|�dksJ�|�dksJ�dS)zsCheck that if a function has a side effect in its arguments, it50    should use the hash of changing arguments.51    rr"rN)rrQr&r�)rWr+r)rrr �test_argument_change�s52r�rKrIc	s�t��d	�fdd�	}t|j|dd�}|�|�}tj�d�}td�D]#}|�d�}td�D]}t�	||�|k�s9J�t53��|dksCJ�q,q!dS)54z.Test memory with a function with numpy arrays.NcrCrDr;rErGrr �n�rHztest_memory_numpy.<locals>.nr�r#rKr$r%)rJrJrr:)rPrrQr&r�randomZRandomStater'Z
random_sample�allr()	rWrKr�r+Zcached_nZrndr,r�r-rrGr �test_memory_numpy�s5556��r�c57Cs�t|jddd�}|��dd��}t�d�}||�}||�}t|tj�s%J�|jdks,J�t|tj�s4J�|jdks;J�~~t�	�t58|�t||�}||�}t|�dksVJ�d}	|	|dvs`J�t|tj�shJ�|jdksoJ�d	S)59z8Check that mmap_mode is respected even at the first callrIrr�cSs|dS�Nrr�r�rrr �twice��z0test_memory_numpy_check_mmap_mode.<locals>.twicer%r�Exception while loading resultsN)
rrQr&rZones�60isinstanceZmemmapr_�gcZcollectr9rBr()61rW�monkeypatchr+r�r�r��c�recorded_warnings�d�
exception_msgrrr �!test_memory_numpy_check_mmap_mode�s*626364r�c	szt|jdd�}Gdd�dt��|jd65�fdd�	�}|�td�D]}t���|d�Wd	�n1s5wYq d	S)z+Smoketest the exception handling of Memory.rr"c@�eZdZdS)z*test_memory_exception.<locals>.MyExceptionN��__name__rV�__qualname__rrrr �MyException��r�cs|r��dSr:r)�exc�r�rr �h�s�z test_memory_exception.<locals>.hr%rN)r)rrQ�	Exceptionr&r'r)rWr+r�r-rr�r �test_memory_exception�s6667���r�cs�t|jdd�}t��|jdgd�d�fdd�	�}|jdgks J�|ddd�t��dks.J�|ddd�t��dks<J�|dd	d�t��dksJJ�d68S)z!Test the ignore feature of memoryrr"r��ignorerc���d�dSrDr;rrGrr �z��ztest_memory_ignore.<locals>.z�rrN�r�rrQrPr&r�r()rWr+r�rrGr �test_memory_ignore�sr�cs�t|jdd�}t��dd�}|jdgd�|d
�fdd	�	��}|jdgks&J�|ddd69�t��dks4J�|ddd70�t��dksBJ�|ddd71�t��dksPJ�dS)z9Test the ignore feature of memory on a decorated functionrr"cst����fdd��}|S)Ncs�|i|��Sr:r)�args�kwargs�r!rr �wrapped�r�z?test_memory_ignore_decorated.<locals>.decorate.<locals>.wrapped)r��wraps)r!r�rr�r �decorate�sz.test_memory_ignore_decorated.<locals>.decoraterr�rcr�rDr;rrGrr r��sz'test_memory_ignore_decorated.<locals>.zr�rNr�r�)rWr+r�r�rrGr �test_memory_ignore_decorated�sr�cCsTt|jdd�}|jdd��}|d�dksJ�|dd�dksJ�|dd�dks(J�d	S)72z_Non-regression test against 0.12.0 changes.73 74    https://github.com/joblib/joblib/pull/75175    rr"cSr�rDrr�rrr �plus_oner�z,test_memory_args_as_kwargs.<locals>.plus_onerrr�r%N)rrQr&)rWr+r�rrr �test_memory_args_as_kwargss76r�zignore, verbose, mmap_moder�drJcCsTt|jdd�}|j|||d�dd��}|j|ksJ�|j|ks!J�|j|ks(J�dS)z7Check cache may be called with kwargs before decoratingrr")r�r$rKcS�dSr:rr|rrr r�'�z"test_partial_decoration.<locals>.zN)rrQr&r�Z_verboserK)rWr�r$rKr+r�rrr �test_partial_decoration"s77r�c	Cs*t|jdd�}t�d�}|�d�|jdg|�R�j}|�t�}tt�}t	j78�|jj|�}||ks3J�t	j79�
|�s;J�|jt	j80�|jj�ksHJ�t��|��rRJ�t	j81�
t	j82�|d��s_J�|��seJ�|�d�}t	j83�|jj|j|�}|d�}t	j84�
|�s�J�t	�t	j85�|d��||d�ks�J�dS)	Nrr"�.r!r`zfunc_code.pyrr/)rrQr��splitr<r6r&r!rr4r5r2r#�exists�dirnamerrT�_check_previous_func_code�_get_args_id�func_id�remove)	rWr+r5rXr�r#�args_id�86output_dirr�rrr �
test_func_dir0s(87888990r�c	Cs�t|jdd�}|�t�}|d�}t�t�|��}|�d�}tj	�91|jj|j
|�}tj	�|�s0J�||j�|j
|g�ks=J�t�t�|��}|jj|jjksOJ�tddd�}t�t�|��|�t�}t�t�|��}|d�dS)Nrr"r)rrQr&r!�pickle�loads�dumpsr�r4r5r6r2r#r�r�Z	load_item)	rWr+rX�outputr�r�r�Zmemory2�gprrr �test_persistencePs929394r��consider_cache_validcs�tt|j�fdd�d�t|jdd�jt�fdd�d�fD]0}|�d�}t|t�s*J�|r.J�|d�dks6J�|�d�}t|t�sBJ�|�ksHJ�|��qt	t�}|�d�rXJ�dS)	Nc��Sr:r�r-�r�rr rkr�z*test_check_call_in_cache.<locals>.<lambda>��cache_validation_callbackrr"cr�r:rr�r�rr rnr�r�)95r	r!rQrr&Zcheck_call_in_cacher��boolrTr)rWr�r)�resultrr�r �test_check_call_in_cachegs"���969798r�c	Cs�ttt|j�tt�t|jdd��t�tdd��t�fttttf�D]@\}}|d�dks-J�|�	d�}t99||�s9J�|��dksAJ�|��t
t��|��Wd�n1sXwY|��q!dS)Nrr"�r#rr�)�zipr	r!rQrrr&r100r
�call_and_shelver��getrTr�KeyError)rWr)�Resultr�rrr �test_call_and_shelve~s$101�102�	103104105�106�r�c	Cs|�d�}|�d�t�|j�j}t�d�|��dksJ�|t�|j�jkr,t	�107d�t|jdd�}|�t
�}|�d�}tj�|jj|j|d�}|d�dksQJ�t�|�j}t�d	�|�d�}t|t�shJ�t�|�j|ksrJ�t�d	�|��dksJ�t�|�j|ks�J�d108S)z6Check call_and_shelve only load stored data if needed.Ztest_access��?z>filesystem does not support fine-grained access time attributerr"rr/r�rN)r6r8r4�statrQ�st_atimersrt�read�pytest�skiprr&r!r�r5r2r#r�r�r�r109r�)	rWZtest_access_time_fileZtest_access_timer+r)r��result_pathZfirst_access_timer�rrr �.test_call_and_shelve_lazily_load_stored_result�s,110111112113114115�116117118r�c	Cs�tt|j�tt�fD]Q}|�d�j}|�d�}t|d��}t�||�Wd�n1s-wYt|d��
}t�	|�}Wd�n1sGwY|�119�|�120�ksVJ�t�|�q121dS)Nzpickling_test.datr�wb�rb)
r	r!rQrr6r�r7r��dump�loadr�r4r�)rWr)r^r��fp�result2rrr �test_memorized_pickling�s122���r�cCs123tt|j�}|�d�}tt|j�}|�d�}|��|��ks J�t|�t|�ks*J�tt�}t|�t|�d��tt|jdt��d�}|�d�}|��tt|jdd�}|�d�}|��tt|jdt��d�}|�d�}|��tt|jdd�}|�d�}|��dS)Nr�)r$�	timestamp)r$r�)r	r!rQr�r��reprrrs)rWr)r�Zfunc2r�rrr �test_memorized_repr�s*124125126127128129rcCs�|�d�j}tj�|d�}d}t|d��
}|�|�Wd�n1s$wY|�|�ddl}t	|jdd�}|�130|j�}	|	d�|	d�|	d�t|d��}|�d	|�Wd�n1sbwY|	d�|	d�t�
|�t�|�d131}t|d��
}|�|�Wd�n1s�wY|	d�|	d�tj�d�tj�d�ddl}|�132|j�}	|	d�|	d�|��\}133}|134d
ks�J�dS)NZ135tmp_importztmp_joblib_.pyz$def f(x):136    print(x)137    return x138r0rr"rrz139 140z-def f(x):141    print("x=%s" % x)142    return x143z144Reloading145�tmp_joblib_z11462147Reloading148x=1149)�mkdirrQr4r5r6r7r8Zsyspath_prependrrr&r!rRrS�sys�stdout�modules�pop�150readouterr)ZcapsysrWr��dir_namer^�contentZmodule_file�tmpr+r!rZ�errrrr �test_memory_file_modification�sD�151�152153�rcCr�r:r�r�r�rrr �_function_to_cacher�rcC�||Sr:rrrrr �_sum#�rcCs||Sr:rrrrr �_product'rrcCs�tjt_t|jdd�}|�t�}|dd�dksJ�|dd�dks"J�tt��tjt_|dd�dks4J�|dd�dks=J�Wd�dS1sHwYdS)Nrr"rrr%)	rrprrrQr&rrr)rWr+r!rrr �*test_memory_in_memory_function_code_change+s154155"�rcCstdd�}|��dS)Nr�)rrT)r+rrr �$test_clear_memory_with_none_location;s156r�kw1�kw2�rrcCs||||fSr:r)r�r�rrrrr �func_with_kwonly_args@srr�r��returncCrr:rrrrr �func_with_signatureDrrcCst|jdd�}|�t�}|dddd�dksJ�tt��}|ddddd	�Wd�n1s.wY|�d157�|ddddd�tt��}|ddddd	�Wd�n1sWwY|�d158�|jtdgd
�}|ddddd�dksuJ�|ddddd�dks�J�dS)Nrr"rrr%)r)rrr%rrk)rz?Keyword-only parameter 'kw1' was passed as positional parameterrrr�)rrr%rkZignored)rrQr&rr�159ValueError�match)rWr+�func_cached�excinforrr �!test_memory_func_with_kwonly_argsHs160161�162163�164r"cCs.t|jdd�}|�t�}|dd�dksJ�dS)Nrr"rg@g@)rrQr&r)rWr+r rrr �test_memory_func_with_signaturebs165r#cstt|jdd�}|��dd���tt|��}|D]}�|�qt����fdd�|D�}��fdd�|D�}||�fS)Nrr"cS�dS)N��aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrErrr �get_1000_byteslr�z(_setup_toy_cache.<locals>.get_1000_bytescsg|]}��|��qSr)r�)rerF)r&rr �166<listcomp>u�z$_setup_toy_cache.<locals>.<listcomp>cs g|]}tj��jj�|��qSr)r4r5r6r2r#)rer��r�r&rr r'ws��)rrQr&rPr'r)rW�167num_inputsr+ZinputsrFZ
hash_dirnamesZ
full_hashdirsrr)r �_setup_toy_cacheis168169�170r+cs�t|�\}}}|j��}dd�|D�}t|�t|�ksJ�dd���fdd�|D�}dd�|D�}||ks7J�dd�|D�}dd�|D�}	d	d�|D�}171|172|	ksRJ�dS)173NcS�g|]}|j�qSr)r5�re�cirrr r'��z#test__get_items.<locals>.<listcomp>cs*�fdd�t���D�}tdd�|D��S)Ncsg|]	}tj��|��qSr�r4r5r6�re�fn��	directoryrr r'��z;test__get_items.<locals>.get_files_size.<locals>.<listcomp>css�|]	}tj�|�VqdSr:)r4r5�getsize)rer�rrr rg�rhz:test__get_items.<locals>.get_files_size.<locals>.<genexpr>)r4rr�sum)r4Z174full_pathsrr3r �get_files_size�sz'test__get_items.<locals>.get_files_sizecsg|]}�|��qSrr�reZhash_dir�r8rr r'�scSr,r)�sizer-rrr r'�r/cSsg|]	}tj�|d��qS)r/r0r9rrr r'�r5cSs g|]}tj�tj�|���qSr)�datetime�
fromtimestampr4r5�getatimer1rrr r'�s�cSr,r�Zlast_accessr-rrr r'�r/)r+r2r3�set)rWr+Zexpected_hash_dirsr-�itemsZ	hash_dirsZexpected_hash_cache_sizesZhash_cache_sizesZoutput_filenamesZexpected_last_accessesZ
last_accessesrr:r �test__get_items~s175�rBc
Cs$t|dd�\}}}|j�d�}|gksJ�t|�\}}}|j��}|j�d�}t|�}t�t|�t|��s7J�t|�|dksAJ�|j�d�}t|�t|�ksQJ�|j�d�}|gks]J�d}	|j�|	�}176t|177�soJt|���|j�d	�}t|��|�}t	d178d�|D��t179d180d�|D��ks�J�dS)Nr)r*Z1KZ2Kri�1M��ipcss�|]}|jVqdSr:r?r-rrr rg�s�z,test__get_items_to_delete.<locals>.<genexpr>)r+r2Z_get_items_to_deleter3r(r@�issubset�sorted�181difference�max�min)
rWr+r-Zitems_to_deleteZexpected_hash_cachedirsrAZ	nb_hashesZitems_to_delete_2048bZitems_to_delete_empty�bytes_limit_too_smallZitems_to_delete_500bZitems_to_delete_6000bZsurviving_itemsrrr �test__get_items_to_delete�s.182��rKcCs�t|�\}}}|j��}|��|j��}t|�t|�ksJ�|jdd�|j��}t|�t|�ks4J�|jdd�|j��}t�t|�t|��sKJ�t|�dksSJ�d}|j|d�|j��}|gksfJ�dS)NrC)Zbytes_limitZ3KrrD�r+r2r3�reduce_sizerFr@rEr()rWr+r-�ref_cache_items�cache_itemsrJrrr �#test_memory_reduce_size_bytes_limit�s 183184185186187rPcCs�t|�\}}}|j��}|��|j��}t|�t|�ksJ�|jdd�|j��}t|�t|�ks4J�|jdd�|j��}t�t|�t|��sKJ�t|�dksSJ�|jdd�|j��}|gksdJ�dS)NrJ)Zitems_limitrrrL)rWr+r-rNrOrrr �#test_memory_reduce_size_items_limit�s188189190191192rQcCsZddl}ddl}t|�\}}}|j��}|��|j��}t|�t|�ks'J�|j|jdd�d�|j��}t|�t|�ks@J�|�d�|d�|d�|j|jdd�d�|j��}t	�193t	|�t	|��rhJ�t|�dkspJ�tj
td	d194��|j|jdd�d�Wd�n1s�wY|�d�|j|jdd�d�|j��}|gks�J�dS)Nrr)�days)Z	age_limit������������secondsrzhas to be a positive�rg����MbP?)r<rsr+r2r3rMrF�	timedeltartr@rEr(r�rr)rWr<rsr+r-Z	put_cacherNrOrrr �!test_memory_reduce_size_age_limit�s0195196197198199�200201rYcCs@t|�\}}}|��t�|jj�gksJ�|jdd�rJ�dS)Nrk)�202stacklevel)r+rTr4rrr2r#r�)rWr+r-rXrrr �test_memory_clearsr[cCsdgd}|S)Nr%i�r)�complex_objrrr �fast_func_with_complex_output#rHr]cCs"dd�ttd��D�}|r|SdS)NcSsi|]}t|�|�qSr)r�rdrrr �203<dictcomp>)r(z=fast_func_with_conditional_complex_output.<locals>.<dictcomp>gj�@z
simple output)r'�int)Zcomplex_outputr\rrr �)fast_func_with_conditional_complex_output(sr`c�bt|jd�}|�t��tdd��fdd�td�D��|��\}}d}||vs)J�||vs/J�dS)Nr�rrac3s�|]}t���VqdSr:rcrd�r rr rg5s�zMtest_cached_function_race_condition_when_persisting_output.<locals>.<genexpr>r%r�)rrQr&r]rr'r204�rWZcapfdr+r�stderrr�rrbr �:test_cached_function_race_condition_when_persisting_output-s205 recra)Nr�rrac3s,�|]}t��|ddkrdnd�VqdS)rrTFNrcrdrbrr rgKs�206�zOtest_cached_function_race_condition_when_persisting_output_2.<locals>.<genexpr>r%r�)rrQr&r`rr'r207rcrrbr �<test_cached_function_race_condition_when_persisting_output_2As208�rfc209Cs�t|jd�}dd�}|�|�}d}||�\}}||ksJ�t|�t||�}||�\}	}210t|�dks4J�d}||dvs>J�|	|ksDJ�|211|ksJJ�t|�|�|�}z|��td��t	yy}
zd	}|t212|
j�vsnJ�WYd}
~
dSd}
~
ww)213Nr�cSst�d�|t��fS)Ng{�G�z�?�rsrtrErrr r)\s214zItest_memory_recomputes_after_an_error_while_loading_results.<locals>.funcrFrr�rz<It normally not possible to load a corrupted MemorizedResultzis corrupted)rrQr&r9rBr(r�r��AssertionErrorr�r�r�)rWr�r+r)Zcached_funcZ	input_argrFrr�Zrecomputed_argZrecomputed_timestampr��	reference�er�rrr �;test_memory_recomputes_after_an_error_while_loading_resultsYs4215216217� ��rkc@seZdZdZdS)�IncompleteStoreBackendzAThis backend cannot be instantiated and should raise a TypeError.N)r�rVr��__doc__rrrr rl�srlc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd218d�Zdd
�Z	dd�Z219dd�ZdS)�DummyStoreBackendz(A dummy store backend that does nothing.cOr$)zOpen an item on store.Nr)�selfr�r�rrr �220_open_item�r�zDummyStoreBackend._open_itemcCr$)z!Check if an item location exists.Nr�ror#rrr �_item_exists�r�zDummyStoreBackend._item_existscCr$)z&Move an item from src to dst in store.Nr)ro�src�dstrrr �221_move_item�r�zDummyStoreBackend._move_itemcCr$)zCreate location on store.Nrrqrrr �create_location�r�z!DummyStoreBackend.create_locationcCr$)z&Check if an object exists in the storeFr�ro�objrrr r��r�zDummyStoreBackend.existscCr$)zClear object on storeNrrwrrr �clear_location�r�z DummyStoreBackend.clear_locationcCsgS)z3Returns the whole list of items available in cache.r)rorrr r3�r�zDummyStoreBackend.get_itemscOr$)zConfigure the storeNr)ror#r�r�rrr �	configure�r�zDummyStoreBackend.configureN)r�rVr�rmrprrrurvr�ryr3rzrrrr rn�srn�invalid_prefixcCs@tt��
}t|d�Wd�n1swY|�d�dS)Nz&Store backend name should be a string*�rrrr)r{r!rrr �(test_register_invalid_store_backends_key��222�r}cCs@tt��
}tdd�Wd�n1swY|�d�dS)N�fsz.Store backend should inherit StoreBackendBase*r|�r!rrr �+test_register_invalid_store_backends_object�r~r�cCsBtt��}tddd�Wd�n1swY|�d�dS)Nz/tmp/joblib�unknown)r#�backendzUnknown location*)r�	TypeErrorrrr�rrr �!test_memory_default_store_backend�s223�r�cCsfGdd�d�}|�}tt��}td|d�Wd�n1swYd}|t|dj�vs1J�dS)Nc@r�)zHtest_warning_on_unknown_location_type.<locals>.NonSupportedLocationClassNr�rrrr �NonSupportedLocationClass�r�r��localr�zbInstantiating a backend using a NonSupportedLocationClass as a location is not supported by joblibr)r�UserWarningrr�r�)r�Zunsupported_locationr�Zexpected_mesagerrr �%test_warning_on_unknown_location_type�s224��r�cCsbd}t|t�|tft��vsJ�tt��
}t|d�Wd�n1s%wY|�d�dS)NZisbZ
fake_locationznCan't instantiate abstract class IncompleteStoreBackend (without an implementation for|with) abstract methods*)rrlrrArr�rr)�backend_namer!rrr �)test_instanciate_incomplete_store_backend�s225226��r�cCs>d}t|t�|tft��vsJ�t|d�}t|t�sJ�dS)NZdsbZdummy_location)rrnrrArr�)r��backend_objrrr �test_dummy_store_backend�s227228229r�c230CsFtd�}td|�}z|jdksJ�Wtjddd�dStjddd�w)NZsome_folderr�TrM)rrr#rRrS)r5r�rrr �0test_instanciate_store_backend_with_pathlib_path�s231232"r�cCsjd}t�}|jdusJ�t|�t|�|jdd�ksJ�|�|j�t|�|j|jd�ks/J�t|�dS)Nz-FileSystemStoreBackend(location="{location}")r�)rr#rr�rlrzrQ)rWZrepr_patternr�rrr �"test_filesystem_store_backend_repr�sr�cCs�dd�}t|jdd�}|�|�}d}t|�|j||jjd�ks!J�|�dd�}d}t|�|j|jj|j|j	d	�ks;J�t|�d233j|jjd�ksIJ�dS)NcSrr:rrrrr �my_funcrz)test_memory_objects_repr.<locals>.my_funcrr"z/MemorizedFunc(func={func}, location={location}))r)r#�*zJMemorizedResult(location="{location}", func="{func}", args_id="{args_id}"))r#r)r�zMemory(location={location})r�)234rrQr&r�rlr2r#r�r�r�)rWr�r+Zmemorized_funcZmemorized_func_repr�memorized_resultZmemorized_result_reprrrr �test_memory_objects_reprs$235236��237�238�r�cCs�t|jd�}|jdd��}|�d�}t�|�}t�|�}|jj|jjks&J�|j	|j	ks.J�|j239|j240ks6J�t|�t|�ks@J�dS)Nr�cS�|dSr�rr|rrr rX6r�z'test_memorized_result_pickle.<locals>.grk)rrQr&r�r�r�r�r2r#r)r�r�)rWr+rXr�Zmemorized_result_pickleZmemorized_result_loadsrrr �test_memorized_result_pickle/s241242243244�r�cCsh|durg}t|�}t|�}t|���t|���ksJ�|��D]}||vr'q ||||ks1J�q dSr:)�varsr@�keys)�left�right�
ignored_attrsZ	left_varsZ245right_vars�attrrrr �compareGs�r��
memory_kwargsr%r)rLr$r�Z	parameterZunused)rKr$Zbackend_optionscCstdd|ji|��}t�t�|��}t|j|j�t||tgd��d�t|�t|�ks.J�|�	t246�}t�t�|��}t|j|j�t||tgd��d�t|�t|�ksWJ�|�d�}t�t�|��}t|j|j�t||tgd��d�t|�t|�ks�J�dS)Nr#)r2rZ
_func_code_id)r�rr)rrQr�r�r�r�r2r@rr&r!r�)rWr�r+Zmemory_reloadedr Zfunc_cached_reloadedr�Zmemorized_result_reloadedrrr �test_memory_pickle_dump_loadTs6247�248249�250251�r�cCs�|�tj�d}t|jdd�}|jdd��}||�}d|jvs!J�|��t|jdd�}|jdd��}||�}d|jvs>J�|��dS)	Nr%�r"cSr�r�rr|rrr r!�r�ztest_info_log.<locals>.fZQueryingrcSr�r�rr|rrr r!�r�)Z	set_level�logging�INFOrrQr&�textrT)rWZcaplogrr+r!r-rrr �
test_info_log�s252253r�c@sLeZdZdZddd�Zdd�Zej�ddd	g�d254d��Z	dd
�Z255dd�ZdS)�TestCacheValidationCallbackz.Tests on parameter `cache_validation_callback`NcCs"d|d<|dur
t�|�|dS)NT�runrrg)rorr��delayrrr �foo�s256zTestCacheValidationCallback.foocCsDd}tjt|d��|jdd�Wd�dS1swYdS)z2Test invalid values for `cache_validation_callbackz9cache_validation_callback needs to be callable. Got True.rWTr�N)r�rrr&)ror+rrrr �&test_invalid_cache_validation_callback�s"�zBTestCacheValidationCallback.test_invalid_cache_validation_callbackr�TFcsr|j|j�fdd�dgd�}ddiddi}}|d|�dks J�|d|�dks)J�|ds/J�|d�ks7J�d	S)257zTest expiry of old resultscr�r:rr�r�rr r�r�zUTestCacheValidationCallback.test_constant_cache_validation_callback.<locals>.<lambda>r��r�r�r�FrrkN�r&r�)ror+r�r!�d1�d2rr�r �'test_constant_cache_validation_callback�s258�zCTestCacheValidationCallback.test_constant_cache_validation_callbackcCs�dd�}|j|j|dgd�}ddiddi}}|d|dd	�d259ks"J�|d|dd	�d260ks-J�|ds3J�|ds9J�ddiddi}}|d|dd	�d261ksMJ�|d|dd	�d262ksXJ�|ds^J�|drdJ�dS)
z*Test cache validity based on run duration.cSs|d}|dkr263dSdS)N�durationg�������?Tr)�metadatar�rrr r��s�z^TestCacheValidationCallback.test_memory_only_cache_long_run.<locals>.cache_validation_callbackr�r�r�Frr)r�rkrjNr�)ror+r�r!r�r�rrr �test_memory_only_cache_long_run�s264�z;TestCacheValidationCallback.test_memory_only_cache_long_runcCs�|j|jtdd�dgd�}ddiddiddi}}}|d|�dks$J�|d|�dks-J�t�d	�|d|�dks;J�|dsAJ�|drGJ�|dsMJ�d265S)z!Test expiry of old cached resultsg333333�?rUr�r�r�Frrkr�N)r&r�rrsrt)ror+r!r�r�Zd3rrr �test_memory_expires_after�s�266z5TestCacheValidationCallback.test_memory_expires_afterr:)r�rVr�rmr�r�r��markrr�r�r�rrrr r��s267268r�c@s,eZdZdZedd��Zdd�Zdd�ZdS)	�TestMemorizedFunc�8Tests for the MemorizedFunc and NotMemorizedFunc classescCs|�|d�d||<||S)Nrr)r�)r�counterrrr r!�szTestMemorizedFunc.fcCsp|j|jdgd�}i}|d|�dksJ�|d|�dksJ�|�d|�\}}|dks-Jd��t|t�s6Jd��dS)�Test calling the functionr�r�rr�f has not been called properly�0Metadata are not returned by MemorizedFunc.call.N)r&r!�callr��dict�ror+r!r�r�metarrr �test_call_method_memorized�s�z,TestMemorizedFunc.test_call_method_memorizedcCsht|j�}i}|d|�dksJ�|d|�dksJ�|�d|�\}}|dks)Jd��t|t�s2Jd��dS)r�rrr%r�r�N)rr!r�r�r�r�rrr �test_call_method_not_memorized�s269�z0TestMemorizedFunc.test_call_method_not_memorizedN)r�rVr�rm�staticmethodr!r�r�rrrr r��s270r�c@s eZdZdZdd�Zdd�ZdS)�TestAutoGitignorer�cCsPt|�d��}t|�}|�t�}|d�|d}|��sJ�|��dks&J�dS)zsTest that using the memory object automatically creates a `.gitignore` file271        within the new cache directory.�test_cache_dirr�272.gitignorez%# Created by joblib automatically.273*274N)rrrr&�idr��	read_text)rorWr#�memZcostly_operation�gitignore_filerrr �test_memory_creates_gitignores275z/TestAutoGitignore.test_memory_creates_gitignorecCsZt|�d��}|d}d}|�|�t|�}|�t�d�|��s#J�|��|ks+J�dS)zvTest that using the memory object does not overwrite an existing276        `.gitignore` file within the cache directory.r�r�z# Existing .gitignore file!rN)rr�277write_textrr&r�r�r�)rorWr#r�Zexisting_contentr�rrr �1test_memory_does_not_overwrite_existing_gitignores278zCTestAutoGitignore.test_memory_does_not_overwrite_existing_gitignoreN)r�rVr�rmr�r�rrrr r�sr�r�)rJ)Tr:)wrmr<r�r�r�r4Zos.pathr�rRrrnrs�pathlibrr�Zjoblib._store_backendsrrZjoblib.hashingrZ
joblib.memoryrrrr	r279rrr
rrrrZjoblib.parallelrrZjoblib.test.commonrrrZjoblib.testingrrrr!r.r9rBr[rurwrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr_�floatrr"r#r+rBrKrPrQrYr[r]r`rerfrkrlrnr�rPr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr �<module>s�8280.281i282283284'285
 286$ 9287(%288 289290291-$292293 294
��295(K'
Aluode/PerceptionLabPortable · CoolFace