B
    Ûö›\ø-  ã               @   s&  d Z ddlmZ ddlZddlmZ ddl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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 ) a½  Test query, coverage 91%).

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)Ú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               @   sF   e Zd ZejjZejjZejjZeƒ Z	i Z
dd„ Zdd„ Zdd„ ZdS )zQueryTest.Dummy_Queryc             C   s&   | j  |¡ d| jd< d | _d| _d S )NÚ ÚtextF)ÚentryÚsetÚentry_errorÚresultÚ	destroyed)ÚselfÚdummy_entry© r   ú-lib/python3.7/idlelib/idle_test/test_query.pyÚ__init__#   s    
zQueryTest.Dummy_Query.__init__c             C   s   || j d< d S )Nr	   )r   )r   Úmessager   r   r   Ú	showerror(   s    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   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 )Nz  good Úgood)NFr	   r   )r   r    r   r   r   r   )r   r"   ÚEqualr   r   r   Útest_entry_ok_good3   s
    
zQueryTest.test_entry_ok_goodc             C   sT   |   d¡}t ¡ |j_|  | ¡ d ¡ |  |jjj¡ |j`|  |j	|j
fd¡ d S )Nr   )NF)r   r   ÚMockr
   Z	focus_setr    r   Ú
assertTrueÚcalledr   r   )r   r"   r   r   r   Útest_ok_blank:   s    
zQueryTest.test_ok_blankc             C   s2   |   d¡}|  | ¡ d ¡ |  |j|jfd¡ d S )Nr$   )r$   T)r   r    r   r   r   )r   r"   r   r   r   Útest_ok_goodB   s    
zQueryTest.test_ok_goodc             C   s2   |   d¡}|  | ¡ d ¡ |  |j|jfd¡ d S )Nzdoes not matter)NT)r   r    r   r   r   )r   r"   r   r   r   Útest_cancelG   s    
zQueryTest.test_cancelN)
r   r   r   Ú__doc__r   r#   r&   r*   r+   r,   r   r   r   r   r      s   r   c               @   s>   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               @   s4   e Zd ZejjZdgZeƒ Zi Z	dd„ Z
dd„ ZdS )z!SectionNameTest.Dummy_SectionNameÚusedc             C   s   | j  |¡ d| jd< d S )Nr   r	   )r
   r   r   )r   r   r   r   r   r   U   s    z*SectionNameTest.Dummy_SectionName.__init__c             C   s   || j d< d S )Nr	   )r   )r   r   r   r   r   r   X   s    z+SectionNameTest.Dummy_SectionName.showerrorN)r   r   r   r   ÚSectionNamer   Ú
used_namesr   r
   r   r   r   r   r   r   r   ÚDummy_SectionNameP   s   r2   c             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nr   zno namer	   )r2   r    r   r!   r   )r   r"   r   r   r   Útest_blank_section_name[   s    
z'SectionNameTest.test_blank_section_namec             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nr/   Zuser	   )r2   r    r   r!   r   )r   r"   r   r   r   Útest_used_section_name`   s    
z&SectionNameTest.test_used_section_namec             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r	   )r2   r    r   r!   r   )r   r"   r   r   r   Útest_long_section_namee   s    
z&SectionNameTest.test_long_section_namec             C   s0   |   d¡}|  | ¡ d¡ |  |jd d¡ d S )Nz  good r$   r	   r   )r2   r    r   r   )r   r"   r   r   r   Útest_good_section_namej   s    
z&SectionNameTest.test_good_section_nameN)	r   r   r   r-   r2   r3   r4   r5   r6   r   r   r   r   r.   M   s   r.   c               @   s>   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 )ÚModuleNameTestz"Test ModuleName subclass of Query.c               @   s2   e Zd ZejjZdZeƒ Zi Z	dd„ Z
dd„ ZdS )zModuleNameTest.Dummy_ModuleNamer   c             C   s   | j  |¡ d| jd< d S )Nr   r	   )r
   r   r   )r   r   r   r   r   r   x   s    z(ModuleNameTest.Dummy_ModuleName.__init__c             C   s   || j d< d S )Nr	   )r   )r   r   r   r   r   r   {   s    z)ModuleNameTest.Dummy_ModuleName.showerrorN)r   r   r   r   Ú
ModuleNamer   Útext0r   r
   r   r   r   r   r   r   r   ÚDummy_ModuleNames   s   r:   c             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nr   zno namer	   )r:   r    r   r!   r   )r   r"   r   r   r   Útest_blank_module_name~   s    
