a
    !f                     @   s
  d Z ddlZddlZddlZddl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 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. e.d! Z/e"dd"d#d$Z0dd%d&d'Z1edd(d)d*Z2e d+d,ed-d.d/Z3G d0d1 d1ej4Z5G d2d3 d3ej4Z6G d4d5 d5e6Z7G d6d7 d7eZ8G d8d9 d9ej9ee Z:d:d;d<d=Z;G d>d? d?e:e< Z=G d@dA dAe:e Z>G dBdC dCe>e? Z@G dDdE dEe>e< ZAG dFdG dGe:e ZBG dHdI dIeBe? ZCG dJdK dKeBe< ZDejEdLksereG dMdN dNeee ZFn"G dOdN dNeGdNdPdQgee ZFG dRdS dSee ZHdTeHe< dUdVdWZIG dXdY dYZJG dZd[ d[ee ZKe&e'eeKe< ddf d\d]d^ZLe&e'eeKe? ddf d\d_d`ZMe&e'eeKe< ddf d\dadbZNe&e'eeKe? ddf d\dcddZOdS )ez+Per-test stdout/stderr capturing mechanism.    NUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)	Generator)Generic)Iterable)Iterator)List)
NamedTuple)Optional)TextIO)Tuple)Type)TYPE_CHECKING)Union)final)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)Final)Literalfdsysnotee-sys)parserreturnc                 C   s<   |  d}|jddddg ddd |jd	d
dddd d S )NZ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.   )ZgetgroupZ
_addoption)r&   group r4   P/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/capture.pypytest_addoption-   s     
r6   r'   c                  C   s0   t jdr,zddl} W n ty*   Y n0 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;   r4   r4   r5   _colorama_workaround@   s
    r=   )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sVd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.
    r8   pypy_version_infoNbufferrawc                    sF    s|d dkrd}nd}t tt|  ||| j| j| j| j	S )Nr   w)
ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingbufferedr4   r5   _reopen_stdiot   s    z3_windowsconsoleio_workaround.<locals>._reopen_stdiorbwb)r#   r9   r:   hasattrr@   rA   
isinstancerD   Z_WindowsConsoleIOstdinstdoutstderr)r>   Z
raw_stdoutrS   r4   rQ   r5   _windowsconsoleio_workaroundO   s    
r[   TZhookwrapper)early_configc                 c   s   | j }|jdkrttj t  | j}t|j}||d | 	|j
 |  d V }|  |jd ur| \}}tj| tj| d S )Nr"   capturemanager)Zknown_args_namespacer0   r[   r#   rY   r=   pluginmanagerCaptureManagerregisterZadd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureexcinforead_global_capturewriterZ   )r]   nsr_   capmanoutcomeouterrr4   r4   r5   pytest_load_initial_conftests   s    



rm   c                   @   s4   e Zd ZdZeedddZeedddZdS )EncodedFiler4   r7   c                 C   s
   t | jS N)reprr@   selfr4   r4   r5   name   s    zEncodedFile.namec                 C   s   | j jddS )Nb )r@   rO   replacerq   r4   r4   r5   rO      s    zEncodedFile.modeN)__name__
__module____qualname__	__slots__propertystrrs   rO   r4   r4   r4   r5   rn      s
   rn   c                       s0   e Zd Zdd fddZedddZ  ZS )	CaptureIONr7   c                    s   t  jt dddd d S )NUTF-8ru   T)rJ   newlinewrite_through)super__init__rD   BytesIOrq   	__class__r4   r5   r      s    zCaptureIO.__init__c                 C   s"   t | jtjsJ | j dS )Nr~   )rW   r@   rD   r   getvaluedecoderq   r4   r4   r5   r      s    zCaptureIO.getvalue)rw   rx   ry   r   r|   r   __classcell__r4   r4   r   r5   r}      s   r}   c                       s8   e Zd Zedd fddZeed fddZ  ZS )TeeCaptureION)otherr'   c                    s   || _ t   d S ro   )_otherr   r   )rr   r   r   r4   r5   r      s    zTeeCaptureIO.__init__)sr'   c                    s   t  | | j|S ro   )r   rg   r   )rr   r   r   r4   r5   rg      s    zTeeCaptureIO.write)	rw   rx   ry   r   r   r|   intrg   r   r4   r4   r   r5   r      s   r   c                   @   sp  e Zd ZeedddZd3eedddZeZeddd	Z	d4e
