
    i+                    @   S r SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	r	SSK
J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  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  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&  SSK'J(r(  SSK)J*r*  \*\+\,\-4      " 5       r.\S   r/\\R`                   " S S5      5       5       r1S+S jr2S,S  jr3S-S! jr4\!" S"S#9S.S$ j5       r5S/S% jr6\!      S0S& j5       r7S1S' jr8\" S(S(S)9    S2S* j5       r9g)3z>Support for providing temporary directories to test functions.    )annotations)	GeneratorN)Path)rmtree)Any)final)Literal   )cleanup_dead_symlinks)LOCK_TIMEOUT)make_numbered_dir)make_numbered_dir_with_cleanup)rm_rf)get_user_id)Config)ExitCode)hookimpl)Parser)check_ispytest)fixture)FixtureRequest)MonkeyPatch)Item)
TestReport)StashKeyallfailednonec                      \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S
\S'    SSS.           SS jjjr\SS.     SS jj5       rSS jr	SSS jjr
SS jrSrg)TempPathFactory(   zFactory for temporary directories under the common base temp directory,
as discussed at :ref:`temporary directory location and retention`.
Path | None_given_basetempr   _trace	_basetempint_retention_countRetentionType_retention_policyNF	_ispytestc                   [        U5        Uc  S U l        O6[        [        R                  R                  [        U5      5      5      U l        X@l        X l        X0l	        XPl
        g N)r   r$   r   ospathabspathstrr%   r(   r*   r&   )selfgiven_basetempretention_countretention_policytracebasetempr,   s          M/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/_pytest/tmpdir.py__init__TempPathFactory.__init__6   sQ     	y!!#'D 
 $(N8K(L#MD  /!1!    c               0   [        U5        [        UR                  S5      5      nUS:  a  [        SU S35      eUR                  S5      nUS;  a  [        SU S35      eU " UR                  R
                  UR                  R                  S5      UUS	S
9$ )zDCreate a factory according to pytest configuration.

:meta private:
tmp_path_retention_countr   z6tmp_path_retention_count must be >= 0. Current input: .tmp_path_retention_policyr   zKtmp_path_retention_policy must be either all, failed, none. Current input: tmpdirT)r4   r7   r5   r6   r,   )r   r'   getini
ValueErroroptionr8   r7   get)clsconfigr,   countpolicys        r9   from_configTempPathFactory.from_configM   s     	y!FMM"<=>19HqQ  :;22]^d]eefg  !==11,,""8,!#
 	
r<   c                    [         R                  R                  U5      nU R                  5       U-  R	                  5       R
                  U R                  5       :w  a  [        U S35      eU$ )Nz& is not a normalized and relative path)r/   r0   normpathgetbasetempresolveparentrC   )r3   basenames     r9   _ensure_relative_to_basetemp,TempPathFactory._ensure_relative_to_basetempm   s\    77##H-)224;;t?O?O?QQz)OPQQr<   c                    U R                  U5      nU(       d0  U R                  5       R                  U5      nUR                  SS9  U$ [	        U R                  5       USS9nU R                  SU5        U$ )a  Create a new temporary directory managed by the factory.

:param basename:
    Directory base name, must be a relative path.

:param numbered:
    If ``True``, ensure the directory is unique by adding a numbered
    suffix greater than any existing one: ``basename="foo-"`` and ``numbered=True``
    means that this function will create directories named ``"foo-0"``,
    ``"foo-1"``, ``"foo-2"`` and so on.

:returns:
    The path to the new directory.
  mode)rootprefixrW   mktemp)rR   rN   joinpathmkdirr   r%   )r3   rQ   numberedps       r9   rZ   TempPathFactory.mktemps   sr     44X>  "++H5AGGG  "t'7'7'9(QVWAKK!$r<   c                   U R                   b  U R                   $ U R                  bM  U R                  nUR                  5       (       a  [        U5        UR	                  SS9  UR                  5       nGO-[        R                  R                  S5      n[        U=(       d    [        R                  " 5       5      R                  5       n[        5       =(       d    SnUR                  SU 35      n UR	                  SSS9  [        5       nUbe  UR!                  5       nUR"                  U:w  a  [        S	U S
35      eUR$                  S-  S:w  a#  [        R&                  " XWR$                  S-  5        U R(                  nU R*                  S:X  a  Sn[-        SUU[.        SS9nUc   U5       eXl         U R1                  SU5        U$ ! [         a$    UR                  S5      nUR	                  SSS9   Nf = f)ziReturn the base temporary directory, creating it if needed.

:returns:
    The base temporary directory.
