o
    hݏ                     @  s  d 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	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 erd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d  Z0dqd%d&Z1drd'd(Z2drd)d*Z3dsd-d.Z4e"d/d0dtd4d5Z5G d6d7 d7e
j6Z7G d8d9 d9e
j6Z8G d:d; d;e8Z9G d<d= d=eZ:G d>d? d?ej;ee Z<d@dAdBdCZ=G dDdE dEe<e> Z?G dFdG dGe<e Z@G dHdI dIe@eA ZBG dJdK dKe@e> ZCG dLdM dMe<e ZDG dNdO dOeDeA ZEG dPdQ dQeDe> ZFejGdRksoer}eG dSdT dTeee ZHnG dUdT dTeIdTdVdWgee ZHG dXdY dYee ZJdud]d^ZKG d_d` d`ZLG dadb dbee ZMe(dvdfdgZNe(dvdhdiZOe(dwdkdlZPe(dvdmdnZQe(dwdodpZRdS )xz+Per-test stdout/stderr capturing mechanism.    )annotationsN)	Generator)Iterable)IteratorUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)cast)Final)final)Generic)Literal)
NamedTuple)TextIO)TYPE_CHECKING)Self)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)CollectReportfdsysnotee-sysparserr   returnNonec                 C  s<   |  d}|jddddg ddd |jd	d
dddd d S )Ngeneralz	--capturestorer!   methodr    z3Per-test capturing method: one of fd|sys|no|tee-sys)actiondefaultmetavarchoiceshelpz-sstore_constr#   capturezShortcut for --capture=no)r+   constdestr/   )getgroup	addoption
_addoption)r%   group r8   P/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/capture.pypytest_addoption1   s    

r:   c                  C  s4   t jdrzddl} W dS  ty   Y dS w dS )a  Ensure colorama is imported so that it attaches to the correct stdio
    handles on Windows.

    colorama uses the terminal on import time. So if something does the
    first import of colorama while I/O capture is active, colorama will
    fail in various ways.
    win32r   N)r"   platform
startswithcoloramaImportError)r>   r8   r8   r9   _colorama_workaroundD   s   r@   c                  C  s$   zddl } W dS  ty   Y dS w )a  Ensure readline is imported early so it attaches to the correct stdio handles.

    This isn't a problem with the default GNU readline implementation, but in
    some configurations, Python uses libedit instead (on macOS, and for prebuilt
    binaries such as used by uv).

    In theory this is only needed if readline.backend == "libedit", but the
    workaround consists of importing readline here, so we already worked around
    the issue by the time we could check if we need to.
    r   N)readliner?   rA   r8   r8   r9   _readline_workaroundS   s
   rC   streamr   c                   s   t jdrtt drdS t dsdS t jdr jjn j}t|tjs)dS  fdd}|t j	dt _	|t j
d	t _
|t jd	t _dS )
a  Workaround for Windows Unicode console handling.

    Python 3.6 implemented Unicode console handling for Windows. This works
    by reading/writing to the raw console handle using
    ``{Read,Write}ConsoleW``.

    The problem is that we are going to ``dup2`` over the stdio file
    descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the
    handles used by Python to write to the console. Though there is still some
    weirdness and the console handle seems to only be closed randomly and not
    on the first call to ``CloseHandle``, or maybe it gets reopened with the
    same handle value when we suspend capturing.

    The workaround in this case will reopen stdio with a different fd which
    also means a different handle by replicating the logic in
    "Py_lifecycle.c:initstdio/create_stdio".

    :param stream:
        In practice ``sys.stdout`` or ``sys.stderr``, but given
        here as parameter for unittesting purposes.

    See https://github.com/pytest-dev/py/issues/103.
    r;   pypy_version_infoNbufferrawc                   sN   t  jds|d dkrd}nd}ttt|  ||| j| j	| j
| jS )NrG   r   w)hasattrrF   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingrD   r8   r9   _reopen_stdio   s   z3_windowsconsoleio_workaround.<locals>._reopen_stdiorbwb)r"   r<   r=   rJ   rF   rG   
isinstancerK   _WindowsConsoleIOstdinstdoutstderr)rD   
raw_stdoutrY   r8   rX   r9   _windowsconsoleio_workaroundd   s   
rb   Twrapperearly_configr   Generator[None]c                 c  s    | j }|jdkrttj t  t  | j}t|j}|	|d | 
|j |  zzd V  W |  W d S |  w  tyW   | \}}tj| tj|  w )Nr!   capturemanager)known_args_namespacer1   rb   r"   r_   r@   rC   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewriter`   )re   nsri   capmanouterrr8   r8   r9   pytest_load_initial_conftests   s*   


