Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_file_eintr.cpython-310.pyc

o

0�ir*�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZe�	ej
dkd�Gdd�d��ZGdd�deej�Z
Gdd	�d	eej�ZGd
d�de�ZGdd
�d
eej�ZGdd�deej�ZGdd�de�ZGdd�deej�ZGdd�deej�Zedkr�e��dSdS)�N�posixztests requires a posix system.c@sVeZdZdd�Zdd�Zdd�Z		dd	d
�Zdd�Zd
Zdd�Z	dd�Z
dd�ZdS)�TestFileIOSignalInterruptcCs
d|_dS�N)�_process��self�r�;/opt/alt/python310/lib64/python3.10/test/test_file_eintr.py�setUps
zTestFileIOSignalInterrupt.setUpcCsB|jr|j��durz|j��WdStyYdSwdSdSr)r�poll�kill�OSErrorrrrr	�tearDowns��z"TestFileIOSignalInterrupt.tearDowncC�
d|jS)z�Returns the infile = ... line of code for the reader process.

        subclasseses should override this to test different IO objects.
        z=import %s as io ;infile = io.FileIO(sys.stdin.fileno(), "rb")��modnamerrrr	�_generate_infile_setup_code$s�z5TestFileIOSignalInterrupt._generate_infile_setup_code�TcCs||j��durt�d�z|j��Wn	tyYnw|r.|j��\}}||7}||7}|�d||��|��f�dS)a;A common way to cleanup and fail with useful debug output.

        Kills the process if it is still running, collects remaining output
        and fails the test with an error message including the output.

        Args:
            why: Text to go after "Error from IO process" in the message.
            stdout, stderr: standard output and error from the process so
                far to include in the error message.
            communicate: bool, when True we call communicate() on the process
                after killing it to gather additional output.
        Ng�������?z/Error from IO process %s:
STDOUT:
%sSTDERR:
%s
)	rr�time�sleepZ	terminater
�communicate�fail�decode)rZwhy�stdout�stderrrZ
stdout_endZ
stderr_endrrr	�fail_with_process_info-s
�
�z0TestFileIOSignalInterrupt.fail_with_process_infocCsJ|��}t|�dksJd��tjtjddd|dd|ddgtjtjtjd	�|_|jj�	td
��}|d
kr@|j
d|d�|jj�|�d
}g}|svt
�
|jjgddd�\}}}|j�tj�|d7}|dkrt|j��|�d�|rM|jj��}|dkr�|j
d|d�|jjdd�\}	}
|jjr�|j
d|jj|	|
dd�dSdS)anGeneric buffered read method test harness to validate EINTR behavior.

        Also validates that Python signal handlers are run during the read.

        Args:
            data_to_write: String to write to the child process for reading
                before sending it a signal, confirming the signal was handled,
                writing a final newline and closing the infile pipe.
            read_and_verify_code: Single "line" of code to read from a file
                object named 'infile' and validate the result.  This will be
                executed as part of a python subprocess fed data_to_write.
        iz#data_to_write must fit in pipe buf.z-uz-czXimport signal, sys ;signal.signal(signal.SIGINT, lambda s, f: sys.stderr.write("$\n")) ;z ;z"sys.stderr.write("Worm Sign!\n") ;zinfile.close())�stdinrrsWorm Sign!
zwhile awaiting a sign)rrrg�������?���z,reader process failed to handle our signals.s$
zwhile awaiting signal�
)�inputzexited rc=%dF)rN)r�len�
subprocess�Popen�sys�
executable�PIPErr�readrr�write�selectZsend_signal�signal�SIGINTrr�readliner�
returncode)r�
data_to_write�read_and_verify_codeZinfile_setup_codeZ	worm_signZsignals_sentZrlist�_Zsignal_linerrrrr	�
_test_readingHsb
�������	��

�	�

��z'TestFileIOSignalInterrupt._test_readingz�got = infile.{read_method_name}() ;expected = {expected!r} ;assert got == expected, ("{read_method_name} returned wrong data.\n""got data %r\nexpected %r" % (got, expected))cC�|jd|jjddd�d�dS)�1readline() must handle signals and not lose data.�
hello, world!r,shello, world!
�Zread_method_nameZexpected�r.r/N�r1�_READING_CODE_TEMPLATE�formatrrrr	�
test_readline���
�z'TestFileIOSignalInterrupt.test_readlinecC�"|jd|jjdddgd�d�dS)�2readlines() must handle signals and not lose data.�hello
world!�	readlinesshello
sworld!
r5r6Nr7rrrr	�test_readlines���
�z(TestFileIOSignalInterrupt.test_readlinescCs8|jd|jjddd�d�|jd|jjddd�d�dS)z0readall() must handle signals and not lose data.r>�readall�
hello
world!
r5r6r'Nr7rrrr	�test_readall�s���
�z&TestFileIOSignalInterrupt.test_readallN)rrT)�__name__�
__module__�__qualname__r
rrrr1r8r:r@rDrrrr	rs	
�I�rc@�eZdZdZdS)�CTestFileIOSignalInterrupt�_ioN�rErFrGrrrrr	rI��rIc@rH)�PyTestFileIOSignalInterrupt�_pyioNrKrrrr	rM�rLrMc@seZdZdd�Zdd�ZdS)�TestBufferedIOSignalInterruptcCr)z?Returns the infile = ... line of code to make a BufferedReader.ziimport %s as io ;infile = io.open(sys.stdin.fileno(), "rb") ;assert isinstance(infile, io.BufferedReader)rrrrr	r�s�z9TestBufferedIOSignalInterrupt._generate_infile_setup_codecCr2)z<BufferedReader.read() must handle signals and not lose data.r>r'rCr5r6Nr7rrrr	rD�r;z*TestBufferedIOSignalInterrupt.test_readallN)rErFrGrrDrrrr	rO�srOc@rH)�CTestBufferedIOSignalInterruptrJNrKrrrr	rP�rLrPc@rH)�PyTestBufferedIOSignalInterruptrNNrKrrrr	rQ�rLrQc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestTextIOSignalInterruptcCr)z>Returns the infile = ... line of code to make a TextIOWrapper.z�import %s as io ;infile = io.open(sys.stdin.fileno(), encoding="utf-8", newline=None) ;assert isinstance(infile, io.TextIOWrapper)rrrrr	r�s�z5TestTextIOSignalInterrupt._generate_infile_setup_codecCr2)r3r4r,zhello, world!
r5r6Nr7rrrr	r:�r;z'TestTextIOSignalInterrupt.test_readlinecCr<)r=s
hello
world!r?zhello
zworld!
r5r6Nr7rrrr	r@�rAz(TestTextIOSignalInterrupt.test_readlinescCr2)z-read() must handle signals and not lose data.r>r'z
hello
world!
r5r6Nr7rrrr	rD�r;z&TestTextIOSignalInterrupt.test_readallN)rErFrGrr:r@rDrrrr	rR�s
rRc@rH)�CTestTextIOSignalInterruptrJNrKrrrr	rS�rLrSc@rH)�PyTestTextIOSignalInterruptrNNrKrrrr	rT�rLrT�__main__)�osr)r*r"r$rZunittestrJrNZ
skipUnless�namerZTestCaserIrMrOrPrQrRrSrTrE�mainrrrr	�<module>s.
 