
    <Bh?                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SS	KJrJrJrJr  SSKrSSKrSS
KJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$J%r%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK3J4r4  SSK5J6r6  SSK7J8r8  SSK9J:r:  \(       a"  SSK;J<r<J=r=  SSK>J?r?  SSKJ@r@JArAJBrBJCrCJDrD  SSKEJFrF  \" \G5      rH\R                  " SS 9S! 5       rJ\R                  " S"S#9S$ 5       rK\R                  " SS 9S% 5       rL\R                  " S"S#9S& 5       rM\R                  " S"S#9S' 5       rN\R                  " 5       S( 5       rO\R                  " \R                  R                  S)S*5      R                  S+5      S,9      SMS. j5       rS\R                        SNS/ j5       rT\R                        SOS0 j5       rU\" S1\S2   \S3   5      rV        SPS4 jrW\R                  " S5S#9\" S6S75      SQS8 j5       5       rX\ " S9 S:5      5       rY\R                  SRS; j5       rZ\R                  " S5S#9SSS< j5       r[\ " S= S>5      5       r\\R                  STS? j5       r]\ " S@ SA5      5       r^\R                        SUSB j5       r_\R                  " S5S#9      SVSC j5       r`\ " SD SE5      5       ra\R                        SWSF j5       rb\R                  " S-SG9SXSH j5       rc\R                        SYSI j5       rd\R                        SYSJ j5       re\R                  " S5SSK9SL 5       rfg)Zz2Collection of pytest fixtures used in conda tests.    )annotationsN)contextmanagernullcontext)	dataclass)	getLogger)Path)copyfile)TYPE_CHECKINGLiteralTypeVaroverload)
deprecated   )CONDA_SOURCE_ROOT)EntityEncoder)dals)PACKAGE_CACHE_MAGIC_FILE)conda_tests_ctxt_mgmt_def_polcontextreset_context)main_subshell)YamlRawParameter)env_vars)yaml_round_trip_load)path_to_url)PackageCacheData)
SubdirData)CondaExitZero)TemporaryDirectory)PackageRecord)IterableIterator)MultiCapture)CaptureFixtureExceptionInfoFixtureRequestMonkeyPatchTempPathFactory)MockerFixtureT)autousec                 6    [         R                  " S[        S9  g)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.13/site-packages/conda/testing/fixtures.pysuppress_resource_warningr4   8   s     H?r2   function)scopec                    [        [        U 5      S9n UR                  U R                  5        [        R
                  R                  U R                  5      $ )N)dir)r   straddfinalizercleanuppypathlocalname)tmpdirrequests     r3   r@   r@   D   s9    CK0F(77==%%r2   c                 .    [         R                  " 5         g N)r   clear_cached_local_channel_datar1   r2   r3   clear_subdir_cacherE   K   s    ..0r2   c               #     #    [        S5      n [        S5        S[        R                  " S[	        U 5      5      0n[
        R                  " U5        Sv   [        S5        g7f)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
        r1   testdataN)r   r   r   make_raw_parametersr   r   _set_raw_data)yaml_strrds     r3   disable_channel_noticesrL   P   s^      	H
 "$88,X6

B
 "	"s   AA!c               #  (   #    Sv   [        5         g7f)z:Resets the context object after each test function is run.N)r   r1   r2   r3   reset_conda_contextrN   j   s      
Os   c              #     #    U R                  S5      n[        S[        U5      0[        S9   Uv   SSS5        g! , (       d  f       g= f7f)z:
Used to isolate package or index cache from other tests.
pkgsCONDA_PKGS_DIRS)stack_callbackN)mktempr   r9   r   )tmp_path_factorypkgs_dirs     r3   temp_package_cacherV   r   sD     
  &&v.H		CM*;X
 
 
 
s   +A;	A
A	ACONDA_TEST_SOLVERSzlibmamba,classic,)paramsmonkeypatchc              #  L   #    [        XU R                  5       Sh  vN   g N7f)a4  
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rA   rZ   s     r3   parametrized_solver_fixturer_   ~   s     < gGMMBBBs   $"$c              #  8   #    [        XS5       S h  vN   g  N7f)Nclassicr\   r^   s     r3   solver_classicrc      s     
 gI>>>   c              #  8   #    [        XS5       S h  vN   g  N7f)Nlibmambarb   r^   s     r3   solver_libmambarg      s     
 gJ???rd   Solverrf   ra   c              #  .  #    [         R                  R                  R                  5         U R	                  [         R                  R                  R                  5        UR                  SU5        [        5         [         R                  U:X  d   eUv   g 7f)NCONDA_SOLVER)r   plugin_managerget_cached_solver_backendcache_clearr:   setenvr   solver)rA   rZ   ro   s      r3   r\   r\      sk      44@@B//IIUUV~v.O>>V###