rw   c                   @  s,   e Zd ZdZed	ddZed	ddZdS )
EncodedFiler8   r&   strc                 C  s
   t | jS N)reprrF   selfr8   r8   r9   name   s   
zEncodedFile.namec                 C  s&   t | jdsJ tt| jjddS )NrV   b )rJ   rF   r   ry   rV   replacer|   r8   r8   r9   rV      s   zEncodedFile.modeNr&   ry   )__name__
__module____qualname__	__slots__propertyr~   rV   r8   r8   r8   r9   rx      s    rx   c                      s(   e Zd Zd fddZd	ddZ  ZS )
	CaptureIOr&   r'   c                   s   t  jt dddd d S )NUTF-8r   T)rQ   newlinewrite_through)super__init__rK   BytesIOr|   	__class__r8   r9   r      s   zCaptureIO.__init__ry   c                 C  s"   t | jtjs	J | j dS )Nr   )r\   rF   rK   r   getvaluedecoder|   r8   r8   r9   r      s   zCaptureIO.getvaluer&   r'   r   )r   r   r   r   r   __classcell__r8   r8   r   r9   r      s    r   c                      s,   e Zd Zd fddZd fd
dZ  ZS )TeeCaptureIOotherr   r&   r'   c                   s   || _ t   d S rz   )_otherr   r   )r}   r   r   r8   r9   r      s   zTeeCaptureIO.__init__sry   intc                   s   t  | | j|S rz   )r   rr   r   )r}   r   r   r8   r9   rr      s   zTeeCaptureIO.write)r   r   r&   r'   )r   ry   r&   r   )r   r   r   r   rr   r   r8   r8   r   r9   r      s    r   c                   @  s   e Zd ZedCddZdDdEdd	ZeZdCd
dZdDdFddZdGddZ	dHddZ
dIddZdJddZdIddZdJddZdKdLd#d$ZdJd%d&ZdHd'd(ZdMdNd*d+ZdOd-d.ZdPd1d2ZdJd3d4ZdQd6d7ZdRd>d?ZedSdAdBZd)S )TDontReadFromInputr&   ry   c                 C  s   t jd usJ t jjS rz   )r"   	__stdin__rQ   r|   r8   r8   r9   rQ      s   zDontReadFromInput.encodingrI   sizer   c                 C     t dNzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr}   r   r8   r8   r9   read      zDontReadFromInput.readc                 C  s   |   S rz   rB   r|   r8   r8   r9   __next__      zDontReadFromInput.__next__hint
int | None	list[str]c                 C  r   r   r   )r}   r   r8   r8   r9   	readlines   r   zDontReadFromInput.readlinesIterator[str]c                 C     | S rz   r8   r|   r8   r8   r9   __iter__      zDontReadFromInput.__iter__c                 C  r   )Nz/redirected stdin is pseudofile, has no fileno()r   r|   r8   r8   r9   rP      r   zDontReadFromInput.filenor'   c                 C  r   )Nz.redirected stdin is pseudofile, has no flush()r   r|   r8   r8   r9   flush   r   zDontReadFromInput.flushboolc                 C     dS NFr8   r|   r8   r8   r9   isatty   r   zDontReadFromInput.isattyc                 C     d S rz   r8   r|   r8   r8   r9   close   r   zDontReadFromInput.closec                 C  r   r   r8   r|   r8   r8   r9   readable  r   zDontReadFromInput.readabler   offsetwhencec                 C  r   )Nz0redirected stdin is pseudofile, has no seek(int)r   )r}   r   r   r8   r8   r9   seek  r   zDontReadFromInput.seekc                 C  r   r   r8   r|   r8   r8   r9   seekable  r   zDontReadFromInput.seekablec                 C  r   )Nz-redirected stdin is pseudofile, has no tell()r   r|   r8   r8   r9   tell  r   zDontReadFromInput.tellNc                 C  r   )Nzcannot truncate stdinr   r   r8   r8   r9   truncate  r   zDontReadFromInput.truncatedatac                 C  r   )Nzcannot write to stdinr   r}   r   r8   r8   r9   rr     r   zDontReadFromInput.writelinesIterable[str]c                 C  r   )NzCannot write to stdinr   )r}   r   r8   r8   r9   
writelines  r   zDontReadFromInput.writelinesc                 C  r   r   r8   r|   r8   r8   r9   writable  r   zDontReadFromInput.writabler   c                 C  r   rz   r8   r|   r8   r8   r9   	__enter__  r   zDontReadFromInput.__enter__typetype[BaseException] | NonevalueBaseException | None	tracebackTracebackType | Nonec                 C  r   rz   r8   )r}   r   r   r   r8   r8   r9   __exit__  s   zDontReadFromInput.__exit__r   c                 C  r   rz   r8   r|   r8   r8   r9   rF   %  s   zDontReadFromInput.bufferr   )rI   )r   r   r&   ry   )r   r   r&   r   )r&   r   )r&   r   r   r&   r   )r   )r   r   r   r   r&   r   rz   )r   r   r&   r   )r   ry   r&   r   )r   r   r&   r'   )r&   r   )r   r   r   r   r   r   r&   r'   )r&   r   )r   r   r   r   rQ   r   rA   r   r   r   rP   r   r   r   r   r   r   r   r   rr   r   r   r   r   rF   r8   r8   r8   r9   r      s0    













