
    ;eL                     \   	 d dl mZ d dlmZmZ d dlZd dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ e
j        Z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S dS )    )dedent)TextTkN)MockNonCallableMagicMockpatchsentinelANY)requires)idleConf)
Percolator)count_lines_with_wrappingExpandingButtonSqueezer)macosx)	view_text)Hovertipc                     	 t          d           t                                                       fd}|                     |           S )Nguic                  X                                                                         d S N)update_idletasksdestroyroots   6/usr/lib/python3.11/idlelib/idle_test/test_squeezer.pycleanup_rootz&get_test_tk_root.<locals>.cleanup_root   s&        )r   r   withdraw
addCleanup)test_instancer   r   s     @r   get_test_tk_rootr"      s[    4UOOO44DMMOOO     \***Kr   c                   @    e Zd Z	 d Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
CountLinesTestc                 J    |                      |t          ||                    S r   assertEqualr   )selfexpectedtext	linewidths       r   checkzCountLinesTest.check$   s*    %dI66
 
 	
r   c                 N    	 |                      t          d          d           d S )N r   r&   r(   s    r   test_count_emptyzCountLinesTest.test_count_empty*   s*    (2266:::::r   c                 N    	 |                      t          d          d           d S )Nz
text   r&   r/   s    r   !test_count_begins_with_empty_linez0CountLinesTest.test_count_begins_with_empty_line.   s*    =28<<a@@@@@r   c                 N    	 |                      t          d          d           d S )Nztext
   r&   r/   s    r   test_count_ends_with_empty_linez.CountLinesTest.test_count_ends_with_empty_line2   s*    ;28<<a@@@@@r   c                 N    	 |                      t          d          d           d S )Nz1
2
3
   r&   r/   s    r   test_count_several_linesz'CountLinesTest.test_count_several_lines6   s*    .2;??CCCCCr   c                     |                      ddd           |                      ddd           |                      ddd           d S )	Nr5   
P   r)   r*   r+   r2   


   z










r,   r/   s    r   test_empty_lineszCountLinesTest.test_empty_lines:   sP    

ADB
777

AFb
999

BY"
=====r   c                 f    |                      ddd           |                      ddd           d S )Nr8   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar<   r=   zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
r@   r/   s    r   test_long_linezCountLinesTest.test_long_line?   s9    

AI
<<<

A$4
CCCCCr   c                    t          d          }|                     d|d           |                     d|dz   d           |                     d|d           |                     d|d	           |                     d
|d           d S )Nz            13 characters
            43 is the number of characters on this line

            7 chars
            13 characters   r<   r=   r;      (            r?   )r   r,   )r(   r*   s     r   $test_several_lines_different_lengthsz3CountLinesTest.test_several_lines_different_lengthsC   s        	

ADB
777

AD4K2
>>>

ADB
777

ADB
777

BTR
88888r   N)__name__
__module____qualname__r,   r0   r3   r6   r9   rA   rD   rL    r   r   r$   r$   "   s        ;
 
 
; ; ;A A AA A AD D D> > >
D D D9 9 9 9 9r   r$   c                   p    e Zd Z	 ddZddZddZd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd ZdS )SqueezerTestFc                     	 t                      }d|_        |rBt          |           |_        |                     |j                  }|x|_        |j        _        |S )Nr<   r   )r   widthr"   r   make_text_widgetr*   perbottom)r(   with_text_widgeteditwintext_widgets       r   make_mock_editor_windowz$SqueezerTest.make_mock_editor_windowS   s\    2&(( 	<+D11GL//W\/BBK0;;GL7;-r   Nc                 R    	 ||                                  }t          |          }|S r   )r[   r   )r(   editor_windowsqueezers      r   make_squeezer_instancez#SqueezerTest.make_squeezer_instance_   s.    J  88::MM**r   c                 |    |t          |           }t          |          }d|d<   |                    dd           |S )N)Courierr?   fontiomark1.0)r"   r   mark_set)r(   r   rZ   s      r   rU   zSqueezerTest.make_text_widgetf   sE    <#D))D4jj-FXu---r   c                     t          j        |||          }t          j        ||||           |                     t           j        ||||           d S r   )r   	GetOption	SetOptionr    )r(   
configTypesectionoptionvalueprev_vals         r    set_idleconf_option_with_cleanupz-SqueezerTest.set_idleconf_option_with_cleanupn   s[    %j'6BB:w>>>*"GVX	? 	? 	? 	? 	?r   c                    	 |                                  }|                     |          }dD ]\  }}}|                     |||          5  t          |          }t	          j        |d|          5  |                     |                    |          |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N))z'\n'r<   r5   )z'\n' * 3r<   r8   )z'a' * 40 + '\n'r<   r5   )z'a' * 80 + '\n'r<   r5   )z'a' * 200 + '\n'r<   r8   )'aa\t' * 20r<   r2   )z'aa\t' * 21r<   r8   )rp   rH      )	text_code
line_widthr)   rT   )r[   r_   subTestevalr   objectr'   count_lines)r(   rY   r^   rr   rs   r)   r*   s          r   test_count_lineszSqueezerTest.test_count_linest   s   >..00..w77	0
 	K 	K+Iz8 	)3'/  1 1 K K I\'7J?? K K$$X%9%9$%?%?JJJK K K K K K K K K K K K K K K	K K K K K K K K K K K K K K K	K 	Ks6   &B>1*B'B>'B++B>.B+/B>>C	C	c                     	 |                                  }|                     |          }|                     |j        |           |                     |j        g            d S r   )r[   r_   assertIsrY   r'   expandingbuttons)r(   rY   r^   s      r   	test_initzSqueezerTest.test_init   s_    6..00..w77h&0002B77777r   c                    	 |                                  }ddddz  dfD ]}t          t                    x|_        }|                     |          }|                     |j                            |d          t                     |                     |j        d           |                    |d           |                     t          |j
                  d	           d S )
