o
    rh-                     @  s  d 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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& ddl'm(Z( ddl)m*Z* e*ee+e,f   Z-ed Z.eej/G dd dZ0dEd"d#Z1dFd'd(Z2dGd+d,Z3e!d-d.dHd1d2Z4dId5d6Z5e!dJd8d9Z6dKd<d=Z7ed>d>d?dLdCdDZ8dS )Mz>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                   @  s   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dZeddd)ddZd*ddZd+d,d#d$Z	d-d%d&Z
dS ).TempPathFactoryzFactory for temporary directories under the common base temp directory.

    The base directory can be configured using the ``--basetemp`` option.
    Path | None_given_basetempr   _trace	_basetempint_retention_countRetentionType_retention_policyNF	_ispytestgiven_basetempretention_countretention_policybasetempr*   boolreturnNonec                C  sJ   t | |d u rd | _nttjt|| _|| _|| _|| _	|| _
d S N)r   r"   r   ospathabspathstrr#   r&   r(   r$   )selfr+   r,   r-   tracer.   r*    r9   L/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/_pytest/tmpdir.py__init__8   s   

zTempPathFactory.__init__configr   c                C  sn   t | t|d}|dk rtd| d|d}|dvr(td| d| |jj|jd||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)r+   r8   r,   r-   r*   )r   r%   getini
ValueErroroptionr.   r8   get)clsr<   r*   countpolicyr9   r9   r:   from_configO   s$   



zTempPathFactory.from_configbasenamer6   c                 C  s8   t j|}|  |  j|  krt| d|S )Nz& is not a normalized and relative path)r3   r4   normpathgetbasetempresolveparentrB   )r7   rI   r9   r9   r:   _ensure_relative_to_basetempo   s   z,TempPathFactory._ensure_relative_to_basetempTnumberedr   c                 C  sN   |  |}|s|  |}|jdd |S t|  |dd}| 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prefixrR   mktemp)rN   rK   joinpathmkdirr   r#   )r7   rI   rO   pr9   r9   r:   rU   u   s   
zTempPathFactory.mktempc           	      C  sZ  | j dur| j S | jdur#| j}| rt| |jdd | }nwtjd}t	|p/t
  }t p7d}|d| }z	|jddd W n ty^   |d	}|jddd Y nw t }|dur| }|j|krwtd
| d|jd@ dkrt||jd@  | j}| jdkrd}td||tdd}|dusJ ||| _ | d| |S )zReturn the base temporary directory, creating it if needed.

        :returns:
            The base temporary directory.
        NrP   rQ   PYTEST_DEBUG_TEMPROOTunknownz
pytest-of-T)rR   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-)rT   rS   keeplock_timeoutrR   znew basetemp)r$   r"   existsr   rW   rL   r3   environrD   r   tempfile
gettempdirget_userrV   OSErrorr   statst_uidst_modechmodr&   r(   r   r   r#   )	r7   r.   from_envtemprootuserrootdiruidrootdir_statr]   r9   r9   r:   rK      sR   








zTempPathFactory.getbasetempr2   )r+   r!   r,   r%   r-   r'   r.   r!   r*   r/   r0   r1   )r<   r   r*   r/   r0   r    )rI   r6   r0   r6   )T)rI   r6   rO   r/   r0   r   )r0   r   )__name__
__module____qualname____doc____annotations__r;   classmethodrH   rN   rU   rK   r9   r9   r9   r:   r    )   s"   
 
r    r0   
str | Nonec               
   C  s.   z	ddl } |  W S  tttfy   Y dS w )zlReturn the current user name, or None if getuser() does not work
    in the current environment (see #1010).r   N)getpassgetuserImportErrorrd   KeyError)rv   r9   r9   r:   rc      s   
rc   r<   r   r1   c                 C  s6   t  }| |j tj| dd}|j| d|dd dS )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    rH   setattr)r<   mprz   r9   r9   r:   pytest_configure   s   r   parserr   c                 C  s$   | j dddd | j dddd d S )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   r9   r9   r:   pytest_addoption   s   
r   session)scoperequestr   c                 C  s   | j jS )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)r<   rz   )r   r9   r9   r:   tmp_path_factory   s   r   factoryr   c                 C  s4   | j j}tdd|}d}|d | }|j|ddS )Nz[\W]_   T)rO   )nodenameresubrU   )r   r   r   MAXVALr9   r9   r:   _mk_tmp   s
   r   Generator[Path]c                 c  s\    t | |}|V  | jjj}|j}| jjt }|dkr'|ddr't	|dd | jjt= dS )ag  Return 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:`temporary directory location and retention`.

    The returned object is a :class:`pathlib.Path` object.
    r   callTignore_errorsN)
r   r   r<   rz   r(   r   stashtmppath_result_keyrD   r   )r   r   r4   rG   result_dictr9   r9   r:   tmp_path   s   

r   
exitstatusint | ExitCodec                 C  sf   | j j}|j}|du rdS |j}|dkr'|dkr'|jdu r'| r't|dd | r1t| dS dS )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   )r<   rz   r$   r(   r"   is_dirr   r   )r   r   r   r.   rG   r9   r9   r:   pytest_sessionfinish!  s   
r   T)wrappertryfirstitemr   'Generator[None, TestReport, TestReport]c                 c  s4    d V }|j d usJ i }|j| jt||j < |S r2   )whenpassedr   
setdefaultr   )r   r   repemptyr9   r9   r:   pytest_runtest_makereport:  s   r   )r0   ru   )r<   r   r0   r1   )r   r   r0   r1   )r   r   r0   r    )r   r   r   r    r0   r   )r   r   r   r    r0   r   )r   r   )r   r   r0   r   )9rr   
__future__r   dataclassesr3   pathlibr   r   shutilr   ra   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   r6   r/   r   r'   	dataclassr    rc   r   r   r   r   r   r   r   r9   r9   r9   r:   <module>   s^    




 
