U
    ½mœd$#  ã                   @   s  d dl mZ d dlmZ d dlZ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 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! d dl"m#Z# ee
j$ƒeeƒk �r&e%d &e¡ƒ‚eedƒkZ'dd„ Z(eeeeee e!dœZ)e'�r\e(e)d< e
j*j+e ,dd¡dkdd�Z-e
j.e
j/ej0e-d �ej1gd!�d"d#„ ƒZ2d$d%„ Z3e3eƒZ4e3eƒZ5e3eƒZ6e3eƒZ7e3eƒZ8e3e ƒZ9e3e!ƒZ:e
 .e(¡Z;d&d'„ Z<e
j.d(d)�d*d+„ ƒZ=d,d-„ Z>d.d/„ Z?dS )0é    )Úenviron)ÚwrapsN)Úsuppress)ÚSkipTest)Úthreadpool_limits)ÚDoctestItem)Ú	_IS_32BIT)Ú_openmp_effective_n_threads)ÚPYTEST_MIN_VERSION)Ú
sp_version)Úparse_version)Úfetch_20newsgroups)Úfetch_20newsgroups_vectorized)Úfetch_california_housing)Úfetch_covtype)Úfetch_kddcup99)Úfetch_olivetti_faces)Ú
fetch_rcv1)Úrandom_seedzSYour version of pytest is too old, you should have at least pytest >= {} installed.z1.10c                  C   sn   t rXt dd¡dk} | s tdƒ‚zdd l}W n tk
rH   tdƒ‚Y nX ddlm} nddlm} |dd	�S )
NÚSKLEARN_SKIP_NETWORK_TESTSÚ1Ú0ú1test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0r   z#test requires pooch to be installed)ÚfaceT)Úgray)	Úscipy_datasets_require_networkr   Úgetr   ÚpoochÚImportErrorZscipy.datasetsr   Z
scipy.misc)Úrun_network_testsr   r   © r    úI/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/conftest.pyÚraccoon_face_or_skip%   s    r"   )Úfetch_20newsgroups_fxtÚ!fetch_20newsgroups_vectorized_fxtÚfetch_california_housing_fxtÚfetch_covtype_fxtÚfetch_kddcup99_fxtÚfetch_olivetti_faces_fxtÚfetch_rcv1_fxtÚraccoon_face_fxtZSKLEARN_RUN_FLOAT32_TESTSr   r   z:Set SKLEARN_RUN_FLOAT32_TESTS=1 to run float32 dtype tests©Úreason)Zmarks)Úparamsc                 c   s   | j V  d S ©N)Úparam)Úrequestr    r    r!   Úglobal_dtypeL   s    r1   c                    s8   t  dd¡dk‰ tˆƒ‡ ‡fdd„ƒ‰t ‡fdd„¡S )zAFetch dataset (download if missing and requested by environment).r   r   r   c               
      sT   ˆ |d< zˆ| |ŽW S  t k
rN } zt|ƒdkr4‚ t d¡ W 5 d }~X Y nX d S )NÚdownload_if_missingz1Data not found and `download_if_missing` is Falser   )ÚIOErrorÚstrÚpytestÚskip)ÚargsÚkwargsÚe)r2   Úfr    r!   ÚwrappedU   s    z_fetch_fixture.<locals>.wrappedc                      s   ˆ S r.   r    r    )r;   r    r!   Ú<lambda>_   ó    z _fetch_fixture.<locals>.<lambda>)r   r   r   r5   Úfixture)r:   r    )r2   r:   r;   r!   Ú_fetch_fixtureQ   s    	r?   c              
   C   s
  t  dd¡dk}tjjdd�}ttƒ}tƒ }|D ]@}t|dƒs@q0t|jƒ}||@ }|sXq0|rf||O }q0| 	|¡ q0t  dd¡}	|	dkr²|r²|D ]"}
t
tƒ� t|
 ƒ  W 5 Q R X qŽ|D ]4}|j d	¡r¶t ¡ d
