Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/test_fdesc.cpython-37.pyc

B

;��]��@s�dZddlZddlZddlZyddlZWnek
r@dZYnXddlmZddl	m
Z
ddlmZGdd�dej
�ZGd	d
�d
ej
�ZGdd�dej
�ZdS)
z&
Tests for L{twisted.internet.fdesc}.
�Nznot supported on this platform)�fdesc)�untilConcludes)�unittestc@s eZdZdZdd�Zdd�ZdS)�NonBlockingTestszE
    Tests for L{fdesc.setNonBlocking} and L{fdesc.setBlocking}.
    cCsjt��\}}|�tj|�|�tj|�|�t�|tj�tj@�t�	|�|�
t�|tj�tj@�dS)zR
        L{fdesc.setNonBlocking} sets a file description to non-blocking.
        N)�os�pipe�
addCleanup�close�assertFalse�fcntl�F_GETFL�
O_NONBLOCKr�setNonBlocking�
assertTrue)�self�r�w�r�J/opt/alt/python37/lib64/python3.7/site-packages/twisted/test/test_fdesc.py�test_setNonBlockings
z$NonBlockingTests.test_setNonBlockingcCsZt��\}}|�tj|�|�tj|�t�|�t�|�|�t�|tj	�tj
@�dS)zK
        L{fdesc.setBlocking} sets a file description to blocking.
        N)rrrr	rrZsetBlockingr
rrr
)rrrrrr�test_setBlocking(s

z!NonBlockingTests.test_setBlockingN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�ReadWriteTestsz<
    Tests for L{fdesc.readFromFD}, L{fdesc.writeToFD}.
    cCs,t��\|_|_t�|j�t�|j�dS)zG
        Create a non-blocking pipe that can be used in tests.
        N)rrrrrr)rrrr�setUp:szReadWriteTests.setUpcCsPyt�|j�Wntk
r$YnXyt�|j�Wntk
rJYnXdS)z
        Close pipes.
        N)rr	r�OSErrorr)rrrr�tearDownCszReadWriteTests.tearDowncCst�|j|�S)z)
        Write data to the pipe.
        )rZ	writeToFDr)r�drrr�writeQszReadWriteTests.writecCs6g}t�|j|j�}|dkr.|r(|dSdSn|SdS)z*
        Read data from the pipe.
        Nr�)r�
readFromFDr�append)r�l�resrrr�readXszReadWriteTests.readcCsH|�d�}|�|dk�|��}|�t|�|�|�dd|�|�dS)z�
        Test that the number of bytes L{fdesc.writeToFD} reports as written
        with its return value are seen by L{fdesc.readFromFD}.
        shellorN)r rr&�assertEqual�len)r�n�srrr�test_writeAndReadgs

z ReadWriteTests.test_writeAndReadcCs�dd}|�|�}|�|dk�g}d}d}x:||ks>|dkrf|�|���|t|d�7}|d7}q.Wd�|�}|�t|�|�|�|d|�|�dS)	z}
        Similar to L{test_writeAndRead}, but use a much larger string to verify
        the behavior for that case.
        s
0123456879i'r�2����r!N)r rr#r&r(�joinr')r�origZwritten�resultZresultlength�irrr�test_writeAndReadLargess

z%ReadWriteTests.test_writeAndReadLargecCs.g}t�|j|j�}|�|g�|�|�dS)z�
        Verify that reading from a file descriptor with no data does not raise
        an exception and does not result in the callback function being called.
        N)rr"rr#r'ZassertIsNone)rr$r1rrr�test_readFromEmpty�sz!ReadWriteTests.test_readFromEmptycCs"t�|j�|�|��tj�dS)z�
        Test that using L{fdesc.readFromFD} on a cleanly closed file descriptor
        returns a connection done indicator.
        N)rr	rr'r&rZCONNECTION_DONE)rrrr�test_readFromCleanClose�sz&ReadWriteTests.test_readFromCleanClosecCs$t�|j�|�|�d�tj�dS)z�
        Verify that writing with L{fdesc.writeToFD} when the read end is closed
        results in a connection lost indicator.
        �sN)rr	rr'r r�CONNECTION_LOST)rrrr�test_writeToClosed�sz!ReadWriteTests.test_writeToClosedcCs"t�|j�|�|��tj�dS)z�
        Verify that reading with L{fdesc.readFromFD} when the read end is
        closed results in a connection lost indicator.
        N)rr	rr'r&rr7)rrrr�test_readFromInvalid�sz#ReadWriteTests.test_readFromInvalidcCs$t�|j�|�|�d�tj�dS)z�
        Verify that writing with L{fdesc.writeToFD} when the write end is
        closed results in a connection lost indicator.
        r6N)rr	rr'r rr7)rrrr�test_writeToInvalid�sz"ReadWriteTests.test_writeToInvalidcCsftj}dd�}|t_z|�|�d�d�Wd|t_Xdd�}|t_z|�|�d�d�Wd|t_XdS)z8
        Test error path for L{fdesc.writeTod}.
        cSst�}tj|_|�dS)N)r�errno�EAGAIN)�fd�data�errrrr�eagainWrite�sz4ReadWriteTests.test_writeErrors.<locals>.eagainWriter6rNcSst�}tj|_|�dS)N)rr;ZEINTR)r=r>r?rrr�
eintrWrite�sz3ReadWriteTests.test_writeErrors.<locals>.eintrWrite)rr r')rZ
oldOsWriter@rArrr�test_writeErrors�szReadWriteTests.test_writeErrorsN)rrrrrrr r&r+r3r4r5r8r9r:rBrrrrr5s					rc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�CloseOnExecTestszL
    Tests for L{fdesc._setCloseOnExec} and L{fdesc._unsetCloseOnExec}.
    z�
import os, errno
try:
    os.write(%d, b'lul')
except OSError as e:
    if e.errno == errno.EBADF:
        os._exit(0)
    os._exit(5)
except:
    os._exit(10)
else:
    os._exit(20)
cCsvt��}|dkr`y&t�tjtjd|j|��fg�Wqrddl}|��t�	d�YqrXnt
tj|d�dSdS)Nrz-c�r.)r�fork�execv�sys�
executable�program�fileno�	traceback�	print_exc�_exitr�waitpid)r�fObj�pidrKrrr�_execWithFileDescriptor�s&z(CloseOnExecTests._execWithFileDescriptorc	CsXt|��d��@}t�|���|�|�}|�t�|��|�	t�
|�d�WdQRXdS)z�
        A file descriptor passed to L{fdesc._setCloseOnExec} is not inherited
        by a new process image created with one of the exec family of
        functions.
        �wbrN)�open�mktempr�_setCloseOnExecrJrQrr�	WIFEXITEDr'�WEXITSTATUS)rrO�statusrrr�test_setCloseOnExec�s

z$CloseOnExecTests.test_setCloseOnExecc	Csft|��d��N}t�|���t�|���|�|�}|�t�	|��|�
t�|�d�WdQRXdS)z�
        A file descriptor passed to L{fdesc._unsetCloseOnExec} is inherited by
        a new process image created with one of the exec family of functions.
        rR�N)rSrTrrUrJZ_unsetCloseOnExecrQrrrVr'rW)rrOrXrrr�test_unsetCloseOnExecs
z&CloseOnExecTests.test_unsetCloseOnExecN)rrrrrIrQrYr[rrrrrC�s


rC)rrrGr;r�ImportError�skipZtwisted.internetrZtwisted.python.utilrZ
twisted.trialrZSynchronousTestCaserrrCrrrr�<module>s