Ls   BBsessionz25.9z26.3c              #     #    U R                   R                  R                  S5      nUR                  5          UR                  v   S S S 5        g ! , (       d  f       g = f7f)Ncapturemanager)configpluginmanager	getpluginglobal_and_fixture_disabled_global_capturing)rA   
capmanagers     r3   session_capsysry      sE      --778HIJ		/	/	1*** 
2	1	1s   6A!A	A!
AA!c                      \ rS rSr% S\S'   \      SS j5       r\    SS j5       rSS.     SS jjr\SS	 j5       rS
r	g)CondaCLIFixture   zCaptureFixture | Nonecapsysc                   g rC   r1   )selfraisesargvs      r3   __call__CondaCLIFixture.__call__   s    
 *-r2   c                    g rC   r1   )r   r   s     r3   r   r      s      #r2   N)r   c                  U R                   (       a  U R                   R                  5         SnU(       a  [        R                  " U5      O	[	        5        n[        U R                  U5      6 nSSS5        U R                   (       a  U R                   R                  5       u  pVOS=pV[        5         XVU(       a  W4$ U4$ ! , (       d  f       NW= f)ax  Test conda CLI. Mimic what is done in `conda.cli.main.main`.

`conda ...` == `conda_cli(...)`

:param argv: Arguments to parse.
:param raises: Expected exception to intercept. If provided, the raised exception
    will be returned instead of exit code (see pytest.raises and pytest.ExceptionInfo).
:return: Command results (stdout, stderr, exit code or pytest.ExceptionInfo).
N)r}   
readouterrpytestr   r   r   
_cast_argsr   )r   r   r   code	exceptionouterrs          r3   r   r      s     ;;KK""$ &,V]]6"+-?9 $//$"78D @ ;;{{--/HCC 	f66$66 @?s   B>>
Cc              #     #    [        [        U 5      n U  H&  nUv   US   S:w  d  M  US:X  a  Sv   U  Sh  vN   M(     g N	7f)zCast args to string and inspect for `conda run`.

`conda run` is a unique case that requires `--dev` to use the src shell scripts
and not the shell scripts provided by the installer.
r   -runz--devN)mapr9   )r   args     r3   r   CondaCLIFixture._cast_args   sH      3~CI 1v} %<!M   s   !AAA 
Ar1   )r   str | os.PathLike[str] | Pathr   z-type[Exception] | tuple[type[Exception], ...]returnztuple[str, str, ExceptionInfo])r   r   r   ztuple[str, str, int])r   r   r   z4type[Exception] | tuple[type[Exception], ...] | Noner   z2tuple[str | None, str | None, int | ExceptionInfo])r   z)tuple[str | os.PathLike[str] | Path, ...]r   zIterable[str])
__name__
__module____qualname____firstlineno____annotations__r   r   staticmethodr   __static_attributes__r1   r2   r3   r{   r{      s    !!-,- >- 
(	- - #,# 
# # HL7,7 E7 
<	7B    r2   r{   c              #  &   #    [        U 5      v   g7f)zA function scoped fixture returning CondaCLIFixture instance.

Use this for any commands that are local to the current test (e.g., creating a
conda environment only used in the test).
Nr{   )r}   s    r3   	conda_clir     s      &
!!   c               #  &   #    [        S5      v   g7f)zA session scoped fixture returning CondaCLIFixture instance.

Use this for any commands that are global to the test session (e.g., creating a
conda environment shared across tests, `conda info`, etc.).
Nr   r1   r2   r3   session_conda_clir     s      $
r   c                  B    \ rS rSr% S\S'      S       SS jjrSrg)	PathFactoryFixturei)  r   tmp_pathNc                    U=(       d    SnU=(       d"    [         R                  " 5       R                  SS nU=(       d    SnU R                  X!-   U-   -  $ )au  Unique, non-existent path factory.

Extends pytest's `tmp_path` fixture with a new unique, non-existent path for usage in cases
where we need a temporary path that doesn't exist yet.

:param name: Path name to append to `tmp_path`
:param prefix: Prefix to prepend to unique name generated
:param suffix: Suffix to append to unique name generated
:return: A new unique path
 N   )uuiduuid4hexr   )r   r?   prefixsuffixs       r3   r   PathFactoryFixture.__call__-  sI      2+tzz|''+2}} 677r2   r1   )NNN)r?   