e ee d
ddZee dddZedddZddddZedddZddddZedddZd5eeedddZedddZedd d!Zd6e
e edd"d#Zeed$d%d&Zee dd'd(d)Zedd*d+Zd dd,d-Ze
ee  e
e e
e  dd.d/d0Z!ee"dd1d2Z#dS )7DontReadFromInputr7   c                 C   s   t jjS ro   )r#   	__stdin__rJ   rq   r4   r4   r5   rJ      s    zDontReadFromInput.encodingrC   )sizer'   c                 C   s   t dd S NzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorrr   r   r4   r4   r5   read   s    zDontReadFromInput.readc                 C   s   |   S ro   )readlinerq   r4   r4   r5   __next__   s    zDontReadFromInput.__next__)hintr'   c                 C   s   t dd S r   r   )rr   r   r4   r4   r5   	readlines   s    zDontReadFromInput.readlinesc                 C   s   | S ro   r4   rq   r4   r4   r5   __iter__   s    zDontReadFromInput.__iter__c                 C   s   t dd S )Nz/redirected stdin is pseudofile, has no fileno()r   rq   r4   r4   r5   rI      s    zDontReadFromInput.filenoNc                 C   s   t dd S )Nz.redirected stdin is pseudofile, has no flush()r   rq   r4   r4   r5   flush   s    zDontReadFromInput.flushc                 C   s   dS NFr4   rq   r4   r4   r5   isatty   s    zDontReadFromInput.isattyc                 C   s   d S ro   r4   rq   r4   r4   r5   close   s    zDontReadFromInput.closec                 C   s   dS r   r4   rq   r4   r4   r5   readable   s    zDontReadFromInput.readabler   )offsetwhencer'   c                 C   s   t dd S )Nz0redirected stdin is pseudofile, has no seek(int)r   )rr   r   r   r4   r4   r5   seek   s    zDontReadFromInput.seekc                 C   s   dS r   r4   rq   r4   r4   r5   seekable   s    zDontReadFromInput.seekablec                 C   s   t dd S )Nz-redirected stdin is pseudofile, has no tell()r   rq   r4   r4   r5   tell   s    zDontReadFromInput.tellc                 C   s   t dd S )Nzcannot truncate stdinr   r   r4   r4   r5   truncate   s    zDontReadFromInput.truncatedatar'   c                 C   s   t dd S )Nzcannot write to stdinr   rr   r   r4   r4   r5   rg      s    zDontReadFromInput.write)linesr'   c                 C   s   t dd S )NzCannot write to stdinr   )rr   r   r4   r4   r5   
writelines   s    zDontReadFromInput.writelinesc                 C   s   dS r   r4   rq   r4   r4   r5   writable   s    zDontReadFromInput.writablec                 C   s   | S ro   r4   rq   r4   r4   r5   	__enter__   s    zDontReadFromInput.__enter__)typevalue	tracebackr'   c                 C   s   d S ro   r4   )rr   r   r   r   r4   r4   r5   __exit__  s    zDontReadFromInput.__exit__c                 C   s   | S ro   r4   rq   r4   r4   r5   r@   
  s    zDontReadFromInput.buffer)rC   )rC   )r   )N)$rw   rx   ry   r{   r|   rJ   r   r   r   r   r   r   r   r   r   rI   r   boolr   r   r   r   r   r   r   rg   r   r   r   r   r   BaseExceptionr   r   r   r@   r4   r4   r4   r5   r      s6   
r   c                   @   s   e Zd ZU eed< ejeddddZejddddZ	ejddd	d
Z
ejddddZejddddZejeddddZejedddZdS )CaptureBaseEMPTY_BUFFERNr"   r'   c                 C   s
   t  d S ro   NotImplementedErrorrr   r"   r4   r4   r5   r     s    zCaptureBase.__init__r7   c                 C   s
   t  d S ro   r   rq   r4   r4   r5   start  s    zCaptureBase.startc                 C   s
   t  d S ro   r   rq   r4   r4   r5   done  s    zCaptureBase.donec                 C   s
   t  d S ro   r   rq   r4   r4   r5   suspend"  s    zCaptureBase.suspendc                 C   s
   t  d S ro   r   rq   r4   r4   r5   resume&  s    zCaptureBase.resumer   c                 C   s
   t  d S ro   r   r   r4   r4   r5   writeorg*  s    zCaptureBase.writeorgc                 C   s
   t  d S ro   r   rq   r4   r4   r5   snap.  s    zCaptureBase.snap)rw   rx   ry   r   __annotations__abcabstractmethodr   r   r   r   r   r   r   r   r4   r4   r4   r5   r     s   
