U
    2dk                     @   s  d dl mZ d dlmZ d dlZd dl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 eejeek re d!eeeeeeeedZ"ej#j$e%dddkddZ&ej'ej(ej)e&dej*gddd Z+dd Z,e,eZ-e,eZ.e,eZ/e,eZ0e,eZ1e,eZ2e,eZ3dd  Z4ej'd!d"d#d$ Z5d%d& Z6d'd( Z7dS ))    )environ)wrapsN)threadpool_limits)DoctestItem)	_IS_32BIT)_openmp_effective_n_threads)PYTEST_MIN_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.)fetch_20newsgroups_fxt!fetch_20newsgroups_vectorized_fxtfetch_california_housing_fxtfetch_covtype_fxtfetch_kddcup99_fxtfetch_olivetti_faces_fxtfetch_rcv1_fxtZSKLEARN_RUN_FLOAT32_TESTS01z:Set SKLEARN_RUN_FLOAT32_TESTS=1 to run float32 dtype testsreason)Zmarks)paramsc                 c   s   | j V  d S N)param)request r!   4/tmp/pip-unpacked-wheel-zrfo1fqw/sklearn/conftest.pyglobal_dtype0   s    r#   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).SKLEARN_SKIP_NETWORK_TESTSr   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 False1test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0)IOErrorstrpytestskip)argskwargse)r%   fr!   r"   wrapped9   s    z_fetch_fixture.<locals>.wrappedc                      s    S r   r!   r!   )r/   r!   r"   <lambda>C       z _fetch_fixture.<locals>.<lambda>)r   getr   r)   fixture)r.   r!   )r%   r.   r/   r"   _fetch_fixture5   s    	r4   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|
   q|D ]4}|j
d	rt d
krtjjdd}|	| qd}zddl}W n tk
r   d}d}Y nX trd}d}ntjdr.d}d}|D ]}t|tr2i |j_q2|rtjj|d}|D ](}t|trf|j
dkrf|	| qfzddl}d}W n tk
r   d}Y nX |stjjdd}|D ]}|j
dkr|	| qdS )zCalled 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   r2   r)   markr*   setdataset_fetchershasattrr5   Z
add_markernameendswithplatformmachineZxfail
matplotlibImportErrorr   sys
startswith
isinstancer   ZdtestZglobsPIL)configitemsZrun_network_testsZskip_networkZdataset_features_setZdatasets_to_downloaditemZitem_fixturesZdataset_to_fetchZ	worker_idr<   markerZskip_doctestsr@   r   Zskip_markerrE   Zpillow_installedr!   r!   r"   pytest_collection_modifyitemsP   sz    






rJ   function)Z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)r)   Zimportorskipclose)pyplotr!   r!   r"   rN      s    

rN   c                 C   sB   t d}|dkrdS t|}t }t|| d}t|dd dS )zSet 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   r2   intr   maxr   )rH   Zxdist_worker_countZopenmp_threadsZthreads_per_workerr!   r!   r"   pytest_runtest_setup   s    	
rR   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)r@   ZuserA   ZpluginmanagerZ	haspluginregisterr   )rF   r@   r!   r!   r"   pytest_configure   s    rT   )8osr   	functoolsr   r>   rB   r)   ZnumpynpZthreadpoolctlr   Z_pytest.doctestr   Zsklearn.utilsr   Zsklearn.utils._openmp_helpersr   Zsklearn._min_dependenciesr   Zsklearn.utils.fixesr	   Zsklearn.datasetsr
   r   r   r   r   r   r   Zsklearn.testsr   __version__rA   formatr:   r8   Zskipifr2   Z_SKIP32_MARKr3   r   Zfloat32Zfloat64r#   r4   r   r   r   r   r   r   r   rJ   rN   rR   rT   r!   r!   r!   r"   <module>   sh   

k

