o
    `^h                     @   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   sh  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 t  ddddddddddd
ks8J W d    n1 sBw   Y  t  d	 du sPJ tdd td d t  d	 du seJ W d    n1 sow   Y  t  d	 du s}J tddF t  d	 du sJ td d t  d	 du sJ tdd t  d	 du sJ W d    n1 sw   Y  t  d	 du sJ W d    n1 sw   Y  t  d	 du sJ W d    n1 sw   Y  t  ddddddddddd
ksJ tt td W d    n	1 sw   Y  tt tdd
  W d    d S 1 s-w   Y  d S )NFi   Tdiagram   default)
assume_finiteworking_memoryprint_changed_onlydisplayarray_api_dispatchpairwise_dist_chunk_sizeenable_cython_pairwise_disttransform_outputenable_metadata_routingskip_parameter_validationr   r   do_something_else)r   r   r   pytestraises	TypeError	__enter__ r   r   W/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/sklearn/tests/test_config.pytest_config_context   s~   


$r   c                   C   st   t  d du s	J ztdd t  d du sJ t 1 sw   Y  W n	 ty.   Y nw t  d du s8J 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 s%J td d t  d du s3J tdd t  d du sAJ tt tdd W d    d S 1 sWw   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 sw   Y  dS )zAReturn the value of assume_finite after waiting `sleep_duration`.r   r   N)r   timesleepr   )r   sleep_durationr   r   r   set_assume_finitet   s   
$r&   backend)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'   n_jobsc                 s   s"    | ]\}}t t||V  qd S )N)r   r&   ).0r   	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   r8   zcannot start threads)reasonc                  C   sf   g d} g d}t dd}dd |t| |D }W d   n1 s$w   Y  |g dks1J 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`.r+   r,   r/   )max_workersc                 S   s   g | ]}|qS r   r   )r1   outputr   r   r   
<listcomp>   s    z*test_config_threadsafe.<locals>.<listcomp>N)r   mapr&   )r5   r6   er7   r   r   r   test_config_threadsafe   s   r?   c              	      s   t j  fdd}| t d| tjtdd tdd W d   n1 s(w   Y  W d   n1 s7w   Y  tjtdd tdd W d   dS 1 sTw   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 Narray_api_compat)ImportErrornameargskwargs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)builtinsrJ   setattrr   r   rB   r   r   monkeypatchrI   r   rG   r   $test_config_array_api_dispatch_error   s   "rR   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 s2w   Y  W d
   n1 sAw   Y  tjt	dd tdd	 W d
   d
S 1 s^w   Y  d
S )z!Check error when NumPy is too oldc                    s$   | dkrt  S  | g|R i |S r@   )objectrC   rG   r   r   rI      s   zAtest_config_array_api_dispatch_error_numpy.<locals>.mocked_importrJ   __version__z1.20zNumPy must be 1.21 or newerrK   TrM   N)rN   rJ   rO   sklearnutils
_array_apinumpyr   r   rB   r   r   rP   r   rG   r   *test_config_array_api_dispatch_error_numpy   s   "rY   )rN   r#   concurrent.futuresr   r   rU   r   r   r   sklearn.utils.fixesr   sklearn.utils.parallelr   r   r   r!   r"   r&   markparametrizer8   xfailr?   rR   rY   r   r   r   r   <module>   s$    L

