B YI~d<\�@s<ddlmZddlZddlmZddlmZddlmZm Z ddl m Z ddl m ZGdd �d ej�ZGd d �d ej�ZGd d �d ej�ZGdd�dej�ZGdd�dej�ZGdd�d�ZGdd�d�Z Gdd�dej�ZGdd�d�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zed k�r8ejd!d!d"�dS)#�)�formatN)�mock)�requires)�Tk�Text)� EditorWindow)�Editorc@s8eZdZdZdZdZdZdZdd�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_whiteZ assertFalse� test_comment)�self�r�B/opt/alt/python37/lib64/python3.7/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 z )� assertEqualr Z 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�#z #z r )rr Zget_comment_headerr rrr�test_nocomment)r rrrr�test_get_comment_header s z#Is_Get_Test.test_get_comment_headerN) �__name__� __module__� __qualname__r rrrrrrrrrrrr sr c@s0eZdZedd��Zdd�Zdd�Zdd�Zd S) �FindTestcCsddlm}|�|_dS)Nr)r)Zidlelib.idle_test.mock_tkr�text)�clsrrrr� setUpClass5s zFindTest.setUpClassc Cs�|j}|�d|�xftd|�D]X}t|�d|��d�d�}x6d|d|fD]$}d||f}|�t�||�|�qNWqW|� dd�dS) Nz1.0�z%d.end�.r�z%d.%d�end) r�insert�range�int�index�splitrr Zfind_paragraph�delete) r Z inserttextZstopline�expectedr�lineZ linelength�colZ tempindexrrr�runcase:s  zFindTest.runcasec Csd}|�|dddd|dd�f�d}|�|d d d d|d d �f�d}|�|d d d d|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 �z1.0z3.0rr�:zG # Comment block with whitespace line before and after # Comment line �z2.0z4.0r!�FzS # Indented comment block with whitespace before and after # Comment line z #�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)r.)r �commentrrr�test_find_commentGs zFindTest.test_find_commentc Cs�d}|�|dddd|dd�f�d}|�|d d d d|d d �f�d}|�|d d d d|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 """ r1z1.0z4.0r rr7zC """String with whitespace line before and after String line. """ �z2.0z5.0r!�BzV """Indented string with whitespace before and after Comment string. """ z �Uz """Single line string.""" r/z3.0�z8 """Single line string with leading whitespace.""" �7)r.)r Z teststringrrr�test_find_paragraph}szFindTest.test_find_paragraphN)rrr� classmethodr r.r:r@rrrrr+s  6rc@seZdZdd�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)rr Zreformat_paragraph)r rZreformZhwrrr�test_reformat_paragraph�s z,ReformatFunctionTest.test_reformat_paragraphN)rrrrIrrrrrB�srBc@seZdZdd�ZdS)�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?"""r2z 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?rzo# this is a test of a reformat for a triple quoted string will it # reformat to less than 70 characters for me?)rr Zreformat_comment)r r� test_string�resultr+r rrr�test_reformat_comment�s z)ReformatCommentTest.test_reformat_commentN)rrrrMrrrrrJ�srJc@seZdZdd�ZdS)�FormatClassTestcCs2t�d�}|�|jd�|��|�|jd�dS)N�editor)r �FormatParagraphrZeditwin�close)r �instancerrr�test_init_close�s zFormatClassTest.test_init_closeN)rrrrSrrrrrN�srNc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) � TextWrappercCst|d�|_dS)N)�master)rr)r rUrrr�__init__�szTextWrapper.__init__cCs t|j|�S)N)�getattrr)r �namerrr� __getattr__�szTextWrapper.__getattr__cCsdS)Nr)r rrr�undo_block_start��zTextWrapper.undo_block_startcCsdS)Nr)r rrr�undo_block_stop�r[zTextWrapper.undo_block_stopN)rrrrVrYrZr\rrrrrT�srTc@seZdZdd�ZejZdS)rcCst|�|_dS)N)rTr)r �rootrrrrV�szEditor.__init__N)rrrrVr�get_selection_indicesrrrrr�src@sPeZdZdZdZdZedd��Zedd��Zdd �Z d d �Z d d �Z dd�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)r]) rrr]�withdrawrrr rPZformat_paragraph_event� formatter)rrOrrrr s    zFormatEventTest.setUpClasscCs$|`|`|j��|j��|`dS)N)rrbr]�update_idletasks�destroy)rrrr� tearDownClasss  zFormatEventTest.tearDownClasscCs@|j�dd�|�d�|�|j�dd�d�|j�dd�dS)Nz1.0z Short line ZDummyr%r$)rr%rbr�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) 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?''') rr%rKZmark_setrbrfrr*�tag_add)r rrLr+rrr�test_long_line&s      zFormatEventTest.test_long_linecCs\|j}|�d|j�|�ddd�|jddd�|�dd�}d }|�||�|�dd �dS) Nz1.0rjz2.0z4.0rhr2)rir%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$)rr%�multiline_test_stringrkrbrfrr*)r rrLr+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) Nz1.0rhr2)rir%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$rjz2.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. )rr%�multiline_test_commentrbrfrr*rk)r rrLr+rrr�test_comment_blockPs     z"FormatEventTest.test_comment_blockN) rrrrKrmrorAr rergrlrnrprrrrr_�s r_c@s eZdZdd�ZejZejZdS)� DummyEditwincCs(||_||_d|_d|_d|_d|_dS)Nr1FT)r]r� indentwidthZtabwidth�usetabsZcontext_use_ps1)r r]rrrrrV}s zDummyEditwin.__init__N)rrrrVrZ _make_blanksr^rrrrrq|srqc@s�eZdZedd��Zedd��Zdd�Zdd�Zd Zd d �Z d d �Z dd�Z dd�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)Nr`)rrr]rarrr�MockrZr\rqrOr � FormatRegionrb)rrrrr �s    zFormatRegionTest.setUpClasscCs(|`|`|`|j��|j��|`dS)N)rrbrOr]rcrd)rrrrre�s   zFormatRegionTest.tearDownClasscCs|j�d|j�dS)Nz1.0)rr%� code_sample)r rrr�setUp�szFormatRegionTest.setUpcCs|j�dd�dS)Nz1.0r$)rr*)r rrr�tearDown�szFormatRegionTest.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 cCsr|jj}|j}|j}|�ddd�ddddg}||�ddd�|�|f�|�ddd �||�d d dddgf�dS) Nrjz7.0z10.0r z def compare(self):z if a > b:� z1.0r$z15.0z16.0)rb� get_regionrrrk�join� tag_remove)r rfr�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)Nr;� rjz6.0z11.0z sel.firstzsel.lastz1.0r$zadded line 1 rzz7.0z10.0z7.0-1cz12.0-1c)rb� set_regionrrZbellrrurw� splitlinesrkr{Zassert_called_oncerfr}r)) r Zset_rr~Z save_bellZline6Zline10�head�tail�chars�linesZ newstring�newlinesrrr�test_set_region�s.   z FormatRegionTest.test_set_regioncCs>|jj}|j}|j}|�ddd�|�||�dd�d�dS)Nrjz7.0z10.0z2 def compare(self): if a > b: )rbZindent_region_eventrrrkrf)r �indentrr~rrr�test_indent_region_event�s z)FormatRegionTest.test_indent_region_eventcCs>|jj}|j}|j}|�ddd�|�||�dd�d�dS)Nrjz7.0z10.0z" def compare(self): if a > b: )rbZdedent_region_eventrrrkrf)r �dedentrr~rrr�test_dedent_region_event�s z)FormatRegionTest.test_dedent_region_eventcCs>|jj}|j}|j}|�ddd�|�||�dd�d�dS)Nrjz7.0z10.0z0## ## def compare(self): ## if a > b: )rb�comment_region_eventrrrkrf)r r9rr~rrr�test_comment_region_event�s z*FormatRegionTest.test_comment_region_eventcCs�|jj}|jj}|j}|j}|�ddd�|�|�||�dd�d�|�ddd�|�ddd�|�||�dd �d �|j�ddd d d g�|�||�dd �d �dS)Nrjz7.0z10.0z* def compare(self): if a > b: z1.0r$z3.0z4.0z3.endz # Class comment.r z# Class comment.z Class comment.) rbr�Zuncomment_region_eventrrrkrfr}r�)r r9Z uncommentrr~rrr�test_uncomment_region_eventsz,FormatRegionTest.test_uncomment_region_event� _asktabwidthcCs\|jj}|j}|j}|�ddd�d|_|�|��d|_|�|��||�dd�d�dS)Nrjz7.0z10.0r/z$ def compare(self): if a > b: ) rb�tabify_region_eventrrrk� return_value� assertIsNone�assertIsNotNonerf)r r�Ztabifyrr~rrr�test_tabify_region_events  z)FormatRegionTest.test_tabify_region_eventcCsl|jj}|j}|j}|�ddd�d|_|�|��d|_|j��d|_|�|��||� dd�d�dS)Nrjz7.0z10.0r#r/z0 def compare(self): if a > b: ) rbZuntabify_region_eventrrrkr�r�r�r�rf)r r�Zuntabifyrr~rrr�test_untabify_region_event)s   z+FormatRegionTest.test_untabify_region_event� askintegercCs |jj}d|_|�|�d�dS)N� )rbr�r�r)r r�Zaskrrr�test_ask_tabwidth:sz"FormatRegionTest.test_ask_tabwidthN)rrrrAr rerxryrwrr�r�r�r�r�r�patch�objectr rvr�r�r�rrrrrt�s #   rtc@s8eZdZej�ed�dd��Zej�ed�dd��ZdS)� IndentsTest�askyesnocCsjtdd�}t�|�}d|_|�d�|�|jd�|�|jd�|�d�|�|jd�|�|jd�dS)NT�F)rqr �Indentsr�Ztoggle_tabs_eventrrsrr)r r�rO�indentsrrr�test_toggle_tabsCs    zIndentsTest.test_toggle_tabsr�cCsxtdd�}t�|�}d|_|�d�|�|jd�d|_|�d�|�|jd�d|_d|_|�d�|�|jd�dS)Nr1r/r;T)rqr r�r�Zchange_indentwidth_eventrrrrs)r r�rOr�rrr�test_change_indentwidthQs     z#IndentsTest.test_change_indentwidthN) rrrrr�r�r r�r�rrrrr�Asr�c@s<eZdZedd��Zedd��Zdd�Zdd�Zd d �Zd S) � RstripTestcCsHtd�t�|_|j��t|j�|_t|jd�|_t� |j�j |_ dS)Nr`)r) rrr]rarr� MockEditorrOr ZRstrip� do_rstrip)rrrrr fs   zRstripTest.setUpClasscCs(|`|`|`|j��|j��|`dS)N)rr�rOr]rcrd)rrrrreos   zRstripTest.tearDownClasscCs|j�dd�dS)Nz1.0zend-1c)rr*)r rrrryvszRstripTest.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 z1.0r%)rr%r�rrf)r Zoriginal�strippedrrr�test_rstrip_linesys zRstripTest.test_rstrip_linesc Cs�|j}xLdD]D}|j|d��.|�d|�|��|�|�dd�d�WdQRXq WxXdD]P}|j|d��:|�dd�|�d|�|��|�|�dd�d�WdQRXqZWdS)N)r rzz )�codez1.0zend-1cr )za za za za )rZsubTestr%r�rrfr*)r rr�rrr�test_rstrip_end�s  "   zRstripTest.test_rstrip_endN) rrrrAr reryr�r�rrrrr�ds  r��__main__r#)� verbosity�exit)Zidlelibrr ZunittestrZ test.supportrZtkinterrrZidlelib.editorrZidlelib.idle_test.mock_idlerr�ZTestCaser rrBrJrNrTr_rqrtr�r�r�mainrrrr�s,     w 9#7