HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/idlelib/idle_test/__pycache__/test_format.cpython-310.opt-2.pyc
o

�i:\�@s@	ddlmZddlZddlmZddlmZddlmZm	Z	ddl
mZddlm
ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�d�ZGdd�d�Z
Gdd�dej�ZGdd�d�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zed kr�ejd!d!d"�dSdS)#�)�formatN)�mock)�requires)�Tk�Text)�EditorWindow)�Editorc@s:eZdZ	dZdZdZdZdZdd�Zdd	�Z	d
d�Z
dS)
�Is_Get_Testz# This is a commentzThis is not a commentz# This is a comment   z    # This is a commentz    This is not a commentcCs6|�t�d��|�t�d��|�t�|j��dS)N�z	

)Z
assertTrue�ftZis_all_whiteZassertFalse�test_comment��self�r�:/usr/local/lib/python3.10/idlelib/idle_test/test_format.py�test_is_all_whiteszIs_Get_Test.test_is_all_whitecCsR|j}|t�|j�d�|t�|j�d�|t�|j�d�|t�|j�d�dS)Nr
�    )�assertEqualrZ
get_indentr�trailingws_comment�leadingws_comment�leadingws_nocomment�r�Equalrrr�test_get_indents
zIs_Get_Test.test_get_indentcCsd|j}|t�|j�d�|t�|j�d�|t�|j�d�|t�|j�d�|t�|j�d�dS)N�#�    #rr
)rrZget_comment_headerrrrr�test_nocommentrrrr�test_get_comment_header sz#Is_Get_Test.test_get_comment_headerN)�__name__�
__module__�__qualname__rrrrrrrrrrrrr	sr	c@s2eZdZ	edd��Zdd�Zdd�Zdd�Zd	S)
�FindTestcCsddlm}|�|_dS)Nr)r)Zidlelib.idle_test.mock_tkr�text)�clsrrrr�
setUpClass5szFindTest.setUpClassc	Cs�|j}|�d|�td|�D]*}t|�d|��d�d�}d|d|fD]}d||f}|�t�||�|�q%q|�	dd�dS)	N�1.0�z%d.end�.r�z%d.%d�end)
r"�insert�range�int�index�splitrrZfind_paragraph�delete)	rZ
inserttextZstopline�expectedr"�lineZ
linelength�colZ	tempindexrrr�runcase:s�zFindTest.runcasec
Csd}|�|dddd|dd�f�d}|�|d	d
dd|dd
�f�d}|�|d	d
dd|dd�f�d}|�|dd
dd|dd�f�d}|�|dd
dd|dd�f�d}|�|dd
dd|dd�f�d}|�|dd
dd|dd�f�d}|�|dd
dd|dd�f�dS)Nz;# Comment block with no blank lines before
# Comment line

�r%�3.0rr�:zG
# Comment block with whitespace line before and after
# Comment line

��2.0�4.0r&�FzS
    # Indented comment block with whitespace before and after
    # Comment line

r�Rz
# Single line comment

�z4
    # Single line comment with leading whitespace

�3z0
# Comment immediately followed by code
x = 42

�(z=
    # Indented comment immediately followed by code
x = 42

�5z=
# Comment immediately followed by indented code
    x = 42

�1�r3)r�commentrrr�test_find_commentGs0��������"zFindTest.test_find_commentc
Cs�d}|�|dddd|dd�f�d}|�|d	d
dd|dd
�f�d}|�|d	d
dd|dd�f�d}|�|dd
dd|dd�f�d}|�|dd
dd|dd�f�dS)Nz6"""String with no blank lines before
String line
"""

r7r%r9r
rr?zC
"""String with whitespace line before and after
String line.
"""

�r8z5.0r&�BzV
    """Indented string with whitespace before and after
    Comment string.
    """

r�Uz
"""Single line string."""

r4r5�z8
    """Single line string with leading whitespace."""

�7rA)rZ
teststringrrr�test_find_paragraph}s�����"zFindTest.test_find_paragraphN)rrr �classmethodr$r3rCrIrrrrr!+s	

