Your IP : 216.73.217.129


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_pty.cpython-38.pyc

U

i�f�/�@s�ddlmZmZmZed�ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZdZ
dZerzdd�Zndd�Zd	d
�Zdd�ZGd
d�dej�ZGdd�dej�Zdd�Zedkr�e��dS)�)�verbose�
import_module�
reap_childrenZtermiosN�I wish to buy a fish license.
�For my pet fish, Eric.
cCst|�dS�N)�print��msg�r�2/opt/alt/python38/lib64/python3.8/test/test_pty.py�debugsr
cCsdSrrr	rrrr
scCs0|�d�r|�dd�S|�d�r,|�dd�S|S)Ns

�
�
)�endswith�replace)�datarrr�normalize_output%s


rcCstj|ddd�}|��S)z8Read one line.  May block forever if no newline is read.�rbF)�mode�closefd)�io�FileIO�readline)�fd�readerrrr�	_readline9src@s8eZdZdd�Zdd�Zedd��Zdd�Zd	d
�ZdS)�PtyTestcCs`t�tj|j�}|�tjtj|�t�tj|j�}|�tjtj|�|�tjd�t�d�dS)Nr�
)�signal�SIGALRM�
handle_sigZ
addCleanup�SIGHUP�
handle_sighup�alarm)�selfZ	old_alarmZ
old_sighuprrr�setUpDsz
PtyTest.setUpcCs|�d�dS)Nzisatty hung)�fail)r%Zsig�framerrrr!PszPtyTest.handle_sigcCsdSrr)Zsignumr(rrrr#SszPtyTest.handle_sighupc
Cs�zLtd�t��\}}td||f�td|f�t�|�}td|�Wntk
rjt�d��YnX|�t�	|�d�t�
|�}z^t�|d�zt�|d�}|�
d	|�Wn0tk
r�}z|jtjkr҂W5d}~XYnXW5t�||�Xtd
�t�|t�t|�}|�
dt|��td�t�|tdd
��t�|td
d��t|�}|�
dt|��t�|�t�|�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_fdrzWriting chunked output�r)r
�ptyZmaster_openZ
slave_open�OSError�unittestZSkipTestZ
assertTrue�os�isatty�get_blocking�set_blocking�read�assertEqual�errnoZEAGAIN�write�
TEST_STRING_1rr�
TEST_STRING_2�close)r%�	master_fdZ
slave_nameZslave_fdZblocking�s1�e�s2rrr�
test_basicZsF�

�
zPtyTest.test_basiccCs�td�t��\}}|tjkr�t�d�s:td�t�d�td�zt��WnRtk
rjtd�YnJt	k
r�td�Yn0td�t�d�YnXtd	�t�d
�t�d�n�td|�zt�
|d
�}Wntk
r�Y�q YnX|�s�q tj�
t|�dd�dd��q�t�|d�\}}|d?}td|||f�|dk�r`|�d�n@|d
k�rv|�d�n*|dk�r�|�d�n|dk�r�|�d�t�|�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.�Prr�ascii)�encodingr�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+�forkZCHILDr.r/�_exit�setsidr,�AttributeErrorr2�sys�stdoutr5�strr�waitpidr'r8)r%�pidr9rZstatus�resrrr�	test_fork�sV



�
	





zPtyTest.test_forkN)	�__name__�
__module__�__qualname__r&r!�staticmethodr#r=rPrrrrrCs
3rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
SmallPtyTestsz)These tests don't spawn children or hang.cCs4tj|_tj|_tj|_g|_g|_g|_	g|_
dSr)r+�STDIN_FILENO�orig_stdin_fileno�
STDOUT_FILENO�orig_stdout_fileno�select�orig_pty_select�fds�files�select_rfds_lengths�select_rfds_results)r%rrrr&�szSmallPtyTests.setUpc	Csz|jt_|jt_|jt_|jD]&}z|��Wqt	k
rBYqXq|j
D](}zt�|�WqLt	k
rrYqLXqLdSr)rWr+rVrYrXr[rZr]r8r,r\r.)r%�filerrrr�tearDown�s

zSmallPtyTests.tearDowncCst��}|j�|�|Sr)r.�piper\�extend)r%Zpipe_fdsrrr�_pipe�szSmallPtyTests._pipecCst��}|j�|�|Sr)�socket�
socketpairr]rc)r%rfrrr�_socketpairszSmallPtyTests._socketpaircCs*|�|j�d�t|��|j�d�ggfS)Nr)r3r^�pop�lenr_)r%�rfdsZwfdsZxfdsrrr�_mock_selectszSmallPtyTests._mock_selectc	Cs|��\}}|t_|��\}}|t_|��}dd�|D�}t�|dd�t�|d�|jt_|j	�
d�|j�
||dg�|j	�
d�|�t
��t�|d�W5QRXt�||dgggd�d}|�||dg|�|�t�|d�d�|�t�|dd�d�d	S)
z6Test the normal data case on both master_fd and stdin.cSsg|]}|���qSr��fileno��.0�srrr�
<listcomp>sz4SmallPtyTests.test__copy_to_each.<locals>.<listcomp>r>sfrom masters
from stdinr@r�N)rdr+rXrVrgr.r5rkrZr^�appendr_�assertRaises�
IndexError�_copyr3r2)r%�read_from_stdout_fd�mock_stdout_fd�
mock_stdin_fd�write_to_stdin_fdrf�mastersrjrrr�test__copy_to_each
s$z SmallPtyTests.test__copy_to_eachc	Cs�|��\}}|t_|��\}}|t_|��}dd�|D�}|d��t�|�|jt_|j	�
d�|j�
||dg�|j	�
d�|�t
��t�|d�W5QRXdS)z9Test the empty read EOF case on both master_fd and stdin.cSsg|]}|���qSrrlrnrrrrq0sz7SmallPtyTests.test__copy_eof_on_all.<locals>.<listcomp>r>r@rN)rdr+rXrVrgr8r.rkrZr^rsr_rtrurv)r%rwrxryrzrfr{rrr�test__copy_eof_on_all)s
z#SmallPtyTests.test__copy_eof_on_allN)rQrRrS�__doc__r&rardrgrkr|r}rrrrrU�s	rUcCs
t�dSr)rrrrr�tearDownModuleAsr�__main__)Ztest.supportrrrr4r+r.rJrZrrerr-r6r7r
rrZTestCaserrUrrQ�mainrrrr�<module>s.

!^