Your IP : 216.73.217.32


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



��Yf�-�@s=dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
mZmZddlmZed�Zejo�dejkZe
jeed	�d
�Gdd�de
j��ZGd
d�de
j�Zdddd�Zedkr9e
j�dS)z:
Very minimal unittests for parts of the readline module.
�)�	ExitStack)�EION)�
import_module�unlink�temp_dir�TESTFN)�assert_python_ok�readline�libedit�
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c@sUeZdZdZdd�Zejeed�d�dd��Z	dd	�Z
d
S)�TestHistoryManipulationz�
    These tests were added to check that the libedit emulation on OSX and the
    "real" readline have the same interface for history manipulation. That's
    why the tests cover only a small subset of the interface.
    cCs9tj�tjd�tjd�|jtjd�d�|jtjd�d�|jtjd�d�tjdd�|jtjd�d�|jtjd�d�|jtjd�d�|jtj�d�tjd�|jtjd�d�|jtjd�d�|jtj�d�dS)Nz
first linezsecond liner��z
replaced line)r	r�add_history�assertEqual�get_history_item�replace_history_item�get_current_history_lengthZremove_history_item)�self�r�7/opt/alt/python35/lib64/python3.5/test/test_readline.py�testHistoryUpdatess



z*TestHistoryManipulation.testHistoryUpdates�append_history_filezappend_history not availablec
Cs�tjdd�}|j�|j}|jt|�tj�tjd�tjd�tj	|�tj�|j
tj�d�tj|�|j
tj�d�|j
tj
d�d�|j
tj
d�d�tjd|�tj�tj|�|j
tj�d�|j
tj
d�d�|j
tj
d�d�|j
tj
d�d�tj|�|jt��tjd|�WdQRXtj	|�dS)	NZdeleteFz
first linezsecond linerrr
�)�tempfileZNamedTemporaryFile�close�name�
addCleanuprr	rr�write_history_filerr�read_history_filerr�osZassertRaises�FileNotFoundError)rZhfileZ	hfilenamerrr�test_write_read_append5s2
	








z.TestHistoryManipulation.test_write_read_appendcCs�tj�ytjd�Wn<tk
rY}z|jdt|��WYdd}~XnXtjd�tjdd�tjt�|j	t
jt�tj�tjt�t
r�tjd�|jtjd�d�|jtjd�d�dS)Nu	entrée 1z Locale cannot encode test data: u	entrée 2r
u
entrée 22Zdummyr)r	rr�UnicodeEncodeError�skipTest�formatrrrrr �remover�is_editlinerr)r�errrrr�test_nonascii_history\s
*




z-TestHistoryManipulation.test_nonascii_historyN)�__name__�
__module__�__qualname__�__doc__r�unittest�
skipUnless�hasattrr	r"r)rrrrrs
&rc@s�eZdZejejdko%ed�dd��Zdd�Z	ejejdkd�ejed	�d
d���Z
dS)
�TestReadlineiz%not supported in this library versioncCs2tdddd�\}}}|j|d�dS)Nz-czimport readlineZTERMzxterm-256color�)rr)r�rc�stdout�stderrrrr�	test_initrszTestReadline.test_initcCs=ytjd�Wn<tk
rO}z|jdt|��WYdd}~XnXd}d}|dtd�7}|d7}|d7}|d	7}t||�}|jd
|�|jd|�|jd|�trt	td
�r|jd|�|jd|�d}|jd|d|�|jd|d|�dS)Nuëïz Locale cannot encode test data: a*import readline

is_editline = readline.__doc__ and "libedit" in readline.__doc__
inserted = "[\xEFnserted]"
macro = "|t\xEB[after]"
set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
if is_editline or not set_pre_input_hook:
    # The insert_line() call via pre_input_hook() does nothing with Editline,
    # so include the extra text that would have been inserted here
    macro = inserted + macro

if is_editline:
    readline.parse_and_bind(r'bind ^B ed-prev-char')
    readline.parse_and_bind(r'bind "\t" rl_complete')
    readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro))