6r!c@�eZdZ	dd�ZdS)�ReformatFunctionTestcCs�|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
�dS)Nz
O hello world� r&zHello    world�zHello  worldz
O
hello
world��z
O hello
world��
z
O hello worldz
O
hello
worldz
O hello
world)rrZreformat_paragraph)rrZreformZhwrrr�test_reformat_paragraph�s z,ReformatFunctionTest.test_reformat_paragraphN)rrr rSrrrrrL��rLc@rK)�ReformatCommentTestcCsJ|j}d}t�|dd�}d}|||�d}t�|dd�}d}|||�dS)Nzu    """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r:rzy    """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?rzo# this is a test of a reformat for a triple quoted string will it
# reformat to less than 70 characters for me?)rrZreformat_comment)rr�test_string�resultr0rrrr�test_reformat_comment�s��
��z)ReformatCommentTest.test_reformat_commentN)rrr rXrrrrrU�rTrUc@seZdZdd�ZdS)�FormatClassTestcCs2t�d�}|�|jd�|��|�|jd�dS)N�editor)r�FormatParagraphrZeditwin�close)r�instancerrr�test_init_close�s
zFormatClassTest.test_init_closeN)rrr r^rrrrrY�srYc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TextWrappercCst|d�|_dS)N)�master)rr")rr`rrr�__init__�szTextWrapper.__init__cCst|j|�S�N)�getattrr")r�namerrr�__getattr__�szTextWrapper.__getattr__cC�dSrbrr
rrr�undo_block_start��zTextWrapper.undo_block_startcCrfrbrr
rrr�undo_block_stop�rhzTextWrapper.undo_block_stopN)rrr rarergrirrrrr_�s
r_c@seZdZdd�ZejZdS)rcCst|�|_dSrb)r_r")r�rootrrrra�szEditor.__init__N)rrr rar�get_selection_indicesrrrrr�s
rc@sReZdZ	dZdZdZedd��Zedd��Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�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.cCsBtd�t�|_|j��t|jd�}|jj|_t�|�j|_	dS)N�gui)rj)
rrrj�withdrawrr"rr[Zformat_paragraph_event�	formatter)r#rZrrrr$s

zFormatEventTest.setUpClasscCs$|`|`|j��|j��|`dSrb)r"rorj�update_idletasks�destroy�r#rrr�
tearDownClasss

zFormatEventTest.tearDownClasscCs@|j�dd�|�d�|�|j�dd�d�|j�dd�dS)Nr%zShort line
ZDummyr*r))r"r*ror�getr/r
rrr�test_short_line s
zFormatEventTest.test_short_linecCs�|j}|�d|j�|�dd�|jddd�|�dd�}d}|�||�|�dd�|�d|j�|�dd	d
�|jddd�|�dd�}d}|�||�|�dd�dS)Nr%r*�ParameterDoesNothingr:��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*rVZmark_setrortrr/�tag_add�rr"rWr0rrr�test_long_line&s"��zFormatEventTest.test_long_linecCs\|j}|�d|j�|�ddd�|jddd�|�dd�}d	}|�||�|�dd
�dS)Nr%ryr8r9rvr:rwr*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_stringrzrortrr/r{rrr�test_multiple_linesAs�z#FormatEventTest.test_multiple_linescCs�|j}|�d|j�|jddd�|�dd�}d}|�||�|�dd�|�d|j�|�dd	d
�|jddd�|�dd�}d}|�||�|�dd�dS)Nr%rvr:rwr*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)ryr8r5z�# 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_commentrortrr/rzr{rrr�test_comment_blockPs ��z"FormatEventTest.test_comment_blockN)
rrr rVr}rrJr$rsrur|r~r�rrrrrl�s ���
	
rlc@s eZdZdd�ZejZejZdS)�DummyEditwincCs(||_||_d|_d|_d|_d|_dS)Nr7FT)rjr"�indentwidthZtabwidth�usetabsZcontext_use_ps1)rrjr"rrrra}s
zDummyEditwin.__init__N)rrr rarZ_make_blanksrkrrrrr�|s
r�c@s�eZdZedd��Zedd��Zdd�Zdd�Zd	Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zej�ejd�dd��Zej�ejd�dd��Zej�ed�dd��ZdS)�FormatRegionTestcCs`td�t�|_|j��t|j�|_t��|j_t��|j_	t
|j|j�|_t�
|j�|_dS)Nrm)rrrjrnrr"r�Mockrgrir�rZr�FormatRegionrorrrrrr$�s
zFormatRegionTest.setUpClasscC�(|`|`|`|j��|j��|`dSrb)r"rorZrjrprqrrrrrrs��

zFormatRegionTest.tearDownClasscCs|j�d|j�dS)Nr%)r"r*�code_sampler
rrr�setUp�szFormatRegionTest.setUpcC�|j�dd�dS)Nr%r)�r"r/r
rrr�tearDown��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
cCsn|jj}|j}|j}|�ddd�gd�}||�ddd�|�|f�|�ddd�||�dd	dd
d
gf�dS)Nry�7.0�10.0)r
z    def compare(self):z        if a > b:r
�
r%r)z15.0z16.0r
)ro�
get_regionr"rrz�join�
tag_remove)rrtr"�eqZexpected_linesrrr�test_get_region�sz FormatRegionTest.test_get_regionc
Cs&|jj}|j}|j}|j}t��|_|j��d}|j��d}|�	ddd�|j�
�\}}}	}
||||	|
�|j��||�dd�|	�||�dd�|	�|�
ddd	�d
}|�d�}|dd
|	|�||�dd�|�||�dd�|�||�dd�|�||�dd�|�|�
ddd	�||_dS)NrD�	ryz6.0z11.0z	sel.firstzsel.lastr%r)zadded line 1



r�r�r�z7.0-1cz12.0-1c)ro�
set_regionr"rZbellrr�r��
splitlinesrzr�Zassert_called_oncertr�r.)
rZset_r"r�Z	save_bellZline6Zline10�head�tail�chars�linesZ	newstring�newlinesrrr�test_set_region�s.



