o
    JAf^<  ã                   @   s€  d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	Z	ddlm
Z
 ddlmZ G dd	„ d	ejƒZG d
d„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG d d!„ d!ejƒZG d"d#„ d#ejƒZG d$d%„ d%ejƒZed&kr¾ejd'd(d) dS dS )*a¼  Test query, coverage 93%.

Non-gui tests for Query, SectionName, ModuleName, and HelpSource use
dummy versions that extract the non-gui methods and add other needed
attributes.  GUI tests create an instance of each class and simulate
entries and button clicks.  Subclass tests only target the new code in
the subclass definition.

The appearance of the widgets is checked by the Query and
HelpSource htests.  These are run by running query.py.
é    )ÚqueryN©Úrequires)ÚTkÚEND)Úmock)ÚVarc                   @   sF   e Zd ZdZG dd„ dƒZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú	QueryTestzTest Query base class.c                   @   s<   e Zd ZejjZejjZejjZdd„ Zdd„ Z	dd„ Z
dS )zQueryTest.Dummy_Queryc                 C   s&   t |d| _ddi| _d | _d| _d S )N©ÚvalueÚtextÚ F)r   ÚentryÚentry_errorÚresultÚ	destroyed©ÚselfZdummy_entry© r   ú3/usr/lib/python3.10/idlelib/idle_test/test_query.pyÚ__init__!   s   

zQueryTest.Dummy_Query.__init__c                 C   ó   || j d< d S ©Nr   ©r   ©r   Úmessager   r   r   Ú	showerror&   ó   zQueryTest.Dummy_Query.showerrorc                 C   s
   d| _ d S ©NT)r   ©r   r   r   r   Údestroy(   s   
zQueryTest.Dummy_Query.destroyN)Ú__name__Ú
__module__Ú__qualname__r   ÚQueryÚentry_okÚokÚcancelr   r   r    r   r   r   r   ÚDummy_Query   s    r(   c                 C   sD   |   d¡}|  | ¡ d ¡ |  |j|jfd¡ |  d|jd ¡ d S )Nú ©NFz
blank liner   )r(   ÚassertEqualr%   r   r   ÚassertInr   ©r   Údialogr   r   r   Útest_entry_ok_blank+   s   
zQueryTest.test_entry_ok_blankc                 C   sD   |   d¡}| j}|| ¡ dƒ ||j|jfdƒ ||jd dƒ d S )Nú  good Úgoodr*   r   r   )r(   r+   r%   r   r   r   )r   r.   ÚEqualr   r   r   Útest_entry_ok_good1   s
   
