U
    _»{j8  ã                   @   s¨   d dl Z d dl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
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d„ Zdd„ ZdS )é    N)ÚThreadPoolExecutor)Úconfig_contextÚ
get_configÚ
set_config)ÚParallelÚdelayedc                   C   sà  t ƒ dd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ddœ
kspt‚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�sLt‚W 5 Q R X t ƒ d	 dk�sjt‚W 5 Q R X t ƒ dd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   TZdiagramé   Údefault)
Úassume_finiteZworking_memoryZprint_changed_onlyÚdisplayÚarray_api_dispatchZpairwise_dist_chunk_sizeZenable_cython_pairwise_distZtransform_outputZenable_metadata_routingZskip_parameter_validation©r
   r
   ©Zdo_something_else)r   ÚAssertionErrorr   r   ÚpytestÚraisesÚ	TypeErrorÚ	__enter__© r   r   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sklearn/tests/test_config.pyÚtest_config_context   sp    ö
ö
ö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_exceptionX   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_configc   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_finites   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_joblibz   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/   c              
      sx   t j‰ ‡ fdd„}|  t d|¡ tjtdd�� tdd�� W 5 Q R X W 5 Q R X tjtdd�� tdd� W 5 Q R X dS )	z=Check error is raised when array_api_compat is not installed.c                    s   | dkrt ‚ˆ | f|ž|ŽS ©NZarray_api_compat)ÚImportError©ÚnameÚargsÚkwargs©Zorig_importr   r   Úmocked_import¤   s    z;test_config_array_api_dispatch_error.<locals>.mocked_importÚ
__import__zarray_api_compat is required©ÚmatchT©r   N)Úbuiltinsr8   Úsetattrr   r   r1   r   r   ©Zmonkeypatchr7   r   r6   r   Ú$test_config_array_api_dispatch_errorž   s    r?   c              
      sŒ   t j‰ ‡ fdd„}|  t d|¡ |  tjjjdd¡ tjt	dd�� t
dd	�� W 5 Q R X W 5 Q R X tjt	dd�� tdd	� W 5 Q R X d
S )z!Check error when NumPy is too oldc                    s   | dkrt ƒ S ˆ | f|ž|ŽS r0   )Úobjectr2   r6   r   r   r7   ¸   s    zAtest_config_array_api_dispatch_error_numpy.<locals>.mocked_importr8   Ú__version__z1.20zNumPy must be 1.21 or newerr9   Tr;   N)r<   r8   r=   ÚsklearnÚutilsZ
_array_apiÚnumpyr   r   r1   r   r   r>   r   r6   r   Ú*test_config_array_api_dispatch_error_numpy³   s    rE   )r<   r   Úconcurrent.futuresr   r   rB   r   r   r   Zsklearn.utils.parallelr   r   r   r   r   r   ÚmarkZparametrizer)   r/   r?   rE   r   r   r   r   Ú<module>   s   L
