a
    �ù»jd  ã                   @   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
 d dlmZmZ dd„ Zdd	„ Zd
d„ Zdd„ Zej dg d¢¡dd„ ƒZejje
dd�dd„ ƒZdd„ Zdd„ ZdS )é    N)ÚThreadPoolExecutor)Úconfig_contextÚ
get_configÚ
set_config)Ú_IS_WASM)ÚParallelÚdelayedc                   C   sz  t ƒ dddddddddddœ
ks$J ‚tdd� t ƒ d	 du s@J ‚tdd��4 t ƒ dddddddddddœ
kspJ ‚W d   ƒ n1 s„0    Y  t ƒ d	 du s J ‚tdd���$ td d��" t ƒ d	 du sÌJ ‚W d   ƒ n1 sà0    Y  t ƒ d	 du süJ ‚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 �sZJ ‚W d   ƒ n1 �sp0    Y  t ƒ d	 du �sŽJ ‚W d   ƒ n1 �s¤0    Y  t ƒ d	 du �sÂJ ‚W d   ƒ n1 �sØ0    Y  t ƒ dddddddddddœ
k�sJ ‚t t¡� tdƒ W d   ƒ n1 �s20    Y  t t¡� tdd
� ¡  W d   ƒ n1 �sl0    Y  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   r   r   ÚpytestÚraisesÚ	TypeErrorÚ	__enter__© r   r   ú?E:\soccer\ml_env\Lib\site-packages\sklearn/tests/test_config.pyÚtest_config_context   sp    ö
ö*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_exceptionY   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 s‚J ‚t t¡� tdd� W d   ƒ n1 s¬0    Y  d S )Nr   Fr   Tr   )r   r   r   r   r   r   r   r   r   Útest_set_configd   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_finitet   s    
r   Úbackend)ZlokyÚmultiprocessingÚ	threadingc                 C   sD   g d¢}g d¢}t | dd�dd„ t||ƒD ƒƒ}|g d¢ks@J ‚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.
    ©FTFT©çš™™™™™¹?çš™™™™™É?r"   r#   é   )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   Úzip)r   Úassume_finitesÚsleep_durationsÚitemsr   r   r   Útest_config_threadsafe_joblib{   s    þr+   zcannot start threads)Úreasonc                  C   sf   g d¢} g d¢}t dd��(}dd„ | t| |¡D ƒ}W d  ƒ n1 sH0    Y  |g d¢ksbJ ‚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`.r    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)   Úer*   r   r   r   Útest_config_threadsafeŽ   s    þ$r2   c              	      s´   t j‰ ‡ fdd„}|  t d|¡ tjtdd��: tdd�� W d  ƒ n1 sP0    Y  W d  ƒ n1 sn0    Y  tjtdd�� tdd� W d  ƒ n1 s¦0    Y  dS )	z=Check error is raised when array_api_compat is not installed.c                    s"   | dkrt ‚ˆ | g|¢R i |¤Ž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)Úbuiltinsr;   Úsetattrr   r   r4   r   r   ©Zmonkeypatchr:   r   r9   r   Ú$test_config_array_api_dispatch_error    s    <rB   c              	      sÈ   t j‰ ‡ fdd„}|  t d|¡ |  tjjjdd¡ tjt	dd��: t
dd	�� W d
  ƒ n1 sd0    Y  W d
  ƒ n1 s‚0    Y  tjt	dd�� tdd	� W d
  ƒ n1 sº0    Y  d
S )z!Check error when NumPy is too oldc                    s$   | dkrt ƒ S ˆ | g|¢R i |¤ŽS r3   )Úobjectr5   r9   r   r   r:   º   s    zAtest_config_array_api_dispatch_error_numpy.<locals>.mocked_importr;   Ú__version__z1.20zNumPy must be 1.21 or newerr<   Tr>   N)r?   r;   r@   ÚsklearnÚutilsZ
_array_apiÚnumpyr   r   r4   r   r   rA   r   r9   r   Ú*test_config_array_api_dispatch_error_numpyµ   s    <rH   )r?   r   Úconcurrent.futuresr   r   rE   r   r   r   Zsklearn.utils.fixesr   Zsklearn.utils.parallelr   r   r   r   r   r   ÚmarkZparametrizer+   Zxfailr2   rB   rH   r   r   r   r   Ú<module>   s"   L

