XylotrechusZ
B
YI~d<\ � @ s< d dl mZ d dlZd dlmZ d dlmZ d dlmZm Z d dl
mZ d dlm
Z G dd � d ej�ZG d
d� dej�ZG dd
� d
ej�ZG dd� dej�ZG dd� dej�ZG dd� d�ZG dd� d�Z
G dd� dej�ZG dd� d�ZG dd� dej�ZG dd� dej�ZG dd� dej�Zed k�r8ejd!d!d"� dS )#� )�formatN)�mock)�requires)�Tk�Text)�EditorWindow)�Editorc @ s8 e Zd ZdZdZdZdZdZdd� Zdd � Z d
d� Z
dS )
�Is_Get_Testz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentc C s6 | � t�d�� | � t�d�� | �t�| j�� d S )N� z
)Z
assertTrue�ftZis_all_whiteZassertFalse�test_comment)�self� r �B/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_format.py�test_is_all_white s zIs_Get_Test.test_is_all_whitec C sR | j }|t�| j�d� |t�| j�d� |t�| j�d� |t�| j�d� d S )Nr
z )�assertEqualr Z
get_indentr �trailingws_comment�leadingws_comment�leadingws_nocomment)r
�Equalr r r �test_get_indent s
zIs_Get_Test.test_get_indentc C sd | j }|t�| j�d� |t�| j�d� |t�| j�d� |t�| j�d� |t�| j�d� d S )N�#z #z r
)r r Zget_comment_headerr r r r �test_nocomment)r
r r r r �test_get_comment_header s z#Is_Get_Test.test_get_comment_headerN)�__name__�
__module__�__qualname__r r r r r r r r r r r r r s r c @ s0 e Zd Zedd� �Zdd� Zdd� Zdd� Zd S )
�FindTestc C s ddl m} |� | _d S )Nr )r )Zidlelib.idle_test.mock_tkr �text)�clsr r r r �
setUpClass5 s zFindTest.setUpClassc C s� | j }|�d|� xftd|�D ]X}t|�d| ��d�d �}x6d|d |fD ]$}d||f }| �t�||�|� qNW qW |� dd� d S ) Nz1.0� z%d.end�.r � z%d.%d�end)
r �insert�range�int�index�splitr r Zfind_paragraph�delete) r
Z
inserttextZstopline�expectedr �lineZ
linelength�colZ tempindexr r r �runcase: s zFindTest.runcasec
C s d}| � |dddd|dd� f� d}| � |d d
dd|dd
� f� d}| � |d d
dd|dd� f� d}| � |dd
dd|dd� f� d}| � |dd
dd|dd� f� d}| � |dd
dd|dd� f� d}| � |dd
dd|dd� f� d}| � |dd
dd|dd� f� d S )Nz;# Comment block with no blank lines before
# Comment line
� z1.0z3.0r r �: zG
# Comment block with whitespace line before and after
# Comment line
� z2.0z4.0r! �F zS
# Indented comment block with whitespace before and after
# Comment line
z #�R z
# Single line comment
� z4
# Single line comment with leading whitespace
�3 z0
# Comment immediately followed by code
x = 42
�( z=
# Indented comment immediately followed by code
x = 42
�5 z=
# Comment immediately followed by indented code
x = 42
�1 )r. )r
�commentr r r �test_find_commentG s zFindTest.test_find_commentc
C s� d}| � |dddd|dd� f� d}| � |d d
dd|dd
� f� d}| � |d d
dd|dd� f� d}| � |dd
dd|dd� f� d}| � |dd
dd|dd� f� d S )Nz6"""String with no blank lines before
String line
"""
r1 z1.0z4.0r
r r7 zC
"""String with whitespace line before and after
String line.
"""
� z2.0z5.0r! �B zV
"""Indented string with whitespace before and after
Comment string.
"""
z �U z
"""Single line string."""
r/ z3.0� z8
"""Single line string with leading whitespace."""
�7 )r. )r
Z
teststringr r r �test_find_paragraph} s zFindTest.test_find_paragraphN)r r r �classmethodr r. r: r@ r r r r r + s
6r c @ s e Zd Zdd� ZdS )�ReformatFunctionTestc C s� | j }tj}d}||dd�d� ||dd�d� |||d�d� |||d�d� |||d �d
� |||d�d
� |||d�d� d
}|||d�d� |||d�d� |||d �d� |||d�d� |||d�d
� d S )Nz
O hello world� r! zHello world� zHello worldz
O
hello
world� � z
O hello
world� �
z
O hello worldz
O
hello
worldz
O hello
world)r r Zreformat_paragraph)r
r ZreformZhwr r r �test_reformat_paragraph� s z,ReformatFunctionTest.test_reformat_paragraphN)r r r rI r r r r rB � s rB c @ s e Zd Zdd� ZdS )�ReformatCommentTestc C sJ | j }d}t�|dd�}d}|||� d}t�|dd�}d}|||� d S )Nzu """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r2 z zy """this is a test of a reformat for a triple quoted string will it
reformat to less than 70 characters for me?"""zm# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?r zo# this is a test of a reformat for a triple quoted string will it
# reformat to less than 70 characters for me?)r r Zreformat_comment)r
r �test_string�resultr+ r r r r �test_reformat_comment� s
z)ReformatCommentTest.test_reformat_commentN)r r r rM r r r r rJ � s rJ c @ s e Zd Zdd� ZdS )�FormatClassTestc C s2 t �d�}| �|jd� |�� | �|jd � d S )N�editor)r �FormatParagraphr Zeditwin�close)r
�instancer r r �test_init_close� s
zFormatClassTest.test_init_closeN)r r r rS r r r r rN � s rN c @ s, e Zd Zdd� Zdd� Zdd� Zdd� Zd S )
�TextWrapperc C s t |d�| _d S )N)�master)r r )r
rU r r r �__init__� s zTextWrapper.__init__c C s t | j|�S )N)�getattrr )r
�namer r r �__getattr__� s zTextWrapper.__getattr__c C s d S )Nr )r
r r r �undo_block_start� � zTextWrapper.undo_block_startc C s d S )Nr )r
r r r �undo_block_stop� r[ zTextWrapper.undo_block_stopN)r r r rV rY rZ r\ r r r r rT � s rT c @ s e Zd Zdd� ZejZdS )r c C s t |�| _d S )N)rT r )r
�rootr r r rV � s zEditor.__init__N)r r r rV r �get_selection_indicesr r r r r � s r c @ sP e Zd ZdZdZdZedd� �Zedd� �Zdd � Z d
d� Z
dd
� Zdd� ZdS )�FormatEventTestzv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?'''
a '''The first line is under the max width.
The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
'''
a, # The first line is under the max width.
# The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
# Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
# The fourth line is short like the first line.c C sB t d� t� | _| j�� t| jd�}|jj| _t�|�j| _ d S )N�gui)r] )
r r r] �withdrawr r r rP Zformat_paragraph_event� formatter)r rO r r r r s
zFormatEventTest.setUpClassc C s$ | ` | `| j�� | j�� | `d S )N)r rb r] �update_idletasks�destroy)r r r r �
tearDownClass s
zFormatEventTest.tearDownClassc C s@ | j �dd� | �d� | �| j �dd�d� | j �dd� d S )Nz1.0zShort line
ZDummyr% r$ )r r% rb r �getr* )r
r r r �test_short_line s
zFormatEventTest.test_short_linec C s� | j }|�d| j� |�dd� | jddd� |�dd�}d}| �||� |�dd� |�d| j� |�dd d
� | jddd� |�dd�}d}| �||� |�dd� d S )Nz1.0r% �ParameterDoesNothingr2 )�limitzz '''this is a test of a reformat for a triple quoted string will it
reformat to less than 70 characters for me?'''
r$ �selz1.11z1.endzv '''this is a test of a reformat for a triple quoted string will it reformat
to less than 70 characters for me?''') r r% rK Zmark_setrb rf r r* �tag_add)r
r rL r+ r r r �test_long_line& s zFormatEventTest.test_long_linec C s\ | j }|�d| j� |�ddd� | jddd� |�dd�}d }| �||� |�dd
� d S )Nz1.0rj z2.0z4.0rh r2 )ri r% z� The second line's length is way over the max width. It goes on and
on until it is over 100 characters long. Same thing with the third
line. It is also way over the max width, but FormatParagraph will
fix it.
r$ )r r% �multiline_test_stringrk rb rf r r* )r
r rL r+ r r r �test_multiple_linesA s z#FormatEventTest.test_multiple_linesc C s� | j }|�d| j� | jddd� |�dd�}d}| �||� |�dd� |�d| j� |�dd d
� | jddd� |�dd�}d}| �||� |�dd� d S )Nz1.0rh r2 )ri r% a/ # The first line is under the max width. The second line's length is
# way over the max width. It goes on and on until it is over 100
# characters long. Same thing with the third line. It is also way over
# the max width, but FormatParagraph will fix it. The fourth line is
# short like the first line.
r$ rj z2.0z3.0z�# The first line is under the max width.
# The second line's length is way over the max width. It goes on and
# on until it is over 100 characters long.
)r r% �multiline_test_commentrb rf r r* rk )r
r rL r+ r r r �test_comment_blockP s z"FormatEventTest.test_comment_blockN)
r r r rK rm ro rA r re rg rl rn rp r r r r r_ � s
r_ c @ s e Zd Zdd� ZejZejZdS )�DummyEditwinc C s( || _ || _d| _d| _d| _d| _d S )Nr1 FT)r] r �indentwidthZtabwidth�usetabsZcontext_use_ps1)r
r] r r r r rV } s zDummyEditwin.__init__N)r r r rV r Z_make_blanksr^ r r r r rq | s rq c @ s� e Zd Zedd� �Zedd� �Zdd� Zdd� Zd Zd
d� Z dd
� Z
dd� Zdd� Zdd� Z
dd� Zej�ejd�dd� �Zej�ejd�dd� �Zej�ed�dd� �ZdS )�FormatRegionTestc C s` t d� t� | _| j�� t| j�| _t�� | j_t�� | j_ t
| j| j�| _t�
| j�| _d S )Nr` )r r r] ra r r r �MockrZ r\ rq rO r �FormatRegionrb )r r r r r � s
zFormatRegionTest.setUpClassc C s( | ` | `| `| j�� | j�� | `d S )N)r rb rO r] rc rd )r r r r re � s
zFormatRegionTest.tearDownClassc C s | j �d| j� d S )Nz1.0)r r% �code_sample)r
r r r �setUp� s zFormatRegionTest.setUpc C s | j �dd� d S )Nz1.0r$ )r r* )r
r r r �tearDown� s zFormatRegionTest.tearDowna # WS line needed for test.
class C1():
# Class comment.
def __init__(self, a, b):
self.a = a
self.b = b
def compare(self):
if a > b:
return a
elif a < b:
return b
else:
return None
c C sr | j j}| j}| j}|�ddd� ddddg}||� ddd�|�|f� |�ddd � ||� d
ddddgf� d S )Nrj z7.0z10.0r
z def compare(self):z if a > b:�
z1.0r$ z15.0z16.0)rb �
get_regionr r rk �join�
tag_remove)r
rf r �eqZexpected_linesr r r �test_get_region� s z FormatRegionTest.test_get_regionc
C s& | j j}| j}| j}|j}t�� |_| j�� d }| j�� d }|� ddd� | j �
� \}}} }
|||| |
� |j�� ||�dd�| � ||�dd�| � |�
ddd � d
}|�d�}|dd
| |� ||�dd�|� ||�dd�|� ||�dd�|� ||�dd�|� |�
ddd � ||_d S )Nr; � rj z6.0z11.0z sel.firstzsel.lastz1.0r$ zadded line 1
rz z7.0z10.0z7.0-1cz12.0-1c)rb �
set_regionr r Zbellr ru rw �
splitlinesrk r{ Zassert_called_oncerf r} r) )
r
Zset_r r~ Z save_bellZline6Zline10�head�tail�chars�linesZ newstring�newlinesr r r �test_set_region� s.
z FormatRegionTest.test_set_regionc C s>