
    ;eU+                         d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
Z
ddlZddlmZ ddlmZ ddlmZ ddlmZ  G d d	          Z G d
 dej                  Zedk    r ej        d           dS dS )z Test autocomplete, coverage 93%.    N)Mockpatch)requires)TkText)Func)Eventc                       e Zd Zd ZdS )DummyEditwinc                 L    || _         || _        d| _        d| _        d| _        d S )N   z>>>)roottextindentwidthtabwidthprompt_last_line)selfr   r   s      :/usr/lib/python3.11/idlelib/idle_test/test_autocomplete.py__init__zDummyEditwin.__init__   s-    		 %    N)__name__
__module____qualname__r    r   r   r   r      s#        & & & & &r   r   c                       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d Zd Z G d d          Zd Zd Zd Zd ZdS )AutoCompleteTestc                     t          d           t                      | _        | j                                         t	          | j                  | _        t          | j        | j                  | _        d S )Ngui)r   r   r   withdrawr   r   r   editorclss    r   
setUpClasszAutoCompleteTest.setUpClass   sT    44>>!#(CH55


r   c                 v    | ` | `| j                                         | j                                         | `d S N)r    r   r   update_idletasksdestroyr!   s    r   tearDownClasszAutoCompleteTest.tearDownClass#   s<    J!!###HHHr   c                 x    | j                             dd           t          j        | j                  | _        d S )N1.0end)r   deleteacAutoCompleter    autocompleter   s    r   setUpzAutoCompleteTest.setUp*   s4    	&&&ODK88r   c                     |                      | j        j        | j                   |                      | j        j        | j                   d S r%   )assertEqualr/   editwinr    r   r0   s    r   	test_initzAutoCompleteTest.test_init.   sD    *2DK@@@*/;;;;;r   c                 x    | j                                         }|                     |t          j                   d S r%   )r/   _make_autocomplete_windowassertIsInstanceacwAutoCompleteWindow)r   testwins     r   test_make_autocomplete_windowz.AutoCompleteTest.test_make_autocomplete_window2   s5    #==??gs'=>>>>>r   c                     | j         }t                      x|_        }|                                 |j                                         |                     |j                   d S r%   )r/   r   autocompletewindow_remove_autocomplete_windowhide_windowassert_called_onceassertIsNone)r   acpms      r   test_remove_autocomplete_windowz0AutoCompleteTest.test_remove_autocomplete_window6   s^    %)VV+'')))	((***#011111r   c                     | j         }t                      }||_        |                     |                    d          d           |                     |j        d         t          j                   d S )Neventbreakr   )r/   r   open_completionsr3   force_open_completions_eventargsr-   FORCE)r   rC   open_cs      r   !test_force_open_completions_eventz2AutoCompleteTest.test_force_open_completions_event=   sc    %99'BBGLLLQ22222r   c                    | j         }| j        }t          d          }|                     |                    |                     |`| j                            dd           |                     |                    |                     | j                            dd           | j                            dd           t                      x|_
        }t          d          |_         ||                    |          d           |j                                         d |_
        t          d	
          }||_         ||                    |          d             ||j        d         t"          j                   d|_         ||                    |          d            ||j        d         t"          j                   d S )NT)mc_stater*   z        """Docstring.
    r+   zre.)return_valuerH   Fresultr   )r3   r/   r	   rB   autocomplete_eventrP   r   insertr,   r   r>   	is_activecompleterA   r   rI   rK   r-   TABrS   )r   EqualrC   evmockrM   s         r   test_autocomplete_eventz(AutoCompleteTest.test_autocomplete_eventE   s     D!!!#0044555K 		 =>>>#0044555	&&& 		&&&(,.4000c$$R(('222((***!% U###%c$$R(($///fk!nbf%%%c$$R(('222fk!nbf%%%%%r   c                 z   | j         }| j        }| j        }|j        }t	          d          }||j        _         |              ||j        d           |                    dd            |              ||j        d           |                    dd           d |_         |              ||j	        |
                    d                      ||j        |j        |j        t          j        f           |j        } ||d           |                    dd           d	|_        t	                      }||j        _         |              ||j	        |
                    d                      ||j        |f            ||j        |j        |j        t          j        f            ||j        d	           d S )
Nafter1rR   r   r*   rerU   z re.z "./Lib/after2)r3   r   r/   try_open_completions_eventr   aftercalledrU   _delayed_completion_id_delayed_completion_indexindexrK   	popupwait_delayed_open_completionsr-   TRY_ArS   after_cancelTRY_F)r   rY   r   rC   trycompletionsrb   cb1cancels           r   test_try_open_completions_eventz0AutoCompleteTest.test_try_open_completions_eventd   s    y7H%%% 	elAE4   elA 	Hf%%%%)"c+TZZ-A-ABBBej}c;RXF	H 	H 	H(c8 	Hj))) &c+TZZ-A-ABBBfkC6"""ej}c;RXF	H 	H 	Hc((33333r   c                 0   | j         }| j        }t                      }||_        | j                            dd           d|_        | j                            d          |_        |	                    d           | 
                    |j                    ||j        d           | j                            d          |_        |	                    dd	d