Nr.   TEXT	LONG TEXT  L  MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
MANY_LINES
return_valuerP   r5   r   )r[   r   SENTINEL_VALUEwriter_   r'   rY   
call_countassert_called_withlenr{   r(   rY   r*   
orig_writer^   s        r   test_write_no_tagszSqueezerTest.test_write_no_tags   s    N..00t!35IJ 	@ 	@D)->)J)J)JJGMJ227;;HX-33D"==~NNNZ2A666))$333S!:;;Q????	@ 	@r   c                    	 ddddz  dfD ]}|                                  }t          |j        _        |j        }|                     |          }|                     |j                            |d          t                     |                     |j        d           |                    |d           |                     t          |j
                  d           d S )	Nr.   r~   r   r   r   stderrr5   r   )r[   r   r   r   r_   r'   rY   r   r   r   r{   )r(   r*   rY   r   r^   s        r   test_write_not_stdoutz"SqueezerTest.test_write_not_stdout   s    Nt!35IJ 
	@ 
	@D2244G)7GM& J227;;HX-33D(CC,. . .Z2A666))$999S!:;;Q????
	@ 
	@r   c                 ,   	 |                                  }dD ]}t          t                    x|_        }|                     |          }d|_        |                     |j                            |d          t                     |                     |j        d           |	                    |d           |                     t          |j                  d           ddz  d	fD ]}t          t                    x|_        }|                     |          }d|_        |                     |j                            |d          d            |                     |j        d           |                     t          |j                  d           d S )
N)r.   r~   r   2   stdoutr5   r   r   r   r   )r[   r   r   r   r_   auto_squeeze_min_linesr'   rY   r   r   r   r{   r   s        r   test_write_stdoutzSqueezerTest.test_write_stdout   s   N..00  		@ 		@D)->)J)J)JJGMJ227;;H.0H+X-33D(CC+- - -Z2A666))$999S!:;;Q???? 4')=> 	@ 	@D)->)J)J)JJGMJ227;;H.0H+X-33D(CCTJJJZ2A666S!:;;Q????	@ 	@r   c                 t   	 |                      d          }|j        }|                     |          }d|_        t	          d          |_        |                    dd           |                     |                    dd	          d
           |                     t          |j
                  d           d S )NTrX   rF   rG   r   zTEXT
TEXT
TEXT
TEXT
TEXT
TEXT
r   rd   endr;   r5   )r[   r*   r_   r   r   rw   r   r'   getr   r{   )r(   rY   rZ   r^   s       r   test_auto_squeezezSqueezerTest.test_auto_squeeze   s    O...EEl..w77*+'#333j(+++66===X677;;;;;r   c                    	 dD ]}|                      d          }|j        }|                     |          }t          d          |_        |                    dd|           |                    dd           |                     |                    dd	          d
           |                     t          |j
                  d           |                                }|                     |d           |                     |                    dd	          d           |                     t          |j
                  d           |                     |j
        d         j        d           |j
        d                                          |                     |                    dd	          d
           |                     t          |j
                  d           d S )N)r   r   Tr   rG   r   rd   
SOME
TEXT
insertr   SOME
TEXT

