
    z%i:\                     F   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ  G d	 d
ej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d d      Z G d d      Z G d dej                         Z G d d      Z G d dej                         Z G d dej                         Z G d d ej                         Zed!k(  r ej:                  d"d"#       yy)$zTest format, coverage 99%.    )formatN)mock)requires)TkText)EditorWindow)Editorc                   6    e Zd ZdZdZdZdZdZdZd Z	d Z
d	 Zy
)Is_Get_TestzTest the is_ and get_ functionsz# This is a commentzThis is not a commentz# This is a comment   z    # This is a commentz    This is not a commentc                     | j                  t        j                  d             | j                  t        j                  d             | j                  t        j                  | j                               y )N z	
)
assertTrueftis_all_whiteassertFalsetest_commentselfs    Q/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_format.pytest_is_all_whitezIs_Get_Test.test_is_all_white   sI    +,56):):;<    c                 L   | j                   } |t        j                  | j                        d        |t        j                  | j                        d        |t        j                  | j
                        d        |t        j                  | j                        d       y )Nr       )assertEqualr   
get_indentr   trailingws_commentleadingws_commentleadingws_nocommentr   Equals     r   test_get_indentzIs_Get_Test.test_get_indent   sq      bmmD--.3bmmD334b9bmmD223V<bmmD445v>r   c                    | j                   } |t        j                  | j                        d        |t        j                  | j                        d        |t        j                  | j
                        d        |t        j                  | j                        d        |t        j                  | j                        d       y )N#    #r   r   )r   r   get_comment_headerr   r   r   r   test_nocommentr   s     r   test_get_comment_headerz#Is_Get_Test.test_get_comment_header    s      b##D$5$56<b##D$;$;<cBb##D$:$:;WEb##D$<$<=vFb##D$7$78"=r   N)__name__
__module____qualname____doc__r   r&   r   r   r   r   r!   r'    r   r   r   r      s0    )(L,N115=
?>r   r   c                   2    e Zd ZdZed        Zd Zd Zd Zy)FindTestaa  Test the find_paragraph function in paragraph module.

    Using the runcase() function, find_paragraph() is called with 'mark' set at
    multiple indexes before and inside the test paragraph.

    It appears that code with the same indentation as a quoted string is grouped
    as part of the same paragraph, which is probably incorrect behavior.
    c                 (    ddl m}  |       | _        y )Nr   )r   )idlelib.idle_test.mock_tkr   text)clsr   s     r   
setUpClasszFindTest.setUpClass5   s    26r   c                 X   | j                   }|j                  d|       t        d|      D ]k  }t        |j	                  d|z        j                  d      d         }d|dz  |fD ]/  }d||fz  }| j                  t        j                  ||      |       1 m |j                  dd       y )	N1.0   z%d.end.r      z%d.%dend)
r1   insertrangeintindexsplitr   r   find_paragraphdelete)	r   
inserttextstoplineexpectedr1   line
linelengthcol	tempindexs	            r   runcasezFindTest.runcase:   s     yyE:&!X& 	ODTZZ48>>sCAFGJ:q=*5 O#tSk1	  !2!24!CXNO	O
 	E5!r   c           
         d}| j                  |dddd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       y )Nz;# Comment block with no blank lines before
# Comment line

   r5   3.0r#   r   :   zG
# Comment block with whitespace line before and after
# Comment line

   2.04.0r6   F   zS
    # Indented comment block with whitespace before and after
    # Comment line

r$   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   rH   )r   comments     r   test_find_commentzFindTest.test_find_commentG   sZ    	 	Wa%WQr]!CD 	
 	Wa%WQr]!CD 	
 	Wa%2!GH 	 	Wa%WQr]!CD 	 	Wa%2!GH 	
 	Wa%WQr]!CD 	
 	Wa%2!GH 	
 	Wa%WQr]!CDr   c           
         d}| j                  |dddd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |d	d
dd|dd f       d}| j                  |dd
dd|dd f       d}| j                  |dd
dd|dd f       y )Nz6"""String with no blank lines before
String line
"""

rM   r5   rO   r   r   rU   zC
"""String with whitespace line before and after
String line.
"""

   rN   z5.0r6   B   zV
    """Indented string with whitespace before and after
    Comment string.
    """

r   U   z
"""Single line string."""

rJ   rK      z8
    """Single line string with leading whitespace."""

