
    wBf                       d Z ddlmZ ddlZddlZddlmZmZmZ ddl	Z	ddl
Z
ddlmZ ddlmZ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 erddlmZ ddl
mZmZ  e
j<                  d      d        Z e
j<                  d      d        Z  e
j<                  d      d        Z! e
j<                  d      d        Z" e
j<                  d      d        Z# e
j<                         d        Z$ e
j<                  ejJ                  jM                  dd      jO                  d            	 	 	 	 	 	 d$d       Z(e
j<                  	 	 	 	 	 	 d%d       Z)e
j<                  	 	 	 	 	 	 d&d       Z* ed ed!   ed"         Z+	 	 	 	 	 	 	 	 d'd#Z,y)(z2Collection of pytest fixtures used in conda tests.    )annotationsN)TYPE_CHECKINGLiteralTypeVar   )dals)conda_tests_ctxt_mgmt_def_polcontextreset_context)YamlRawParameter)env_vars)yaml_round_trip_load)
SubdirData)TemporaryDirectory)Iterable)FixtureRequestMonkeyPatchT)autousec                 :    t        j                  dt               y)z
    Suppress `Unclosed Socket Warning`

    It seems urllib3 keeps a socket open to avoid costly recreation costs.

    xref: https://github.com/kennethreitz/requests/issues/1882
    ignore)categoryN)warningsfilterwarningsResourceWarning     6lib/python3.12/site-packages/conda/testing/fixtures.pysuppress_resource_warningr      s     H?r   function)scopec                    t        t        |             } |j                  | j                         t        j
                  j                  | j                        S )N)dir)r   straddfinalizercleanuppypathlocalname)tmpdirrequests     r   r*   r*   (   s9    CK0F(77==%%r   c                 ,    t        j                          y )N)r   clear_cached_local_channel_datar   r   r   clear_subdir_cacher.   /   s    ..0r   c               #     K   t        d      } t        d       dt        j                  dt	        |             i}t        j                  |       d t        d       yw)z
    Fixture that will set "context.number_channel_notices" to 0 and then set
    it back to its original value.

    This is also a good example of how to override values in the context object.
    z+
        number_channel_notices: 0
        r   testdataN)r   r   r   make_raw_parametersr   r
   _set_raw_data)yaml_strrds     r   disable_channel_noticesr5   4   s_      	H
 "$88,X6

B
 "	"s   AAc               #  (   K   d t                yw)z:Resets the context object after each test function is run.N)r   r   r   r   reset_conda_contextr7   N   s      
Os   c              #     K   | j                  d      }t        dt        |      it              5  | ddd       y# 1 sw Y   yxY ww)zB
    Used to isolate package or index cache from other tests.
    pkgsCONDA_PKGS_DIRS)stack_callbackN)mktempr   r#   r	   )tmp_path_factorypkgs_dirs     r   temp_package_cacher?   V   sJ     
  &&v.H		CM*;X
    s   .A
>	A
AA
CONDA_TEST_SOLVERSzlibmamba,classic,)paramsc              #  N   K   t        | || j                        E d{    y7 w)at  
    A parameterized fixture that sets the solver backend to (1) libmamba
    and (2) classic for each test. It's using autouse=True, so only import it in
    modules that actually need it.

    Note that skips and xfails need to be done _inside_ the test body.
    Decorators can't be used because they are evaluated before the
    fixture has done its work!

    So, instead of:

        @pytest.mark.skipif(context.solver == "libmamba", reason="...")
        def test_foo():
            ...

    Do:

        def test_foo():
            if context.solver == "libmamba":
                pytest.skip("...")
            ...
    N)_solver_helperparamr+   monkeypatchs     r   parametrized_solver_fixturerH   b   s     < g{GMMBBBs   %#%c              #  :   K   t        | |d      E d {    y 7 w)NclassicrD   rF   s     r   solver_classicrL      s     
 g{I>>>   c              #  :   K   t        | |d      E d {    y 7 w)NlibmambarK   rF   s     r   solver_libmambarP      s     
 g{J???rM   SolverrO   rJ   c              #  ,  K   t         j                  j                  j                          | j	                  t         j                  j                  j                         |j                  d|       t                t         j                  |k(  sJ | y w)NCONDA_SOLVER)r
   plugin_managerget_cached_solver_backendcache_clearr$   setenvr   solver)r+   rG   rX   s      r   rD   rD      sl      44@@B//IIUUV~v.O>>V###
Ls   BB)r+   r   rG   r   returnz(Iterable[Literal['libmamba', 'classic']])r+   r   rG   r   rY   zIterable[Literal['classic']])r+   r   rG   r   rY   zIterable[Literal['libmamba']])r+   r   rG   r   rX   rQ   rY   zIterable[Solver])-__doc__
__future__r   osr   typingr   r   r   r&   pytest
auxlib.ishr   base.contextr	   r
   r   common.configurationr   	common.ior   common.serializer   core.subdir_datar   gateways.disk.creater   r   r   r   fixturer   r*   r.   r5   r7   r?   environgetsplitrH   rL   rP   rQ   rD   r   r   r   <module>rj      s   9 " 	  2 2 	   P P 3   3 ) 52 @ @ j!& "& 1 1 j! "2 j! "   ::>>.0BCII#NCCC .C	C: ??? "? ? @@@ #@ @ 
7:.	0B	C  	r   