a
    ;Za                     @   s   d dl Z d dlmZ d dlmZ d dlZd dlZd dlmZmZm	Z	 d dl
mZ d dl
mZ dd Zd	d
 Zdd Zdd Zejdg ddd Zdd ZdS )    N)ThreadPoolExecutor)Parallel)
get_config
set_configconfig_context)delayed)parse_versionc                
   C   sV  t  dddddksJ tdd t  d du s4J tdd( t  dddddksXJ W d    n1 sl0    Y  t  d du sJ tdd$ td d" t  d du sJ W d    n1 s0    Y  t  d du sJ tdd t  d du sJ td dB t  d du s$J tdd t  d du sBJ W d    n1 sX0    Y  t  d du svJ W d    n1 s0    Y  t  d du sJ W d    n1 s0    Y  t  dddddksJ tt td W d    n1 s0    Y  tt tdd  W d    n1 sH0    Y  d S )	NFi   Ttext)assume_finiteZworking_memoryZprint_changed_onlyZdisplayr
   r
   Zdo_something_else)r   r   r   pytestraises	TypeError	__enter__ r   r   8lib/python3.9/site-packages/sklearn/tests/test_config.pytest_config_context   sL    
*0
444(r   c                   C   s   t  d du sJ zFtdd( t  d du s2J t W d    n1 sL0    Y  W n tyj   Y n0 t  d du s~J d S )Nr
   FTr   )r   r   
ValueErrorr   r   r   r   test_config_context_exceptionG   s    (r   c                   C   s   t  d du sJ td d t  d du s.J tdd t  d du sJJ td d t  d du sfJ tdd t  d du sJ tt tdd W d    n1 s0    Y  d S )Nr
   Fr   Tr   )r   r   r   r   r   r   r   r   r   test_set_configR   s    



r   c                 C   sB   t | d$ t| t d W  d   S 1 s40    Y  dS )zAReturn the value of assume_finite after waiting `sleep_duration`.r   r
   N)r   timesleepr   )r
   Zsleep_durationr   r   r   set_assume_finiteb   s    
r   backend)lokyZmultiprocessingZ	threadingc                 C   sh   t tjt dk r$| dkr$td ddg}ddg}t| dd	d
d t||D }|ddgksdJ dS )ao  Test that the global config is threadsafe with all joblib backends.
    Two jobs are spawned and sets assume_finite to two different values.
    When the job with a duration 0.1s completes, the assume_finite value
    should be the same as the value passed to the function. In other words,
    it is not influenced by the other job setting assume_finite to True.
    z0.12r   z+loky backend does not exist in joblib <0.12FT皙?皙?   )r   Zn_jobsc                 s   s    | ]\}}t t||V  qd S )N)r   r   ).0r
   Z	sleep_durr   r   r   	<genexpr>x   s   z0test_config_threadsafe_joblib.<locals>.<genexpr>N)r   joblib__version__r   skipr   zip)r   assume_finitessleep_durationsitemsr   r   r   test_config_threadsafe_joblibi   s    	
r(   c                  C   sf   ddg} ddg}t dd(}dd |t| |D }W d	   n1 sH0    Y  |ddgksbJ d	S )
zUses threads directly to test that the global config does not change
    between threads. Same test as `test_config_threadsafe_joblib` but with
    `ThreadPoolExecutor`.FTr   r   r   )Zmax_workersc                 S   s   g | ]}|qS r   r   )r   outputr   r   r   
<listcomp>   s   z*test_config_threadsafe.<locals>.<listcomp>N)r   mapr   )r%   r&   er'   r   r   r   test_config_threadsafe   s    $r-   )r   Zconcurrent.futuresr   r!   r   r   Zsklearnr   r   r   Zsklearn.utils.fixesr   r   r   r   r   r   ZmarkZparametrizer(   r-   r   r   r   r   <module>   s   :
