Ë
    æØjj×3  ã                  óX  — d Z ddlmZ ddlZddlmZ ddlmZ ddlZddl	Z	ddl
mZ ddlZddlmZ ddlZddl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 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 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% 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.e/e0e1f      «       Z2ed   Z3eejh                   G d„ d«      «       «       Z5d,d „Z6d-d!„Z7d.d"„Z8 e%d#¬$«      d/d%„«       Z9d0d&„Z:e%	 	 	 	 	 	 d1d'„«       Z;d2d(„Z< ed)d)¬*«      	 	 	 	 d3d+„«       Z=y)4z>Support for providing temporary directories to test functions.é    )ÚannotationsN)Ú	Generator)Ú	ExitStack)Ú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                  ó¨   — e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   	 dddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zeddœ	 	 	 	 	 dd„«       Zdd„Zddd„Z	dd„Z
y)ÚTempPathFactoryz“Factory 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               óð   — t        |«       |€d | _        n6t        t        j                  j                  t        |«      «      «      | _        || _        || _        || _	        || _
        t        «       | _        y ©N)r   r$   r   ÚosÚpathÚabspathÚstrr%   r(   r*   r&   r   Ú_exit_stack)ÚselfÚgiven_basetempÚretention_countÚretention_policyÚtraceÚbasetempr,   s          úP/opt/eval-harness/bench_task/venv/lib/python3.12/site-packages/_pytest/tmpdir.pyÚ__init__zTempPathFactory.__init__9   se   € ô 	�yÔ!ØÐ!Ø#'ˆDÕ ô
 $(¬¯©¯©¼¸NÓ8KÓ(LÓ#MˆDÔ ØˆŒØ /ˆÔØ!1ˆÔØ!ˆŒô %›;ˆÕó    c               ó0  — t        |«       t        |j                  d«      «      }|dk  rt        d|› d�«      ‚|j                  d«      }|dvrt        d|› d�«      ‚ | |j                  j
                  |j                  j                  d«      ||d	¬
«      S )zTCreate 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_configzTempPathFactory.from_configS   s­   € ô 	�yÔ!Ü�F—M‘MÐ"<Ó=Ó>ˆØ�1Š9ÜØHÈÈÈqÐQóð ð —‘Ð:Ó;ˆØÐ2Ñ2ÜØ]Ð^dÐ]eÐefÐgóð ñ Ø!Ÿ=™=×1Ñ1Ø—,‘,×"Ñ" 8Ó,Ø!Ø#Øô
ð 	
r<   c                óØ   — t         j                  j                  |«      }| j                  «       |z  j	                  «       j
                  | j                  «       k7  rt        |› d�«      ‚|S )Nz& is not a normalized and relative path)r/   r0   ÚnormpathÚgetbasetempÚresolveÚparentrC   )r4   Úbasenames     r:   Ú_ensure_relative_to_basetempz,TempPathFactory._ensure_relative_to_basetemps   s\   € Ü—7‘7×#Ñ# HÓ-ˆØ×ÑÓ Ñ)×2Ñ2Ó4×;Ñ;¸t×?OÑ?OÓ?QÒQÜ ˜zÐ)OÐPÓQÐQØˆr<   c                óî   — | j                  |«      }|s3| j                  «       j                  |«      }|j                  d¬«       |S t	        | j                  «       |d¬«      }| j                  d|«       |S )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ÚprefixrU   Úmktemp)rQ   rM   ÚjoinpathÚmkdirr   r%   )r4   rP   ÚnumberedÚps       r:   rX   zTempPathFactory.mktempy   sr   € ð ×4Ñ4°XÓ>ˆÙØ× Ñ Ó"×+Ñ+¨HÓ5ˆAØ�G‰G˜ˆGÔð ˆô " t×'7Ñ'7Ó'9À(ÐQVÔWˆAØ�K‰K˜ !Ô$Øˆr<   c                óº  — | j                   �| j                   S | j                  �K| j                  }|j                  «       rt        |«       |j	                  d¬«       |j                  «       }�nt        j                  j                  d«      }t        |xs t        j                  «       «      j                  «       }t        «       xs d}|j                  d|› �«      }	 |j	                  dd¬«       t        «       }|�Øt        j                   t        j"                  v rd	nd}|j!                  |¬
