HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/_pytest/__pycache__/tmpdir.cpython-310.pyc
o

%we�-�
@sVdZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddl	mZddl	m
Z
dd	l	mZdd
l	mZddlmZddlmZdd
lmZer`ddlmZedZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!m"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl'm(Z(ddl)m*Z*ddl)m+Z+ddl,m-Z-eee.e/f�Z0e!ej1Gdd �d ���Z2d!e
e.fd"d#�Z3d$e$d!dfd%d&�Z4d'ed!dfd(d)�Z5e*d*d+�d,e+d!e2fd-d.��Z6d,e+d/e2d!efd0d1�Z7e*d,e+d.e2d!eeddffd2d3��Z8d4ee9e%ffd5d6�Z:e&d7d7d8�d9efd:d;��Z;dS)<z>Support for providing temporary directories to test functions.�N)�Path)�rmtree)�Any)�Dict)�	Generator)�Optional)�
TYPE_CHECKING)�Union)�Item)�
CollectReport)�StashKey)�Literal��all�failed�none)�Parser�)�LOCK_TIMEOUT)�make_numbered_dir)�make_numbered_dir_with_cleanup)�rm_rf)�cleanup_dead_symlinks)�final�get_user_id)�Config)�ExitCode)�hookimpl)�check_ispytest)�fixture)�FixtureRequest)�MonkeyPatchc@s�eZdZUdZeeed<eed<eeed<eed<ded<	dd	d
�deeded
ddeede	ddfdd�Z
ed	d
�dede	ddfdd��Z
dedefdd�Zd dede	defdd�Zdefdd�ZdS)!�TempPathFactoryz�Factory for temporary directories under the common base temp directory.

    The base directory can be configured using the ``--basetemp`` option.
    �_given_basetemp�_trace�	_basetemp�_retention_count�
RetentionType�_retention_policyNF��	_ispytest�given_basetemp�retention_count�retention_policy�basetempr*�returncCsJt|�|durd|_nttj�t|���|_||_||_||_	||_
dS�N)rr#r�os�path�abspath�strr$r&r(r%)�selfr+r,r-�tracer.r*�r7�G/home/arjun/projects/env/lib/python3.10/site-packages/_pytest/tmpdir.py�__init__;s

zTempPathFactory.__init__�configcCsnt|�t|�d��}|dkrtd|�d���|�d�}|dvr(td|�d���||jj|j�d�||d	d
�S)zTCreate a factory according to pytest configuration.

        :meta private:
        �tmp_path_retention_countrz6tmp_path_retention_count must be >= 0. Current input: �.�tmp_path_retention_policyrzKtmp_path_retention_policy must be either all, failed, none. Current input: �tmpdirT)r+r6r,r-r*)r�int�getini�
ValueError�optionr.r6�get)�clsr:r*�count�policyr7r7r8�from_configRs$
�

�
�zTempPathFactory.from_config�basenamecCs8tj�|�}|��|��j|��krt|�d���|S)Nz& is not a normalized and relative path)r1r2�normpath�getbasetemp�resolve�parentrA)r5rHr7r7r8�_ensure_relative_to_basetemprsz,TempPathFactory._ensure_relative_to_basetempT�numberedcCsN|�|�}|s|���|�}|jdd�|St|��|dd�}|�d|�|S)aCreate 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�prefixrQ�mktemp)rMrJ�joinpath�mkdirrr$)r5rHrN�pr7r7r8rTxs
�zTempPathFactory.mktempc	CsZ|jdur|jS|jdur#|j}|��rt|�|jdd�|��}nwtj�d�}t	|p/t
�����}t�p7d}|�
d|���}z	|jddd�Wnty^|�
d	�}|jddd�Ynwt�}|dur�|��}|j|krwtd
|�d���|jd@d
kr�t�||jd@�|j}|jdkr�d
}td||tdd�}|dus�J|��||_|�d|�|S)z�Return the base temporary directory, creating it if needed.

        :returns:
            The base temporary directory.
        NrOrP�PYTEST_DEBUG_TEMPROOT�unknownz
pytest-of-T)rQ�exist_okzpytest-of-unknownzThe temporary directory z: is not owned by the current user. Fix this and try again.�?ri����rzpytest-)rSrR�keep�lock_timeoutrQznew basetemp)r%r#�existsrrVrKr1�environrCr�tempfile�
gettempdir�get_userrU�OSErrorr�stat�st_uid�st_mode�chmodr&r(rrr$)	r5r.�from_env�temproot�user�rootdir�uid�rootdir_statr\r7r7r8rJ�sR




�


�
�zTempPathFactory.getbasetempr0)T)�__name__�
__module__�__qualname__�__doc__rr�__annotations__rr?�boolr9�classmethodrrGr4rMrTrJr7r7r7r8r",sF
�������	
�����r"r/c	Cs,z	ddl}|��WSttfyYdSw)zlReturn the current user name, or None if getuser() does not work
    in the current environment (see #1010).rN)�getpass�getuser�ImportError�KeyError)rur7r7r8rb�s
�rbr:cCs6t�}|�|j�tj|dd�}|j|d|dd�dS)aCreate 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"rG�setattr)r:�mpryr7r7r8�pytest_configure�sr�parsercCs$|jdddd�|jdddd�dS)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)r�r7r7r8�pytest_addoption�s�
�r��session)�scope�requestcCs|jjS)zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)r:ry)r�r7r7r8�tmp_path_factory�sr��factorycCs4|jj}t�dd|�}d}|d|�}|j|dd�S)Nz[\W]�_�T)rN)�node�name�re�subrT)r�r�r��MAXVALr7r7r8�_mk_tmp�s
r�ccs\�t||�}|V|jjj}|j}|jjt}|dkr'|�dd�r't	|dd�|jjt=dS)aUReturn a temporary directory path object which is unique to each test
    function invocation, created as a sub directory of the base temporary
    directory.

    By default, a new base temporary directory is created each test session,
    and old bases are removed after 3 sessions, to aid in debugging.
    This behavior can be configured with :confval:`tmp_path_retention_count` and
    :confval:`tmp_path_retention_policy`.
    If ``--basetemp`` is used then it is cleared each session. See :ref:`base
    temporary directory`.

    The returned object is a :class:`pathlib.Path` object.
    r�callT��
ignore_errorsN)
r�r�r:ryr(r��stash�tmppath_result_keyrCr)r�r�r2rF�result_dictr7r7r8�tmp_paths�

r��
exitstatuscCsf|jj}|j}|dur
dS|j}|dkr'|dkr'|jdur'|��r't|dd�|��r1t|�dSdS)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.
    NrrTr�)r:ryr%r(r#�is_dirrr)r�r�r�r.rFr7r7r8�pytest_sessionfinish%s
�r�T)�tryfirst�hookwrapper�itemccs.�dV}|��}i}|j|j�t|�|j<dSr0)�
get_result�passedr��
setdefaultr��when)r�r��outcome�result�emptyr7r7r8�pytest_runtest_makereport>s
�r�)<rq�dataclassesr1r�r`�pathlibr�shutilr�typingrrrrrr	�
_pytest.nodesr
�_pytest.reportsr�
_pytest.stashr�typing_extensionsr
r'�_pytest.config.argparsingrrrrrr�_pytest.compatrr�_pytest.configrrr�_pytest.deprecatedr�_pytest.fixturesrr �_pytest.monkeypatchr!r4rsr��	dataclassr"rbrr�r�r�r�r?r�r�r7r7r7r8�<module>sn
���!