Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/_pytest/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/_pytest/__pycache__/capture.cpython-37.pyc

B

C$�XW;�@s*dZddlmZddlZddlZddlZddlmZddlZddl	Z	ddl
mZejj
Zdddd	�Zd
d�Ze	jdd
�dd��ZGdd�d�ZdZe	jdd��Ze	jdd��ZGdd�d�Zd*dd�ZGdd�de�ZGdd�de�ZGd d!�d!�ZGd"d#�d#�ZGd$d%�d%�ZGd&d'�d'�Z d(d)�Z!dS)+z.
per-test stdout/stderr capturing mechanism.

�)�with_statementN)�
TemporaryFile)�TextIO�stdin�stdout�stderr)r��cCsL|�d�}|jddttd�r dndddddgd	d
�|jdddd
dd�dS)NZgeneralz	--capture�store�dup�fd�sys�method�noz,per-test capturing method: one of fd|sys|no.)�action�default�metavar�choices�helpz-sZstore_const�capturezshortcut for --capture=no.)r�const�destr)ZgetgroupZ
_addoption�hasattr�os)�parser�group�r�@/opt/alt/python37/lib/python3.7/site-packages/_pytest/capture.py�pytest_addoptions

rT)�hookwrapperc
cs�t�|j}|j}t|j�}|�|d�|�|j�dd�}|�|�|��dV}|�	�\}}	|j
dk	r�tj�
|�tj�
|	�dS)N�capturemanagercSsdtjkrdtjd_dS)NZloggingF)r
�modulesZraiseExceptionsrrrr�silence_logging_at_shutdown-s
zBpytest_load_initial_conftests.<locals>.silence_logging_at_shutdown)�_readline_workaroundZknown_args_namespace�
pluginmanager�CaptureManagerr�registerZadd_cleanup�reset_capturings�init_capturings�suspendcapture�excinfor
r�writer)
Zearly_configr�args�nsr$Zcapmanr"�outcome�out�errrrr�pytest_load_initial_conftests!s


r1c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zd$dd
�Zdd�Z	dd�Z
ejdd�dd��Z
ejdd�dd��Zejdd�dd��Zejdd�dd��Zejdd�dd��Zejdd�dd ��Zd%d!d"�Zd#S)&r%cCs
||_dS)N)�_method)�selfrrrr�__init__<szCaptureManager.__init__cCsR|dkrtddtd�S|dkr,tddtd�S|dkrBtdddd�Std|��dS)	NrT)r/r0�Capturer
rF)r/r0�in_zunknown capturing method: %r)�MultiCapture�	FDCapture�
SysCapture�
ValueError)r3rrrr�_getcapture?szCaptureManager._getcapturecCs*t|d�rt�|�|j�|_|j��dS)N�
_capturing)r�AssertionErrorr;r2r<�start_capturing)r3rrrr(IszCaptureManager.init_capturingscCs*|j�dd�}|dk	r&|��|��dS)Nr<)�__dict__�pop�pop_outerr_to_orig�stop_capturing)r3�caprrrr'NszCaptureManager.reset_capturingscCs|j��dS)N)r<�resume_capturing)r3rrr�
resumecaptureTszCaptureManager.resumecaptureFc	Cs@|��t|dd�}|dk	r<z|��}Wd|j|d�X|SdS)Nr<)r6)�deactivate_funcargs�getattr�
readouterr�suspend_capturing)r3r6rCZouterrrrrr)WszCaptureManager.suspendcapturecCs(|j�dd�}|dk	r$|��||_dS)N�_capfuncarg)r?r@�_startrJ)r3Z
pyfuncitem�
capfuncargrrr�activate_funcargsasz CaptureManager.activate_funcargscCs"|j�dd�}|dk	r|��dS)NrJ)r?r@�close)r3rLrrrrFgsz"CaptureManager.deactivate_funcargsT)rccsbt|tj�rX|��dV}|��\}}|��}|rB|j�d|f�|r^|j�d|f�ndVdS)NzCaptured stdoutzCaptured stderr)�
isinstance�pytestZFilerEr)Z
get_result�sections�append)r3Z	collectorr.r/r0�reprrr�pytest_make_collect_reportlsz)CaptureManager.pytest_make_collect_reportccs|��dV|�|d�dS)N�setup)rE�suspendcapture_item)r3�itemrrr�pytest_runtest_setupzsz#CaptureManager.pytest_runtest_setupccs(|��|�|�dV|�|d�dS)N�call)rErMrV)r3rWrrr�pytest_runtest_call�s
z"CaptureManager.pytest_runtest_callccs|��dV|�|d�dS)NZteardown)rErV)r3rWrrr�pytest_runtest_teardown�sz&CaptureManager.pytest_runtest_teardown)ZtryfirstcCs|��dS)N)r')r3r*rrr�pytest_keyboard_interrupt�sz(CaptureManager.pytest_keyboard_interruptcCs|��dS)N)r')r3r*rrr�pytest_internalerror�sz#CaptureManager.pytest_internalerrorcCs0|j|d�\}}|�|d|�|�|d|�dS)N)r6rr)r)Zadd_report_section)r3rWZwhenr6r/r0rrrrV�sz"CaptureManager.suspendcapture_itemN)F)F)�__name__�
__module__�__qualname__r4r;r(r'rEr)rMrFrP�hookimplrTrXrZr[r\r]rVrrrrr%;s


r%z,cannot use capsys and capfd at the same timecCs*d|jkr|�t��tt|�|j_}|S)z�Enable capturing of writes to sys.stdout/sys.stderr and make
    captured output available via ``capsys.readouterr()`` method calls
    which return a ``(out, err)`` tuple.
    �capfd)�fixturenames�
