a
    åze˜*  ã                   @   s°   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	„ d	ƒZG d
d„ dejƒZedkr¬ejdd dS )z Test autocomplete, coverage 93%.é    N)ÚMockÚpatch)Úrequires)ÚTkÚText)ÚFunc)ÚEventc                   @   s   e Zd Zdd„ ZdS )ÚDummyEditwinc                 C   s"   || _ || _d| _d| _d| _d S )Né   z>>>)ÚrootÚtextZindentwidthZtabwidthZprompt_last_line)Úselfr   r   © r   ú9/usr/lib/python3.9/idlelib/idle_test/test_autocomplete.pyÚ__init__   s
    zDummyEditwin.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	      s   r	   c                   @   s¢   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ dƒZdd„ Zdd „ Zd!d"„ Zd#S )$ÚAutoCompleteTestc                 C   s:   t dƒ tƒ | _| j ¡  t| jƒ| _t| j| jƒ| _d S )NZgui)r   r   r   Zwithdrawr   r   r	   Úeditor©Úclsr   r   r   Ú
setUpClass   s
    
zAutoCompleteTest.setUpClassc                 C   s$   | ` | `| j ¡  | j ¡  | `d S ©N)r   r   r   Zupdate_idletasksZdestroyr   r   r   r   ÚtearDownClass#   s    

zAutoCompleteTest.tearDownClassc                 C   s    | j  dd¡ t | j¡| _d S )Nú1.0Úend)r   ÚdeleteÚacÚAutoCompleter   Úautocomplete©r   r   r   r   ÚsetUp*   s    zAutoCompleteTest.setUpc                 C   s(   |   | jj| j¡ |   | jj| j¡ d S r   )ÚassertEqualr    Zeditwinr   r   r!   r   r   r   Ú	test_init.   s    zAutoCompleteTest.test_initc                 C   s   | j  ¡ }|  |tj¡ d S r   )r    Ú_make_autocomplete_windowÚassertIsInstanceÚacwZAutoCompleteWindow)r   Ztestwinr   r   r   Útest_make_autocomplete_window2   s    
z.AutoCompleteTest.test_make_autocomplete_windowc                 C   s4   | j }tƒ  |_}| ¡  |j ¡  |  |j¡ d S r   )r    r   ÚautocompletewindowZ_remove_autocomplete_windowÚhide_windowÚassert_called_onceÚassertIsNone)r   ÚacpÚmr   r   r   Útest_remove_autocomplete_window6   s
    
z0AutoCompleteTest.test_remove_autocomplete_windowc                 C   s<   | j }tƒ }||_|  | d¡d¡ |  |jd tj¡ d S )NÚeventÚbreakr   )r    r   Úopen_completionsr#   Zforce_open_completions_eventÚargsr   ZFORCE)r   r-   Úopen_cr   r   r   Ú!test_force_open_completions_event=   s
    z2AutoCompleteTest.test_force_open_completions_eventc                 C   sú   | j }| j}tdd}|  | |¡¡ |`| j dd¡ |  | |¡¡ | j dd¡ | j dd¡ t	ƒ  |_
}t	dd|_|| |¡dƒ |j ¡  d |_
td	d
}||_|| |¡d ƒ ||jd tjƒ d|_|| |¡dƒ ||jd tjƒ d S )NT)Úmc_stater   z        """Docstring.
    r   zre.)Zreturn_valuer1   F©Úresultr   )r#   r    r   r,   Zautocomplete_eventr6   r   Úinsertr   r   r)   Z	is_activeZcompleter+   r   r2   r3   r   ÚTABr8   )r   ÚEqualr-   ZevÚmockr4   r   r   r   Útest_autocomplete_eventE   s*    


z(AutoCompleteTest.test_autocomplete_eventc                 C   s  | j }| j}| j}|j}td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 )
NZafter1r7   r   r   Úrer9   z re.z "./Lib/Zafter2)r#   r   r    Ztry_open_completions_eventr   ÚafterÚcalledr9   Ú_delayed_completion_idÚ_delayed_completion_indexÚindexr3   Z	popupwaitÚ_delayed_open_completionsr   ZTRY_Ar8   Úafter_cancelZTRY_F)r   r;   r   r-   Ztrycompletionsr?   Zcb1Úcancelr   r   r   Útest_try_open_completions_eventd   s>    
ÿ
ÿz0AutoCompleteTest.test_try_open_completions_eventc                 C   sž   | 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.r?   z	insert+1cÚdummyr   r9   é   é   é   )r#   r    r   r2   r   r9   rA   rC   rB   rD   r,   r@   r   ÚFILESr3   )r   r;   r-   r4   r   r   r   Útest_delayed_open_completions‰   s    
z.AutoCompleteTest.test_delayed_open_completionsc                 C   sP   | j }| j}d|_tdd}||j_| j dd¡ || tj	¡ƒ ||jƒ d S )Nr?   r7   ç      ð?z	# comment)
r,   r    rA   r   r   rE   r9   r2   r   r:   )r   Únoner-   r?   r   r   r   Útest_oc_cancel_comment   s    
z'AutoCompleteTest.test_oc_cancel_commentc                 C   sl   | j }tg g fd}||_| j dd¡ |  | tj¡¡ | j dd¡ |  | tj¡¡ |  	|j
d¡ d S )Nr7   r   Úobjectr9   Ú.rJ   )r    r   Úfetch_completionsr   r9   r,   r2   r   r:   r#   r@   )r   r-   Úfetchr   r   r   Útest_oc_no_list©   s    z AutoCompleteTest.test_oc_no_listc                 C   sš   | 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 )NrN   rR   r9   z int().r   r   ú")	r,   r    r   r9   r2   r   r:   r   ZassertFalse)r   rO   r-   r   r   r   Útest_open_completions_none´   s    z+AutoCompleteTest.test_open_completions_nonec                   @   s"   e Zd Zeƒ ZeddZeƒ ZdS )zAutoCompleteTest.dummy_acwFr7   N)r   r   r   r   r   Zshow_windowr*   r   r   r   r   Ú	dummy_acwÆ   s   
rX   c                    sœ   ˆ j }tdgddgfd}||_‡ fdd„}||_ˆ j dd¡ | tj¡ ˆ  	|j
ˆ j¡ ˆ j dd¡ ˆ j dd	¡ ˆ  | tj¡¡ ˆ j dd¡ d S )
NZtemZ_temr7   c                      s   ˆ   ¡ S r   )rX   r   r!   r   r   Úmake_acwÐ   ó    z8AutoCompleteTest.test_open_completions.<locals>.make_acwr   zint.r   z"t)r    r   rS   r%   r   r9   r2   r   r:   r&   r)   rX   r   Ú
assertTrue)r   r-   rT   rY   r   r!   r   Útest_open_completionsË   s    z&AutoCompleteTest.test_open_completionsc           	      C   sf  | j }| dtj¡\}}ttdƒr:tjtjkr:|  d|¡ | dtj¡\}}|  t	|ƒt	|ƒ¡ |  
ttdd„ |ƒƒ¡ |  
ttdd„ |ƒƒ¡ t ddd	d
gi¡t | dtj¡\}}|  |d	d
g¡ |  d|¡ |  d|¡ |  d|¡ | d¡}|  ||d  d¡ W d   ƒ n1 s 0    Y  tƒ }tƒ |_t dd|i¡l | dtj¡\}}|  d|¡ |  d|¡ |  |dd„ tt|ƒƒD ƒ¡ |  |tt|ƒƒ¡ W d   ƒ n1 s¼0    Y  dd„ }t td|¡t | dtj¡\}}|  |ddg¡ |  |g d¢¡ | dtj¡\}}|  |ddg¡ |  |g d¢¡ W d   ƒ n1 sX0    Y  d S )NÚ Ú__file__r   c                 S   s
   |   d¡S ©NÚ_©Ú
startswith©Úxr   r   r   Ú<lambda>ì   rZ   z9AutoCompleteTest.test_fetch_completions.<locals>.<lambda>c                 S   s
   |   d¡S r_   ra   rc   r   r   r   re   í   rZ   ú__main__.__dict__Ú__all__ÚaÚbr   ÚsumÚnonlocalÚFalserI   ÚfooÚ_privatec                 S   s    g | ]}|d d… dkr|‘qS )NrI   r`   r   )Ú.0Úir   r   r   Ú
<listcomp>   rZ   z;AutoCompleteTest.test_fetch_completions.<locals>.<listcomp>c                 S   s   | dkrg d¢S g d¢S )NrR   )rm   Úbarú.hidden)ÚmontyÚpythonrs   r   )Úpathr   r   r   Ú_listdir  s    z9AutoCompleteTest.test_fetch_completions.<locals>._listdirÚlistdirrr   )rs   rr   rm   ú~rt   ru   )rs   rt   ru   )r    rS   r   ZATTRSÚhasattrÚ__main__r^   ZassertNotInZ
assertLessÚlenr[   ÚallÚfilterÚanyr   Údictr#   ZassertInrC   ZassertNotEqualr   rn   ÚsortedÚdirrQ   ÚosrL   )	r   r-   ZsmallZlargeÚsri   Úposr<   rw   r   r   r   Útest_fetch_completionsÝ   sD    ÿ
44z'AutoCompleteTest.test_fetch_completionsc              	   C   s  | j }| j}|| d¡tƒ tƒ }t dd|i¡  || d¡|ƒ W d   ƒ n1 sX0    Y  dddœ}t dd|i¡  || d¡|ƒ W d   ƒ n1 s¢0    Y  t di ¡D |  t¡ | d	¡ W d   ƒ n1 sä0    Y  W d   ƒ n1 s0    Y  d S )
NÚintzsys.modulesÚtempfileé
   é   )rm   rr   rf   ÚdZ	not_exist)	r    r#   Z
get_entityr‡   r   r   r€   ZassertRaisesÚ	NameError)r   r-   r;   r<   Zdir   r   r   Útest_get_entity  s    .
.z AutoCompleteTest.test_get_entityN)r   r   r   Úclassmethodr   r   r"   r$   r(   r/   r5   r=   rG   rM   rP   rU   rW   rX   r\   r†   r   r   r   r   r   r      s&   

%6r   r{   rJ   )Ú	verbosity)Ú__doc__ZunittestZunittest.mockr   r   Ztest.supportr   Útkinterr   r   rƒ   r{   Zidlelib.autocompleter    r   Zidlelib.autocomplete_wZautocomplete_wr'   Zidlelib.idle_test.mock_idler   Zidlelib.idle_test.mock_tkr   r	   ZTestCaser   r   Úmainr   r   r   r   Ú<module>   s    	  