File: //usr/local/lib/python3.10/test/__pycache__/test_file_eintr.cpython-310.opt-1.pyc
o
�ir* � @ s d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZe� e j
dkd�G dd� d��ZG dd� deej�Z
G dd � d eej�ZG d
d� de�ZG dd
� d
eej�ZG dd� deej�ZG dd� de�ZG dd� deej�ZG dd� deej�Zedkr�e�� dS dS )� N�posixztests requires a posix system.c @ sV e Zd Zdd� Zdd� Zdd� Z dd d
�Zdd� Zd
Zdd� Z dd� Z
dd� ZdS )�TestFileIOSignalInterruptc C s
d | _ d S �N)�_process��self� r �1/usr/local/lib/python3.10/test/test_file_eintr.py�setUp s
zTestFileIOSignalInterrupt.setUpc C sB | j r| j �� d u rz| j �� W d S ty Y d S w d S d S r )r �poll�kill�OSErrorr r r r �tearDown s ��z"TestFileIOSignalInterrupt.tearDownc C �
d| j S )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")��modnamer r r r �_generate_infile_setup_code$ s �z5TestFileIOSignalInterrupt._generate_infile_setup_code� Tc C s| | j �� du rt�d� z| j �� W n ty Y nw |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
) r r �time�sleep� terminater
�communicate�fail�decode)r �why�stdout�stderrr Z
stdout_endZ
stderr_endr r r �fail_with_process_info- s
�
�z0TestFileIOSignalInterrupt.fail_with_process_infoc C s6 | � � }tjtjddd| d d | d d gtjtjtjd�| _| jj�t d��}|dkr6| j
d |d
� | jj�|� d}g }|slt
�
| jjgddd
�\}}}| j�tj� |d7 }|dkrj| j�� | �d� |rC| jj�� }|dkr}| j
d|d
� | jjdd�\} }
| jjr�| j
d| jj | |
dd� dS dS )an Generic 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.
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())�stdinr r s Worm Sign!
zwhile awaiting a sign)r r r g�������?� �� z,reader process failed to handle our signals.s $
zwhile awaiting signal�
)�inputzexited rc=%dF)r N)r �
subprocess�Popen�sys�
executable�PIPEr r �read�lenr r �write�select�send_signal�signal�SIGINTr r �readliner �
returncode)r �
data_to_write�read_and_verify_codeZinfile_setup_codeZ worm_signZsignals_sentZrlist�_Zsignal_liner r r r r �
_test_readingH s`
������� ��
� �
��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))c C � | j d| jjddd�d� dS )�1readline() must handle signals and not lose data.�
hello, world!r/ s hello, world!
�Zread_method_nameZexpected�r1 r2 N�r4 �_READING_CODE_TEMPLATE�formatr r r r �
test_readline� � �
�z'TestFileIOSignalInterrupt.test_readlinec C �"