zQueryTest.test_entry_ok_goodc                 C   sT   |   d¡}t ¡ |j_|  | ¡ d ¡ |  |jjj¡ |j`|  |j	|j
fd¡ d S )Nr   r*   )r(   r   ÚMockr   Z	focus_setr+   r&   Ú
assertTrueÚcalledr   r   r-   r   r   r   Útest_ok_blank8   s   
zQueryTest.test_ok_blankc                 C   ó2   |   d¡}|  | ¡ d ¡ |  |j|jfd¡ d S )Nr1   )r1   T)r(   r+   r&   r   r   r-   r   r   r   Útest_ok_good@   ó   
zQueryTest.test_ok_goodc                 C   r8   )Nzdoes not matterr   )r(   r+   r'   r   r   r-   r   r   r   Útest_cancelE   r:   zQueryTest.test_cancelN)
r!   r"   r#   Ú__doc__r(   r/   r3   r7   r9   r;   r   r   r   r   r	      s    r	   c                   @   ó>   e Zd ZdZG dd„ dƒZdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚSectionNameTestz#Test SectionName subclass of Query.c                   @   s*   e Zd ZejjZdgZdd„ Zdd„ ZdS )z!SectionNameTest.Dummy_SectionNameÚusedc                 C   ó   t |d| _ddi| _d S ©Nr
   r   r   ©r   r   r   r   r   r   r   r   Q   ó   z*SectionNameTest.Dummy_SectionName.__init__c                 C   r   r   r   r   r   r   r   r   T   r   z+SectionNameTest.Dummy_SectionName.showerrorN)	r!   r"   r#   r   ÚSectionNamer%   Ú
used_namesr   r   r   r   r   r   ÚDummy_SectionNameN   s
    rF   c                 C   ó0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S ©Nr)   zno namer   ©rF   r+   r%   r,   r   r-   r   r   r   Útest_blank_section_nameW   ó   
z'SectionNameTest.test_blank_section_namec                 C   rG   )Nr?   Zuser   rI   r-   r   r   r   Útest_used_section_name\   rK   z&SectionNameTest.test_used_section_namec                 C   rG   )NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r   rI   r-   r   r   r   Útest_long_section_namea   rK   z&SectionNameTest.test_long_section_namec                 C   ó0   |   d¡}|  | ¡ d¡ |  |jd d¡ d S )Nr0   r1   r   r   )rF   r+   r%   r   r-   r   r   r   Útest_good_section_namef   rK   z&SectionNameTest.test_good_section_nameN)	r!   r"   r#   r<   rF   rJ   rL   rM   rO   r   r   r   r   r>   K   ó    	r>   c                   @   r=   )ÚModuleNameTestz"Test ModuleName subclass of Query.c                   @   s(   e Zd ZejjZdZdd„ Zdd„ ZdS )zModuleNameTest.Dummy_ModuleNamer   c                 C   r@   rA   rB   r   r   r   r   r   r   rC   z(ModuleNameTest.Dummy_ModuleName.__init__c                 C   r   r   r   r   r   r   r   r   u   r   z)ModuleNameTest.Dummy_ModuleName.showerrorN)	r!   r"   r#   r   Ú
ModuleNamer%   Útext0r   r   r   r   r   r   ÚDummy_ModuleNameo   s
    rT   c                 C   rG   rH   ©rT   r+   r%   r,   r   r-   r   r   r   Útest_blank_module_namex   rK   z%ModuleNameTest.test_blank_module_namec                 C   rG   )NZ __name_xyz123_should_not_exist__z	not foundr   rU   r-   r   r   r   Útest_bogus_module_name}   rK   z%ModuleNameTest.test_bogus_module_namec                 C   rG   )NÚ	itertoolszsource-basedr   rU   r-   r   r   r   Útest_c_source_name‚   rK   z!ModuleNameTest.test_c_source_namec                 C   sd   |   d¡}|  | ¡  d¡¡ |  |jd d¡ |   d¡}|  | ¡  d¡¡ |  |jd d¡ d S )NÚidlelibú__init__.pyr   r   zidlelib.idlezidle.py)rT   r5   r%   Úendswithr+   r   r-   r   r   r   Útest_good_module_name‡   s   

z$ModuleNameTest.test_good_module_nameN)	r!   r"   r#   r<   rT   rV   rW   rY   r]   r   r   r   r   rQ   l   rP   rQ   c                   @   ó6   e Zd ZdZG dd„ dƒZdd„ Zdd„ Zdd	„ Zd
S )ÚGotoTestzTest Goto subclass of Query.c                   @   ó$   e Zd ZejjZdd„ Zdd„ ZdS )zGotoTest.Dummy_ModuleNamec                 C   r@   rA   rB   r   r   r   r   r   •   rC   z"GotoTest.Dummy_ModuleName.__init__c                 C   r   r   r   r   r   r   r   r   ˜   r   z#GotoTest.Dummy_ModuleName.showerrorN)r!   r"   r#   r   ÚGotor%   r   r   r   r   r   r   rT   “   ó    rT   c                 C   rG   )NÚaznot a base 10 integerr   rU   r-   r   r   r   Útest_bogus_goto›   rK   zGotoTest.test_bogus_gotoc                 C   rG   )NÚ0znot a positive integerr   rU   r-   r   r   r   Útest_bad_goto    rK   zGotoTest.test_bad_gotoc                 C   rN   )NÚ1é   r   r   )rT   r+   r%   r   r-   r   r   r   Útest_good_goto¥   rK   zGotoTest.test_good_gotoN)r!   r"   r#   r<   rT   rd   rf   ri   r   r   r   r   r_      s    r_   c                   @   ó&   e Zd ZdZG dd„ dƒZdd„ ZdS )ÚHelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c                   @   s   e Zd ZejjZeƒ ZdS )z)HelpsourceBrowsefileTest.Dummy_HelpSourceN)r!   r"   r#   r   Ú
HelpSourceÚbrowse_filer   Úpathvarr   r   r   r   ÚDummy_HelpSource°   s    
ro   c              	   C   s    |   ¡ }ddd„ dfddd„ tfddd„ dfddd„ tffD ]/\}}}|  ¡  |j |¡ ||_| ¡  |  |j ¡ |¡ W d   ƒ n1 sHw   Y  qd S )Nr   c                 S   ó   dS ©Nr   r   ©rc   ÚbÚcr   r   r   Ú<lambda>»   ó    zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>c                 S   ó   t S ©N©Ú__file__rr   r   r   r   ru   ¼   rv   Zhtestc                 S   rp   rq   r   rr   r   r   r   ru   ½   rv   c                 S   rw   rx   ry   rr   r   r   r   ru   ¾   rv   )	ro   rz   ÚsubTestrn   ÚsetZaskfilenamerm   r+   Úget)r   r.   ÚpathÚfuncr   r   r   r   Útest_file_replaces_path´   s   ü
ü€ûz0HelpsourceBrowsefileTest.test_file_replaces_pathN)r!   r"   r#   r<   ro   r€   r   r   r   r   rk   ­   s    rk   c                   @   sP   e Zd ZdZG dd„ dƒZejZedd„ ƒZ	dd„ Z
dd	„ Zd
d„ Zdd„ ZdS )ÚHelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c                   @   s&   e Zd ZejjZdd„ Zddd„ZdS )z%HelpsourcePathokTest.Dummy_HelpSourcec                 C   r@   rA   )r   r~   Ú
path_error)r   Z
dummy_pathr   r   r   r   Ë   rC   z.HelpsourcePathokTest.Dummy_HelpSource.__init__Nc                 C   r   r   )r‚   )r   r   Zwidgetr   r   r   r   Î   r   z/HelpsourcePathokTest.Dummy_HelpSource.showerrorrx   )r!   r"   r#   r   rl   Úpath_okr   r   r   r   r   r   ro   É   s    ro   c                 C   s   | j t_d S rx   )Úorig_platformr   Úplatform©Úclsr   r   r   ÚtearDownClassÒ   ó   z"HelpsourcePathokTest.tearDownClassc                 C   rG   )Nr)   zno help filer   )ro   r+   rƒ   r,   r‚   r-   r   r   r   Útest_path_ok_blankÖ   rK   z'HelpsourcePathokTest.test_path_ok_blankc                 C   s4   |   td ¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nzbad-bad-badz	not existr   )ro   rz   r+   rƒ   r,   r‚   r-   r   r   r   Útest_path_ok_badÛ   s   z%HelpsourcePathokTest.test_path_ok_badc              	   C   st   |   d¡}| j}dD ]-}|  ¡  |j |¡ |  | ¡ |¡ |  |jd d¡ W d   ƒ n1 s2w   Y  q
d S )Nr   )z
www.py.orgzhttp://py.orgr   )ro   r+   r{   r~   r|   rƒ   r‚   )r   r.   r2   Úurlr   r   r   Útest_path_ok_webà   s   

ý€ÿz%HelpsourcePathokTest.test_path_ok_webc              	   C   s|   |   d¡}dD ]4\}}|  ¡ $ |t_|j t¡ |  | ¡ |t ¡ |  |j	d d¡ W d   ƒ n1 s6w   Y  qd S )Nr   ))Údarwinúfile://)Úotherr   r   )
ro   r{   r   r…   r~   r|   rz   r+   rƒ   r‚   )r   r.   r…   Úprefixr   r   r   Útest_path_ok_fileé   s   

ü€ÿz&HelpsourcePathokTest.test_path_ok_fileN)r!   r"   r#   r<   ro   r   r…   r„   Úclassmethodrˆ   rŠ   r‹   r   r’   r   r   r   r   r   Æ   s    
	r   c                   @   rj   )ÚHelpsourceEntryokTestz5Test entry_ok method of HelpSource subclass of Query.c                   @   s,   e Zd ZejjZi Zi Zdd„ Zdd„ Z	dS )z&HelpsourceEntryokTest.Dummy_HelpSourcec                 C   ó   | j S rx   )Únamer   r   r   r   Úitem_okú   ó   z.HelpsourceEntryokTest.Dummy_HelpSource.item_okc                 C   r•   rx   )r~   r   r   r   r   rƒ   ü   r˜   z.HelpsourceEntryokTest.Dummy_HelpSource.path_okN)
r!   r"   r#   r   rl   r%   r   r‚   r—   rƒ   r   r   r   r   ro   ö   s    ro   c              	   C   sb   |   ¡ }dD ](\}}}|  ¡  |||_|_|  | ¡ |¡ W d   ƒ n1 s)w   Y  qd S )N))NNN)Núdoc.txtN)ÚdocNN)rš   r™   )rš   r™   )ro   r{   r–   r~   r+   r%   )r   r.   r–   r~   r   r   r   r   Útest_entry_ok_helpsourceÿ   s   
þ€üz.HelpsourceEntryokTest.test_entry_ok_helpsourceN)r!   r"   r#   r<   ro   r›   r   r   r   r   r”   ó   s    	r”   c                   @   r^   )ÚCustomRunCLIargsokTestz6Test cli_ok method of the CustomRun subclass of Query.c                   @   r`   )z&CustomRunCLIargsokTest.Dummy_CustomRunc                 C   r@   rA   rB   r   r   r   r   r     rC   z/CustomRunCLIargsokTest.Dummy_CustomRun.__init__c                 C   r   r   r   r   r   r   r   r     r   z0CustomRunCLIargsokTest.Dummy_CustomRun.showerrorN)r!   r"   r#   r   Ú	CustomRunÚcli_args_okr   r   r   r   r   r   ÚDummy_CustomRun  rb   rŸ   c                 C   s   |   d¡}|  | ¡ g ¡ d S )Nr)   )rŸ   r+   rž   r-   r   r   r   Útest_blank_args  s   
z&CustomRunCLIargsokTest.test_blank_argsc                 C   rG   )Nz'no-closing-quotez
No closingr   )rŸ   r+   rž   r,   r   r-   r   r   r   Útest_invalid_args  rK   z(CustomRunCLIargsokTest.test_invalid_argsc                 C   sH   g d¢}|   d |¡d ¡}|  | ¡ |dg ¡ |  |jd d¡ d S )N)z-nZ10z	--verbosez-pz/pathz--namer)   z
 "my name"zmy namer   r   )rŸ   Újoinr+   rž   r   )r   Úargsr.   r   r   r   Útest_good_args   s   z%CustomRunCLIargsokTest.test_good_argsN)r!   r"   r#   r<   rŸ   r    r¡   r¤   r   r   r   r   rœ     s    rœ   c                   @   rj   )ÚCustomRunEntryokTestz8Test entry_ok method of the CustomRun subclass of Query.c                   @   s&   e Zd ZejjZi Zeƒ Zdd„ Z	dS )z$CustomRunEntryokTest.Dummy_CustomRunc                 C   r•   rx   )Úcli_argsr   r   r   r   rž   .  r˜   z0CustomRunEntryokTest.Dummy_CustomRun.cli_args_okN)