r   rX   rY   rZ   )r         c                   @   sv   e Zd ZdZeddddZddddZddd	d
ZddddZddddZ	e
dddZe
ddddZdS )	NoCaptureru   Nr   c                 C   s   d S ro   r4   r   r4   r4   r5   r   9  s    zNoCapture.__init__r7   c                 C   s   d S ro   r4   rq   r4   r4   r5   r   <  s    zNoCapture.startc                 C   s   d S ro   r4   rq   r4   r4   r5   r   ?  s    zNoCapture.donec                 C   s   d S ro   r4   rq   r4   r4   r5   r   B  s    zNoCapture.suspendc                 C   s   d S ro   r4   rq   r4   r4   r5   r   E  s    zNoCapture.resumec                 C   s   dS Nru   r4   rq   r4   r4   r5   r   H  s    zNoCapture.snapr   c                 C   s   d S ro   r4   r   r4   r4   r5   r   K  s    zNoCapture.writeorg)rw   rx   ry   r   r   r   r   r   r   r   r|   r   r   r4   r4   r4   r5   r   6  s   r   c                   @   s   e Zd Zdddeee eddddZeeddd	Z	ed
ddZ
eeedf ddddZdd
ddZdd
ddZdd
ddZdd
ddZdS )SysCaptureBaseNFtee)r"   tmpfiler   r'   c                C   sV   t | }tt|| _|| _|d u rF|dkr2t }n|s<t nt| j}|| _d| _	d S )NrX   initialized)
patchsysdictgetattrr#   _oldrs   r   r}   r   r   _state)rr   r"   r   r   rs   r4   r4   r5   r   P  s    zSysCaptureBase.__init__)
class_namer'   c                 C   s,   d || jt| drt| jp d| j| jS Nz(<{} {} _old={} _state={!r} tmpfile={!r}>r   z<UNSET>)formatrs   rV   rp   r   r   r   )rr   r   r4   r4   r5   rp   ^  s    zSysCaptureBase.reprr7   c                 C   s0   d | jj| jt| dr"t| jp$d| j| jS r   )	r   r   rw   rs   rV   rp   r   r   r   rq   r4   r4   r5   __repr__g  s    zSysCaptureBase.__repr__.opstatesr'   c                 C   s(   | j |v s$J d|| j d|d S Nz+cannot {} in state {!r}: expected one of {}z, r   r   joinrr   r   r   r4   r4   r5   _assert_statep  s    zSysCaptureBase._assert_statec                 C   s&   |  dd tt| j| j d| _d S )Nr   r   started)r   setattrr#   rs   r   r   rq   r4   r4   r5   r   w  s    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#   rs   r   r   r   rq   r4   r4   r5   r   |  s    

zSysCaptureBase.donec                 C   s&   |  dd tt| j| j d| _d S Nr   r   r   r   )r   r   r#   rs   r   r   rq   r4   r4   r5   r     s    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#   rs   r   rq   r4   r4   r5   r     s
    
zSysCaptureBase.resume)N)rw   rx   ry   r   r   r   r   r   r|   rp   r   r   r   r   r   r   r   r4   r4   r4   r5   r   O  s    
			r   c                   @   s.   e Zd ZdZedddZeddddZdS )	SysCaptureBinary    r7   c                 C   s>   |  dd | jd | jj }| jd | j  |S Nr   r   r   r   r   r   r@   r   r   rr   resr4   r4   r5   r     s    
