Sindbad~EG File Manager
a
��g.5 � @ s d Z ddlmZ ddlmZ ddlZddlZddlZddlZddl Z ddl
Z
ddlZddlm
Z
mZmZmZmZ ddlmZ e
d�Zeed�r�d ejv Znej o�d
ej v Zdd� Ze�eed
�d�G dd� dej��ZG dd� dej�Zddd�Zedk�re�� dS )z:
Very minimal unittests for parts of the readline module.
� )� ExitStack)�EION)�
import_module�unlink�temp_dir�TESTFN�verbose)�assert_python_ok�readline�_READLINE_LIBRARY_VERSIONzEditLine wrapper�libeditc C s^ t rZttd�r2tdtjd��� tdtjd��� ttd�rLtdtj��� tdt� �� d S )N�_READLINE_VERSIONzreadline version: z#xzreadline runtime version: r zreadline library version: zuse libedit emulation? )r �hasattrr
�printr
Z_READLINE_RUNTIME_VERSIONr �is_editline� r r �./usr/local/lib/python3.9/test/test_readline.py�setUpModule s
r �
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c @ s: e Zd ZdZdd� Ze�eed�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.
c C s� t �� t �d� t �d� | �t �d�d � | �t �d�d� | �t �d�d� t �dd� | �t �d�d � | �t �d�d� | �t �d�d� | �t �� d� t �d� | �t �d�d � | �t �d�d� | �t �� d� d S )N�
first line�second liner � � z
replaced line)r
r �add_history�assertEqual�get_history_item�replace_history_item�get_current_history_lengthZremove_history_item)�selfr r r �testHistoryUpdates/ s
z*TestHistoryManipulation.testHistoryUpdates�append_history_filezappend_history not availablec C sV t jdd�}|�� |j}| �t|� t�� t�d� t�d� t� |� t�� | �
t�� d� t�|� | �
t�� d� | �
t�
d�d� | �
t�
d�d� t�d|� t�� t�|� | �
t�� d� | �
t�
d�d� | �
t�
d�d� | �
t�
d�d� t�|� | �t�� t�d|� W d � n1 �s>0 Y t� |� d S ) NF)�deleter r r r r � )�tempfile�NamedTemporaryFile�close�name�
addCleanupr r
r r �write_history_filer r �read_history_filer r! �osZassertRaises�FileNotFoundError)r ZhfileZ hfilenamer r r �test_write_read_appendF s2
,z.TestHistoryManipulation.test_write_read_appendc
C s� t �� zt �d� W n6 tyL } z| �dt|� � W Y d }~n
d }~0 0 t �d� t �dd� t �t� | � t
jt� t �� t �t� t
r�t �d� | �t �d�d� | �t �d�d� d S )Nu entrée 1� Locale cannot encode test data: u entrée 2r u
entrée 22�dummyr )r
r r �UnicodeEncodeError�skipTest�formatr r) r r( r+ �remover* r r r )r �errr r r �test_nonascii_historym s (
z-TestHistoryManipulation.test_nonascii_historyN)�__name__�
__module__�__qualname__�__doc__r �unittest�
skipUnlessr r
r- r5 r r r r r % s �
%r c @ sn e Zd Ze�ejdk oe d�dd� �ZdZ dd� Z
dd � Zd
d� Ze�ejdk d
�e�ed�dd� ��Z
dS )�TestReadlinei z%not supported in this library versionc C s$ t dddd�\}}}| �|d� d S )N�-czimport readlinezxterm-256color)ZTERM� )r r )r �rc�stdout�stderrr r r � test_init� s �zTestReadline.test_initzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
c C s t | j�d��}| �d|� d S )NTs History length: 1��run_pty�auto_history_scriptr2 �assertIn�r �outputr r r �test_auto_history_enabled� s z&TestReadline.test_auto_history_enabledc C s t | j�d��}| �d|� d S )NFs History length: 0rC rG r r r �test_auto_history_disabled� s z'TestReadline.test_auto_history_disabledc
C s t �t jd �}|dv r&| �d|��� zt�d� W n6 tyj } z| �dt|� � W Y d }~n
d }~0 0 d}d}|dtd� 7 }|d 7 }|d
7 }|d7 }t ||�}| �
d|� | �
d
|� | �
d|� ts�ttd�r�| �
d|� | �
d|� d}| �
d| d |� | �
d| |� d S )N)�CZPOSIXzthe LC_CTYPE locale is u ëïr. 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)))
� � z[after]s s x �
s text 't\xeb'
s# line '[\xefnserted]|t\xeb[after]'
s indexes 11 13
Zset_pre_input_hooks substitution 't\xeb'
s matches ['t\xebnt', 't\xebxt']
s '[\xefnserted]|t\xebxt[after]'s result s
s history )
�locale� setlocale�LC_CTYPEr1 r
r r0 r2 �lenrD rF r r )r �locr4 �script�inputrH Zexpectedr r r �
test_nonascii� s. (4
zTestReadline.test_nonasciii z3this readline version does not support history-sizez-editline history size configuration is brokenc
C sZ d}t � ��8}tj�|d�}t|d��}|�d| � W d � n1 sJ0 Y tj�|d�}t|d��6}d�dd� t|d �D ��}|�|� W d � n1 s�0 Y d
}ttj�}||d<