z%ModuleNameTest.test_blank_module_namec             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )NZ __name_xyz123_should_not_exist__z	not foundr	   )r:   r    r   r!   r   )r   r"   r   r   r   Útest_bogus_module_nameƒ   s    
z%ModuleNameTest.test_bogus_module_namec             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )NÚ	itertoolszsource-basedr	   )r:   r    r   r!   r   )r   r"   r   r   r   Útest_c_source_nameˆ   s    
z!ModuleNameTest.test_c_source_namec             C   s4   |   d¡}|  | ¡  d¡¡ |  |jd d¡ d S )NÚidlelibz__init__.pyr	   r   )r:   r(   r   Úendswithr    r   )r   r"   r   r   r   Útest_good_module_name   s    
z$ModuleNameTest.test_good_module_nameN)	r   r   r   r-   r:   r;   r<   r>   rA   r   r   r   r   r7   p   s   r7   c               @   s&   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   rF   c          
   C   s   |   ¡ }x‚ddd„ dfddd„ tfddd„ dfddd„ tffD ]J\}}}|  ¡ 2 |j |¡ ||_| ¡  |  |j ¡ |¡ W d Q R X q>W d S )Nr   c             S   s   dS )Nr   r   )ÚaÚbÚcr   r   r   Ú<lambda>¥   ó    zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>c             S   s   t S )N)Ú__file__)rG   rH   rI   r   r   r   rJ   ¦   rK   Zhtestc             S   s   dS )Nr   r   )rG   rH   rI   r   r   r   rJ   §   rK   c             S   s   t S )N)rL   )rG   rH   rI   r   r   r   rJ   ¨   rK   )	rF   rL   ÚsubTestrE   r   ZaskfilenamerD   r    Úget)r   r"   ÚpathÚfuncr   r   r   r   Útest_file_replaces_pathž   s    
z0HelpsourceBrowsefileTest.test_file_replaces_pathN)r   r   r   r-   rF   rQ   r   r   r   r   rB   —   s   rB   c               @   sJ   e Zd ZdZG dd„ dƒ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               @   s0   e Zd ZejjZeƒ Zi Zdd„ Z	ddd„Z
dS )z%HelpsourcePathokTest.Dummy_HelpSourcec             C   s   | j  |¡ d| jd< d S )Nr   r	   )rO   r   Ú
path_error)r   Z
dummy_pathr   r   r   r   ·   s    z.HelpsourcePathokTest.Dummy_HelpSource.__init__Nc             C   s   || j d< d S )Nr	   )rS   )r   r   Zwidgetr   r   r   r   º   s    z/HelpsourcePathokTest.Dummy_HelpSource.showerror)N)r   r   r   r   rC   Úpath_okr   rO   rS   r   r   r   r   r   r   rF   ³   s
   rF   c             C   s
   t t_d S )N)Úorig_platformr   Úplatform)Úclsr   r   r   ÚtearDownClass½   s    z"HelpsourcePathokTest.tearDownClassc             C   s0   |   d¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nr   zno help filer	   )rF   r    rT   r!   rS   )r   r"   r   r   r   Útest_path_ok_blankÁ   s    
z'HelpsourcePathokTest.test_path_ok_blankc             C   s4   |   td ¡}|  | ¡ d ¡ |  d|jd ¡ d S )Nzbad-bad-badz	not existr	   )rF   rL   r    rT   r!   rS   )r   r"   r   r   r   Útest_path_ok_badÆ   s    z%HelpsourcePathokTest.test_path_ok_badc          
   C   sd   |   d¡}| j}xNdD ]F}|  ¡ 4 |j |¡ |  | ¡ |¡ |  |jd d¡ W d Q R X qW d S )Nr   )z
www.py.orgzhttp://py.orgr	   )rF   r    rM   rO   r   rT   rS   )r   r"   r%   Zurlr   r   r   Útest_path_ok_webË   s    


z%HelpsourcePathokTest.test_path_ok_webc          
   C   sl   |   d¡}x\dD ]T\}}|  ¡ > |t_|j t¡ |  | ¡ |t ¡ |  |j	d d¡ W d Q R X qW d S )Nr   ))Údarwinzfile://)Úotherr   r	   )
rF   rM   r   rV   rO   r   rL   r    rT   rS   )r   r"   rV   Úprefixr   r   r   Útest_path_ok_fileÔ   s    

z&HelpsourcePathokTest.test_path_ok_fileN)r   r   r   r-   rF   ÚclassmethodrX   rY   rZ   r[   r_   r   r   r   r   rR   °   s   
	rR   c               @   s&   e Zd ZdZG dd„ dƒZdd„ ZdS )Ú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   s   | j S )N)Úname)r   r   r   r   Úitem_okå   s    z.HelpsourceEntryokTest.Dummy_HelpSource.item_okc             C   s   | j S )N)rO   )r   r   r   r   rT   ç   s    z.HelpsourceEntryokTest.Dummy_HelpSource.path_okN)