zSysCaptureBinary.snapNr   c                 C   s4   |  dd | j  | jj| | jj  d S Nr   r   )r   r   r   r@   rg   r   r4   r4   r5   r     s    
zSysCaptureBinary.writeorg)rw   rx   ry   r   bytesr   r   r4   r4   r4   r5   r     s   r   c                   @   s.   e Zd ZdZedddZeddddZdS )	
SysCaptureru   r7   c                 C   s@   |  dd t| jtsJ | j }| jd | j  |S r   )r   rW   r   r}   r   r   r   r   r4   r4   r5   r     s    

zSysCapture.snapNr   c                 C   s&   |  dd | j| | j  d S r   )r   r   rg   r   r   r4   r4   r5   r     s    zSysCapture.writeorg)rw   rx   ry   r   r|   r   r   r4   r4   r4   r5   r     s   r   c                   @   s|   e Zd ZeddddZedddZeeedf dd	d
dZddddZ	ddddZ
ddddZddddZdS )FDCaptureBaseN)targetfdr'   c                 C   s   || _ zt| W n2 tyF   ttjtj| _t| j| Y n0 d | _t	|| _
|dkr~ttjdd| _t|| _n<ttddddddd| _|tv rt|| j| _n
t|| _d	| _d S )
Nr   utf-8)rJ   )rP   rv   ru   T)rJ   rK   r   r   r   )r   rG   fstatr   rF   devnullO_RDWRtargetfd_invaliddup2rH   targetfd_saver   r   
syscapturern   r   r   r   r   )rr   r   r4   r4   r5   r     s,    
zFDCaptureBase.__init__r7   c                 C   s   d | jj| j| j| j| jS )Nz)<{} {} oldfd={} _state={!r} tmpfile={!r}>)r   r   rw   r   r   r   r   rq   r4   r4   r5   r     s    zFDCaptureBase.__repr__.r   c                 C   s(   | j |v s$J d|| j d|d S r   r   r   r4   r4   r5   r     s    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   rG   r   r   rI   r   r   r   r   rq   r4   r4   r5   r     s    
zFDCaptureBase.startc                 C   s   |  dd | jdkrdS t| j| j t| j | jdurd| j| jkrXt| 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   rG   r   r   r   r   r   r   r   r   rq   r4   r4   r5   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   rG   r   r   r   rq   r4   r4   r5   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   rG   r   r   rI   r   rq   r4   r4   r5   r     s    

zFDCaptureBase.resume)rw   rx   ry   r   r   r|   r   r   r   r   r   r   r   r4   r4   r4   r5   r     s   )	r   c                   @   s2   e Zd ZdZdZedddZedddd	ZdS )
FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor.

    snap() produces `bytes`.
    r   r7   c                 C   s>   |  dd | jd | jj }| jd | j  |S r   r   r   r4   r4   r5   r     s    
zFDCaptureBinary.snapNr   c                 C   s   |  dd t| j| dS )"Write to original file descriptor.r   r   N)r   rG   rg   r   r   r4   r4   r5   r   '  s    zFDCaptureBinary.writeorg)rw   rx   ry   __doc__r   r   r   r   r4   r4   r4   r5   r     s   r   c                   @   s2   e Zd ZdZdZedddZedddd	ZdS )
	FDCapturezTCapture IO to/from a given OS-level file descriptor.

    snap() produces text.
    ru   r7   c                 C   s<   |  dd | jd | j }| jd | j  |S r   )r   r   r   r   r   r   r4   r4   r5   r   5  s    

zFDCapture.snapNr   c                 C   s$   |  dd t| j|d dS )r   r   r   r   N)r   rG   rg   r   encoder   r4   r4   r5   r   =  s    zFDCapture.writeorg)rw   rx   ry   r   r   r|   r   r   r4   r4   r4   r5   r   -  s   r   )      c                   @   s"   e Zd ZU dZeed< eed< dS )CaptureResult2The result of :method:`CaptureFixture.readouterr`.rk   rl   N)rw   rx   ry   r   r   r   r4   r4   r4   r5   r   J  s   
r   c                   @   s   e Zd ZdZdZdS )r   r   r4   N)rw   rx   ry   r   rz   r4   r4   r4   r5   r   S  s   rk   rl   c                   @   s   e Zd ZdZdZeee  eee  eee  ddddZe	dddZ
ddd	d
Zeeef dddZdeddddZddddZddddZedddZee dddZdS )MultiCaptureNF)in_rk   rl   r'   c                 C   s   || _ || _|| _d S ro   r   rk   rl   )rr   r   rk   rl   r4   r4   r5   r   _  s    zMultiCapture.__init__r7   c                 C   s   d | j| j| j| j| jS )NzH<MultiCapture out={!r} err={!r} in_={!r} _state={!r} _in_suspended={!r}>)r   rk   rl   r   r   _in_suspendedrq   r4   r4   r5   r   i  s    zMultiCapture.__repr__c                 C   s:   d| _ | jr| j  | jr&| j  | jr6| j  d S )Nr   )r   r   r   rk   rl   rq   r4   r4   r5   start_capturingr  s    