r   breakr>   r5   z	SOME
TEXT)r[   r*   r_   r   rw   r   re   r'   r   r   r{   squeeze_current_textsexpand)r(   tag_namerY   rZ   r^   retvals         r   test_squeeze_current_textz&SqueezerTest.test_squeeze_current_text   s   3, 	@ 	@H22D2IIG!,K227;;H#'Q#7#7#7H  unh???  5111[__UE::<LMMMS!:;;Q??? 2244FVW---[__UE::FCCCS!:;;Q???X6q9;\JJJ %a(//111[__UE::<LMMMS!:;;Q????1	@ 	@r   c                    	 |                      d          }|j        }|                     |          }t          d          |_        |                    ddd           |                    dd           |                     |                    dd	          d
           |                     t          |j
                  d           |                                }|                     |d           |                     |                    dd	          d
           |                     t          |j
                  d           d S )NTr   rG   r   rd   r   TAGr   r   r   r   r   )r[   r*   r_   r   rw   r   re   r'   r   r   r{   r   r(   rY   rZ   r^   r   s        r   )test_squeeze_current_text_no_allowed_tagsz6SqueezerTest.test_squeeze_current_text_no_allowed_tags   s3   N...EEl..w77#333 	5.%888Xu---668HIIIX677;;; ..00)))668HIIIX677;;;;;r   c                 :   	 |                      d          }|j        }|                     |          }t          d          |_        |                    ddd           |                    dd           |                                 |                     t          |j
                  d	           |                    dd
d           |                    dd           |                                }|                     |d           |                     |                    dd          d           |                     t          |j
                  d           |                     |                    |j
        d         d|j
        d	                              d S )NTr   rG   r   rd   r   r   r   r5   zMORE
STUFF
r   r   z


r2   r   <)r[   r*   r_   r   rw   r   re   r   r'   r   r{   r   
assertTruecomparer   s        r   /test_squeeze_text_before_existing_squeezed_textz<SqueezerTest.test_squeeze_text_before_existing_squeezed_text   s   @...EEl..w77#333 	5.(;;;Xu---%%'''X677;;; 	5/8<<<Xu---..00)))66AAAX677;;;++%a(%a(
 
 	 	 	 	 	r   c                    	 |                      d          }|                     |          }|j        }|dz   }|                     dddt	          |                     t          j                     |                     |j        |           d S )NTr   r?   mainPyShellzauto-squeeze-min-lines)r[   r_   r   rn   strr   reloadr'   )r(   rY   r^   orig_auto_squeeze_min_linesnew_auto_squeeze_min_liness        r   test_reloadzSqueezerTest.test_reload  s    -...EE..w77&.&E# &A2%E"--I7*++	- 	- 	- 	83	5 	5 	5 	5 	5r   c                 .    	 t          j                     d S r   )r   r   r/   s    r   !test_reload_no_squeezer_instancesz.SqueezerTest.test_reload_no_squeezer_instances+  s    Nr   )Fr   )rM   rN   rO   r[   r_   rU   rn   rx   r|   r   r   r   r   r   r   r   r   r   rP   r   r   rR   rR   Q   s       '
 
 
 
      ? ? ?K K K,8 8 8
@ 
@ 
@@ @ @@ @ @0
< 
< 
<@ @ @:< < <(  45 5 5"    r   rR   c                   `    e Zd Z	 d Z ede          d             Zd Zd Zd Z	d Z
d	 Zd
S )ExpandingButtonTestc                    	 t          |           }t                      }t          |          |j        _        t          |j        j                  |j        _        |                     |j        j        j                   d|_	        |S )Nr   )
r"   r   r   rY   r*   r   rV   r    closer   )r(   r   r^   s      r   make_mock_squeezerz&ExpandingButtonTest.make_mock_squeezer4  so    >%%66 $T

)(*:*?@@(,2333 +-'r   zidlelib.squeezer.Hovertipautospecc                 D   	 |                                  }|j        j        }t          ddd|          }|                     |j        d           |                     |j        |           |                     d|                    d          v            |                     |	                    dd          d           | 
                    d	|                                           d
t          j                    rdndz  }| 
                    ||                                           |                     |j        d           |                    |t           t                      |j        d         d         }| 
                    d|                                           d S )Nr~   TAGSr   z50 linesr*   rd   r   r;   z<Double-Button-1>z<Button-%s>23r5   )hover_delayr   zright-click)r   rY   r*   r   r'   r   masterr   cgetr   assertInbindr   isAquaTkr   r   r
   	call_argslower)r(   MockHovertipr^   rZ   expandingbuttonright_button_codetooltip_texts          r   r|   zExpandingButtonTest.test_init@  s   ?**,,&+)&&"hGG*F333 	/===
o&:&:6&B&BBCCC 	66=== 	)?+?+?+A+ABBB)FO4E4E-NSS3O')=)=)?)?@@@ 	0!444''#'NNN $-a03m\%7%7%9%9:::::r   c                    	 |                                  }t          ddd|          }|j        j        }|                    d|           |                    t                                }|                     |d            |                     |                    dd          d           |	                    d	          }|                     |                    d|          d           |                     |
                    dd          d|f           |                     |j        j        j        d
           |j        j                            |           d S )Nr~   r   r   rd   windoweventr   zTEXT