str | Noner   r   r   r   r   r   )r   r   r   r   r   r   r   r1   r2   r3   r   r   )  sB    N  !!	88 8 	8
 
8 8r2   r   c              #  &   #    [        U 5      v   g7f)zA function scoped fixture returning PathFactoryFixture instance.

Use this to generate any number of temporary paths for the test that are unique and
do not exist yet.
N)r   )r   s    r3   path_factoryr   C  s      X
&&r   c                  Z    \ rS rSr% S\S'   S\S'   SS jr\SS.     SS	 jj5       rS
rg)TmpEnvFixtureiM  z$PathFactoryFixture | TempPathFactoryr   r{   r   c                    [        U R                  [        5      (       a  U R                  5       $ U R                  R                  S5      $ )Nztmp_env-)
isinstancer   r   rS   )r   s    r3   get_pathTmpEnvFixture.get_pathR  s>    d'');<<$$&& $$++J77r2   N)r   c             '     #    [        U=(       d    U R                  5       5      nU R                  " SSU/UQSPSP76   Uv   g7f)zGenerate a conda environment with the provided packages.

:param packages: The packages to install into environment
:param prefix: The prefix at which to install the conda environment
:return: The conda environment's prefix
createz--prefix--yes--quietN)r   r   r   )r   r   packagess      r3   r   TmpEnvFixture.__call__Z  s@      f/0xVShSSSs   AAr1   )r   r   )r   r9   r   zstr | os.PathLike | Noner   Iterator[Path])	r   r   r   r   r   r   r   r   r   r1   r2   r3   r   r   M  sH    668  ,0 ) 
	 r2   r   c              #  &   #    [        X5      v   g7f)zA function scoped fixture returning TmpEnvFixture instance.

Use this when creating a conda environment that is local to the current test.
Nr   r   r   s     r3   tmp_envr   n  s      
00r   c              #  &   #    [        X5      v   g7f)zA session scoped fixture returning TmpEnvFixture instance.