zMultiCapture.start_capturingc                 C   sP   |   \}}|r*| jdusJ | j| |rH| jdus<J | j| ||fS )z?Pop current snapshot out/err capture and flush to orig streams.N)
readouterrrk   r   rl   rr   rk   rl   r4   r4   r5   pop_outerr_to_orig{  s    zMultiCapture.pop_outerr_to_origr   r'   c                 C   sD   d| _ | jr| j  | jr&| j  |r@| jr@| j  d| _d S )Nr   T)r   rk   r   rl   r   r  rr   r   r4   r4   r5   suspend_capturing  s    



zMultiCapture.suspend_capturingc                 C   sN   d| _ | jr| j  | jr&| j  | jrJ| jd us:J | j  d| _d S )Nr   F)r   rk   r   rl   r  r   rq   r4   r4   r5   resume_capturing  s    


zMultiCapture.resume_capturingc                 C   sL   | j dkrtdd| _ | jr(| j  | jr8| j  | jrH| j  dS )z+Stop capturing and reset capturing streams.stoppedzwas already stoppedN)r   
ValueErrorrk   r   rl   r   rq   r4   r4   r5   stop_capturing  s    


zMultiCapture.stop_capturingc                 C   s
   | j dkS )z7Whether actively capturing -- not suspended or stopped.r   )r   rq   r4   r4   r5   
is_started  s    zMultiCapture.is_startedc                 C   s2   | j r| j  nd}| jr$| j nd}t||S r   )rk   r   rl   r   r  r4   r4   r5   r    s    zMultiCapture.readouterr)F)rw   rx   ry   r   r  r   r   r   r   r|   r   r  r   r  r   r	  r
  r  r  r   r  r4   r4   r4   r5   r   [  s   



		
r   _CaptureMethodr)   r'   c                 C   s   | dkr"t tdtdtddS | dkrDt tdtdtddS | dkrZt d d d dS | dkrt d tdd	d
tdd	d
dS td| d S )Nr"   r   r   r   r  r#   r$   r%   Tr   zunknown capturing method: )r   r   r   r  )r)   r4   r4   r5   _get_multicapture  s    r  c                   @   s  e Zd ZdZdddddZeddd	Zeeef dd
dZ	edddZ
ddddZddddZddddZdCeddddZdDeddddZddddZee dddZdddd d!Zddd"d#Zddd$d%Zddd&d'Zddd(d)Zddd*d+Zejed, dd-d.Zejeeed, d/d0d1Zed2d3e d4d5d6Z!ed2d3eed, d7d8d9Z"ed2d3eed, d7d:d;Z#ed2d3eed, d7d<d=Z$ed2d>ddd?d@Z%ed2d>dddAdBZ&dS )Er`   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  Nr  c                 C   s   || _ d | _d | _d S ro   )_method_global_capturing_capture_fixture)rr   r)   r4   r4   r5   r     s    zCaptureManager.__init__r7   c                 C   s   d | j| j| jS )NzJ<CaptureManager _method={!r} _global_capturing={!r} _capture_fixture={!r}>)r   r  r  r  rq   r4   r4   r5   r     s    zCaptureManager.__repr__c                 C   s$   |   rdS | jr d| jjj S dS )Nglobalz
fixture %sF)is_globally_capturingr  requestfixturenamerq   r4   r4   r5   is_capturing  s
    zCaptureManager.is_capturingc                 C   s
   | j dkS )Nr$   )r  rq   r4   r4   r5   r    s    z$CaptureManager.is_globally_capturingc                 C   s(   | j d u sJ t| j| _ | j   d S ro   )r  r  r  r  rq   r4   r4   r5   rc     s    z%CaptureManager.start_global_capturingc                 C   s(   | j d ur$| j   | j   d | _ d S ro   )r  r  r  rq   r4   r4   r5   rb     s    


