
    {Kg                     H    d Z ddlmZ ddlmZ ddlZ G d d      Zd Zd Zy)	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
    )environ)RandomNc                       e Zd ZddZy)
XDistHooksNc                 X    |j                   j                  d      }||j                  d<   y )Nrandom_seeds)config	getoptionworkerinput)selfnoder   s      ]/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/tests/random_seed.pypytest_configure_nodez XDistHooks.pytest_configure_node   s&    {{,,^<+7(    )returnN)__name__
__module____qualname__r    r   r   r   r      s    8r   r   c                    | j                   j                  d      r#| j                   j                  t                      t	        t        d            }t        j                  d      }t        | d      rd| j                  v r| j                  d   n|dgn|dk(  rt               j                  |      gn|dk(  r|nyd	|v r?|j                  d	      \  }}t	        t        t        |      t        |      d
z               nt        |      gt              dk  st              dkD  rt!        d|       | j"                  _         G fdd      }| j                   j                   |              y )N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                   B    e Zd Z ej                  W        d        Zy)0pytest_configure.<locals>.GlobalRandomSeedPlugin)paramsc              3   (   K   |j                    yw)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   requests     r   global_random_seedzCpytest_configure.<locals>.GlobalRandomSeedPlugin.global_random_seed:   s      --s   N)r   r   r   pytestfixturer&   )r   s   r   GlobalRandomSeedPluginr!   9   s     	|	,	  
-	 r   r)   )pluginmanager	haspluginregisterr   listranger   gethasattrr   r   choicesplitintminmax
ValueErroroptionr   )r	   RANDOM_SEED_RANGErandom_seed_varstartstopr)   r   s         @r   pytest_configurer<      sV   %%g.%%jl3U3Z(kk"DEOv}%.F<N<N*N)).9		 t	E	!(9:;	E	!(/!)//4KE4c%j#d)a- @AL01L|q C$5$:--<,=? 
 ".FMM    !!"8":;r   c                 x    t        j                  d      }|dk(  r dd| j                  j                  d    ddgS y )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/   r7   r   )r	   r9   s     r   pytest_report_headerr?   K   sN    kk"DEO%Q4V]]5O5OPQ5R4SSTU4	
 	
  r   )	__doc__osr   randomr   r'   r   r<   r?   r   r   r   <module>rC      s*   	   8 8/<d

r   