B
    0d                 @   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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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 red eeeeeeeedZ!dd Z"e"eZ#e"eZ$e"eZ%e"eZ&e"eZ'e"eZ(e"eZ)dd Z*ej+dddd Z,dd Z-dd Z.dS )     )environ)wrapsN)threadpool_limits)DoctestItem)	_IS_32BIT)_openmp_effective_n_threads)_pilutil)PYTEST_MIN_VERSION)
np_versionparse_version)fetch_20newsgroups)fetch_20newsgroups_vectorized)fetch_california_housing)fetch_covtype)fetch_kddcup99)fetch_olivetti_faces)
fetch_rcv1zSYour 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_fxtc                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_TESTS10c           
      sR    |d< y
| |S  t k
rL } zt|dkr2 td W d d }~X Y nX d S )Ndownload_if_missingz1Data not found and `download_if_missing` is Falsez1test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0)IOErrorstrpytestskip)argskwargse)r   f B/var/www/html/venv/lib/python3.7/site-packages/sklearn/conftest.pywrapped-   s    
z_fetch_fixture.<locals>.wrappedc                  s    S )Nr&   r&   )r(   r&   r'   <lambda>7       z _fetch_fixture.<locals>.<lambda>)r   getr   r    fixture)r%   r&   )r   r%   r(   r'   _fetch_fixture)   s    
r-   c             C   sL  t dddk}tjjdd}tt}t }xH|D ]@}t|dsBq2t|j}||@ }|sZq2|rh||O }q2|	| q2W t dd}	|	dkr|rx|D ]}
t|
   qW xn|D ]f}|j
d	rt d
krtjjdd}|	| q|j
drt dkrtjjdd}|	| qW d}yddl}W n tk
rD   d}d}Y nX yBttdk r`d}d}n&trpd}d}ntjdrd}d}W n tk
r   Y nX x"|D ]}t|tri |j_qW |rtjj|d}xn|D ](}t|tr|j
dkr|	| qW n<tjsHtjjdd}x$|D ]}|j
dkr(|	| q(W dS )zCalled after collect is completed.

    Parameters
    ----------
    config : pytest config
    items : list of collected items
    r   r   r   z1test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0)reasonfixturenamesZPYTEST_XDIST_WORKERZgw0)z_hash.FeatureHasherztext.HashingVectorizerPyPyz)FeatureHasher is not compatible with PyPyZGradientBoostingClassifieraarch64zKknow failure. See https://github.com/scikit-learn/scikit-learn/issues/17797Fr   NTz*matplotlib is required to run the doctestsz1.14z'doctests are only run for numpy >= 1.14z;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+   r    markr!   setdataset_fetchershasattrr/   Z
add_markernameendswithplatformpython_implementationmachineZxfail
matplotlibImportErrorr
   r   r   sys
startswith
isinstancer   ZdtestZglobsr   Zpillow_installed)configitemsZrun_network_testsZskip_networkZdataset_features_setZdatasets_to_downloaditemZitem_fixturesZdataset_to_fetchZ	worker_idr7   markerZskip_doctestsr<   r.   Zskip_markerr&   r&   r'   pytest_collection_modifyitemsD   s|    









rE   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)r    Zimportorskipclose)pyplotr&   r&   r'   rJ      s    

rJ   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   r+   intr   maxr   )rC   Zxdist_worker_countZopenmp_threadsZthreads_per_workerr&   r&   r'   pytest_runtest_setup   s    	
rN   c             C   s0   ydd l }|d W n tk
r*   Y nX d S )Nr   Zagg)r<   Zuser=   )rA   r<   r&   r&   r'   pytest_configure   s
    rO   )/osr   	functoolsr   r9   r>   r    Zthreadpoolctlr   Z_pytest.doctestr   Zsklearn.utilsr   Zsklearn.utils._openmp_helpersr   Zsklearn.externalsr   Zsklearn._min_dependenciesr	   Zsklearn.utils.fixesr
   r   Zsklearn.datasetsr   r   r   r   r   r   r   __version__r=   formatr5   r-   r   r   r   r   r   r   r   rE   r,   rJ   rN   rO   r&   r&   r&   r'   <module>   sR   u