r   c                   @  s   e Zd ZU ded< ejdddZejdd	d
ZejdddZejdddZ	ejdddZ
ejdddZejdddZdS )CaptureBaser   EMPTY_BUFFERr!   r   r&   r'   c                 C     t  rz   NotImplementedErrorr}   r!   r8   r8   r9   r   1     zCaptureBase.__init__c                 C  r   rz   r   r|   r8   r8   r9   start5  r   zCaptureBase.startc                 C  r   rz   r   r|   r8   r8   r9   done9  r   zCaptureBase.donec                 C  r   rz   r   r|   r8   r8   r9   suspend=  r   zCaptureBase.suspendc                 C  r   rz   r   r|   r8   r8   r9   resumeA  r   zCaptureBase.resumer   c                 C  r   rz   r   r   r8   r8   r9   writeorgE  r   zCaptureBase.writeorgc                 C  r   rz   r   r|   r8   r8   r9   snapI  r   zCaptureBase.snapNr!   r   r&   r'   r   )r   r   r&   r'   )r&   r   )r   r   r   __annotations__abcabstractmethodr   r   r   r   r   r   r   r8   r8   r8   r9   r   .  s    
 r   r^   r_   r`   )r         c                   @  sV   e Zd ZdZdddZddd	Zdd
dZdddZdddZdddZ	dddZ
dS )	NoCapturer   r!   r   r&   r'   c                 C  r   rz   r8   r   r8   r8   r9   r   T  r   zNoCapture.__init__c                 C  r   rz   r8   r|   r8   r8   r9   r   W  r   zNoCapture.startc                 C  r   rz   r8   r|   r8   r8   r9   r   Z  r   zNoCapture.donec                 C  r   rz   r8   r|   r8   r8   r9   r   ]  r   zNoCapture.suspendc                 C  r   rz   r8   r|   r8   r8   r9   r   `  r   zNoCapture.resumery   c                 C  r   Nr   r8   r|   r8   r8   r9   r   c  r   zNoCapture.snapr   c                 C  r   rz   r8   r   r8   r8   r9   r   f  r   zNoCapture.writeorgNr   r   r   r   ry   r&   r'   )r   r   r   r   r   r   r   r   r   r   r   r8   r8   r8   r9   r   Q  s    





r   c                   @  sf   e Zd Z	d!ddd"ddZd#ddZd$ddZd%ddZd&ddZd&ddZd&ddZ	d&dd Z
dS )'SysCaptureBaseNFteer!   r   tmpfileTextIO | Noner   r   r&   r'   c                C  sV   t | }tt|| _|| _|d u r#|dkrt }n
|st nt| j}|| _d| _	d S )Nr^   initialized)
patchsysdictgetattrr"   _oldr~   r   r   r   r   _state)r}   r!   r   r   r~   r8   r8   r9   r   k  s   
zSysCaptureBase.__init__
class_namery   c                 C  s,   d || jt| drt| jpd| j| jS Nz(<{} {} _old={} _state={!r} tmpfile={!r}>r   z<UNSET>)formatr~   rJ   r{   r   r   r   )r}   r   r8   r8   r9   r{   y  s   zSysCaptureBase.reprc                 C  s0   d | jj| jt| drt| jpd| j| jS r   )	r   r   r   r~   rJ   r{   r   r   r   r|   r8   r8   r9   __repr__  s   zSysCaptureBase.__repr__opstatestuple[str, ...]c                 C  (   | j |v sJ d|| j d|d S Nz+cannot {} in state {!r}: expected one of {}z, r   r   joinr}   r   r   r8   r8   r9   _assert_state  
   zSysCaptureBase._assert_statec                 C  &   |  dd tt| j| j d| _d S )Nr   r   started)r   setattrr"   r~   r   r   r|   r8   r8   r9   r        