t          j        f           |                      |j        d         dd	d
t          j        f           d S )Nr*   z"dict.rb   z	insert+1cdummyr   rU            )r3   r/   r   rI   r   rU   rd   rf   re   rh   rB   rc   r-   FILESrK   )r   rY   rC   rM   s       r   test_delayed_open_completionsz.AutoCompleteTest.test_delayed_open_completions   s     %	))) &-"(,	(D(D%%%g...#4555fmQ )-	(A(A%%%q!Q&9:::Q!Q28)<=====r   c                    | j         }| j        }d|_        t          d          }||j        _        | j                            dd            ||                    t          j	                              ||j                   d S )Nrb   rR         ?z	# comment)
rB   r/   rd   r   r   rj   rU   rI   r-   rX   )r   nonerC   rb   s       r   test_oc_cancel_commentz'AutoCompleteTest.test_oc_cancel_comment   s      &-"G$$$ %	k***S!!"&))***S'(((((r   c                    | j         }t          g g f          }||_        | j                            dd           |                     |                    t          j                             | j                            dd           |                     |                    t          j                             | 	                    |j
        d           d S )NrR   r*   objectrU   .rs   )r/   r   fetch_completionsr   rU   rB   rI   r-   rX   r3   rc   )r   rC   fetchs      r   test_oc_no_listz AutoCompleteTest.test_oc_no_list   s    RG$$$ %	)))#..rv66777	3'''#..rv66777q)))))r   c                    | j         }| j        }| j                            dd            ||                    t
          j                             | j                            dd            ||                    t
          j                             | j                            dd           |                     |                    t
          j                             | j                            dd           |                     |                    t
          j                             | j                            dd           d S )Nrx   r}   rU   z int().r+   r*   ")	rB   r/   r   rU   rI   r-   rX   r,   assertFalse)r   ry   rC   s      r   test_open_completions_nonez+AutoCompleteTest.test_open_completions_none   s     		c"""S!!"&))***	9---S!!"&))*** 		e$$$--bf55666	$$$--bf55666	&&&&&r   c                   N    e Zd Z e            Z ed          Z e            ZdS )AutoCompleteTest.dummy_acwFrR   N)r   r   r   r   r   show_windowr@   r   r   r   	dummy_acwr      s6        466d%(((dffr   r   c                       j         }t          dgddgf          }||_         fd}||_         j                            dd           |                    t          j                    	                    |j
         j                    j                            dd            j                            dd                                |                    t          j                              j                            dd           d S )	Ntem_temrR   c                  ,                                      S r%   )r   r0   s   r   make_acwz8AutoCompleteTest.test_open_completions.<locals>.make_acw   s    t~~///r   r*   zint.r+   z"t)r/   r   r~   r7   r   rU   rI   r-   rX   r8   r>   r   r,   
