
    jo,                    t   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                                  Z0d>d"Z1d?d&Z2d@d)Z3 e!d*+          dAd.            Z4dBd1Z5e!dCd4            Z6dDd7Z7 ed8d89          dEd=            Z8dS )Fz>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                      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/   tracer0   r,   s          X/lsinfo/ai/hellotax_ai/base_platform/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optionr0   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>   basenamer9   c                    t           j                            |          }|                                 |z                                  j        |                                 k    rt          | d          |S )Nz& is not a normalized and relative path)r6   r7   normpathgetbasetempresolveparentrF   )r:   rM   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prefixrX   mktemp)rS   rP   joinpathmkdirr   r%   )r:   rM   rT   ps       r<   r[   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           |                                }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.
        NrV   rW   PYTEST_DEBUG_TEMPROOTunknownz
pytest-of-T)rX   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-)rZ   rY   keeplock_timeoutrX   znew basetemp)r&   r$   existsr   r]   rQ   r6   environrH   r   tempfile
gettempdirget_userr\   OSErrorr   statst_uidst_modechmodr(   r*   r   r   r%   )	r:   r0   from_envtemprootuserrootdiruidrootdir_statrd   s	            r<   rP   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r5   )r-   r#   r.   r'   r/   r)   r0   r#   r,   r1   r2   r3   )r?   r   r,   r1   r2   r"   )rM   r9   r2   r9   )T)rM   r9   rT   r1   r2   r   )r2   r   )__name__
__module____qualname____doc____annotations__r=   classmethodrL   rS   r[   rP    r>   r<   r"   r"   )   s           !   KKK$$$$ !%"  " " " " " ". 
  	
 
 
 
 
 [
>       09 9 9 9 9 9r>   r"   r2   
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   r3   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"   rL   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 )NrA   zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.   )helpdefaultrC   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)rT   )nodenameresubr[   )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        }|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?   r   r*   r   stashtmppath_result_keyrH   r   )r   r   r7   rK   result_dicts        r<   tmp_pathr      s       7,--D
JJJ )0(>(P/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   r0   rK   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 r5   )whenpassedr   
setdefaultr   )r   r   repemptys       r<   pytest_runtest_makereportr   2  sJ       %%C8EADDJ,e44SX>Jr>   )r2   r}   )r?   r   r2   r3   )r   r   r2   r3   )r   r   r2   r"   )r   r   r   r"   r2   r   )r   r   r   r"   r2   r   )r   r   )r   r   r2   r   )9ry   
__future__r   dataclassesr6   pathlibr   r   shutilr   rh   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   r9   r1   r   r)   	dataclassr"   rj   r   r   r   r   r   r   r   r|   r>   r<   <module>r      sW   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, , , ,/ / / / 	/ / / 	/2( ( ( (2 
$&&&   '&  r>   