Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_file_eintr.cpython-34.pyo

�
g f[(�@s�ddlZddlZddlZddlZddlZddlmZddlZddlZddl	m
Z
ejejdkd�Gdd�dej
��ZGdd	�d	e�ZGd
d�de�Zdd
�Zedkr�e�ndS)�N)�run_unittest)�FileIO�posixztests requires a posix system.c@seZdZdd�Zdd�Zdd�Zdddd	d
�Zdd�Zd
Zdd�Z	dd�Z
dd�ZdS)�TestFileIOSignalInterruptcCs
d|_dS)N)�_process)�self�r�9/opt/alt/python34/lib64/python3.4/test/test_file_eintr.py�setUpszTestFileIOSignalInterrupt.setUpcCsK|jrG|jj�dkrGy|jj�WqGtk
rCYqGXndS)N)r�poll�kill�OSError)rrrr	�tearDowns

z"TestFileIOSignalInterrupt.tearDowncCsdS)z�Returns the infile = ... line of code for the reader process.

        subclasseses should override this to test different IO objects.
        z9import _io ;infile = _io.FileIO(sys.stdin.fileno(), "rb")r)rrrr	�_generate_infile_setup_code$sz5TestFileIOSignalInterrupt._generate_infile_setup_code�Tc
Cs�|jj�dkrKtjd�y|jj�WqKtk
rGYqKXn|r}|jj�\}}||7}||7}n|jd||j�|j�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�timeZsleepZ	terminater
�communicate�fail�decode)rZwhy�stdout�stderrrZ
stdout_endZ
stderr_endrrr	�fail_with_process_info,s



	z0TestFileIOSignalInterrupt.fail_with_process_infocCs�|j�}tjtjddd|dd|ddgdtjdtjd	tj�|_|jjjt	d
��}|d
kr�|j
dd	|�n|jjj|�d}g}xz|s8t
j
|jjgffd
�\}}}|jjtj�|d7}|dkr�|jj�|jd�q�q�W|jjj�}|dkrm|j
dd	|�n|jjdd�\}	}
|jjr�|j
d|jj|	|
dd�ndS)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.
        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 signrg�������?���z,reader process failed to handle our signals.s$
zwhile awaiting signal�inputs
zexited rc=%drFN)r�
subprocess�Popen�sys�
executable�PIPErr�read�lenrr�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_readingGs<


	*



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	Cs/|jddd|jjdddd��dS)	z1readline() must handle signals and not lose data.r)s
hello, world!r*�read_method_namer'�expectedshello, world!
N)r,�_READING_CODE_TEMPLATE�format)rrrr	�
test_readline�s
	z'TestFileIOSignalInterrupt.test_readlinec
Cs5|jddd|jjdddddg��d	S)
z2readlines() must handle signals and not lose data.r)shello
world!r*r-�	readlinesr.shello
sworld!
N)r,r/r0)rrrr	�test_readlines�s
	z(TestFileIOSignalInterrupt.test_readlinesc	CsZ|jddd|jjdddd��|jddd|jjdddd��d	S)
z0readall() must handle signals and not lose data.r)shello
world!r*r-�readallr.s
hello
world!
r!N)r,r/r0)rrrr	�test_readall�s	
	z&TestFileIOSignalInterrupt.test_readallN)�__name__�
__module__�__qualname__r
rrrr,r/r1r3r5rrrr	rsIrc@s(eZdZdd�Zdd�ZdS)�TestBufferedIOSignalInterruptcCsdS)z?Returns the infile = ... line of code to make a BufferedReader.zbinfile = open(sys.stdin.fileno(), "rb") ;import _io ;assert isinstance(infile, _io.BufferedReader)r)rrrr	r�sz9TestBufferedIOSignalInterrupt._generate_infile_setup_codec	Cs/|jddd|jjdddd��dS)	z<BufferedReader.read() must handle signals and not lose data.r)shello
world!r*r-r!r.s
hello
world!
N)r,r/r0)rrrr	r5�s
	z*TestBufferedIOSignalInterrupt.test_readallN)r6r7r8rr5rrrr	r9�sr9c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestTextIOSignalInterruptcCsdS)z>Returns the infile = ... line of code to make a TextIOWrapper.zoinfile = open(sys.stdin.fileno(), "rt", newline=None) ;import _io ;assert isinstance(infile, _io.TextIOWrapper)r)rrrr	r�sz5TestTextIOSignalInterrupt._generate_infile_setup_codec	Cs/|jddd|jjdddd��dS)	z1readline() must handle signals and not lose data.r)s
hello, world!r*r-r'r.zhello, world!
N)r,r/r0)rrrr	r1�s
	z'TestTextIOSignalInterrupt.test_readlinec
Cs5|jddd|jjdddddg��d	S)
z2readlines() must handle signals and not lose data.r)s
hello
world!r*r-r2r.zhello
zworld!
N)r,r/r0)rrrr	r3�s
	z(TestTextIOSignalInterrupt.test_readlinesc	Cs/|jddd|jjdddd��dS)	z-read() must handle signals and not lose data.r)shello
world!r*r-r!r.z
hello
world!
N)r,r/r0)rrrr	r5�s
	z&TestTextIOSignalInterrupt.test_readallN)r6r7r8rr1r3r5rrrr	r:�sr:cCs*dd�t�j�D�}t|�dS)NcSs7g|]-}t|t�rt|tj�r|�qSr)�
isinstance�type�
issubclass�unittest�TestCase)�.0Ztcrrr	�
<listcomp>�s	ztest_main.<locals>.<listcomp>)�globals�valuesr)Z
test_casesrrr	�	test_main�srD�__main__)�osr$r%rrZtest.supportrrr>�_iorZ
skipUnless�namer?rr9r:rDr6rrrr	�<module>s%