o
    JAf^<  ã                   @   s~  	 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 ))é    )ÚqueryN©Úrequires)ÚTkÚEND)Úmock)ÚVarc                   @   sD   e 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 )Ú	QueryTestc                   @   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#   r(   r/   r3   r7   r9   r;   r   r   r   r   r	      s    r	   c                   @   ó<   e Zd Z	 G dd„ dƒZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSectionNameTestc                   @   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
    rE   c                 C   ó0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S ©Nr)   zno namer   ©rE   r+   r%   r,   r   r-   r   r   r   Útest_blank_section_nameW   ó   
z'SectionNameTest.test_blank_section_namec                 C   rF   )Nr>   Zuser   rH   r-   r   r   r   Útest_used_section_name\   rJ   z&SectionNameTest.test_used_section_namec                 C   rF   )NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r   rH   r-   r   r   r   Útest_long_section_namea   rJ   z&SectionNameTest.test_long_section_namec                 C   ó0   |   d¡}|  | ¡ d¡ |  |jd d¡ d S )Nr0   r1   r   r   )rE   r+   r%   r   r-   r   r   r   Útest_good_section_namef   rJ   z&SectionNameTest.test_good_section_nameN)r!   r"   r#   rE   rI   rK   rL   rN   r   r   r   r   r=   K   ó    	r=   c                   @   r<   )ÚModuleNameTestc                   @   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?   r@   rA   r   r   r   r   r   r   rB   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
    rS   c                 C   rF   rG   ©rS   r+   r%   r,   r   r-   r   r   r   Útest_blank_module_namex   rJ   z%ModuleNameTest.test_blank_module_namec                 C   rF   )NZ __name_xyz123_should_not_exist__z	not foundr   rT   r-   r   r   r   Útest_bogus_module_name}   rJ   z%ModuleNameTest.test_bogus_module_namec                 C   rF   )NÚ	itertoolszsource-basedr   rT   r-   r   r   r   Útest_c_source_name‚   rJ   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)rS   r5   r%   Úendswithr+   r   r-   r   r   r   Útest_good_module_name‡   s   

z$ModuleNameTest.test_good_module_nameN)r!   r"   r#   rS   rU   rV   rX   r\   r   r   r   r   rP   l   rO   rP   c                   @   ó4   e Zd Z	 G dd„ dƒZdd„ Zdd„ Zdd„ Zd	S )
ÚGotoTestc                   @   ó$   e Zd ZejjZdd„ Zdd„ ZdS )zGotoTest.Dummy_ModuleNamec                 C   r?   r@   rA   r   r   r   r   r   •   rB   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   rS   “   ó    rS   c                 C   rF   )NÚaznot a base 10 integerr   rT   r-   r   r   r   Útest_bogus_goto›   rJ   zGotoTest.test_bogus_gotoc                 C   rF   )NÚ0znot a positive integerr   rT   r-   r   r   r   Útest_bad_goto    rJ   zGotoTest.test_bad_gotoc                 C   rM   )NÚ1é   r   r   )rS   r+   r%   r   r-   r   r   r   Útest_good_goto¥   rJ   zGotoTest.test_good_gotoN)r!   r"   r#   rS   rc   re   rh   r   r   r   r   r^      s    r^   c                   @   ó$   e Zd Z	 G dd„ dƒZdd„ ZdS )ÚHelpsourceBrowsefileTestc                   @   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    
rn   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   ©rb   ÚbÚcr   r   r   Ú<lambda>»   ó    zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>c                 S   ó   t S ©N©Ú__file__rq   r   r   r   rt   ¼   ru   Zhtestc                 S   ro   rp   r   rq   r   r   r   rt   ½   ru   c                 S   rv   rw   rx   rq   r   r   r   rt   ¾   ru   )	rn   ry   ÚsubTestrm   ÚsetZaskfilenamerl   r+   Úget)r   r.   ÚpathÚfuncr   r   r   r   Útest_file_replaces_path´   s   ü
ü€ûz0HelpsourceBrowsefileTest.test_file_replaces_pathN)r!   r"   r#   rn   r   r   r   r   r   rj   ­   s    rj   c                   @   sN   e 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 )ÚHelpsourcePathokTestc                   @   s&   e Zd ZejjZdd„ Zddd„ZdS )z%HelpsourcePathokTest.Dummy_HelpSourcec                 C   r?   r@   )r   r}   Ú
path_error)r   Z
dummy_pathr   r   r   r   Ë   rB   z.HelpsourcePathokTest.Dummy_HelpSource.__init__Nc                 C   r   r   )r   )r   r   Zwidgetr   r   r   r   Î   r   z/HelpsourcePathokTest.Dummy_HelpSource.showerrorrw   )r!   r"   r#   r   rk   Úpath_okr   r   r   r   r   r   rn   É   s    rn   c                 C   s   | j t_d S rw   )Úorig_platformr   Úplatform©Úclsr   r   r   ÚtearDownClassÒ   ó   z"HelpsourcePathokTest.tearDownClassc                 C   rF   )Nr)   zno help filer   )rn   r+   r‚   r,   r   r-   r   r   r   Útest_path_ok_blankÖ   rJ   z'HelpsourcePathokTest.test_path_ok_blankc                 C   s4   |   td ¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nzbad-bad-badz	not existr   )rn   ry   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   )rn   r+   rz   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   )
rn   rz   r   r„   r}   r{   ry   r+   r‚   r   )r   r.   r„   Úprefixr   r   r   Útest_path_ok_fileé   s   

ü€ÿz&HelpsourcePathokTest.test_path_ok_fileN)r!   r"   r#   rn   r   r„   rƒ   Úclassmethodr‡   r‰   rŠ   rŒ   r‘   r   r   r   r   r€   Æ   s    
	r€   c                   @   ri   )ÚHelpsourceEntryokTestc                   @   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 rw   )Únamer   r   r   r   Úitem_okú   ó   z.HelpsourceEntryokTest.Dummy_HelpSource.item_okc                 C   r”   rw   )r}   r   r   r   r   r‚   ü   r—   z.HelpsourceEntryokTest.Dummy_HelpSource.path_okN)
r!   r"   r#   r   rk   r%   r   r   r–   r‚   r   r   r   r   rn   ö   s    rn   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˜   )rn   rz   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#   rn   rš   r   r   r   r   r“   ó   s    	r“   c                   @   r]   )
ÚCustomRunCLIargsokTestc                   @   r_   )z&CustomRunCLIargsokTest.Dummy_CustomRunc                 C   r?   r@   rA   r   r   r   r   r     rB   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  ra   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   rF   )Nz'no-closing-quotez
No closingr   )rž   r+   r   r,   r   r-   r   r   r   Útest_invalid_args  rJ   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›     s    r›   c                   @   ri   )ÚCustomRunEntryokTestc                   @   s&   e Zd ZejjZi Zeƒ Zdd„ Z	dS )z$CustomRunEntryokTest.Dummy_CustomRunc                 C   r”   rw   )Ú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{   rz   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¤   '  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 rw   )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 rw   )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   rC   r+   rD   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Â   rY   Tr¬   rZ   )r   r¯   r   rQ   r+   rR   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   r`   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   rk   ry   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Titlerb   úb=1T)r¥   r­   za b=1z c)rb   rÐ   rs   )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)rY   r   ZunittestZtest.supportr   Útkinterr   r   rÍ   r   Zidlelib.idle_test.mock_tkr   ZTestCaser	   r=   rP   r^   rj   r€   r“   r›   r¤   r©   r¾   rÅ   rÉ   rË   rÏ   r!   Úmainr   r   r   r   Ú<module>   s4    3!$-+ÿ