«      }t!        j$                  |j&                  «      rt        d|› d�«      ‚|j(                  |k7  rt        d|› d�«      ‚|j&                  dz  dk7  rDt        j*                  t        j"                  v rd	nd}	|j+                  |j&                  dz  |	¬
«       | j,                  }
| j.                  dk(  rd}
t1        d||
t2        d| j4                  j6                  ¬«      }t9        j:                  | j4                  j<                  «       | j4                  j7                  t8        j>                  | j4                  j<                  «       |€J |«       ‚|| _         | jA                  d|«       |S # t        $ r( |j                  d«      }|j	                  dd¬«       Y �Œåw xY w)z�Return the base temporary directory, creating it if needed.

        :returns:
            The base temporary directory.
        rS   rT   ÚPYTEST_DEBUG_TEMPROOTÚunknownz
pytest-of-T)rU   Úexist_okzpytest-of-unknownF)Úfollow_symlinkszThe temporary directory z, is a symbolic link. Fix this and try again.z: is not owned by the current user. Fix this and try again.é?   r   iÀÿÿÿr    zpytest-)rW   rV   ÚkeepÚlock_timeoutrU   Úregisterznew basetemp)!r&   r$   Úexistsr   rZ   rN   r/   ÚenvironrE   r   ÚtempfileÚ
gettempdirÚget_userrY   ÚOSErrorr   ÚstatÚsupports_follow_symlinksÚS_ISLNKÚst_modeÚst_uidÚchmodr(   r*   r   r   r3   ÚcallbackÚatexitre   ÚcloseÚ
unregisterr%   )r4   r9   Úfrom_envÚtemprootÚuserÚrootdirÚuidÚstat_follow_symlinksÚrootdir_statÚchmod_follow_symlinksrc   s              r:   rM   zTempPathFactory.getbasetemp‘   s   € ð �>‰>Ð%Ø—>‘>Ð!à×ÑÐ+Ø×+Ñ+ˆHØ�‰Ô Ü�h”Ø�N‰N ˆNÔ&Ø×'Ñ'Ó)ŠHä—z‘z—~‘~Ð&=Ó>ˆHÜ˜HÒ=¬×(;Ñ(;Ó(=Ó>×FÑFÓHˆHÜ“:Ò* ˆDð ×'Ñ'¨*°T°FÐ(;Ó<ˆGð9Ø—‘ 5°4�Ô8ô$ “-ˆCØˆäŸW™W¬×(CÑ(CÑC‘EÈð %ð  'Ÿ|™|Ð<P˜|ÓQ�Ü—<‘< × 4Ñ 4Ô5Ü!Ø2°7°)ð <2ð 2óð ð  ×&Ñ&¨#Ò-Ü!Ø2°7°)ð <2ð 2óð ð !×(Ñ(¨5Ñ0°QÒ6ä!#§¡¬R×-HÑ-HÑ!H™Èdð *ð —M‘MØ$×,Ñ,¨vÑ5Ø(=ð "ô ð ×(Ñ(ˆDØ×%Ñ%¨Ò/Ø�Ü5Ø ØØÜ)ØØ×)Ñ)×2Ñ2ôˆHô �O‰O˜D×,Ñ,×2Ñ2Ô3Ø×Ñ×%Ñ%¤f×&7Ñ&7¸×9IÑ9I×9OÑ9OÔPØÐ#Ð- XÓ-Ð#Ø!ˆŒØ�‰�N HÔ-Øˆøôy ò 9à"×+Ñ+Ð,?Ó@�Ø—‘ 5°4�×8ð9ús   Ã!J) Ê)-KËKr.   )r5   r#   r6   r'   r7   r)   r9   r#   r,   ÚboolÚreturnÚNone)rG   r   r,   r~   r   r"   )rP   r2   r   r2   )T)rP   r2   r[   r~   r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r;   ÚclassmethodrJ   rQ   rX   rM   © r<   r:   r"   r"   +   s¹   … ñð !Ó àƒKØÓØÓØ$Ó$ð !%ð'ð  ñ'à#ð'ð ð'ð (ð	'ð ð'ð ð'ð 
ó'ð4 ð
  ñ	
àð
ð ð	
ð
 
ò
ó ð
ó>ôô0Tr<   r"   c                 ó`   — 	 ddl } | j                  «       S # t        t        t        f$ r Y yw xY w)zlReturn the current user name, or None if getuser() does not work
    in the current environment (see #1010).r   N)ÚgetpassÚgetuserÚImportErrorrk   ÚKeyError)r‰   s    r:   rj   rj   è   s0   € ðãà�‰Ó Ð øÜœ¤(Ð+ò Ùðús   ‚ –-¬-c                ó¦   — t        «       }| j                  |j                  «       t        j	                  | d¬«      }|j                  | d|d¬«       y)a  Create 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      r:   Úpytest_configurer”   ô   sI   € ô 
‹€BØ
×Ñ�r—w‘wÔÜ'×3Ñ3°FÀdÐ3ÓKÐØ‡J�JˆvÐ*Ð,=Àu€JÕMr<   c                óX   — | j                  dddd¬«       | j                  dddd¬	«       y )
Nr>   zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.Ú3Ústring)ÚhelpÚdefaultÚtyper@   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )r˜   rš   r™   )Úaddini)Úparsers    r:   Úpytest_addoptionr�     s@   € Ø
‡M�MØ"ØuØàð ô ð ‡M�MØ#ðàØð õ r<   Úsession)Úscopec                ó.   — | j                   j                  S )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)rG   rŽ   )Úrequests    r:   Útmp_path_factoryr¢     s   € ð �>‰>×+Ñ+Ð+r<   c                ó�   — | j                   j                  }t        j                  dd|«      }d}|d | }|j	                  |d¬«      S )Nz[\W]Ú_é   T)r[   )ÚnodeÚnameÚreÚsubrX   )r¡   Úfactoryr§   ÚMAXVALs       r:   Ú_mk_tmpr¬     sF   € Ø�<‰<×Ñ€DÜ�6‰6�'˜3 Ó%€DØ€FØ��ˆ=€DØ�>‰>˜$¨ˆ>Ó.Ð.r<   c              #  óü   K  — t        | |«      }|–— |j                  }| j                  j                  t           }|dk(  r|j                  dd«      rt        |d¬«       | j                  j                  t        = y­w)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        r:   Útmp_pathr´   "  sp   è ø€ ô �7Ð,Ó-€DØ
‚Jð ×/Ñ/€FØ—,‘,×$Ñ$Ô%7Ñ8€Kà�Ò˜kŸo™o¨f°dÔ;ô 	ˆt 4Õ(à�‰×ÑÔ-Ñ.ùs   ‚A:A<c                ó6  — | j                   j                  }|j                  }|€y|j                  }|dk(  r.|dk(  r)|j                  €|j                  «       rt        |d¬«       |j                  «       rt        |«       |j                  j                  «        y)z�After 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   r3   rt   )rž   Ú
exitstatusr¢   r9   rI   s        r:   Úpytest_sessionfinishr¸   ;  sŒ   € ð )0¯©×(HÑ(HÐØ×)Ñ)€HØÐØà×/Ñ/€Fà�aŠØ�hÒØ×,Ñ,Ð4à�?‰?Ôô �8¨4Õ0ð ‡�ÔÜ˜hÔ'ð × Ñ ×&Ñ&Õ(r<   T)ÚwrapperÚtryfirstc              #  ó¤   K  — d –—}|j                   €J ‚i }|j                  | j                  j                  t        |«      |j                   <   |S ­wr.   )ÚwhenÚpassedr±   Ú
setdefaultr²   )Úitemr®   ÚrepÚemptys       r:   Úpytest_runtest_makereportrÂ   W  sK   è ø€ ò €CØ�8‰8ÐÐÐØ€EØADÇÁ€D‡J�J×ÑÔ,¨eÓ4°S·X±XÑ>Ø€Jùs   ‚AA)r   z
str | None)rG   r   r   r€   )rœ   r   r   r€   )r¡   r   r   r"   )r¡   r   rª   r"   r   r   )r¡   r   r¢   r"   r   zGenerator[Path])r·   zint | ExitCode)r¿   r   r   z'Generator[None, TestReport, TestReport])>r„   Ú
__future__r   rs   Úcollections.abcr   Ú
contextlibr   Údataclassesr/   Úpathlibr   r¨   Úshutilr   rl   rh   Ú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   r~   r²   r)   Ú	dataclassr"   rj   r”   r�   r¢   r¬   r´   r¸   rÂ   r‡   r<   r:   ú<module>rÕ      s?  ðá Då "ã Ý %Ý  Û Û 	Ý Û 	Ý Û Û Ý Ý Ý å *Ý !Ý &Ý 3Ý Ý &Ý !Ý #Ý #Ý ,Ý -Ý $Ý +Ý +Ý Ý &Ý "ð /�X˜d 3¨ 9™oÑ.Ó0Ð ØÐ/Ñ0€ð Ø×Ñ÷xð xó ó ðxóv	ó
Nóñ$ 	ˆyÔò,ó ð,ó/ð 	ð/Øð/Ø/>ð/àò/ó 	ð/ó0)ñ8 
�$ Ô&ðØ
ðà,òó 'ñr<   