
    [Fi-              
          d 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& 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!ee+   fd"Z1d#ed!dfd$Z2d%ed!dfd&Z3 e!d'(      d)e"d!e0fd*       Z4d)e"d+e0d!efd,Z5e!d)e"d-e0d!eeddf   fd.       Z6d/ee7ef   fd0Z8 ed1d12      d3e&d!ede(e(f   fd4       Z9y)5z>Support for providing temporary directories to test functions.    N)Path)rmtree)Any)Dict)final)	Generator)Literal)Optional)Union   )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ee   ed<   eed<   ee   ed<   eed<   e	ed<   	 ddd	d
ee   dede	dee   de
ddfdZedd	dede
dd fd       ZdedefdZddede
defdZdefdZy)TempPathFactoryzFactory 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_retention_policyNF	_ispytestgiven_basetempretention_countretention_policybasetempr*   returnc                    t        |       |d | _        n6t        t        j                  j                  t        |                  | _        || _        || _        || _	        || _
        y N)r   r$   r   ospathabspathstrr%   r'   r(   r&   )selfr+   r,   r-   tracer.   r*   s          `/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/tmpdir.py__init__zTempPathFactory.__init__8   sY     	y!!#'D 
 $(N8K(L#MD  /!1!    configc                0   t        |       t        |j                  d            }|dk  rt        d| d      |j                  d      }|dvrt        d| d       | |j                  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+   r7   r,   r-   r*   )r   intgetini
ValueErroroptionr.   r7   get)clsr;   r*   countpolicys        r8   from_configzTempPathFactory.from_configO   s     	y!FMM"<=>19HqQ  :;22]^d]eefg  !==11,,""8,!#
 	
r:   basenamec                     t         j                  j                  |      }| j                         |z  j	                         j
                  | j                         k7  rt        | d      |S )Nz& is not a normalized and relative path)r2   r3   normpathgetbasetempresolveparentrC   )r6   rJ   s     r8   _ensure_relative_to_basetempz,TempPathFactory._ensure_relative_to_basetempo   s\    77##H-)224;;t?O?O?QQz)OPQQr:   numberedc                     | j                  |      }|s3| j                         j                  |      }|j                  d       |S t	        | j                         |d      }| j                  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prefixrU   mktemp)rP   rM   joinpathmkdirr   r%   )r6   rJ   rQ   ps       r8   rX   zTempPathFactory.mktempu   sr     44X>  "++H5AGGG  "t'7'7'9(QVWAKK!$r:   c                    | j                   | j                   S | j                  K| j                  }|j                         rt        |       |j	                  d       |j                         }n$t        j                  j                  d      }t        |xs t        j                               j                         }t               xs d}|j                  d|       }	 |j	                  dd       t               }|c|j!                         }|j"                  |k7  rt        d	| d
      |j$                  dz  dk7  r#t        j&                  ||j$                  dz         | j(                  }| j*                  dk(  rd}t-        d||t.        d      }|J |       || _         | j1                  d|       |S # t        $ r' |j                  d      }|j	                  dd       Y w xY w)zReturn the base temporary directory, creating it if needed.

        :returns:
            The base temporary directory.
        rS   rT   PYTEST_DEBUG_TEMPROOTunknownz
pytest-of-T)rU   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-)rW   rV   keeplock_timeoutrU   znew basetemp)r&   r$   existsr   rZ   rN   r2   environrE   r   tempfile
gettempdirget_userrY   OSErrorr   statst_uidst_modechmodr'   r(   r   r   r%   )	r6   r.   from_envtemprootuserrootdiruidrootdir_statra   s	            r8   rM   zTempPathFactory.getbasetemp   s    >>%>>!+++H hNNN&'')Hzz~~&=>HH=(;(;(=>FFHH:*D ''*TF(;<G9548 -C&||~&&#-!27) <2 2  !((50Q6HHWl&:&:V&CD((D%%/5 )H #-X-#!NH-C  9"++,?@5489s   !F8 8-G('G(r1   )T)__name__
__module____qualname____doc__r
   r   __annotations__r   rA   RetentionTypeboolr9   classmethodr   rI   r5   rP   rX   rM    r:   r8   r#   r#   )   s    
 d^#K~$$ $("  " " " (	" 4." " 
". 
  	

 	

 

 
>S S s d d 09T 9r:   r#   r/   c                  `    	 ddl } | j                         S # t        t        t        f$ r Y y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ImportErrorrh   KeyError)r}   s    r8   rg   rg      s0      (+ s    --r;   c                     t               }| j                  |j                         t        j	                  | d      }|j                  | d|d       y)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#   rI   setattr)r;   mpr   s      r8   pytest_configurer      sI     
B
rww'33Fd3KJJv*,=uJMr:   parserc                 T    | j                  ddd       | j                  ddd       y )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   s    r8   pytest_addoptionr      s:    
MM"u   MM#	  r:   session)scoperequestc                 .    | j                   j                  S )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)r;   r   )r   s    r8   tmp_path_factoryr      s     >>+++r:   factoryc                     | j                   j                  }t        j                  dd|      }d}|d | }|j	                  |d      S )Nz[\W]_   T)rQ   )nodenameresubrX   )r   r   r   MAXVALs       r8   _mk_tmpr      sF    <<D66'3%DF=D>>$>..r:   r   c              #   <  K   t        | |      }| | j                  j                  j                  }|j                  }| j
                  j                  t           }|dk(  r|j                  dd      rt        |d       | j
                  j                  t        = yw)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;   r   r(   r   stashtmppath_result_keyrE   r   )r   r   r3   rH   result_dicts        r8   tmp_pathr      s     " 7,-D
J )0(>(>(P(P//F,,$$%78Kkoofd; 	t4(-.s   BB
exitstatusc                    | j                   j                  }|j                  }|y|j                  }|dk(  r.|dk(  r)|j                  |j                         rt        |d       |j                         rt        |       yy)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.   rH   s        r8   pytest_sessionfinishr   !  s}     )0(H(H))H//Fah,,4?? 840 h' r:   T)wrappertryfirstitemc              #      K   d }|j                   J i }|j                  | j                  j                  t        |      |j                   <   |S wr1   )whenpassedr   
setdefaultr   )r   r   repemptys       r8   pytest_runtest_makereportr   :  sK      C88EADDJJ,e4SXX>Js   AA):rv   dataclassesr2   pathlibr   r   shutilr   re   typingr   r   r   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   r5   ry   r   rx   	dataclassr#   rg   r   r   r   r   r   rA   r   r   r{   r:   r8   <module>r      s   D  	  	          * ! & 3  & ! # # , - $ + +  & " /Xd39o.0 /0 [ [  [|	(3- 	
NV 
N 
NV   	y,n , , ,/^ /o /$ / 	///>/tT4 / 	/@(eCM.B (2 
$&
tZ+, 'r:   