raiseerror�error_capsysfderror�CaptureFixturer9�noderJ)�request�crrr�capsys�s

rjcCs>d|jkr|�t�ttd�s(t�d�tt|�|j	_
}|S)z�Enable capturing of writes to file descriptors 1 and 2 and make
    captured output available via ``capfd.readouterr()`` method calls
    which return a ``(out, err)`` tuple.
    rjrzcapfd funcarg needs os.dup)rcrdrerrrP�skiprfr8rgrJ)rhrirrrrb�s



rbc@s:eZdZdd�Zdd�Zdd�Zdd�Zejd	d
��Z	dS)rfcCs||_||_dS)N)�captureclassrh)r3rlrhrrrr4�szCaptureFixture.__init__cCs"tddd|jd�|_|j��dS)NTF)r/r0r6r5)r7rl�_capturer>)r3rrrrK�szCaptureFixture._startcCs,|j�dd�}|dk	r(|��|_|��dS)Nrm)r?r@rA�_outerrrB)r3rCrrrrN�s
zCaptureFixture.closecCs&y
|j��Stk
r |jSXdS)N)rmrH�AttributeErrorrn)r3rrrrH�s
zCaptureFixture.readouterrccs>|jjj�d�}|j|jjddd�z
dVWd|��XdS)Nr rYT)r6)rh�configr$Z	getpluginrVrgrE)r3Z
capmanagerrrr�disabled�s

zCaptureFixture.disabledN)
r^r_r`r4rKrNrH�
contextlib�contextmanagerrqrrrrrf�s
rf�UTF8cCs�t|dd�}y|��}Wn2tk
rJdt|dd�krFt|d�rF|SYn*Xt�|�}d|krf|d7}t�||d�}t||p~|�S)za return a open text file object that's a duplicate of f on the
        FD-level if possible.
    �encodingN�b�mode�r)rG�fileno�	Exceptionrrr�fdopen�EncodedFile)�frwZdefault_encodingrurZnewfdrrr�safe_text_dupfile�s

r~c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r|�strictcCs||_||_dS)N)�bufferru)r3r�rurrrr4�szEncodedFile.__init__cCs(t|t�r|�|jd�}|j�|�dS)N�replace)rO�unicode�encoderur�r+)r3�objrrrr+�s
zEncodedFile.writecCsd�|�}|�|�dS)Nrx)�joinr+)r3Zlinelist�datarrr�
writelines�s
zEncodedFile.writelinescCstt�|d�|�S)Nr�)rG�object�__getattribute__)r3�namerrr�__getattr__�szEncodedFile.__getattr__N)r^r_r`�errorsr4r+r�r�rrrrr|�s
r|c@sTeZdZdZZZddd�Zdd�Zdd�Zdd
d�Z	dd
�Z
dd�Zdd�ZdS)r7NTcCs.|r|d�|_|r|d�|_|r*|d�|_dS)Nrrr	)r6r/r0)r3r/r0r6r5rrrr4s