else:
    readline.parse_and_bind(r'Control-b: backward-char')
    readline.parse_and_bind(r'"\t": complete')
    readline.parse_and_bind(r'set disable-completion off')
    readline.parse_and_bind(r'set show-all-if-ambiguous off')
    readline.parse_and_bind(r'set show-all-if-unmodified off')
    readline.parse_and_bind(r'Control-a: "{}"'.format(macro))

def pre_input_hook():
    readline.insert_text(inserted)
    readline.redisplay()
if set_pre_input_hook:
    set_pre_input_hook(pre_input_hook)

def completer(text, state):
    if text == "t\xEB":
        if state == 0:
            print("text", ascii(text))
            print("line", ascii(readline.get_line_buffer()))
            print("indexes", readline.get_begidx(), readline.get_endidx())
            return "t\xEBnt"
        if state == 1:
            return "t\xEBxt"
    if text == "t\xEBx" and state == 0:
        return "t\xEBxt"
    return None
readline.set_completer(completer)

def display(substitution, matches, longest_match_length):
    print("substitution", ascii(substitution))
    print("matches", ascii(matches))
readline.set_completion_display_matches_hook(display)

print("result", ascii(input()))
print("history", ascii(readline.get_history_item(1)))
ssz[after]s		sx	s
stext 't\xeb'
s#line '[\xefnserted]|t\xeb[after]'
sindexes 11 13
Zset_pre_input_hookssubstitution 't\xeb'
s matches ['t\xebnt', 't\xebxt']
s'[\xefnserted]|t\xebxt[after]'sresult s
shistory )
r	rr#r$r%�len�run_ptyZassertInr'r0)rr(�script�input�outputZexpectedrrr�
test_nonascii|s(*4


zTestReadline.test_nonasciiiz3this readline version does not support history-sizez-editline history size configuration is brokenc
CsQd}t��;}tjj|d�}t|d��}|jd|�WdQRXtjj|d�}t|d��:}djdd�t|d	�D��}|j|�WdQRXd
}ttj�}||d<||d<t	|d
dd|�t|d��}|j
�}	WdQRX|jt|	�|�|j|	dj
�d�WdQRXdS)N�
�inputrc�wbsset history-size %d
�historyr2css|]}d|VqdS)sitem %d
Nr)�.0�irrr�	<genexpr>�sz1TestReadline.test_history_size.<locals>.<genexpr>rz�
import os
import readline

history_file = os.environ["HISTORY_FILE"]
readline.read_history_file(history_file)
input()
readline.write_history_file(history_file)
ZINPUTRCZHISTORY_FILEr:slast input
�env�rbr
s
last input���)rr �path�join�open�write�range�dict�environr8�	readlinesrr7�strip)
rZhistory_sizeZtest_dirr>�fZhistory_file�datar9rD�linesrrr�test_history_size�s&


zTestReadline.test_history_sizeN)r*r+r,r.ZskipIfr	Z_READLINE_VERSIONr'r6r<rSrrrrr1ps	O	r1sdummy input
c'Cs#td�}t�}|j�\}}tjd|f}tj|d|d|d|d|�}tj|�t	���}	|	j
|�dd�}
|	j|
|�|	jtj|�|	j
tj
��}|j|tjtjB�tj|d	�x!x|j�D]\}}
|
tj@r�ytj|d
�}Wn=tk
rr}z|jtkrZ�d}WYdd}~XnX|s}|S|j|�|
tj@ry |tj||�d�}Wn=tk
r�}z|jtkr��d}WYdd}~XnX|s|j|tj�qWq�WWdQRXdS)N�ptyz-c�stdinr4r5rDcSs'y|j�Wntk
r"YnXdS)N)�	terminate�ProcessLookupError)�procrrrrV�s
zrun_pty.<locals>.terminateFir2)r�	bytearray�openpty�sys�
executable�
subprocess�Popenr rr�
enter_context�callback�	selectorsZSelectSelector�registerZ
EVENT_READZEVENT_WRITE�set_blockingZselect�read�OSError�errnor�extendrJZmodify)r9r:rDrTr;ZmasterZslave�argsrXZcleanuprVZsel�_Zevents�chunkr(rrrr8�sF	'




 r8�__main__)r-�
contextlibrrfrr rar]r[rr.Ztest.supportrrrrZtest.support.script_helperrr	r'r/r0ZTestCaserr1r8r*�mainrrrr�<module>s&"Y�2