end-1cr5   )r   r   rY   r*   window_creater   r   r'   r   indextag_nextranger{   remover   r   )r(   r^   r   rZ   r   text_end_indexs         r   test_expandzExpandingButtonTest.test_expand]  sS   $**,,)&&"hGG &+!!%!@@@ !''dff'55&&& 	66AAA %**844??HHH2265AA .1	3 	3 	3 	29DaHHH!(;;OLLLLLr   c                    	 |                                  }ddz  }t          |dd|          }|                                 |                     |j                   |j        }|                    d|           t          d          5 }d|j        _	        d|j
        _	        |                    t                      	          }d d d            n# 1 swxY w Y   |                     |d
           |                     |j                            dd          d           t          d          5 }d|j        _	        d|j
        _	        |                    t                      	          }d d d            n# 1 swxY w Y   |                     |d            |                     |j                            dd          |           d S )Nai r   r   rd   r   zidlelib.squeezer.messageboxFr   r   r   r.   T)r   r   set_is_dangerousr   is_dangerousr*   r   r   askokcancelr   askyesnor   r   r'   r   )r(   r^   r*   r   rZ   mock_msgboxr   s          r   test_expand_dangerous_oupputz0ExpandingButtonTest.test_expand_dangerous_oupputx  s*   N**,,U{)$HEE((***4555 &*!!%!@@@ 011 	:[38K#005K -$++$&&+99F		: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	)))-11%BBBGGG 011 	:[37K#004K -$++$&&+99F		: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	&&&-11%BBDIIIIIs$   ;CCC.;E55E9<E9c                    	 |                                  }t          ddd|          }t                      |_        t                      |_        |                    t                                }|                     |d            |                     |j        j        d           |                     |j        j        d           |j                            d           d S )Nr~   r   r   r   r5   )	r   r   r   clipboard_clearclipboard_appendcopyr'   r   r   )r(   r^   r   r   s       r   	test_copyzExpandingButtonTest.test_copy  s    " **,,)&&"hGG*.&&'+/66( !%%DFF%33&&& 	8CQGGG9DaHHH(;;FCCCCCr   c                    	 |                                  }t          ddd|          }t                      |_        t	          dt
                    5 }|                    t                                 |                     |j        d           |                     |j	        d         d	         d           d d d            d S # 1 swxY w Y   d S )
Nr~   r   r   zidlelib.squeezer.view_textr   r   r5   r   r2   )
r   r   r   selection_ownr   r   viewr'   r   r   )r(   r^   r   mock_view_texts       r   	test_viewzExpandingButtonTest.test_view  s   "**,,)&&"hGG(,%/)DDD 		E!  tvv ... ^6::: ^5a8;VDDD		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		E 		Es   A%CC
Cc                    	 |                                  }t          ddd|          }t          d          5 }t                      }||_        t                      }d|_        d|_        |                    |           |                     |j	        j
        t          |j                             |j        D ]%^}}|j	                            |t                     &	 d d d            d S # 1 swxY w Y   d S )Nr~   r   r   ztkinter.Menur?   r   )labelcommand)r   r   r   r   r   xycontext_menu_eventr'   add_commandr   r   rmenu_specsassert_any_callr
   )r(   r^   r   	mock_Menu	mock_menu
mock_eventr   datas           r   
test_rmenuzExpandingButtonTest.test_rmenu  sU   $**,,)&&"hGG>"" 
	PiI%.I"JJLJL..Z.@@@Y2= !<==? ? ? / ; P P%55E35OOOOP
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	P 
	Ps   B'C,,C03C0N)rM   rN   rO   r   r   r   r|   r   r   r   r   r   rP   r   r   r   r   0  s        .
 
 
 U&:::; ; ;:;8M M M6!J !J !JFD D D(E E E"P P P P Pr   r   __main__r2   )	verbosity)$textwrapr   tkinterr   r   unittestunittest.mockr   r   r   r	   r
   test.supportr   idlelib.configr   idlelib.percolatorr   idlelib.squeezerr   r   r   idlelibr   idlelib.textviewr   idlelib.tooltipr   r   r"   TestCaser$   rR   r   rM   r   rP   r   r   <module>r     s                   J J J J J J J J J J J J J J ! ! ! ! ! ! # # # # # # ) ) ) ) ) )                & & & & & & $ $ $ $ $ $(  ,9 ,9 ,9 ,9 ,9X& ,9 ,9 ,9^\ \ \ \ \8$ \ \ \~^P ^P ^P ^P ^P(+ ^P ^P ^PB zHMA r   