zSysCaptureBase.startc                 C  sB   |  dd | jdkrd S tt| j| j | `| j  d| _d S )Nr   r   r   	suspendedr   )r   r   r   r"   r~   r   r   r   r|   r8   r8   r9   r     s   


zSysCaptureBase.donec                 C  r   Nr   r   r   r   )r   r   r"   r~   r   r   r|   r8   r8   r9   r     r   zSysCaptureBase.suspendc                 C  s4   |  dd | jdkrd S tt| j| j d| _d S Nr   r  r   )r   r   r   r"   r~   r   r|   r8   r8   r9   r     s
   

zSysCaptureBase.resumerz   )r!   r   r   r   r   r   r&   r'   )r   ry   r&   ry   r   r   ry   r   r   r&   r'   r   )r   r   r   r   r{   r   r   r   r   r   r   r8   r8   r8   r9   r   j  s    

	
	


	r   c                   @  $   e Zd ZdZdddZddd	Zd
S )SysCaptureBinary    r&   bytesc                 C  >   |  dd | jd | jj }| jd | j  |S Nr   r  r   r   r   r   rF   r   r   r}   resr8   r8   r9   r        
zSysCaptureBinary.snapr   r'   c                 C  s4   |  dd | j  | jj| | jj  d S Nr   r  )r   r   r   rF   rr   r   r8   r8   r9   r     s   
zSysCaptureBinary.writeorgNr&   r  r   r  r&   r'   r   r   r   r   r   r   r8   r8   r8   r9   r        
r  c                   @  r  )
SysCapturer   r&   ry   c                 C  s@   |  dd t| jtsJ | j }| jd | j  |S r	  )r   r\   r   r   r   r   r   r  r8   r8   r9   r     s   

zSysCapture.snapr   r'   c                 C  s&   |  dd | j| | j  d S r  )r   r   rr   r   r   r8   r8   r9   r     s   zSysCapture.writeorgNr   r   r  r8   r8   r8   r9   r    r  r  c                   @  sR   e Zd ZdddZddd	ZdddZdddZdddZdddZdddZ	dS )FDCaptureBasetargetfdr   r&   r'   c                 C  s   || _ zt| W n ty#   ttjtj| _t| j| Y nw d | _t	|| _
|dkr?ttjdd| _t|| _nttddddddd| _|tv rXt|| j| _nt|| _d	| _d S )
Nr   utf-8)rQ   )rW   r   r   T)rQ   rR   r   r   r   )r  rN   fstatr   rM   devnullO_RDWRtargetfd_invaliddup2rO   targetfd_saver   r  
syscapturerx   r   r   r   r   )r}   r  r8   r8   r9   r     s.   

zFDCaptureBase.__init__ry   c                 C  s0   d| j j d| j d| j d| jd| jdS )N< z oldfd= _state=z	 tmpfile=>)r   r   r  r  r   r   r|   r8   r8   r9   r     s   zFDCaptureBase.__repr__r   r   r   c                 C  r   r   r   r   r8   r8   r9   r      r   zFDCaptureBase._assert_statec                 C  s4   |  dd t| j | j | j  d| _dS )z4Start capturing on targetfd using memorized tmpfile.r   r   r   N)	r   rN   r  r   rP   r  r  r   r   r|   r8   r8   r9   r     s   

zFDCaptureBase.startc                 C  s   |  dd | jdkrdS t| j| j t| j | jdur2| j| jkr,t| j t| j | j	  | j
  d| _dS )z_Stop capturing, restore streams, return original capture file,
        seeked to position zero.r   r   N)r   r   rN   r  r  r  r   r  r  r   r   r|   r8   r8   r9   r     s   




zFDCaptureBase.donec                 C  s>   |  dd | jdkrd S | j  t| j| j d| _d S r   )r   r   r  r   rN   r  r  r  r|   r8   r8   r9   r     s   


zFDCaptureBase.suspendc                 C  sB   |  dd | jdkrd S | j  t| j | j d| _d S r  )	r   r   r  r   rN   r  r   rP   r  r|   r8   r8   r9   r   &  s   


zFDCaptureBase.resumeN)r  r   r&   r'   r   r  r   )
r   r   r   r   r   r   r   r   r   r   r8   r8   r8   r9   r    s    

)



r  c                   @  (   e Zd ZdZdZdddZdd	d
ZdS )FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor.

    snap() produces `bytes`.
    r  r&   r  c                 C  r  r	  r
  r  r8   r8   r9   r   7  r  zFDCaptureBinary.snapr   r'   c                 C  s   |  dd t| j| dS )"Write to original file descriptor.r   r  N)r   rN   rr   r  r   r8   r8   r9   r   ?  s   zFDCaptureBinary.writeorgNr  r  r   r   r   __doc__r   r   r   r8   r8   r8   r9   r#  /  
    
r#  c                   @  r"  )	FDCapturezTCapture IO to/from a given OS-level file descriptor.

    snap() produces text.
    r   r&   ry   c                 C  s<   |  dd | jd | j }| jd | j  |S r	  )r   r   r   r   r   r  r8   r8   r9   r   M  s   

zFDCapture.snapr   r'   c                 C  s$   |  dd t| j|d dS )r$  r   r  r  N)r   rN   rr   r  encoder   r8   r8   r9   r   U  s   zFDCapture.writeorgNr   r   r%  r8   r8   r8   r9   r(  E  r'  r(  )      c                   @  s"   e Zd ZU dZded< ded< dS )CaptureResultOThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r   ru   rv   N)r   r   r   r&  r   r8   r8   r8   r9   r,  b  s   
 r,  c                   @  s   e Zd ZdZdZdS )r,  r-  r8   N)r   r   r   r&  r   r8   r8   r8   r9   r,  k  s    ru   rv   c                   @  sp   e Zd ZdZdZdd	d
Zd ddZd!ddZd"ddZd#d$ddZ	d!ddZ
d!ddZd%ddZd&ddZdS )'MultiCaptureNFin_CaptureBase[AnyStr] | Noneru   rv   r&   r'   c                 C  s   || _ || _|| _d S rz   r/  ru   rv   )r}   r/  ru   rv   r8   r8   r9   r   x  s   
zMultiCapture.__init__ry   c                 C  s.   d| j d| jd| jd| jd| jdS )Nz<MultiCapture out=z err=z in_=r   z _in_suspended=r!  )ru   rv   r/  r   _in_suspendedr|   r8   r8   r9   r     s   zMultiCapture.__repr__c                 C  s>   d| _ | jr| j  | jr| j  | jr| j  d S d S )Nr   )r   r/  r   ru   rv   r|   r8   r8   r9   start_capturing  s   

zMultiCapture.start_capturingtuple[AnyStr, AnyStr]c                 C  sP   |   \}}|r| jdusJ | j| |r$| jdusJ | j| ||fS )z?Pop current snapshot out/err capture and flush to orig streams.N)
readouterrru   r   rv   r}   ru   rv   r8   r8   r9   pop_outerr_to_orig  s   zMultiCapture.pop_outerr_to_origr   c                 C  sL   d| _ | jr| j  | jr| j  |r"| jr$| j  d| _d S d S d S )Nr   T)r   ru   r   rv   r/  r2  r}   r/  r8   r8   r9   suspend_capturing  s   




zMultiCapture.suspend_capturingc                 C  sR   d| _ | jr| j  | jr| j  | jr'| jd usJ | j  d| _d S d S )Nr   F)r   ru   r   rv   r2  r/  r|   r8   r8   r9   resume_capturing  s   



zMultiCapture.resume_capturingc                 C  sP   | j dkr	tdd| _ | jr| j  | jr| j  | jr&| j  dS dS )z+Stop capturing and reset capturing streams.stoppedzwas already stoppedN)r   
ValueErrorru   r   rv   r/  r|   r8   r8   r9   stop_capturing  s   


zMultiCapture.stop_capturingc                 C  s
   | j dkS )z7Whether actively capturing -- not suspended or stopped.r   )r   r|   r8   r8   r9   
is_started  s   
zMultiCapture.is_startedCaptureResult[AnyStr]c                 C  s2   | j r| j  nd}| jr| j nd}t||S r   )ru   r   rv   r,  r6  r8   r8   r9   r5    s   
zMultiCapture.readouterr)r/  r0  ru   r0  rv   r0  r&   r'   r   r   )r&   r4  Fr/  r   r&   r'   r   r&   r?  )r   r   r   r   r2  r   r   r3  r7  r9  r:  r=  r>  r5  r8   r8   r8   r9   r.  t  s    




	



r.  r*   _CaptureMethodMultiCapture[str]c                 C  s   | dkrt tdtdtddS | dkr"t tdtdtddS | dkr-t d d d dS | dkr@t d tdd	d
tdd	d
dS td| )Nr!   r   r   r   r1  r"   r#   r$   Tr   zunknown capturing method: )r.  r(  r  r<  )r*   r8   r8   r9   _get_multicapture  s   rE  c                   @  sV  e Zd ZdZdKddZdLd	d
ZdMddZdNddZdOddZdOddZ	dOddZ
dPdQddZdPdQddZdOddZdRd d!ZdSd$d%ZdOd&d'ZdOd(d)ZdOd*d+ZdOd,d-ZdOd.d/ZejdTd1d2ZejdUd6d7Zed8d9dVd=d>Zed8d9dWd?d@Zed8d9dWdAdBZed8d9dWdCdDZed8dEdOdFdGZed8dEdOdHdIZdJS )Xrj   a  The capture plugin.

    Manages that the appropriate capture method is enabled/disabled during
    collection and each test phase (setup, call, teardown). After each of
    those points, the captured output is obtained and attached to the
    collection/runtest report.

    There are two levels of capture:

    * global: enabled by default and can be suppressed by the ``-s``
      option. This is always enabled/disabled during collection and each test
      phase.

    * fixture: when a test function or one of its fixture depend on the
      ``capsys`` or ``capfd`` fixtures. In this case special handling is
      needed to ensure the fixtures take precedence over the global capture.
    r*   rC  r&   r'   c                 C  s   || _ d | _d | _d S rz   _method_global_capturing_capture_fixture)r}   r*   r8   r8   r9   r     s   
zCaptureManager.__init__ry   c                 C  s   d| j d| jd| jdS )Nz<CaptureManager _method=z _global_capturing=z _capture_fixture=r!  rF  r|   r8   r8   r9   r     s   zCaptureManager.__repr__
str | boolc                 C  s&   |   rdS | jrd| jjj S dS )Nglobalzfixture F)is_globally_capturingrI  requestfixturenamer|   r8   r8   r9   is_capturing  s
   zCaptureManager.is_capturingr   c                 C  s
   | j dkS )Nr#   )rG  r|   r8   r8   r9   rL        
z$CaptureManager.is_globally_capturingc                 C  s(   | j d u sJ t| j| _ | j   d S rz   )rH  rE  rG  r3  r|   r8   r8   r9   rn     s   z%CaptureManager.start_global_capturingc                 C  s,   | j d ur| j   | j   d | _ d S d S rz   )rH  r7  r=  r|   r8   r8   r9   rm     s
   



z$CaptureManager.stop_global_capturingc                 C  s   | j d ur| j   d S d S rz   )rH  r:  r|   r8   r8   r9   resume_global_capture  s   
z$CaptureManager.resume_global_captureFr/  c                 C  s    | j d ur| j j|d d S d S )Nr/  )rH  r9  r8  r8   r8   r9   ro     s   
z%CaptureManager.suspend_global_capturec                 C  s   |    | | d S rz   )suspend_fixturero   r8  r8   r8   r9   r     s   zCaptureManager.suspendc                 C  s   |    |   d S rz   )rQ  resume_fixturer|   r8   r8   r9   r     s   zCaptureManager.resumeCaptureResult[str]c                 C  s   | j d usJ | j  S rz   )rH  r5  r|   r8   r8   r9   rq   !  s   
z"CaptureManager.read_global_capturecapture_fixtureCaptureFixture[Any]c                 C  s<   | j r| j jj}|jj}|jd| d| d || _ d S )Nzcannot use z and z at the same time)rI  rM  rN  
raiseerror)r}   rV  current_fixturerequested_fixturer8   r8   r9   set_fixture'  s   

zCaptureManager.set_fixturec                 C  s
   d | _ d S rz   )rI  r|   r8   r8   r9   unset_fixture0  rP  zCaptureManager.unset_fixturec                 C     | j r
| j   dS dS )z|If the current item is using ``capsys`` or ``capfd``, activate
        them so they take precedence over the global capture.N)rI  _startr|   r8   r8   r9   activate_fixture3  s   zCaptureManager.activate_fixturec                 C  r]  )zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)rI  r   r|   r8   r8   r9   deactivate_fixture9  s   z!CaptureManager.deactivate_fixturec                 C     | j r
| j   d S d S rz   )rI  _suspendr|   r8   r8   r9   rS  >     zCaptureManager.suspend_fixturec                 C  ra  rz   )rI  _resumer|   r8   r8   r9   rT  B  rc  zCaptureManager.resume_fixturerf   c                 c  s    | j o| j  }|r|   | jo| j }|r|   zdV  W |r(|   |r0|   dS dS |r8|   |r?|   w w )zLContext manager to temporarily disable global and current fixture capturing.N)rI  _is_startedrS  rH  r>  ro   rQ  rT  )r}   
do_fixture	do_globalr8   r8   r9   global_and_fixture_disabledH  s&   
z*CaptureManager.global_and_fixture_disabledwhenitemr   c                 c  s    |    |   z$d V  W |   | jdd |  \}}||d| ||d| d S |   | jdd |  \}}||d| ||d| w )NFrR  r_   r`   )rQ  r_  r`  ro   rq   add_report_section)r}   ri  rj  ru   rv   r8   r8   r9   item_captureY  s   zCaptureManager.item_captureTrc   	collectorr   -Generator[None, CollectReport, CollectReport]c                 c  st    t |tr5|   z	d V }W |   n|   w |  \}}|r)|jd|f |r3|jd|f |S d V }|S )NzCaptured stdoutzCaptured stderr)r\   r   rQ  ro   rq   sectionsappend)r}   rm  repru   rv   r8   r8   r9   pytest_make_collect_reporti  s   
z)CaptureManager.pytest_make_collect_reportc                 c  8    |  d| d V W  d    S 1 sw   Y  d S )Nsetuprl  r}   rj  r8   r8   r9   pytest_runtest_setup|     $z#CaptureManager.pytest_runtest_setupc                 c  rs  )Ncallru  rv  r8   r8   r9   pytest_runtest_call  rx  z"CaptureManager.pytest_runtest_callc                 c  rs  )Nteardownru  rv  r8   r8   r9   pytest_runtest_teardown  rx  z&CaptureManager.pytest_runtest_teardown)tryfirstc                 C     |    d S rz   rm   r|   r8   r8   r9   pytest_keyboard_interrupt     z(CaptureManager.pytest_keyboard_interruptc                 C  r~  rz   r  r|   r8   r8   r9   pytest_internalerror  r  z#CaptureManager.pytest_internalerrorN)r*   rC  r&   r'   r   )r&   rJ  r   r   r@  rA  )r&   rU  )rV  rW  r&   r'   r&   rf   )ri  ry   rj  r   r&   rf   )rm  r   r&   rn  )rj  r   r&   rf   ) r   r   r   r&  r   r   rO  rL  rn   rm   rQ  ro   r   r   rq   r[  r\  r_  r`  rS  rT  
contextlibcontextmanagerrh  rl  r   rr  rw  rz  r|  r  r  r8   r8   r8   r9   rj     sF    



	






	



