
    ESj3                    X   d Z ddlmZ ddl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/e0e1f             Z2ed   Z3eejh                   G d d                    Z5d,d Z6d-d!Z7d.d"Z8 e%d#$      d/d%       Z9d0d&Z:e%	 	 	 	 	 	 d1d'       Z;d2d(Z< ed)d)*      	 	 	 	 d3d+       Z=y)4z>Support for providing temporary directories to test functions.    )annotationsN)	Generator)	ExitStack)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
y)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	_ispytestc                   t        |       |d | _        n6t        t        j                  j                  t        |                  | _        || _        || _        || _	        || _
        t               | _        y N)r   r$   r   ospathabspathstrr%   r(   r*   r&   r   _exit_stack)selfgiven_basetempretention_countretention_policytracebasetempr,   s          _/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/_pytest/tmpdir.py__init__zTempPathFactory.__init__9   se     	y!!#'D 
 $(N8K(L#MD  /!1! %;    c               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)r5   r8   r6   r7   r,   )r   r'   getini
ValueErroroptionr9   r8   get)clsconfigr,   countpolicys        r:   from_configzTempPathFactory.from_configS   s     	y!FMM"<=>19HqQ  :;22]^d]eefg  !==11,,""8,!#
 	
r<   c                    t         j                  j                  |      }| j                         |z  j	                         j
                  | j                         k7  rt        | d      |S )Nz& is not a normalized and relative path)r/   r0   normpathgetbasetempresolveparentrC   )r4   basenames     r:   _ensure_relative_to_basetempz,TempPathFactory._ensure_relative_to_basetemps   s\    77##H-)224;;t?O?O?QQz)OPQQr<   c                    | 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)rQ   rM   joinpathmkdirr   r%   )r4   rP   numberedps       r:   rX   zTempPathFactory.mktempy   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               }|t        j                   t        j"                  v rd	nd}|j!                  |
      }t!        j$                  |j&                        rt        d| d      |j(                  |k7  rt        d| d      |j&                  dz  dk7  rDt        j*                  t        j"                  v rd	nd}	|j+                  |j&                  dz  |	
       | j,                  }
| j.                  dk(  rd}
t1        d||
t2        d| j4                  j6                        }t9        j:                  | j4                  j<                         | j4                  j7                  t8        j>                  | j4                  j<                         |J |       || _         | jA                  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-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-)rW   rV   keeplock_timeoutrU   registerznew basetemp)!r&   r$   existsr   rZ   rN   r/   environrE   r   tempfile
gettempdirget_userrY   OSErrorr   statsupports_follow_symlinksS_ISLNKst_modest_uidchmodr(   r*   r   r   r3   callbackatexitre   close
unregisterr%   )r4   r9   from_envtemprootuserrootdiruidstat_follow_symlinksrootdir_statchmod_follow_symlinksrc   s              r:   rM   zTempPathFactory.getbasetemp   s    >>%>>!+++H hNNN&'')Hzz~~&=>HH=(;(;(=>FFHH:*D ''*TF(;<G9548$ -CWW(C(CCE %  '||<P|Q<< 4 45!27) <2 2   &&#-!27) <2 2  !((50Q6!#R-H-H!Hd * MM$,,v5(= "  ((D%%/5 )))22H OOD,,223%%f&7&79I9I9O9OP#-X-#!NH-y  9"++,?@5489s   !J) )-KKr.   )r5   r#   r6   r'   r7   r)   r9   r#   r,   boolreturnNone)rG   r   r,   r~   r   r"   )rP   r2   r   r2   )T)rP   r2   r[   r~   r   r   )r   r   )__name__
__module____qualname____doc____annotations__r;   classmethodrJ   rQ   rX   rM    r<   r:   r"   r"   +   s     ! K$$ !%'  '#' ' (	' ' ' 
'4 
  	

 	

 

 
>0T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ImportErrorrk   KeyError)r   s    r:   rj   rj      s0      (+ s    --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"   rJ   setattr)rG   mpr   s      r:   pytest_configurer      sI     
B
rww'33Fd3KJJv*,=uJMr<   c                X    | j                  dddd       | j                  dddd	       y )
Nr>   zfHow many sessions should we keep the `tmp_path` directories, according to `tmp_path_retention_policy`.3string)helpdefaulttyper@   zvControls which directories created by the `tmp_path` fixture are kept around, based on test outcome. (all/failed/none)r   )r   r   r   )addini)parsers    r:   pytest_addoptionr     s@    
MM"u   MM#  r<   session)scopec                .    | j                   j                  S )zGReturn a :class:`pytest.TempPathFactory` instance for the test session.)rG   r   )requests    r:   tmp_path_factoryr     s     >>+++r<   c                    | j                   j                  }t        j                  dd|      }d}|d | }|j	                  |d      S )Nz[\W]_   T)r[   )nodenameresubrX   )r   factoryr   MAXVALs       r:   _mk_tmpr     sF    <<D66'3%DF=D>>$>..r<   c              #     K   t        | |      }| |j                  }| j                  j                  t           }|dk(  r|j                  dd      rt        |d       | j                  j                  t        = yw)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_keyrE   r   )r   r   r0   rI   result_dicts        r:   tmp_pathr   "  sp      7,-D
J //F,,$$%78Kkoofd; 	t4(-.s   A:A<c                6   | j                   j                  }|j                  }|y|j                  }|dk(  r.|dk(  r)|j                  |j                         rt        |d       |j                         rt        |       |j                  j                          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   )
rG   r   r&   r*   r$   is_dirr   r   r3   rt   )r   
exitstatusr   r9   rI   s        r:   pytest_sessionfinishr   ;  s     )0(H(H))H//Fah,,4?? 840 h'   &&(r<   T)wrappertryfirstc              #     K   d }|j                   J i }|j                  | j                  j                  t        |      |j                   <   |S wr.   )whenpassedr   
setdefaultr   )itemr   repemptys       r:   pytest_runtest_makereportr   W  sK      C88EADDJJ,e4SXX>Js   AA)r   z
str | None)rG   r   r   r   )r   r   r   r   )r   r   r   r"   )r   r   r   r"   r   r   )r   r   r   r"   r   zGenerator[Path])r   zint | ExitCode)r   r   r   z'Generator[None, TestReport, TestReport])>r   
__future__r   rs   collections.abcr   
contextlibr   dataclassesr/   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   dictr2   r~   r   r)   	dataclassr"   rj   r   r   r   r   r   r   r   r   r<   r:   <module>r      s?   D "  %    	  	       * ! & 3  & ! # # , - $ + +  & " /Xd39o.0 /0 x x  xv	
N$ 	y, ,/ 	///>// 	/0)8 
$&
, 'r<   