7   rW   )r   
teststrings     r   test_find_paragraphzFindTest.test_find_paragraph}   s     	
 	ZUE2z!B7G$HI 	 	ZUE2z!B7G$HI 	 	ZUE6:a;K$LM 	 	ZUE2z!B7G$HI 	 	ZUE6:a;K$LMr   N)	r(   r)   r*   r+   classmethodr3   rH   rY   ra   r,   r   r   r.   r.   +   s-      "4El"Nr   r.   c                       e Zd ZdZd Zy)ReformatFunctionTestz?Test the reformat_paragraph function without the editor window.c                    | j                   }t        j                  }d} | |dd      d        | |dd      d        | ||d      d        | ||d      d        | ||d	      d
        | ||d      d
        | ||d      d       d} | ||d      d        | ||d      d        | ||d	      d        | ||d      d        | ||d      d       y )NzO hello world r6   zHello    world   zHello  worldzO
hello
world      zO hello
world      z
O hello worldz
O
hello
worldz
O hello
world)r   r   reformat_paragraph)r   r    reformhws       r   test_reformat_paragraphz,ReformatFunctionTest.test_reformat_paragraph   s      &&fS!nc"f%r*N; 	fRm./fRm./fRm-.fRn./fRno. fRm01fRm01fRm/0fRn01fRn/0r   N)r(   r)   r*   r+   ro   r,   r   r   rd   rd      s
    I1r   rd   c                       e Zd ZdZd Zy)ReformatCommentTestz=Test the reformat_comment function without the editor window.c                     | j                   }d}t        j                  |dd      }d} |||       d}t        j                  |dd      }d} |||       y )Nzu    """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""rP   r   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   reformat_comment)r   r    test_stringresultrC   r   s         r   test_reformat_commentz)ReformatCommentTest.test_reformat_comment   s{      I 	 $$["f=D 	 	fh= 	 $$\2s;< 	 	fhr   N)r(   r)   r*   r+   rv   r,   r   r   rq   rq      s
    G r   rq   c                       e Zd Zd Zy)FormatClassTestc                     t        j                  d      }| j                  |j                  d       |j	                          | j                  |j                  d        y )Neditor)r   FormatParagraphr   editwinclose)r   instances     r   test_init_closezFormatClassTest.test_init_close   sH    %%h/))84))40r   N)r(   r)   r*   r   r,   r   r   rx   rx      s    1r   rx   c                   $    e Zd Zd Zd Zd Zd Zy)TextWrapperc                 &    t        |      | _        y )N)master)r   r1   )r   r   s     r   __init__zTextWrapper.__init__   s    '	r   c                 .    t        | j                  |      S N)getattrr1   )r   names     r   __getattr__zTextWrapper.__getattr__   s    tyy$''r   c                      y r   r,   r   s    r   undo_block_startzTextWrapper.undo_block_start       r   c                      y r   r,   r   s    r   undo_block_stopzTextWrapper.undo_block_stop   r   r   N)r(   r)   r*   r   r   r   r   r,   r   r   r   r      s    (($#r   r   c                   *    e Zd Zd Zej
                  Zy)r	   c                 $    t        |      | _        y r   )r   r1   )r   roots     r   r   zEditor.__init__   s    %	r   N)r(   r)   r*   r   r   get_selection_indicesr,   r   r   r	   r	      s    &(??r   r	   c                   T    e Zd ZdZdZdZdZed        Zed        Z	d Z
d Zd	 Zd
 Zy)FormatEventTestzTest the formatting of text inside a Text widget.

    This is done with FormatParagraph.format.paragraph_event,
    which calls functions in the module as appropriate.
    zv    '''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                    t        d       t               | _        | j                  j                          t	        | j                        }|j
                  j
                  | _        t        j                  |      j                  | _	        y )Ngui)r   )
r   r   r   withdrawr	   r1   r   r{   format_paragraph_event	formatter)r2   rz   s     r   r3   zFormatEventTest.setUpClass  sY    4SXX&;;##**62IIr   c                 x    | ` | `| j                  j                          | j                  j	                          | `y r   )r1   r   r   update_idletasksdestroyr2   s    r   tearDownClasszFormatEventTest.tearDownClass  s0    Hcm!!#Hr   c                     | j                   j                  dd       | j                  d       | j                  | j                   j	                  dd      d       | j                   j                  dd       y )Nr5   zShort line
Dummyr:   r9   )r1   r:   r   r   getr@   r   s    r   test_short_linezFormatEventTest.test_short_line   sU    		/wuh7I		&r   c                    | j                   }|j                  d| j                         |j                  dd       | j	                  dd       |j                  dd      }d}| j                  ||       |j                  dd       |j                  d| j                         |j                  dd	d
       | j	                  dd       |j                  dd      }d}| j                  ||       |j                  dd       y )Nr5   r:   ParameterDoesNothingrP   limitzz    '''this is a test of a reformat for a triple quoted string will it
    reformat to less than 70 characters for me?'''
r9   selz1.11z1.endzv    '''this is a test of a reformat for a triple quoted string will it reformat
 to less than 70 characters for me?''')	r1   r:   rt   mark_setr   r   r   r@   tag_addr   r1   ru   rC   s       r   test_long_linezFormatEventTest.test_long_line&  s    yy 	E4++,h&-R8%*7 	 	*E5! 	E4++,UFG,-R8%*) 	 	*E5!r   c                    | j                   }|j                  d| j                         |j                  ddd       | j	                  dd       |j                  dd      }d	}| j                  ||       |j                  dd
       y )Nr5   r   rN   rO   r   rP   r   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.
r9   )r1   r:   multiline_test_stringr   r   r   r   r@   r   s       r   test_multiple_linesz#FormatEventTest.test_multiple_linesA  sz    yyE4556UE5)-R8%* 	
 	*E5!r   c                    | j                   }|j                  d| j                         | j                  dd       |j	                  dd      }d}| j                  ||       |j                  dd       |j                  d| j                         |j                  dd	d
       | j                  dd       |j	                  dd      }d}| j                  ||       |j                  dd       y )Nr5   r   rP   r   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.
r9   r   rN   rK   z# 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.
)r1   r:   multiline_test_commentr   r   r   r@   r   r   s       r   test_comment_blockz"FormatEventTest.test_comment_blockP  s    yy 	E4667-R8%*! 	 	*E5! 	E4667UE5)-R8%*/ 	 	*E5!r   N)r(   r)   r*   r+   rt   r   r   rb   r3   r   r   r   r   r   r,   r   r   r   r      sc    	" 
	 	:  J J  '"6""r   r   c                   B    e Zd Zd Zej
                  Zej                  Zy)DummyEditwinc                 X    || _         || _        d| _        d| _        d| _        d| _        y )NrM   FT)r   r1   indentwidthtabwidthusetabscontext_use_ps1)r   r   r1   s      r   r   zDummyEditwin.__init__}  s.    		#r   N)r(   r)   r*   r   r   _make_blanksr   r,   r   r   r   r   |  s     $  ,,L(>>r   r   c                   T   e Zd Zed        Zed        Zd Zd ZdZd Z	d Z
d Zd	 Zd
 Zd Zej                   j#                  ej&                  d      d        Zej                   j#                  ej&                  d      d        Zej                   j#                  ed      d        Zy)FormatRegionTestc                    t        d       t               | _        | j                  j                          t	        | j                        | _        t        j                         | j
                  _        t        j                         | j
                  _	        t        | j                  | j
                        | _        t        j                  | j                        | _        y )Nr   )r   r   r   r   r   r1   r   Mockr   r   r   rz   r   FormatRegionr   r   s    r   r3   zFormatRegionTest.setUpClass  s    4>$(IIK!#'99; !#((CHH5


3r   c                 |    | ` | `| `| j                  j	                          | j                  j                          | `y r   )r1   r   rz   r   r   r   r   s    r   r   zFormatRegionTest.tearDownClass  4    HcmSZ!!#Hr   c                 P    | j                   j                  d| j                         y )Nr5   )r1   r:   code_sampler   s    r   setUpzFormatRegionTest.setUp  s    		 0 01r   c                 <    | j                   j                  dd       y )Nr5   r9   r1   r@   r   s    r   tearDownzFormatRegionTest.tearDown  s    		&r   a  # 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                    | j                   j                  }| j                  }| j                  }|j	                  ddd       g d} | |       dddj                  |      |f       |j                  ddd        | |       dd	dd
d
gf       y )Nr   7.010.0)r   z    def compare(self):z        if a > b:r   
r5   r9   z15.0z16.0r   )r   
get_regionr1   r   r   join
tag_remove)r   r   r1   eqexpected_liness        r   test_get_regionz FormatRegionTest.test_get_region  s    nn''yy 	UE6* 	355&$))N";^LM 	ue,
35664"b23r   c                    | j                   j                  }| j                  }| j                  }|j                  }t        j                         |_        | j                  j                         d   }| j                  j                         d   }|j                  ddd       | j                   j                         \  }}}	}
 ||||	|
       |j                  j                           ||j                  dd      |	        ||j                  dd      |	       |j                  ddd	       d
}|j                  d      } |dd|	|        ||j                  dd      |        ||j                  dd      |        ||j                  dd      |        ||j                  dd      |       |j                  ddd	       ||_        y )Nr[   	   r   z6.0z11.0z	sel.firstzsel.lastr5   r9   zadded line 1



r   r   r   z7.0-1cz12.0-1c)r   
set_regionr1   r   bellr   r   r   
splitlinesr   r   assert_called_oncer   r   r>   )r   set_r1   r   	save_bellline6line10headtailcharslines	newstringnewliness                r   test_set_regionz FormatRegionTest.test_set_region  s   ~~((yyII	IIK	  ++-a0!!,,.q1UE6*#'>>#<#<#> dE5 	T4&		$$&
488E6"E*
488K,e4ue, +	??4(UFE8,
488K,i8
488E6"I.
488E8$e,
488FI&/ue,	r   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z2
        def compare(self):
            if a > b:
)r   indent_region_eventr1   r   r   r   )r   indentr1   r   s       r   test_indent_region_eventz)FormatRegionTest.test_indent_region_event  sP    33yyUE6*
488E6"%\^r   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z"
def compare(self):
    if a > b:
)r   dedent_region_eventr1   r   r   r   )r   dedentr1   r   s       r   test_dedent_region_eventz)FormatRegionTest.test_dedent_region_event  sP    33yyUE6*
488E6"%LNr   c                     | j                   j                  }| j                  }| j                  }|j	                  ddd        |         ||j                  dd      d       y )Nr   r   r   z0##
##    def compare(self):
##        if a > b:
)r   comment_region_eventr1   r   r   r   )r   rX   r1   r   s       r   test_comment_region_eventz*FormatRegionTest.test_comment_region_event  sP    ..55yyUE6*	
488E6"%Z\r   c                    | j                   j                  }| j                   j                  }| j                  }| j                  }|j                  ddd        |         |         ||j                  dd      d       |j                  ddd       |j                  ddd        |         ||j                  dd	      d
       | j                   j                  dddddg        |         ||j                  dd	      d       y )Nr   r   r   z*
    def compare(self):
        if a > b:
r5   r9   rK   rO   z3.endz    # Class comment.r   z# Class comment.z Class comment.)	r   r   uncomment_region_eventr1   r   r   r   r   r   )r   rX   	uncommentr1   r   s        r   test_uncomment_region_eventz,FormatRegionTest.test_uncomment_region_event  s    ..55NN99	yyUE6*	
488E6"%TV 	ue,UE5)
488E7#&<>!!%5G4LM
488E7#&79r   _asktabwidthc                 ,   | j                   j                  }| j                  }| j                  }|j	                  ddd       d |_        | j                   |              d|_        | j                   |               ||j                  dd      d       y )Nr   r   r   rJ   z$
	 def compare(self):
		  if a > b:
)	r   tabify_region_eventr1   r   r   return_valueassertIsNoneassertIsNotNoner   )r   r   tabifyr1   r   s        r   test_tabify_region_eventz)FormatRegionTest.test_tabify_region_event  s{    33yyUE6*$(!&(#$%!VX&
488E6"%QSr   c                 n   | j                   j                  }| j                  }| j                  }|j	                  ddd       d |_        | j                   |              d|_        | j                   j                          d|_        | j                   |               ||j                  dd      d       y )Nr   r   r   r8   rJ   z0
      def compare(self):
            if a > b:
)
r   untabify_region_eventr1   r   r   r   r   r   r   r   )r   r   untabifyr1   r   s        r   test_untabify_region_eventz+FormatRegionTest.test_untabify_region_event)  s    >>77yyUE6*$(!(*%$%!**,$%!XZ(
488E6"%Z\r   
askintegerc                 l    | j                   j                  }d|_        | j                   |       d       y )N
   )r   r   r   r   )r   r   asks      r   test_ask_tabwidthz"FormatRegionTest.test_ask_tabwidth:  s+    nn))"$
#r   N)r(   r)   r*   rb   r3   r   r   r   r   r   r   r   r   r   r   r   patchobjectr   r   r   r   r  r,   r   r   r   r     s    4 4  2'K"4"!F_O]:* 
ZZr7T 8T 
ZZr7] 8]  
ZZr<($ )$r   r   c                       e Zd Zej                  j                  ed      d        Zej                  j                  ed      d        Zy)IndentsTestaskyesnoc                 x   t        d d       }t        j                  |      }d|_        |j	                  d        | j                  |j                  d       | j                  |j                  d       |j	                  d        | j                  |j                  d       | j                  |j                  d       y )NT   F)r   r   Indentsr   toggle_tabs_eventr   r   r   )r   r  rz   indentss       r   test_toggle_tabszIndentsTest.test_toggle_tabsC  s    dD)**V$ $!!$'.++Q/!!$'/++Q/r   r   c                    t        d d       }t        j                  |      }d |_        |j	                  d        | j                  |j                  d       d|_        |j	                  d        | j                  |j                  d       d|_        d|_        |j	                  d        | j                  |j                  d       y )NrM   rJ   r[   T)r   r   r	  r   change_indentwidth_eventr   r   r   )r   r   rz   r  s       r   test_change_indentwidthz#IndentsTest.test_change_indentwidthQ  s    dD)**V$"&
((.++Q/"#
((.++Q/"#
((.++Q/r   N)	r(   r)   r*   r   r  r  r   r  r  r,   r   r   r  r  A  sJ    	ZZr:&0 '0 
ZZr<(0 )0r   r  c                   >    e Zd Zed        Zed        Zd Zd Zd Zy)
RstripTestc                 2   t        d       t               | _        | j                  j                          t	        | j                        | _        t        | j
                        | _        t        j                  | j                        j                  | _
        y )Nr   )r1   )r   r   r   r   r   r1   
MockEditorrz   r   Rstrip	do_rstripr   s    r   r3   zRstripTest.setUpClassf  s[    4>SXX.
		#**-77r   c                 |    | ` | `| `| j                  j	                          | j                  j                          | `y r   )r1   r  rz   r   r   r   r   s    r   r   zRstripTest.tearDownClasso  r   r   c                 <    | j                   j                  dd       y )Nr5   end-1cr   r   s    r   r   zRstripTest.tearDownv  s    		)r   c                     d}d}| j                   j                  d|       | j                          | j                  | j                   j	                  dd      |       y )NzLine 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
r5   r:   )r1   r:   r  r   r   )r   originalstrippeds      r   test_rstrip_lineszRstripTest.test_rstrip_linesy  sU     	6 	 			)uh7Br   c                    | j                   }dD ]a  }| j                  |      5  |j                  d|       | j                          | j	                  |j                  dd      d       d d d        c dD ]s  }| j                  |      5  |j                  dd       |j                  d|       | j                          | j	                  |j                  dd      d       d d d        u y # 1 sw Y   xY w# 1 sw Y   xY w)N)r   r   z


)coder5   r  r   )a
za

za


r  )r1   subTestr:   r  r   r   r@   )r   r1   r  s      r   test_rstrip_endzRstripTest.test_rstrip_end  s    yy( 	?D4( ?E4(   %!92>? ?	?
 0 	BD4( BE8,E4(   %!95A	B B	B	? ?
B Bs   AC,
AC8,C5	8D	N)	r(   r)   r*   rb   r3   r   r   r  r!  r,   r   r   r  r  d  s9    8 8  *C&Br   r  __main__r8   )	verbosityexit)r+   idlelibr   r   unittestr   test.supportr   tkinterr   r   idlelib.editorr   idlelib.idle_test.mock_idler	   r  TestCaser   r.   rd   rq   rx   r   r   r   r   r  r  r(   mainr,   r   r   <module>r-     s        !  ' <>(## >>tNx   tNn18,, 14 (++  41h'' 1&$ $@ @
t"h'' t"L
? 
?u$x(( u$p 0(##  0F4B"" 4Bn zHMMAA& r   