assertTrue)r   rC   r   r   s   `   r   test_open_completionsz&AutoCompleteTest.test_open_completions   s    eWeV_5666 %/////(0%	'''RV$$$c4dnEEE	&&& 		%%%,,RV44555	&&&&&r   c                     |                      dt          j                   |                      dt          j                   |                     dt          j                   d S )NandcaseNone)assertInr-   completion_kwdsassertNotInr0   s    r   test_completion_kwdsz%AutoCompleteTest.test_completion_kwds   sO    eR/000fb0111!344444r   c           
         | j         }|                    dt          j                  \  }}t	          t
          d          r0t
          j        t          j        k    r|                     d|           |                    dt          j                  \  }}|                     t          |          t          |                     | 
                    t          t          d |                               | 
                    t          t          d |                               t          j        dddd	gi          5  |                    dt          j                  \  }}|                     |dd	g           |                     d
|           |                     d|           |                     d|           |                    d          }|                     ||dz            d           d d d            n# 1 swxY w Y   t)                      }t)                      |_        t          j        dd|i          5  |                    dt          j                  \  }}|                     d|           |                     d|           |                     |d t-          t/          |                    D                        |                     |t-          t/          |                               d d d            n# 1 swxY w Y   d }t          j        t2          d|          5  |                    dt          j                  \  }}|                     |ddg           |                     |g d           |                    dt          j                  \  }}|                     |ddg           |                     |g d           d d d            d S # 1 swxY w Y   d S )N __file__r.   c                 ,    |                      d          S N_
startswithxs    r   <lambda>z9AutoCompleteTest.test_fetch_completions.<locals>.<lambda>       Q\\#->-> r   c                 ,    |                      d          S r   r   r   s    r   r   z9AutoCompleteTest.test_fetch_completions.<locals>.<lambda>   r   r   __main__.__dict____all__abr   sumnonlocalFalserr   foo_privatec                 .    g | ]}|d d         dk    |S )Nrr   r   r   ).0is     r   
<listcomp>z;AutoCompleteTest.test_fetch_completions.<locals>.<listcomp>  s%     N N Nq2A2#r   c                     | dk    rg dS g dS )Nr}   )r   bar.hidden)montypythonr   r   )paths    r   _listdirz9AutoCompleteTest.test_fetch_completions.<locals>._listdir	  s#    s{{00001111r   listdirr   )r   r   r   ~r   r   )r   r   r   )r/   r~   r-   ATTRShasattr__main__r   r   
assertLesslenr   allfilteranyr   dictr3   r   rf   assertNotEqualr   r   sorteddirr|   osru   )	r   rC   smalllargesr   posr[   r   s	            r   test_fetch_completionsz'AutoCompleteTest.test_fetch_completions   sc    ,,BH u8Z(( 	4X->"+-M-M^U333 $$R221E

CJJ///F#>#>BBCCDDDF#>#>BBCCDDD Z+i#s-DEE 	3 	3((RX66DAqQc
+++MM*a(((MM%###MM*a((('''""C#a%'222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 vvZ+eT];; 	3 	3((99DAqZ+++MM*a(((Q N NF3t99,=,= N N NOOOQs4yy 1 1222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3	2 	2 	2 \"i22 	@ 	@((RX66DAqQ///Q 9 9 9:::((bh77DAqQ( 3444Q > > >???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s9   >B2G<<H H ?B:LL	L	.B'O""O&)O&c                    | j         }| j        } ||                    d          t                     t	                      }t          j        dd|i          5   ||                    d          |           d d d            n# 1 swxY w Y   ddd}t          j        dd|i          5   ||                    d          |           d d d            n# 1 swxY w Y   t          j        di           5  |                     t                    5  |                    d	           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )
Nintzsys.modulestempfile
      )r   r   r   d	not_exist)	r/   r3   
get_entityr   r   r   r   assertRaises	NameError)r   rC   rY   r[   dis        r   test_get_entityz AutoCompleteTest.test_get_entity  sT     cnnU##S))) vvZ
D'9:: 	4 	4E#..,,d333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ##Z+c2Y77 	+ 	+E#..%%r***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ Z+R00 	, 	,""9-- , ,{+++, , , , , , , , , , , , , , ,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,sZ    BBB+ CCC7ED4(E4D8	8E;D8	<EEEN)r   r   r   classmethodr#   r(   r1   r5   r<   rE   rN   r\   ro   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r      sV       6 6 [6   [9 9 9< < <? ? ?2 2 23 3 3& & &>#4 #4 #4J> > >(
) 
) 
)* * *' ' '$       
' ' '$5 5 5
4@ 4@ 4@l, , , , ,r   r   r   rs   )	verbosity)__doc__unittestunittest.mockr   r   test.supportr   tkinterr   r   r   r   idlelib.autocompleter/   r-   idlelib.autocomplete_wautocomplete_wr9   idlelib.idle_test.mock_idler   idlelib.idle_test.mock_tkr	   r   TestCaser   r   mainr   r   r   <module>r      s>   " "  % % % % % % % % ! ! ! ! ! !         				  ! ! ! ! ! ! $ $ $ $ $ $ , , , , , , + + + + + +& & & & & & & &T, T, T, T, T,x( T, T, T,n zHMA r   