z$CaptureManager.stop_global_capturingc                 C   s   | j d ur| j   d S ro   )r  r
  rq   r4   r4   r5   resume_global_capture  s    
z$CaptureManager.resume_global_captureFr  c                 C   s   | j d ur| j j|d d S )Nr   )r  r	  r  r4   r4   r5   rd     s    
z%CaptureManager.suspend_global_capturec                 C   s   |    | | d S ro   )suspend_fixturerd   r  r4   r4   r5   r     s    zCaptureManager.suspendc                 C   s   |    |   d S ro   )r  resume_fixturerq   r4   r4   r5   r     s    zCaptureManager.resumec                 C   s   | j d usJ | j  S ro   )r  r  rq   r4   r4   r5   rf   
  s    z"CaptureManager.read_global_capturezCaptureFixture[Any])capture_fixturer'   c                 C   s6   | j r,| j jj}|jj}|jd|| || _ d S )Nz%cannot use {} and {} at the same time)r  r  r  Z
raiseerrorr   )rr   r  Zcurrent_fixtureZrequested_fixturer4   r4   r5   set_fixture  s    
zCaptureManager.set_fixturec                 C   s
   d | _ d S ro   )r  rq   r4   r4   r5   unset_fixture  s    zCaptureManager.unset_fixturec                 C   s   | j r| j   dS )z|If the current item is using ``capsys`` or ``capfd``, activate
        them so they take precedence over the global capture.N)r  _startrq   r4   r4   r5   activate_fixture  s    zCaptureManager.activate_fixturec                 C   s   | j r| j   dS )zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)r  r   rq   r4   r4   r5   deactivate_fixture$  s    z!CaptureManager.deactivate_fixturec                 C   s   | j r| j   d S ro   )r  _suspendrq   r4   r4   r5   r  )  s    zCaptureManager.suspend_fixturec                 C   s   | j r| j   d S ro   )r  _resumerq   r4   r4   r5   r  -  s    zCaptureManager.resume_fixtureNNNc                 c   sz   | j o| j  }|r|   | jo*| j }|r8|   z"dV  W |rN|   |rv|   n|rh|   |rt|   0 dS )zLContext manager to temporarily disable global and current fixture capturing.N)r  _is_startedr  r  r  rd   r  r  )rr   Z
do_fixtureZ	do_globalr4   r4   r5   global_and_fixture_disabled3  s     
z*CaptureManager.global_and_fixture_disabled)whenitemr'   c              	   c   sr   |    |   zd V  W |   | jdd n|   | jdd 0 |  \}}||d| ||d| d S )NFr  rY   rZ   )r  r"  r#  rd   rf   Zadd_report_section)rr   r)  r*  rk   rl   r4   r4   r5   item_captureD  s    zCaptureManager.item_captureTr\   )	collectorc                 c   sh   t |tr^|   d V }|   |  \}}| }|rH|jd|f |rd|jd|f nd V  d S )NzCaptured stdoutzCaptured stderr)rW   r   r  rd   rf   Z
get_resultsectionsappend)rr   r,  rj   rk   rl   repr4   r4   r5   pytest_make_collect_reportT  s    
z)CaptureManager.pytest_make_collect_report)r*  r'   c                 c   s6   |  d| d V  W d    n1 s(0    Y  d S )Nsetupr+  rr   r*  r4   r4   r5   pytest_runtest_setupc  s    z#CaptureManager.pytest_runtest_setupc                 c   s6   |  d| d V  W d    n1 s(0    Y  d S )Ncallr2  r3  r4   r4   r5   pytest_runtest_callh  s    z"CaptureManager.pytest_runtest_callc                 c   s6   |  d| d V  W d    n1 s(0    Y  d S )NZteardownr2  r3  r4   r4   r5   pytest_runtest_teardownm  s    z&CaptureManager.pytest_runtest_teardown)Ztryfirstc                 C   s   |    d S ro   rb   rq   r4   r4   r5   pytest_keyboard_interruptr  s    z(CaptureManager.pytest_keyboard_interruptc                 C   s   |    d S ro   r8  rq   r4   r4   r5   pytest_internalerrorv  s    z#CaptureManager.pytest_internalerror)F)F)'rw   rx   ry   r   r   r|   r   r   r   r  r  rc   rb   r  rd   r   r   r   rf   r  r   r"  r#  r  r  
contextlibcontextmanagerr	   r(  r   r+  r   r   r0  r4  r6  r7  r9  r:  r4   r4   r4   r5   r`     sD   	r`   c                   @   s   e Zd ZdZddeee  eeddddZ	ddd	d
Z
ddddZee dddZddddZddddZedddZejed dddZdS )CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
    :fixture:`capfd` and :fixture:`capfdbinary` fixtures.F	_ispytestN)captureclassr  r?  r'   c                C   s2   t | || _|| _d | _| jj| _| jj| _d S ro   )r   r@  r  _capturer   _captured_out_captured_err)rr   r@  r  r?  r4   r4   r5   r     s    
