Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_pty.cpython-35.opt-1.pyc



��Yf�+�@sddlmZmZmZed�ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZdZdZ
er�dd�Zndd�Zd	d
�ZGdd�dej�ZGd
d�dej�Zdd�Zedkrej�dS)�)�verbose�
import_module�
reap_childrenZtermiosNsI wish to buy a fish license.
sFor my pet fish, Eric.
cCst|�dS)N)�print)�msg�r�2/opt/alt/python35/lib64/python3.5/test/test_pty.py�debugsr	cCsdS)Nr)rrrrr	scCsB|jd�r|jdd�S|jd�r>|jdd�S|S)Ns

s
s
)�endswith�replace)�datarrr�normalize_outputs
r
c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�PtyTestcCs,tjtj|j�|_tjd�dS)N�
)�signal�SIGALRM�
handle_sig�	old_alarm�alarm)�selfrrr�setUp4sz
PtyTest.setUpcCs'tjd�tjtj|j�dS)Nr)rrrr)rrrr�tearDown:s
zPtyTest.tearDowncCs|jd�dS)Nzisatty hung)�fail)rZsig�framerrrr?szPtyTest.handle_sigc!Cs�ybtd�tj�\}}td||f�td|f�tj|�}td|�Wn!tk
r�tjd��YnX|jtj	|�d�tj
|�}zwtj|d�y&tj|d�}|j
d	|�Wn:tk
r#}z|jtjkr�WYdd}~XnXWdtj||�Xtd
�tj|t�tj|d�}|j
dt|��td�tj|tdd
��tj|td
d��tj|d�}|j
dt|��tj|�tj|�dS)NzCalling master_open()z#Got master_fd '%d', slave_name '%s'zCalling slave_open(%r)zGot slave_fd '%d'z,Pseudo-terminals (seemingly) not functional.zslave_fd is not a ttyFi�zWriting to slave_fdsI wish to buy a fish license.
zWriting chunked output�sFor my pet fish, Eric.
)r	�ptyZmaster_openZ
slave_open�OSError�unittestZSkipTestZ
assertTrue�os�isatty�get_blocking�set_blocking�read�assertEqual�errnoZEAGAIN�write�
TEST_STRING_1r
�
TEST_STRING_2�close)r�	master_fdZ
slave_nameZslave_fdZblocking�s1�e�s2rrr�
test_basicBsB


	


zPtyTest.test_basicc
Cstd�tj�\}}|tjkr�tjd�sQtd�tjd�td�ytj�WnUtk
r�td�YnQt	k
r�td�Yn6td�tjd�YnXtd	�tjd
�tjd�ntd|�x_ytj
|d
�}Wntk
r$PYnX|s,Ptjj
t|jdd�dd��q�Wtj|d�\}}|d?}td|||f�|dkr�|jd�nQ|d
kr�|jd�n5|dkr�|jd�n|dkr�|jd�tj|�dS)Nzcalling pty.fork()�zChild's fd 1 is not a tty?!�zIn child, calling os.setsid()zGood: OSError was raised.zNo setsid() available?zAn unexpected error was raised.zos.setsid() succeeded! (bad!)��z!Waiting for child (%d) to finish.�Ps
s
�encoding�asciir�z&Child (%d) exited with status %d (%d).z3Child raised an unexpected exception in os.setsid()z1pty.fork() failed to make child a session leader.z8Child spawned by pty.fork() did not have a tty as stdoutz&pty.fork() failed for unknown reasons.)r	r�forkZCHILDrr �_exit�setsidr�AttributeErrorr#�sys�stdoutr&�strr�waitpidrr))r�pidr*rZstatus�resrrr�	test_forkssV













zPtyTest.test_forkN)�__name__�
__module__�__qualname__rrrr.rArrrrr3s
1rc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
SmallPtyTestsz)These tests don't spawn children or hang.cCsLtj|_tj|_tj|_g|_g|_g|_	g|_
dS)N)r�STDIN_FILENO�orig_stdin_fileno�
STDOUT_FILENO�orig_stdout_fileno�select�orig_pty_select�fds�files�select_rfds_lengths�select_rfds_results)rrrrr�s			zSmallPtyTests.setUpcCs�|jt_|jt_|jt_x4|jD])}y|j�Wq.t	k
rVYq.Xq.Wx7|j
D],}ytj|�Wqet	k
r�YqeXqeWdS)N)rGrrFrIrHrKrJrMr)rrLr)r�file�fdrrrr�s
	
zSmallPtyTests.tearDowncCs tj�}|jj|�|S)N)r�piperL�extend)rZpipe_fdsrrr�_pipe�szSmallPtyTests._pipecCs tj�}|jj|�|S)N)�socket�
socketpairrMrS)rrVrrr�_socketpair�szSmallPtyTests._socketpaircCs;|j|jjd�t|��|jjd�ggfS)Nr)r$rN�pop�lenrO)r�rfdsZwfdsZxfdsrrr�_mock_select�s"zSmallPtyTests._mock_selectcCsg|j�\}}|t_|j�\}}|t_|j�}dd�|D�}tj|dd�tj|d�|jt_|j	j
d�|jj
||dg�|j	j
d�|jt
��tj|d�WdQRXtj||dgggd�d}|j||dg|�|jtj|d	�d�|jtj|dd	�d�dS)
z6Test the normal data case on both master_fd and stdin.cSsg|]}|j��qSr)�fileno)�.0�srrr�
<listcomp>�s	z4SmallPtyTests.test__copy_to_each.<locals>.<listcomp>r/sfrom masters
from stdinr1rN�)rTrrHrFrWrr&r[rJrN�appendrO�assertRaises�
IndexError�_copyr$r#)r�read_from_stdout_fd�mock_stdout_fd�
mock_stdin_fd�write_to_stdin_fdrV�mastersrZrrr�test__copy_to_each�s$		&z SmallPtyTests.test__copy_to_eachc
Cs�|j�\}}|t_|j�\}}|t_|j�}dd�|D�}tj|d�|dj�tj|�|jt_|j	j
d�|jj
||dg�|j	j
d�|jt
��tj|d�WdQRXdS)z9Test the empty read EOF case on both master_fd and stdin.cSsg|]}|j��qSr)r\)r]r^rrrr_s	z7SmallPtyTests.test__copy_eof_on_all.<locals>.<listcomp>r/r1rN)rTrrHrFrWrr)r[rJrNrarOrbrcrd)rrerfrgrhrVrirrr�test__copy_eof_on_alls		
z#SmallPtyTests.test__copy_eof_on_allN)rBrCrD�__doc__rrrTrWr[rjrkrrrrrE�s	rEcCst�dS)N)rrrrr�tearDownModule(srm�__main__)Ztest.supportrrrr%rrr;rJrrUrr'r(r	r
ZTestCaserrErmrB�mainrrrr�<module>s(
�_