zMultiCapture.__init__cCs4|jr|j��|jr |j��|jr0|j��dS)N)r6�startr/r0)r3rrrr>	s

zMultiCapture.start_capturingcCs4|��\}}|r|j�|�|r,|j�|�||fS)zA pop current snapshot out/err capture and flush to orig streams. )rHr/�writeorgr0)r3r/r0rrrrAszMultiCapture.pop_outerr_to_origFcCs>|jr|j��|jr |j��|r:|jr:|j��d|_dS)NT)r/�suspendr0r6�
_in_suspended)r3r6rrrrIs



zMultiCapture.suspend_capturingcCs<|jr|j��|jr |j��t|d�r8|j��|`dS)Nr�)r/�resumer0rr6r�)r3rrrrD#s



zMultiCapture.resume_capturingcCsLt|d�rtd��d|_|jr(|j��|jr8|j��|jrH|j��dS)z, stop capturing and reset capturing streams �_resetzwas already stoppedTN)rr:r�r/�doner0r6)r3rrrrB,s


zMultiCapture.stop_capturingcCs0|jdk	r|j��nd|jdk	r*|j��ndfS)z< return snapshot unicode value of stdout/stderr capturings. Nrx)r/�snapr0)r3rrrrH8szMultiCapture.readouterr)TTTN)F)
r^r_r`r/r0r6r4r>rArIrDrBrHrrrrr7�s
	
		r7c@s$eZdZdd�ZZZZZdS)�	NoCapturecGsdS)Nr)r,rrr�<lambda>>�zNoCapture.<lambda>N)r^r_r`r4r�r�r�r�rrrrr�=sr�c@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)r8z5 Capture IO to/from a given os-level filedescriptor. Nc	Cs�||_yt�|j�|_Wn(tk
r@dd�|_dd�|_Yn�X|dkrn|rVtd��ttj	d�}t
|�|_nH|dkr�t�}|�t
|dd�}WdQRX|tkr�t
||�|_nt�|_||_|��|_dS)	NcSsdS)Nrrrrrr�Hr�z$FDCapture.__init__.<locals>.<lambda>cSsdS)Nrrrrrr�Ir�rzcannot set tmpfile with stdin�rzwb+)rw)�targetfdrr�
targetfd_save�OSErrorr�r�r=�open�devnullr9�
syscapturerr~�patchsysdictr��tmpfilery�
tmpfile_fd)r3r�r�r}rrrr4Cs&
zFDCapture.__init__cCsd|j|jfS)Nz<FDCapture %s oldfd=%s>)r�r�)r3rrr�__repr__[szFDCapture.__repr__c	CsPyt�|j�Wn ttfk
r0td��YnXt�|j|j�|j	�
�dS)z6 Start capturing on targetfd using memorized tmpfile. z&saved filedescriptor not valid anymoreN)r�fstatr�ror�r:�dup2r�r�r�r�)r3rrrr�^szFDCapture.startcCsb|j}|�d�|��}|r^t|dd�}|rFt|t�rFtj�||d�}|�	d�|�d�|SdS)Nrrur�rx)
r��seek�readrGrO�bytes�py�builtinZ_totext�truncate)r3r}�res�encrrrr�gs


zFDCapture.snapcCs<|j�d�}t�||j�t�|�|j��|j��dS)za stop capturing, restore streams, return original capture file,
        seeked to position zero. r�N)	r?r@rr�r�rNr�r�r�)r3r�rrrr�ts


zFDCapture.donecCs|j��t�|j|j�dS)N)r�r�rr�r�r�)r3rrrr�}s
zFDCapture.suspendcCs|j��t�|j|j�dS)N)r�r�rr�r�r�)r3rrrr��s
zFDCapture.resumecCs(tj�|�r|�d�}t�|j|�dS)z$ write to original file descriptor. �utf8N)r�r�Z_istextr�rr+r�)r3r�rrrr��s
zFDCapture.writeorg)N)r^r_r`�__doc__r4r�r�r�r�r�r�r�rrrrr8@s
	
	r8c@sFeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)r9NcCsBt|}tt|�|_||_|dkr8|dkr2t�}nt�}||_dS)Nr)r�rGr
