U
    3d                     @   sF   d Z ddlZddlmZ ddlmZ G dd dZdd Zd	d
 ZdS )az  global_random_seed fixture

The goal of this fixture is to prevent tests that use it to be sensitive
to a specific seed value while still being deterministic by default.

See the documentation for the SKLEARN_TESTS_GLOBAL_RANDOM_SEED
variable for insrtuctions on how to use this fixture.

https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed
    N)environ)Randomc                   @   s   e Zd ZddddZdS )
XDistHooksN)returnc                 C   s   |j d}||jd< d S )Nrandom_seeds)configZ	getoptionworkerinput)selfnoder    r   =/tmp/pip-unpacked-wheel-zrfo1fqw/sklearn/tests/random_seed.pypytest_configure_node   s    z XDistHooks.pytest_configure_node)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                    s  | j dr| j t  ttd}td}t| drPd| j	krP| j	d  n|d kr`dg n|dkrxt
 |g np|dkr| nbd	|kr|d	\}}ttt|t|d
  n
t|g t dk st dkrtd|  | j_G  fddd}| j |  d S )NZxdistd    SKLEARN_TESTS_GLOBAL_RANDOM_SEEDr   r   *   anyall-   r   c   zThe value(s) of the environment variable SKLEARN_TESTS_GLOBAL_RANDOM_SEED must be in the range [0, 99] (or 'any' or 'all'), got: c                       s    e Zd Zej ddd ZdS )z0pytest_configure.<locals>.GlobalRandomSeedPlugin)paramsc                 s   s   |j V  dS )a  Fixture to ask for a random yet controllable random seed.

            All tests that use this fixture accept the contract that they should
            deterministically pass for any seed value from 0 to 99 included.

            See the documentation for the SKLEARN_TESTS_GLOBAL_RANDOM_SEED
            variable for insrtuctions on how to use this fixture.

            https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed
            N)param)r	   requestr   r   r   global_random_seed8   s    zCpytest_configure.<locals>.GlobalRandomSeedPlugin.global_random_seedN)r   r   r   pytestZfixturer   r   r   r   r   GlobalRandomSeedPlugin7   s   
r   )ZpluginmanagerZ	haspluginregisterr   listranger   gethasattrr   r   choicesplitintminmax
ValueErroroptionr   )r   ZRANDOM_SEED_RANGErandom_seed_varstartstopr   r   r   r   pytest_configure   s.    

r/   c                 C   s0   t d}|dkr,dd| jjd  ddgS d S )Nr   r   zCTo reproduce this test run, set the following environment variable:z&    SKLEARN_TESTS_GLOBAL_RANDOM_SEED="r   "z]See: https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed)r   r#   r+   r   )r   r,   r   r   r   pytest_report_headerI   s    
r1   )	__doc__r   osr   randomr   r   r/   r1   r   r   r   r   <module>   s   
2