U
    ½mœdT  ã                   @   sˆ   d dl Z d dlmZ d dlZd dlmZmZmZ d dlm	Z	m
Z
 dd„ Zdd„ Zd	d
„ Zdd„ Zej ddddg¡dd„ ƒZdd„ ZdS )é    N)ÚThreadPoolExecutor)Ú
get_configÚ
set_configÚconfig_context)ÚdelayedÚParallelc                   C   sÔ  t ƒ dddddddddœks t‚tdd� t ƒ d	 dks<t‚tdd��& t ƒ dddddddddœksht‚W 5 Q R X t ƒ d	 dks„t‚tdd��Ø td d�� t ƒ d	 dks®t‚W 5 Q R X t ƒ d	 dksÊt‚tdd��t t ƒ d	 dksèt‚td d��8 t ƒ d	 dk�st‚tdd� t ƒ d	 dk�s&t‚W 5 Q R X t ƒ d	 dk�sDt‚W 5 Q R X t ƒ d	 dk�sbt‚W 5 Q R X t ƒ dddddddddœk�sŽt‚t t¡� tdƒ W 5 Q R X t t¡� tdd
� ¡  W 5 Q R X d S )NFi   TÚdiagramé   Údefault)Úassume_finiteZworking_memoryZprint_changed_onlyÚdisplayZarray_api_dispatchZpairwise_dist_chunk_sizeZenable_cython_pairwise_distZtransform_output©r   r   ©Zdo_something_else)r   ÚAssertionErrorr   r   ÚpytestÚraisesÚ	TypeErrorÚ	__enter__© r   r   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/tests/test_config.pyÚtest_config_context
   sd    ø
ø

ør   c                	   C   sp   t ƒ d dkst‚z2tdd�� t ƒ d dks2t‚tƒ ‚W 5 Q R X W n tk
rX   Y nX t ƒ d dkslt‚d S )Nr   FTr   )r   r   r   Ú
ValueErrorr   r   r   r   Útest_config_context_exceptionP   s    r   c                	   C   s¦   t ƒ d dkst‚td d� t ƒ d dks.t‚tdd� t ƒ d dksJt‚td d� t ƒ d dksft‚tdd� t ƒ d dks‚t‚t t¡� tdd� W 5 Q R X d S )Nr   Fr   Tr   )r   r   r   r   r   r   r   r   r   r   Útest_set_config[   s    



r   c              
   C   s6   t | d��" t |¡ tƒ d W  5 Q R £ S Q R X 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_finitek   s    
r   ÚbackendZlokyÚmultiprocessingÚ	threadingc                 C   sP   ddddg}ddddg}t | dd�dd„ t||ƒD ƒƒ}|ddddgksLt‚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.
    FTçš™™™™™¹?çš™™™™™É?é   )r   Zn_jobsc                 s   s    | ]\}}t tƒ||ƒV  qd S )N)r   r   )Ú.0r   Z	sleep_durr   r   r   Ú	<genexpr>}   s   ÿz0test_config_threadsafe_joblib.<locals>.<genexpr>N)r   Úzipr   )r   Úassume_finitesÚsleep_durationsÚitemsr   r   r   Útest_config_threadsafe_joblibr   s    þr)   c               	   C   s^   ddddg} ddddg}t dd��}dd„ | t| |¡D ƒ}W 5 Q R X |ddddgksZt‚d	S )
z©Uses 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"   )Ú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&   r'   Úer(   r   r   r   Útest_config_threadsafe…   s    þr/   )r   Úconcurrent.futuresr   r   Zsklearnr   r   r   Zsklearn.utils.parallelr   r   r   r   r   r   ÚmarkZparametrizer)   r/   r   r   r   r   Ú<module>   s   F