�_oldr��DontReadFromInputrr�)r3rr�r�rrrr4�szSysCapture.__init__cCstt|j|j�dS)N)�setattrr
r�r�)r3rrrr��szSysCapture.startcCs&|j}|��}|�d�|�d�|S)Nr)r��getvaluer�r�)r3r}r�rrrr��s


zSysCapture.snapcCs"tt|j|j�|`|j��dS)N)r�r
r�r�r�rN)r3rrrr��szSysCapture.donecCstt|j|j�dS)N)r�r
r�r�)r3rrrr��szSysCapture.suspendcCstt|j|j�dS)N)r�r
r�r�)r3rrrr��szSysCapture.resumecCs|j�|�|j��dS)N)r�r+�flush)r3r�rrrr��szSysCapture.writeorg)N)
r^r_r`r4r�r�r�r�r�r�rrrrr9�s
r9c@sLeZdZdZdZdd�ZeZeZeZdd�Z	dd�Z
d	d
�Zedd��Z
dS)
r�aTemporary stub class.  Ideally when stdin is accessed, the
    capturing should be turned off, with possibly all data captured
    so far sent to the screen.  This should be configurable, though,
    because in automated test runs it is better to crash than
    hang indefinitely.
    NcGstd��dS)Nz+reading from stdin while output is captured)�IOError)r3r,rrrr��szDontReadFromInput.readcCstd��dS)Nz/redirected Stdin is pseudofile, has no fileno())r:)r3rrrry�szDontReadFromInput.filenocCsdS)NFr)r3rrr�isatty�szDontReadFromInput.isattycCsdS)Nr)r3rrrrN�szDontReadFromInput.closecCstjdkr|Std��dS)N)�rz(redirected stdin has no attribute buffer)r
�version_inforo)r3rrrr��s
zDontReadFromInput.buffer)r^r_r`r�rur��readline�	readlines�__iter__ryr�rN�propertyr�rrrrr��sr�cCs6tj�d�sdSyddl}Wntk
r0YnXdS)aF
    Ensure readline is imported so that it attaches to the correct stdio
    handles on Windows.

    Pdb uses readline support where available--when not running from the Python
    prompt, the readline module is not imported until running the pdb REPL.  If
    running pytest with the --pdb option this means the readline module is not
    imported until after I/O capture has been started.

    This is a problem for pyreadline, which is often used to implement readline
    support on Windows, as it does not attach to the correct handles for stdout
    and/or stdin if they have been redirected by the FDCapture mechanism.  This
    workaround ensures that readline is imported before I/O capture is setup so
    that it can attach to the actual stdin/out for the console.

    See https://github.com/pytest-dev/pytest/pull/1281
    �win32Nr)r
�platform�
startswithr��ImportError)r�rrrr#�sr#)rt)"r��
__future__rrrr
r�tempfilerr�rPZpy.iorr��textr�r�rrar1r%reZfixturerjrbrfr~r�r|r7r�r8r9r�r#rrrr�<module>s2a 
?L&!