r   r   r   r   rC   r   r   rS   rc   rT   r   r   r   r   rF   á   s
   rF   c          
   C   sR   |   ¡ }xDdD ]<\}}}|  ¡ $ || |_|_|  | ¡ |¡ W d Q R X qW d S )N))NNN)Nzdoc.txtN)ÚdocNN)rd   zdoc.txt)rd   zdoc.txt)rF   rM   rb   rO   r    r   )r   r"   rb   rO   r   r   r   r   Útest_entry_ok_helpsourceê   s
    
z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)r   r   r   r-   rF   re   r   r   r   r   ra   Þ   s   	ra   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TESTZtestT)Ú_utest)
r   r   ÚrootÚwithdrawr   r   r"   r   r'   r   )rW   ri   r   r   r   Ú
setUpClassù   s
    
zQueryGuiTest.setUpClassc             C   s   | j `| ` | j ¡  | `d S )N)r"   r   ri   )rW   r   r   r   rX     s    
zQueryGuiTest.tearDownClassc             C   s(   | j j dd¡ d | j _| j j ¡  d S )Nr   Úend)r"   r
   Údeleter   r   Z
reset_mock)r   r   r   r   ÚsetUp  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   r(   r   r)   )r   r"   r   r   r   Útest_click_ok  s
    
zQueryGuiTest.test_click_okc             C   s0   | j }|j ¡  |  |jd ¡ |  |jj¡ d S )N)r"   rq   rr   r    r   ZassertFalser   r)   )r   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 )Nr   ro   )
r"   r
   rp   Zbutton_cancelrr   r    r   r(   r   r)   )r   r"   r   r   r   Útest_click_cancel  s
    
zQueryGuiTest.test_click_cancelN)
r   r   r   r`   rk   rX   rn   rs   rt   ru   r   r   r   r   rf   ÷   s   rf   c               @   s    e Zd Zedd„ ƒZdd„ ZdS )ÚSectionnameGuiTestc             C   s   t dƒ d S )Nrg   )r   )rW   r   r   r   rk   $  s    zSectionnameGuiTest.setUpClassc             C   sp   t ƒ }| ¡  tj|dddhdd}| j}|  |jdh¡ |j dd¡ |j 	¡  |  |j
d¡ ~| ¡  ~d S )NÚTÚtro   T)rh   r   Zokay)r   rj   r   r0   r    r1   r
   rp   rq   rr   r   r   )r   ri   r"   r%   r   r   r   Útest_click_section_name(  s    
z*SectionnameGuiTest.test_click_section_nameN)r   r   r   r`   rk   ry   r   r   r   r   rv   "  s   rv   c               @   s    e Zd Zedd„ ƒZdd„ ZdS )ÚModulenameGuiTestc             C   s   t dƒ d S )Nrg   )r   )rW   r   r   r   rk   8  s    zModulenameGuiTest.setUpClassc             C   sn   t ƒ }| ¡  tj|ddddd}|  |jd¡ |  |j ¡ d¡ |j 	¡  |  
|j d¡¡ ~| ¡  ~d S )Nrw   rx   r?   T)rh   z__init__.py)r   rj   r   r8   r    r9   r
   rN   rq   rr   r(   r   r@   r   )r   ri   r"   r   r   r   Útest_click_module_name<  s    
z(ModulenameGuiTest.test_click_module_nameN)r   r   r   r`   rk   r{   r   r   r   r   rz   6  s   rz   c               @   s    e Zd Zedd„ ƒZdd„ ZdS )ÚHelpsourceGuiTestc             C   s   t dƒ d S )Nrg   )r   )rW   r   r   r   rk   K  s    zHelpsourceGuiTest.setUpClassc             C   sˆ   t ƒ }| ¡  tj|ddtdd}| j}||j ¡ dƒ ||j ¡ tƒ |j	 
¡  tjdkr`dnd}||jd|t fƒ ~| ¡  ~d S )Nrw   Z__test__T)ZmenuitemÚfilepathrh   r\   zfile://r   )r   rj   r   rC   rL   r    r
   rN   rO   rq   rr   ÚsysrV   r   r   )r   ri   r"   r%   r^   r   r   r   Útest_click_help_sourceO  s    


z(HelpsourceGuiTest.test_click_help_sourceN)r   r   r   r`   rk   r   r   r   r   r   r|   I  s   r|   Ú__main__é   F)Ú	verbosityÚexit)r-   r?   r   ZunittestZtest.supportr   Ztkinterr   r~   r   Zidlelib.idle_test.mock_tkr   ZTestCaser   r.   r7   rV   rU   rB   rR   ra   rf   rv   rz   r|   r   Úmainr   r   r   r   Ú<module>   s(   5#%.+
