
    ?go,                    L   S 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&  SSK'J(r(  SSK)J*r*  \*\\+\,4      " 5       r-\S   r.\\R^                   " S S5      5       5       r0S,S  jr1S-S! jr2S.S" jr3\!" S#S$9S/S% j5       r4S0S& jr5\!      S1S' j5       r6S2S( jr7\" S)S)S*9    S3S+ j5       r8g)4z>Support for providing temporary directories to test functions.    )annotationsN)Path)rmtree)Any)Dict)final)	Generator)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          0/usr/lib/python3/dist-packages/_pytest/tmpdir.py__init__TempPathFactory.__init__7   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)r5   r8   r6   r7   r-   )r   r(   getini
ValueErroroptionr9   r8   get)clsconfigr-   countpolicys        r:   from_configTempPathFactory.from_configN   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)r0   r1   normpathgetbasetempresolveparentrD   )r4   basenames     r:   _ensure_relative_to_basetemp,TempPathFactory._ensure_relative_to_basetempn   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prefixrX   mktemp)rS   rO   joinpathmkdirr   r&   )r4   rR   numberedps       r:   r[   TempPathFactory.mktempt   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.
rV   rW   PYTEST_DEBUG_TEMPROOTunknownz
pytest-of-T)rX   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-)rZ   rY   keeplock_timeoutrX   znew basetemp)r'   r%   existsr   r]   rP   r0   environrF   r   tempfile
gettempdirget_userr\   OSErrorr   statst_uidst_modechmodr)   r+   r   r   r&   )	r4   r9   from_envtemprootuserrootdiruidrootdir_statrf   s	            r:   rO   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/   )r5   r$   r6   r(   r7   r*   r9   r$   r-   boolreturnNone)rH   r   r-   ry   rz   r"   )rR   r3   rz   r3   )T)rR   r3   r^   ry   rz   r   )rz   r   )__name__
__module____qualname____firstlineno____doc____annotations__r;   classmethodrK   rS   r[   rO   __static_attributes__ r=   r:   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ImportErrorrm   KeyError)r   s    r:   rl   rl      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"   rK   setattr)rH   mpr   s      r:   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defaultrA   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )addini)parsers    r:   pytest_addoptionr      s:    
MM"u   MM#	  r=   session)scopec                .    U R                   R                  $ )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)rH   r   )requests    r:   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subr[   )r   factoryr   MAXVALs       r:   _mk_tmpr      sF    <<D66'3%DF=D>>$>..r=   c              #  @  #    [        X5      nUv   U R                  R                  R                  n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   rH   r   r+   r   stashtmppath_result_keyrF   r   )r   r   r1   rJ   result_dicts        r:   tmp_pathr      s      7-D
J )0(>(>(P(P//F,,$$%78Kkoofd;; 	t4(-.s   BB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   )rH   r   r'   r+   r%   is_dirr   r   )r   
exitstatusr   r9   rJ   s        r:   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       r:   pytest_runtest_makereportr   2  sJ      C88EADDJJ,e4SXX>Js   AA)rz   z
str | None)rH   r   rz   r{   )r   r   rz   r{   )r   r   rz   r"   )r   r   r   r"   rz   r   )r   r   r   r"   rz   zGenerator[Path])r   zint | ExitCode)r   r   rz   z'Generator[None, TestReport, TestReport])9r   
__future__r   dataclassesr0   pathlibr   r   shutilr   rj   typingr   r   r   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   r3   ry   r   r*   	dataclassr"   rl   r   r   r   r   r   r   r   r   r=   r:   <module>r      s7   D "  	  	        * ! & 3  & ! # # , - $ + +  & " d39o.0 /0 Z Z  Zz	
N 	y, ,/ 	///>// 	/2(2 
$&
, 'r=   