
    i0                    p   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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         Z0eej1         G d d                                  Z2d=d!Z3d>d%Z4d?d(Z5 e"d)*          d@d-            Z6dAd0Z7e"dBd3            Z8dCd6Z9 ed7d78          dDd<            Z:d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          K/root/projects/qq-shell/venv/lib/python3.11/site-packages/_pytest/tmpdir.py__init__zTempPathFactory.__init__7   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_configN   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_basetempn   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.mktempt   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           |                                }nt          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                      }|t          j        t          j        v rd
nd}|                    |          }t!          j        |j                  rt          d| d          |j        |k    rt          d| d          |j        dz  dk    r;t          j        t          j        v rd
nd}	|                    |j        dz  |	           | j        }
| j        dk    rd}
t1          d||
t2          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-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   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supports_follow_symlinksS_ISLNKst_modest_uidchmodr'   r)   r   r   r$   )r9   r/   from_envtemprootuserrootdiruidstat_follow_symlinksrootdir_statchmod_follow_symlinksrd   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W(CCCEE %  '||<P|QQ< 455 !27 2 2 2    &#--!27 2 2 2   !(50Q66!#R-H!H!Hd * MM$,v5(= "    (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$$$$ !%"  " " " " " ". 
  	
 
 
 
 
 [
>       0N N N N N N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ImportErrorrk   KeyError)r   s    r;   rj   rj      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                j    |                      dd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`.3string)helpdefaulttyperB   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )r   r   r   )addini)r   s    r;   pytest_addoptionr      s^    
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   0  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   I  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   );r}   
__future__r   collections.abcr   dataclassesr5   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   dictr8   r0   r   r(   	dataclassr!   rj   r   r   r   r   r   r   r   r   r=   r;   <module>r      sN   D D " " " " " " % % % % % %     				       				                           * * * * * * ! ! ! ! ! ! & & & & & & 3 3 3 3 3 3       & & & & & & ! ! ! ! ! ! # # # # # # # # # # # # , , , , , , - - - - - - $ $ $ $ $ $ + + + + + + + + + + + +       & & & & & & " " " " " " /Xd39o.00 /0 o o o o o o o  od	 	 	 	
N 
N 
N 
N   $ 	y, , , ,/ / / / 	/ / / 	/0( ( ( (2 
$&&&   '&  r=   