rj   c                   @  sn   e Zd ZdZdddd!ddZd"ddZd"ddZd#ddZd"ddZd"ddZ	d$ddZ
ejd%dd ZdS )&CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
    :fixture:`capfd` and :fixture:`capfdbinary` fixtures.NFconfig	_ispytestcaptureclasstype[CaptureBase[AnyStr]]rM  r   r  dict[str, Any] | Noner  r   r&   r'   c                C  s@   t | || _|| _|r|ni | _d | _| jj| _| jj| _d S rz   )r   r  rM  _config_capturer   _captured_out_captured_err)r}   r  rM  r  r  r8   r8   r9   r     s   
zCaptureFixture.__init__c                 C  sH   | j d u r"td | jdi | j| jdi | jd| _ | j   d S d S )Nr   r   r1  )r   )r   )r  r.  r  r  r3  r|   r8   r8   r9   r^    s   
zCaptureFixture._startc                 C  sL   | j d ur$| j  \}}|  j|7  _|  j|7  _| j   d | _ d S d S rz   )r  r7  r  r  r=  r6  r8   r8   r9   r     s   


zCaptureFixture.closer?  c                 C  sT   | j | j}}| jdur| j \}}||7 }||7 }| jj| _ | jj| _t||S )zRead and return the captured output so far, resetting the internal
        buffer.

        :returns:
            The captured content as a namedtuple with ``out`` and ``err``
            string attributes.
        N)r  r  r  r5  r  r   r,  )r}   captured_outcaptured_errru   rv   r8   r8   r9   r5    s   