zCaptureFixture.__init__r7   c                 C   s4   | j d u r0td | d| dd| _ | j   d S )Nr   r   r  )rA  r   r@  r  rq   r4   r4   r5   r!    s    
zCaptureFixture._startc                 C   sH   | j d urD| j  \}}|  j|7  _|  j|7  _| j   d | _ d S ro   )rA  r  rB  rC  r  r  r4   r4   r5   r     s    

zCaptureFixture.closec                 C   sT   | j | j }}| jdur6| 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)rB  rC  rA  r  r@  r   r   )rr   Zcaptured_outZcaptured_errrk   rl   r4   r4   r5   r    s    


zCaptureFixture.readouterrc                 C   s   | j dur| j   dS )z1Suspend this fixture's own capturing temporarily.N)rA  r	  rq   r4   r4   r5   r$    s    
zCaptureFixture._suspendc                 C   s   | j dur| j   dS )z0Resume this fixture's own capturing temporarily.N)rA  r
  rq   r4   r4   r5   r%    s    
zCaptureFixture._resumec                 C   s   | j dur| j  S dS )z5Whether actively capturing -- not disabled or closed.NF)rA  r  rq   r4   r4   r5   r'    s    

zCaptureFixture._is_startedr&  c                 c   sB   | j jjd}|  dV  W d   n1 s40    Y  dS )z>Temporarily disable capturing while inside the ``with`` block.r^   N)r  configr_   	getpluginr(  )rr   Z
capmanagerr4   r4   r5   disabled  s
    

zCaptureFixture.disabled)rw   rx   ry   r   r   r   r   r   r   r   r!  r   r   r  r$  r%  r'  r;  r<  r	   rF  r4   r4   r4   r5   r=  {  s    
	r=  )r  r'   c                 c   sH   | 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"
    r^   Tr>  N)	rD  r_   rE  r=  r   r  r!  r   r   r  ri   r  r4   r4   r5   capsys  s    
rH  c                 c   sH   | j jd}tt| dd}|| |  |V  |  |  dS )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"
    r^   Tr>  N)	rD  r_   rE  r=  r   r  r!  r   r   rG  r4   r4   r5   capsysbinary  s    
rI  c                 c   sH   | j jd}tt| dd}|| |  |V  |  |  dS )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"
    r^   Tr>  N)	rD  r_   rE  r=  r   r  r!  r   r   rG  r4   r4   r5   capfd  s    
rJ  c                 c   sH   | j jd}tt| dd}|| |  |V  |  |  dS )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"

    r^   Tr>  N)	rD  r_   rE  r=  r   r  r!  r   r   rG  r4   r4   r5   capfdbinary   s    
rK  )Pr   r   collectionsr;  rD   rG   r#   r   tempfiler   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Z_pytest.compatr   Z_pytest.configr   r   Z_pytest.config.argparsingr   Z_pytest.deprecatedr   Z_pytest.fixturesr   r   Z_pytest.nodesr   r   r   Ztyping_extensionsr   r    r  r6   r=   r[   rm   rE   rn   r}   r   r   ABCr   r   r|   r   r   r   r   r   r   r   r   version_infor   
namedtupler   r  r`   r=  rH  rI  rJ  rK  r4   r4   r4   r5   <module>   s   8	
O Cb
W 9Q   