Use this when creating a conda environment that is shared across tests.
Nr   )rT   r   s     r3   session_tmp_envr   z  s      (
<<r   c                  >    \ rS rSr% S\S'   S\S'   \S	S j5       rSrg)
TmpChannelFixturei  r   r   r{   r   c              '    #    U R                   " SSU R                  5        3/UQSPSPSP7S[        06  [        [        R
                  " 5       R                  5      n[	        U5      nU R                  5       nU[        R                  -  nUR                  SS9  US	-  nUR                  SS9  0 0 S
.nU Hy  nUR                  U5       Ha  n	U	S   n
[        X*-  XZ-  5        [        S0 U	R                  5       R                  5       VVs0 s H  u  pUS;  d  M  X_M     snnD6US   U
'   Mc     M{     US-  R                  [         R"                  " U[$        S95        US-  R                  [         R"                  " 0 [$        S95        U H)  n['        [        R(                  " U5      5      (       a  M)   e   U[+        [-        U5      5      4v   g s  snnf 7f)Nr   z	--prefix=r   r   z--download-onlyr   Tparentsnoarch)infor   fn)urlchannelschannelchannel_namer   zrepodata.json)clsr1   )r   r   r   r   r   first_writablerU   r   subdirmkdirqueryr	   r    dumpitems
write_textjsondumpsr   any	query_allr   r9   )r   r   rU   
pkgs_cacher   r   r   repodatapackagepkg_datafnamefieldvalues                r3   r   TmpChannelFixture.__call__  s     	))+,-	
 	
 		

 	
 	
 !	
 (779BBC%h/
##%7>>)T"8#T"B/G&,,W5 )6>:.; / -5MMO,A,A,C,CLE (VV %,C/$U+ 6   
/	!--djj}.UV	/	!--djj.OPG'11':;;;;   {3w<000s   DGGGBG3#Gr1   N)r   r9   r   zIterator[tuple[Path, str]])r   r   r   r   r   r   r   r   r1   r2   r3   r   r     s     $$*1 *1r2   r   c              #  &   #    [        X5      v   g7f)z?A function scoped fixture returning TmpChannelFixture instance.N)r   r   s     r3   tmp_channelr     s      L
44r   )r?   c              #  V  #    U v   U R                   VVVs/ s H5  u  pnU[        R                  L d  M  UR                  S5      (       d  M3  UPM7     snnn=n(       aC  [        R                  SSR                  U5       35        U R                  5         [        / 5        ggs  snnnf 7f)z:A monkeypatch fixture that resets context after each test.CONDA_z+monkeypatch cleanup: undo & reset context: z, N)	_setitemosenviron
startswithlogdebugjoinundor   )rZ   objr?   _
conda_varss        r3   context_aware_monkeypatchr     s      
 (000LCq"** 	!%!: 	0 z 
 			?		*@U?VWXb s   B)B"B"B"AB)c              #  0  #    U " 5       S-  nUR                  SS9  U[        -  R                  5         UR                  SUR                  [        U5      =n4S9  [        R                  U4:X  d   eUv   [        R                  R                  US5        g7f)zHA function scoped fixture returning a temporary package cache directory.rP   Tr   z$conda.base.context.Context.pkgs_dirsnew_callablereturn_valueN)r   r   touchpatchPropertyMockr9   r   	pkgs_dirsr   _cache_pop)r   mockerrU   pkgs_dir_strs       r3   tmp_pkgs_dirr     s     
 ~&HNN4N ((//1
LL.((&)(m3l5  
 ///
N  t4s   BBc              #     #    U " 5       S-  nUR                  SS9  UR                  SUR                  [        U5      =n4S9  [        R
                  U4:X  d   eUv   g7f)zFA function scoped fixture returning a temporary environment directory.envsTr   z$conda.base.context.Context.envs_dirsr   N)r   r   r   r9   r   	envs_dirs)r   r   envs_direnvs_dir_strs       r3   tmp_envs_dirr    sj     
 ~&HNN4N 
LL.((&)(m3l5  
 ///
Ns   AA)r6   r*   c               #     #    S[         R                  ;   a  Sv   g[        R                  R	                  5        n U R                  S[        5        Sv   SSS5        g! , (       d  f       g= f7f)a  
We need to set this so Python loads the dev version of 'conda', usually taken
from `conda/` in the root of the cloned repo. This root is usually the working
directory when we run `pytest`.
Otherwise, it will import the one installed in the base environment, which might
have not been overwritten with `pip install -e . --no-deps`. This doesn't happen
in other tests because they run with the equivalent of `python -m conda`. However,
some tests directly run `conda (shell function) which calls `conda` (Python entry
point). When a script is called this way, it bypasses the automatic "working directory
is first on sys.path" behavior you find in `python -m` style calls. See
https://docs.python.org/3/library/sys_path_init.html for details.

PYTHONPATHN)r   r   r   r'   r   rn   r   )rZ   s    r3   r  r    sI      rzz!'')[|->? *))s   8A/A	A/
A,(A/)rA   r&   rZ   r'   r   z(Iterable[Literal['libmamba', 'classic']])rA   r&   rZ   r'   r   zIterable[Literal['classic']])rA   r&   rZ   r'   r   zIterable[Literal['libmamba']])rA   r&   rZ   r'   ro   rh   r   zIterable[Solver])r   zIterator[MultiCapture])r}   r$   r   Iterator[CondaCLIFixture])r   r	  )r   r   r   zIterator[PathFactoryFixture])r   r   r   r{   r   Iterator[TmpEnvFixture])rT   r(   r   r{   r   r
  )r   r   r   r{   r   zIterator[TmpChannelFixture])rZ   r'   r   r'   )r   r   r   r)   r   r   )g__doc__
__future__r   r   r   r   r.   
contextlibr   r   dataclassesr   loggingr   pathlibr   shutilr	   typingr
   r   r   r   r<   r   conda.deprecationsr   r   r   auxlib.entityr   
auxlib.ishr   base.constantsr   base.contextr   r   r   cli.mainr   common.configurationr   	common.ior   common.serializer   
common.urlr   core.package_cache_datar   core.subdir_datar   
exceptionsr   gateways.disk.creater   models.recordsr    collections.abcr!   r"   _pytest.capturer#   r$   r%   r&   r'   r(   pytest_mockr)   r   r   fixturer4   r@   rE   rL   rN   rV   r   getsplitr_   rc   rg   rh   r\   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r  r  r1   r2   r3   <module>r(     sZ   9 "  	   2 !    < < 	  )   )  5 P P $ 3   3 $ 6 ) & 5 *2,  *  @ @ j!& "& 1 1 j! "2 j! "   ::>>.0BCII#NCCC .C	C: ??? "? ? @@@ #@ @ 
7:.	0B	C  	  i FF+  !+ F  F  F R " " i   !  8 8 82 ' '   @ 1$11 1 1 i =%=&= = != /1 /1 /1d 5$55 !5 5 ]# $  5$5.;55 5( $.; " i. /r2   