z FormatRegionTest.test_set_regioncC�>|jj}|j}|j}|�ddd�|�||�dd�d�dS)Nryr�r�z2
        def compare(self):
            if a > b:
)roZindent_region_eventr"rrzrt)r�indentr"r�rrr�test_indent_region_event��z)FormatRegionTest.test_indent_region_eventcCr�)Nryr�r�z"
def compare(self):
    if a > b:
)roZdedent_region_eventr"rrzrt)r�dedentr"r�rrr�test_dedent_region_event�r�z)FormatRegionTest.test_dedent_region_eventcCr�)Nryr�r�z0##
##    def compare(self):
##        if a > b:
)ro�comment_region_eventr"rrzrt)rrBr"r�rrr�test_comment_region_event�sz*FormatRegionTest.test_comment_region_eventcCs�|jj}|jj}|j}|j}|�ddd�|�|�||�dd�d�|�ddd�|�ddd�|�||�dd	�d
�|j�dddddg�|�||�dd	�d
�dS)Nryr�r�z*
    def compare(self):
        if a > b:
r%r)r5r9z3.endz    # Class comment.r
z# Class comment.z Class comment.)	ror�Zuncomment_region_eventr"rrzrtr�r�)rrBZ	uncommentr"r�rrr�test_uncomment_region_eventsz,FormatRegionTest.test_uncomment_region_event�_asktabwidthcCs\|jj}|j}|j}|�ddd�d|_|�|��d|_|�|��||�dd�d�dS)Nryr�r�r4z$
	 def compare(self):
		  if a > b:
)	ro�tabify_region_eventr"rrz�return_value�assertIsNone�assertIsNotNonert)rr�Ztabifyr"r�rrr�test_tabify_region_eventsz)FormatRegionTest.test_tabify_region_eventcCsl|jj}|j}|j}|�ddd�d|_|�|��d|_|j��d|_|�|��||�	dd�d�dS)Nryr�r�r(r4z0
      def compare(self):
            if a > b:
)
roZuntabify_region_eventr"rrzr�r�r�r�rt)rr�Zuntabifyr"r�rrr�test_untabify_region_event)s
z+FormatRegionTest.test_untabify_region_event�
askintegercCs |jj}d|_|�|�d�dS)N�
)ror�r�r)rr�Zaskrrr�test_ask_tabwidth:sz"FormatRegionTest.test_ask_tabwidthN)rrr rJr$rsr�r�r�r�r�r�r�r�r�r�patch�objectrr�r�r�r�rrrrr��s(


#

	

r�c@s8eZdZej�ed�dd��Zej�ed�dd��ZdS)�IndentsTest�askyesnocCsjtdd�}t�|�}d|_|�d�|�|jd�|�|jd�|�d�|�|jd�|�|jd�dS)NT�F)r�r�Indentsr�Ztoggle_tabs_eventrr�r�)rr�rZ�indentsrrr�test_toggle_tabsCs



zIndentsTest.test_toggle_tabsr�cCsxtdd�}t�|�}d|_|�d�|�|jd�d|_|�d�|�|jd�d|_d|_|�d�|�|jd�dS)Nr7r4rDT)r�rr�r�Zchange_indentwidth_eventrr�r�)rr�rZr�rrr�test_change_indentwidthQs




z#IndentsTest.test_change_indentwidthN)	rrr rr�r�rr�r�rrrrr�As


r�c@s<eZdZedd��Zedd��Zdd�Zdd�Zd	d
�ZdS)�
RstripTestcCsHtd�t�|_|j��t|j�|_t|jd�|_t�	|j�j
|_
dS)Nrm)r")rrrjrnrr"�
MockEditorrZrZRstrip�	do_rstriprrrrrr$fs
zRstripTest.setUpClasscCr�rb)r"r�rZrjrprqrrrrrrsor�zRstripTest.tearDownClasscCr�)Nr%�end-1cr�r
rrrr�vr�zRstripTest.tearDowncCs8d}d}|j�d|�|��|�|j�dd�|�dS)Nz�Line with an ending tab    
Line ending in 5 spaces     
Linewithnospaces
    indented line
    indented line with trailing space 
    
zyLine with an ending tab
Line ending in 5 spaces
Linewithnospaces
    indented line
    indented line with trailing space
r%r*)r"r*r�rrt)rZoriginal�strippedrrr�test_rstrip_linesys��zRstripTest.test_rstrip_linesc	Cs�|j}dD],}|j|d��|�d|�|��|�|�dd�d�Wd�n1s,wYqdD]2}|j|d��"|�dd�|�d|�|��|�|�dd�d�Wd�n1sawYq4dS)N)r
r�z


)�coder%r�r
)�a
za

za


r�)r"ZsubTestr*r�rrtr/)rr"r�rrr�test_rstrip_end�s"�����zRstripTest.test_rstrip_endN)	rrr rJr$rsr�r�r�rrrrr�ds

r��__main__r()�	verbosity�exit)ZidlelibrrZunittestrZtest.supportr�tkinterrrZidlelib.editorrZidlelib.idle_test.mock_idlerr�ZTestCaser	r!rLrUrYr_rlr�r�r�r�r�mainrrrr�<module>s2w
9#7