zCaptureFixture.readouterrc                 C     | j dur| j   dS dS )z1Suspend this fixture's own capturing temporarily.N)r  r9  r|   r8   r8   r9   rb       
zCaptureFixture._suspendc                 C  r  )z0Resume this fixture's own capturing temporarily.N)r  r:  r|   r8   r8   r9   rd    r  zCaptureFixture._resumec                 C  s   | j dur
| j  S dS )z5Whether actively capturing -- not disabled or closed.NF)r  r>  r|   r8   r8   r9   re    s   

zCaptureFixture._is_startedrf   c                 c  sF    | j jjd}|  dV  W d   dS 1 sw   Y  dS )z>Temporarily disable capturing while inside the ``with`` block.rg   N)rM  r  ri   	getpluginrh  )r}   
capmanagerr8   r8   r9   disabled  s   

"zCaptureFixture.disabled)
r  r  rM  r   r  r  r  r   r&   r'   r   rB  r   r  )r   r   r   r&  r   r^  r   r5  rb  rd  re  r  r  r  r8   r8   r8   r9   r    s    

	



r  rM  r   Generator[CaptureFixture[str]]c                 c  J    | j jd}tt| dd}|| |  |V  |  |  dS )a  Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsys.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capsys):
            print("hello")
            captured = capsys.readouterr()
            assert captured.out == "hello\n"
    rg   Tr  N)	r  ri   r  r  r  r[  r^  r   r\  rM  rt   rV  r8   r8   r9   capsys     
r  c                 c  sR    | j jd}tt| tdddd}|| |  |V  |  |	  dS )a  Enable simultaneous text capturing and pass-through of writes
    to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``.


    The captured output is made available via ``capteesys.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    The output is also passed-through, allowing it to be "live-printed",
    reported, or both as defined by ``--capture=``.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capteesys):
            print("hello")
            captured = capteesys.readouterr()
            assert captured.out == "hello\n"
    rg   Tr   r  N)