rU   rV   PYTEST_DEBUG_TEMPROOTunknownz
pytest-of-T)rW   exist_okzpytest-of-unknownzThe temporary directory z: is not owned by the current user. Fix this and try again.?   r   ir   zpytest-)rY   rX   keeplock_timeoutrW   znew basetemp)r&   r$   existsr   r\   rO   r/   environrE   r   tempfile
gettempdirget_userr[   OSErrorr   statst_uidst_modechmodr(   r*   r   r   r%   )	r3   r8   from_envtemprootuserrootdiruidrootdir_statre   s	            r9   rN   TempPathFactory.getbasetemp   s    >>%>>!+++H  hNNN&'')Hzz~~&=>HH=(;(;(=>FFHH:*D ''*TF(;<G9548 -C&||~&&#-!27) <2 2  !((50Q6HHW&:&:V&CD((D%%/5 )H #-X-#!NH-C  9"++,?@5489s   0G +G32G3)r&   r$   r(   r*   r%   r.   )r4   r#   r5   r'   r6   r)   r8   r#   r,   boolreturnNone)rG   r   r,   rx   ry   r!   )rQ   r2   ry   r2   )T)rQ   r2   r]   rx   ry   r   )ry   r   )__name__
__module____qualname____firstlineno____doc____annotations__r:   classmethodrJ   rR   rZ   rN   __static_attributes__ r<   r9   r!   r!   (   s     ! K$$ !%"  "#" " (	" " " 
". 
  	

 	

 

 
>09r<   r!   c                 b     SSK n U R                  5       $ ! [        [        [        4 a     gf = f)zhReturn the current user name, or None if getuser() does not work
in the current environment (see #1010).r   N)getpassgetuserImportErrorrl   KeyError)r   s    r9   rk   rk      s0      (+ s    ..c                    [        5       nU R                  UR                  5        [        R	                  U SS9nUR                  U SUSS9  g)zCreate a TempPathFactory and attach it to the config object.

This is to comply with existing plugins which expect the handler to be
available at pytest_configure time, but ideally should be moved entirely
to the tmp_path_factory session fixture.
Tr+   _tmp_path_factoryF)raisingN)r   add_cleanupundor!   rJ   setattr)rG   mpr   s      r9   pytest_configurer      sI     
B
rww'33Fd3KJJv*,=uJMr<   c                H    U R                  SSSS9  U R                  SSSS9  g )Nr>   zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.   )helpdefaultr@   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )addini)parsers    r9   pytest_addoptionr      s:    
MM"u   MM#	  r<   session)scopec                .    U R                   R                  $ )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)rG   r   )requests    r9   tmp_path_factoryr      s     >>+++r<   c                    U R                   R                  n[        R                  " SSU5      nSnUS U nUR	                  USS9$ )Nz[\W]_   T)r]   )nodenameresubrZ   )r   factoryr   MAXVALs       r9   _mk_tmpr      sF    <<D66'3%DF=D>>$>..r<   c              #     #    [        X5      nUv   UR                  nU R                  R                  [           nUS:X  a!  UR                  SS5      (       a
  [        USS9  U R                  R                  [        	 g7f)a'  Return a temporary directory (as :class:`pathlib.Path` object)
which is unique to each test function invocation.
The temporary directory is created as a subdirectory
of the base temporary directory, with configurable retention,
as discussed in :ref:`temporary directory location and retention`.
r   callTignore_errorsN)r   r*   r   stashtmppath_result_keyrE   r   )r   r   r0   rI   result_dicts        r9   tmp_pathr      so      7-D
J //F,,$$%78Kkoofd;; 	t4(-.s   A<A>c                   U R                   R                  nUR                  nUc  gUR                  nUS:X  a2  US:X  a,  UR                  c  UR                  5       (       a
  [        USS9  UR                  5       (       a  [        U5        gg)zAfter each session, remove base directory if all the tests passed,
the policy is "failed", and the basetemp is not specified by a user.
Nr   r   Tr   )rG   r   r&   r*   r$   is_dirr   r   )r   
exitstatusr   r8   rI   s        r9   pytest_sessionfinishr     s     )0(H(H))H//Fah,,4?? 840 h' r<   T)wrappertryfirstc              #     #    S v nUR                   c   e0 nUR                  U R                  R                  [        U5      UR                   '   U$ 7fr.   )whenpassedr   
setdefaultr   )itemr   repemptys       r9   pytest_runtest_makereportr   0  sJ      C88EADDJJ,e4SXX>Js   AA)ry   z
str | None)rG   r   ry   rz   )r   r   ry   rz   )r   r   ry   r!   )r   r   r   r!   ry   r   )r   r   r   r!   ry   zGenerator[Path])r   zint | ExitCode)r   r   ry   z'Generator[None, TestReport, TestReport]):r   
__future__r   collections.abcr   dataclassesr/   pathlibr   r   shutilr   ri   typingr   r   r	   r   r   r   r   r   _pytest.compatr   _pytest.configr   r   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.monkeypatchr   _pytest.nodesr   _pytest.reportsr   _pytest.stashr   dictr2   rx   r   r)   	dataclassr!   rk   r   r   r   r   r   r   r   r   r<   r9   <module>r      s4   D " %  	  	      * ! & 3  & ! # # , - $ + +  & " d39o.0 /0 Z Z  Zz	
N 	y, ,/ 	///>// 	/0(2 
$&
, 'r<   