
    F-Ph+                    h   d 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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j0         G d d                                  Z1d=d!Z2d>d%Z3d?d(Z4 e!d)*          d@d-            Z5dAd0Z6e!dBd3            Z7dCd6Z8 ed7d78          dDd<            Z9dS )Ez>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                      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
dS ))TempPathFactoryzFactory 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	_ispytestgiven_basetempretention_countretention_policybasetempr+   boolreturnNonec                   t          |           |d | _        n>t          t          j                            t          |                              | _        || _        || _        || _	        || _
        d S N)r   r#   r   ospathabspathstrr$   r'   r)   r%   )selfr,   r-   r.   tracer/   r+   s          N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/_pytest/tmpdir.py__init__zTempPathFactory.__init__6   sm     	y!!!!#'D  
 $(N8K8K(L(L#M#MD  /!1!    configr   c               R   t          |           t          |                    d                    }|dk     rt          d| d          |                    d          }|dvrt          d| d           | |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)r,   r:   r-   r.   r+   )r   r&   getini
ValueErroroptionr/   r:   get)clsr>   r+   countpolicys        r;   from_configzTempPathFactory.from_configM   s     	y!!!FMM"<==>>199QQQQ   :;;222g^dggg   s!=1,""8,,!#
 
 
 	
r=   basenamer8   c                    t           j                            |          }|                                 |z                                  j        |                                 k    rt          | d          |S )Nz& is not a normalized and relative path)r5   r6   normpathgetbasetempresolveparentrE   )r9   rL   s     r;   _ensure_relative_to_basetempz,TempPathFactory._ensure_relative_to_basetempm   sj    7##H--)2244;t?O?O?Q?QQQPPPQQQr=   Tnumberedr   c                $   |                      |          }|s>|                                                     |          }|                    d           n:t	          |                                 |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prefixrW   mktemp)rR   rO   joinpathmkdirr   r$   )r9   rL   rS   ps       r;   rZ   zTempPathFactory.mktemps   s     44X>> 	%  ""++H55AGGG!t'7'7'9'9(QVWWWAKK!$$$r=   c                   | j         | j         S | j        V| j        }|                                rt          |           |                    d           |                                }njt          j                            d          }t          |pt          j                                                              }t                      pd}|                    d|           }	 |                    dd           n<# t          $ r/ |                    d	          }|                    dd           Y nw xY wt                      }|]|                                }|j        |k    rt          d
| d          |j        dz  dk    rt          j        ||j        dz             | j        }| j        dk    rd}t-          d||t.          d          }|
J |            || _         |                     d|           |S )zReturn the base temporary directory, creating it if needed.

        :returns:
            The base temporary directory.
        NrU   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\   rP   r5   environrG   r   tempfile
gettempdirget_userr[   OSErrorr   statst_uidst_modechmodr'   r)   r   r   r$   )	r9   r/   from_envtemprootuserrootdiruidrootdir_statrc   s	            r;   rO   zTempPathFactory.getbasetemp   s/    >%>!++H    hNNN&&&''))HHz~~&=>>HH=(;(=(=>>FFHHH::*D ''(;T(;(;<<G9548888 9 9 9"++,?@@54888889 --C&||~~&#--!27 2 2 2   !(50Q66HWl&:V&CDDD(D%//5 )  H ##X###!NH---s   (D   6D98D9r4   )r,   r"   r-   r&   r.   r(   r/   r"   r+   r0   r1   r2   )r>   r   r+   r0   r1   r!   )rL   r8   r1   r8   )T)rL   r8   rS   r0   r1   r   )r1   r   )__name__
__module____qualname____doc____annotations__r<   classmethodrK   rR   rZ   rO    r=   r;   r!   r!   (   s           !   KKK$$$$ !%"  " " " " " ". 
  	
 
 
 
 
 [
>       09 9 9 9 9 9r=   r!   r1   
str | Nonec                 p    	 ddl } |                                 S # t          t          t          f$ r Y dS 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ImportErrorrj   KeyError)r~   s    r;   ri   ri      sI       (+   tts    55r>   r   r2   c                    t                      }|                     |j                   t                              | 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!   rK   setattr)r>   mpr   s      r;   pytest_configurer      s^     
B
rw'33Fd3KKJJv*,=uJMMMMMr=   parserr   c                f    |                      ddd           |                      ddd           d S )Nr@   zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.   )helpdefaultrB   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )addini)r   s    r;   pytest_addoptionr      sX    
MM"u     MM#	      r=   session)scoperequestr   c                    | j         j        S )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)r>   r   )r   s    r;   tmp_path_factoryr      s     >++r=   factoryr   c                    | j         j        }t          j        dd|          }d}|d |         }|                    |d          S )Nz[\W]_   T)rS   )nodenameresubrZ   )r   r   r   MAXVALs       r;   _mk_tmpr      sG    <D6'3%%DF=D>>$>...r=   r   Generator[Path]c              #     K   t          | |          }|V  |j        }| j        j        t                   }|dk    r'|                    dd          rt          |d           | j        j        t          = dS )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_keyrG   r   )r   r   r6   rJ   result_dicts        r;   tmp_pathr      s       7,--D
JJJ /F,$%78Kkoofd;; 	t4((((-...r=   
exitstatusint | ExitCodec                    | j         j        }|j        }|dS |j        }|dk    r2|dk    r,|j        %|                                rt          |d           |                                rt          |           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>   r   r%   r)   r#   is_dirr   r   )r   r   r   r/   rJ   s        r;   pytest_sessionfinishr     s     )0(H)H/Fah,4?? 	1 840000  (h'''''( (r=   T)wrappertryfirstitemr   'Generator[None, TestReport, TestReport]c              #     K   d V }|j         J i }|j        | j                            t          |          |j         <   |S r4   )whenpassedr   
setdefaultr   )r   r   repemptys       r;   pytest_runtest_makereportr   0  sJ       %%C8EADDJ,e44SX>Jr=   )r1   r|   )r>   r   r1   r2   )r   r   r1   r2   )r   r   r1   r!   )r   r   r   r!   r1   r   )r   r   r   r!   r1   r   )r   r   )r   r   r1   r   ):rx   
__future__r   collections.abcr   dataclassesr5   pathlibr   r   shutilr   rg   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   dictr8   r0   r   r(   	dataclassr!   ri   r   r   r   r   r   r   r   r{   r=   r;   <module>r      sE   D D " " " " " " % % % % % %     				       				                          * * * * * * ! ! ! ! ! ! & & & & & & 3 3 3 3 3 3       & & & & & & ! ! ! ! ! ! # # # # # # # # # # # # , , , , , , - - - - - - $ $ $ $ $ $ + + + + + + + + + + + +       & & & & & & " " " " " " /Xd39o.00 /0 Z Z Z Z Z Z Z  Zz	 	 	 	
N 
N 
N 
N    	y, , , ,/ / / / 	/ / / 	/0( ( ( (2 
$&&&   '&  r=   