U
    ½mœ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   úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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 sÚtˆ ƒdkrètd|› �ƒ‚ˆ | j_G ‡ fdd„dƒ}| j  |ƒ ¡ d S )NZxdistéd   Ú SKLEARN_TESTS_GLOBAL_RANDOM_SEEDr   r   é*   ÚanyÚallú-é   r   éc   z�The 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