r  ri   r  r  r  dictr[  r^  r   r\  r  r8   r8   r9   	capteesys  s   
r   Generator[CaptureFixture[bytes]]c                 c  r  )a'  Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsysbinary.readouterr()``
    method calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``bytes`` objects.

    Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capsysbinary):
            print("hello")
            captured = capsysbinary.readouterr()
            assert captured.out == b"hello\n"
    rg   Tr  N)	r  ri   r  r  r  r[  r^  r   r\  r  r8   r8   r9   capsysbinary&  r  r  c                 c  r  )a  Enable text capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_system_echo(capfd):
            os.system('echo "hello"')
            captured = capfd.readouterr()
            assert captured.out == "hello\n"
    rg   Tr  N)	r  ri   r  r  r(  r[  r^  r   r\  r  r8   r8   r9   capfdB  r  r  c                 c  r  )a-  Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``byte`` objects.

    Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_system_echo(capfdbinary):
            os.system('echo "hello"')
            captured = capfdbinary.readouterr()
            assert captured.out == b"hello\n"

    rg   Tr  N)	r  ri   r  r  r#  r[  r^  r   r\  r  r8   r8   r9   capfdbinary^  s   
r  )r%   r   r&   r'   r   )rD   r   r&   r'   )re   r   r&   rf   )r*   rC  r&   rD  )rM  r   r&   r  )rM  r   r&   r  )Sr&  
__future__r   r   collectionscollections.abcr   r   r   r  rK   r   rN   r"   tempfiler   typesr	   typingr
   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   _pytest.configr   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.nodesr   r   r   _pytest.reportsr   rC  r:   r@   rC   rb   rw   rL   rx   r   r   r   ABCr   r   ry   r   r   r  r  r  r  r#  r(  version_infor,  
namedtupler.  rE  rj   r  r  r  r  r  r  r8   r8   r8   r9   <module>   s   



7	
P C_
	
T <S"