kr¶tjjdd�}| 	|¡ q¶d}zddl}W n tk
�r   d}d}Y nX t�r,d}d}ntj d¡�rBd}d}|D ]}t|tƒ�rFi |j_�qF|�r¤tjj|d�}|D ](}t|tƒ�rz|jdk�rz| 	|¡ �qzzddl}d}W n tk
�rÎ   d}Y nX |�stjjdd�}|D ]}|jdk�rè| 	|¡ �qèdS )z…Called after collect is completed.

    Parameters
    ----------
    config : pytest config
    items : list of collected items
    r   r   r   r   r+   ÚfixturenamesZPYTEST_XDIST_WORKERZgw0ZGradientBoostingClassifierÚaarch64zKknow failure. See https://github.com/scikit-learn/scikit-learn/issues/17797Fr   NTz*matplotlib is required to run the doctestsz;doctest are only run when the default numpy int is 64 bits.Úwin32z\doctests are not run for Windows because numpy arrays repr is inconsistent across platforms.zsklearn._config.config_contextzpillow (or PIL) not installed!)z/sklearn.feature_extraction.image.PatchExtractorz3sklearn.feature_extraction.image.extract_patches_2d)r   r   r5   Úmarkr6   ÚsetÚdataset_fetchersÚhasattrr@   Z
add_markerr   r   ÚnameÚendswithÚplatformÚmachineZxfailÚ
matplotlibr   r   ÚsysÚ
startswithÚ
isinstancer   ZdtestZglobsÚPIL)ÚconfigÚitemsr   Zskip_networkZdataset_features_setZdatasets_to_downloadÚitemZitem_fixturesZdataset_to_fetchZ	worker_idrG   ÚmarkerZskip_doctestsrK   r,   Zskip_markerrO   Zpillow_installedr    r    r!   Úpytest_collection_modifyitemsm   s|    ÿ




ÿ
þþ
ÿ
rT   Úfunction)Úscopec                  c   s(   t  d¡} |  d¡ | V  |  d¡ dS )a/  Setup and teardown fixture for matplotlib.

    This fixture checks if we can import matplotlib. If not, the tests will be
    skipped. Otherwise, we close the figures before and after running the
    functions.

    Returns
    -------
    pyplot : module
        The ``matplotlib.pyplot`` module.
    zmatplotlib.pyplotÚallN)r5   ZimportorskipÚclose)Úpyplotr    r    r!   rY   Ù   s    

rY   c                 C   sB   t  d¡}|dkrdS t|ƒ}tƒ }t|| dƒ}t|dd� dS )zÇSet the number of openmp threads based on the number of workers
    xdist is using to prevent oversubscription.

    Parameters
    ----------
    item : pytest item
        item to be processed
    ZPYTEST_XDIST_WORKER_COUNTNé   Zopenmp)Zuser_api)r   r   Úintr	   Úmaxr   )rR   Zxdist_worker_countZopenmp_threadsZthreads_per_workerr    r    r!   Úpytest_runtest_setupì   s    	
r]   c                 C   sH   zdd l }| d¡ W n tk
r*   Y nX | j d¡sD| j t¡ d S )Nr   Zaggzsklearn.tests.random_seed)rK   Zuser   ZpluginmanagerZ	haspluginÚregisterr   )rP   rK   r    r    r!   Úpytest_configure  s    r_   )@Úosr   Ú	functoolsr   rI   rL   Ú
contextlibr   Zunittestr   r5   ÚnumpyÚnpZthreadpoolctlr   Z_pytest.doctestr   Zsklearn.utilsr   Zsklearn.utils._openmp_helpersr	   Zsklearn._min_dependenciesr
   Zsklearn.utils.fixesr   r   Zsklearn.datasetsr   r   r   r   r   r   r   Zsklearn.testsr   Ú__version__r   Úformatr   r"   rE   rC   Zskipifr   Z_SKIP32_MARKr>   r/   Zfloat32Zfloat64r1   r?   r#   r$   r%   r&   r'   r(   r)   r*   rT   rY   r]   r_   r    r    r    r!   Ú<module>   sx   ÿÿù
þ

l