r!   r"   r#   r   r   r%   r   r   Ú
restartvarrž   r   r   r   r   rŸ   *  s
    rŸ   c              
   C   s„   |   ¡ }dD ]9}|j |¡ ddgdg|fffD ]&\}}| j||d ||_|  | ¡ |¡ W d   ƒ n1 s9w   Y  qqd S )N>   FT)NNzmy arg)Úrestartr¦   )rŸ   r§   r|   r{   r¦   r+   r%   )r   r.   r¨   r¦   r   r   r   r   Útest_entry_ok_customrun1  s   ÿþ€þþz,CustomRunEntryokTest.test_entry_ok_customrunN)r!   r"   r#   r<   rŸ   r©   r   r   r   r   r¥   '  s    r¥   c                   @   sD   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S )ÚQueryGuiTestc                 C   sB   t dƒ tƒ  | _}| j ¡  tj|dddd| _t ¡ | j_	d S )NÚguiZTESTÚtestT©Ú_utest)
r   r   ÚrootÚwithdrawr   r$   r.   r   r4   r    )r‡   r¯   r   r   r   Ú
setUpClass@  s
   
zQueryGuiTest.setUpClassc                 C   s   | j `| ` | j ¡  | `d S rx   )r.   r    r¯   r†   r   r   r   rˆ   H  s   
zQueryGuiTest.tearDownClassc                 C   s(   | j j dd¡ d | j _| j j ¡  d S )Nr   Úend)r.   r   Údeleter   r    Z
reset_mockr   r   r   r   ÚsetUpO  s   zQueryGuiTest.setUpc                 C   s>   | j }|j dd¡ |j ¡  |  |jd¡ |  |jj	¡ d S ©Nr   Úabc)
r.   r   ÚinsertÚ	button_okÚinvoker+   r   r5   r    r6   r-   r   r   r   Útest_click_okT  ó
   
zQueryGuiTest.test_click_okc                 C   s0   | j }|j ¡  |  |jd ¡ |  |jj¡ d S rx   )r.   r¸   r¹   r+   r   ZassertFalser    r6   r-   r   r   r   Útest_click_blank[  s   
zQueryGuiTest.test_click_blankc                 C   s>   | j }|j dd¡ |j ¡  |  |jd ¡ |  |jj	¡ d S rµ   )
r.   r   r·   Zbutton_cancelr¹   r+   r   r5   r    r6   r-   r   r   r   Útest_click_cancela  r»   zQueryGuiTest.test_click_cancelN)
r!   r"   r#   r“   r±   rˆ   r´   rº   r¼   r½   r   r   r   r   rª   >  s    

rª   c                   @   ó    e Zd Zedd„ ƒZdd„ ZdS )ÚSectionnameGuiTestc                 C   ó   t dƒ d S ©Nr«   r   r†   r   r   r   r±   k  r‰   zSectionnameGuiTest.setUpClassc                 C   sl   t ƒ }| ¡  tj|dddhdd}| j}|  |jdh¡ |j dd¡ |j 	¡  |  |j
d¡ | ¡  d S )NÚTÚtr¶   Tr­   r   Zokay)r   r°   r   rD   r+   rE   r   r·   r¸   r¹   r   r    )r   r¯   r.   r2   r   r   r   Útest_click_section_nameo  s   
z*SectionnameGuiTest.test_click_section_nameN)r!   r"   r#   r“   r±   rÄ   r   r   r   r   r¿   i  ó    
r¿   c                   @   r¾   )ÚModulenameGuiTestc                 C   rÀ   rÁ   r   r†   r   r   r   r±   }  r‰   zModulenameGuiTest.setUpClassc                 C   sj   t ƒ }| ¡  tj|ddddd}|  |jd¡ |  |j ¡ d¡ |j 	¡  |  
|j d¡¡ | ¡  d S )NrÂ   rÃ   rZ   Tr­   r[   )r   r°   r   rR   r+   rS   r   r}   r¸   r¹   r5   r   r\   r    ©r   r¯   r.   r   r   r   Útest_click_module_name  s   
z(ModulenameGuiTest.test_click_module_nameN©r!   r"   r#   r“   r±   rÈ   r   r   r   r   rÆ   {  rÅ   rÆ   c                   @   r¾   )ÚGotoGuiTestc                 C   rÀ   rÁ   r   r†   r   r   r   r±   Ž  r‰   zGotoGuiTest.setUpClassc                 C   sR   t ƒ }| ¡  tj|dddd}|j dd¡ |j ¡  |  |j	d¡ | 
¡  d S )NrÂ   rÃ   Tr­   r   Z22é   )r   r°   r   ra   r   r·   r¸   r¹   r+   r   r    rÇ   r   r   r   rÈ   ’  s   
z"GotoGuiTest.test_click_module_nameNrÉ   r   r   r   r   rÊ   Œ  rÅ   rÊ   c                   @   r¾   )ÚHelpsourceGuiTestc                 C   rÀ   rÁ   r   r†   r   r   r   r±   ž  r‰   zHelpsourceGuiTest.setUpClassc                 C   s„   t ƒ }| ¡  tj|ddtdd}| j}||j ¡ dƒ ||j ¡ tƒ |j	 
¡  tjdkr0dnd}||jd|t fƒ | ¡  d S )NrÂ   Z__test__T)ZmenuitemÚfilepathr®   rŽ   r   r   )r   r°   r   rl   rz   r+   r   r}   r~   r¸   r¹   Úsysr…   r   r    )r   r¯   r.   r2   r‘   r   r   r   Útest_click_help_source¢  s   
ÿ
z(HelpsourceGuiTest.test_click_help_sourceN)r!   r"   r#   r“   r±   rÏ   r   r   r   r   rÌ   œ  rÅ   rÌ   c                   @   r¾   )ÚCustomRunGuiTestc                 C   rÀ   rÁ   r   r†   r   r   r   r±   ²  r‰   zCustomRunGuiTest.setUpClassc                 C   sp   t ƒ }| ¡  tj|dddgdd}|  |j ¡ d¡ |j td¡ |j	 
¡  |  |jg d¢df¡ | ¡  d S )	NZTitlerc   úb=1T)r¦   r®   za b=1z c)rc   rÑ   rt   )r   r°   r   r   r+   r   r}   r·   r   r¸   r¹   r   r    rÇ   r   r   r   Útest_click_args¶  s   ÿ
z CustomRunGuiTest.test_click_argsN)r!   r"   r#   r“   r±   rÒ   r   r   r   r   rÐ   °  rÅ   rÐ   Ú__main__é   F)Ú	verbosityÚexit)r<   rZ   r   ZunittestZtest.supportr   Útkinterr   r   rÎ   r   Zidlelib.idle_test.mock_tkr   ZTestCaser	   r>   rQ   r_   rk   r   r”   rœ   r¥   rª   r¿   rÆ   rÊ   rÌ   rÐ   r!   Úmainr   r   r   r   Ú<module>   s4    3!$-+ÿ