o
    JAf;  ã                   @   sŒ   d Z ddlZddlmZ ddlmZmZm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
ejƒZedkrDejddd dS dS )zTest searchbase, coverage 98%.é    N)Úrequires)ÚTextÚTkÚToplevel)ÚFrame)Úsearchengine)Ú
searchbase)ÚFuncc                   @   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dd„ ZdS )ÚSearchDialogBaseTestc                 C   s   t dƒ tƒ | _d S )NZgui)r   r   Úroot©Úcls© r   ú8/usr/lib/python3.10/idlelib/idle_test/test_searchbase.pyÚ
setUpClass   s   zSearchDialogBaseTest.setUpClassc                 C   s   | j  ¡  | j  ¡  | ` d S ©N)r   Úupdate_idletasksÚdestroyr   r   r   r   ÚtearDownClass!   s   

z"SearchDialogBaseTest.tearDownClassc                 C   s&   t  | j¡| _tj| j| jd| _d S )N)r   Úengine)ÚseZSearchEnginer   r   ÚsdbZSearchDialogBaseÚdialog©Úselfr   r   r   ÚsetUp'   s   zSearchDialogBaseTest.setUpc                 C   s   | j  ¡  d S r   )r   Úcloser   r   r   r   ÚtearDown+   s   zSearchDialogBaseTest.tearDownc                 C   s   d | j _t| jƒ}t|ƒ}| j  |¡ |  | j j ¡ d¡ | j  	¡  |  | j j ¡ d¡ | j j|dd |  | j j
 ¡ d¡ | ¡  | ¡  d S )NZnormalZ	withdrawnÚhello)Zsearchphrase)r   Údefault_commandr   r   r   ÚopenÚassertEqualÚtopÚstater   ÚentÚgetr   r   )r   ZtoplevelÚtextr   r   r   Útest_open_and_close.   s   

z(SearchDialogBaseTest.test_open_and_closec                 C   s~   t ƒ | j_t ƒ | j_t ƒ | j_t ƒ | j_d | j_| j ¡  |  | jjj	¡ |  | jjj	¡ |  | jjj	¡ |  | jjj	¡ d S r   )
r	   r   Úcreate_entriesÚcreate_option_buttonsÚcreate_other_buttonsÚcreate_command_buttonsr   Zcreate_widgetsZ
assertTrueZcalledr   r   r   r   Útest_create_widgets>   s   




z(SearchDialogBaseTest.test_create_widgetsc                 C   s®   | j }d| j_t| jƒ| j_| j dd¡\}}||d dƒ |  | ¡ d¡ | 	¡ }|t
|d ƒdƒ |t
|d ƒdƒ |t
|d ƒdƒ |t
|d	 ƒdƒ || jjdƒ d S )
Nr   zTest:r   r&   ÚrowÚcolumné   ZrowspanZ
columnspan)r!   r   r-   r   r   ÚframeZ
make_entryÚassertInr%   Z	grid_infoÚint)r   ZequalÚentryÚlabelZegir   r   r   Útest_make_entryL   s   z$SearchDialogBaseTest.test_make_entryc                 C   sD   t | jƒ| j_d| j_| j d¡ | j ¡  |  | jj	 
¡ d¡ d S )Nr   r   )r   r   r   r0   r-   r   Zsetpatr(   r1   r$   r%   r   r   r   r   Útest_create_entries[   s
   
z(SearchDialogBaseTest.test_create_entriesc                 C   sh   d| j _t| jƒ| j _| j  ¡ \}}|  |d¡ |  tt|ƒƒd¡ | j  d¡\}}|  |d d¡ d S )Nr   Ú z<class 'tkinter.ttk.Frame'>Z	testlabelr&   )	r   r-   r   r   r0   Z
make_framer!   ÚstrÚtype)r   r0   r4   r   r   r   Útest_make_frameb   s   z$SearchDialogBaseTest.test_make_framec                 C   s   t | jƒ| j_d| j_|ƒ S )Nr   )r   r   r   r0   r-   )r   Úmethr   r   r   Úbtn_test_setupn   s   z#SearchDialogBaseTest.btn_test_setupc           	      C   sŠ   | j }dD ]=}|j|j|j|jfD ]}| |¡ q|  | jj¡\}}t	|| 
¡ ƒD ]\}}|\}}|  |d |¡ |  | ¡ |¡ q)qd S )N)r   r/   r&   )r   ZrevarZcasevarZwordvarZwrapvarÚsetr<   r   r)   ÚzipÚpack_slavesr!   r%   )	r   Úer#   Úvarr0   ÚoptionsÚspecÚbuttonr4   r   r   r   Útest_create_option_buttonss   s   ÿýûz/SearchDialogBaseTest.test_create_option_buttonsc           
      C   s~   dD ]:}| j j}| |¡ |  | jj¡\}}| ¡ }t||ƒD ]\}}|\}}	|  |d |	¡ ||kr;|  | 	¡ |¡ qqd S )N)FTr&   )
r   Zbackvarr=   r<   r   r*   r?   r>   r!   r%   )
r   r#   rA   r0   ZothersZbuttonsrC   rD   Úvalr4   r   r   r   Útest_create_other_buttons   s   
ÿ€úúz.SearchDialogBaseTest.test_create_other_buttonsc                 C   sD   t | jƒ| j_t | jjƒ| j_| j d| jj¡}|  |d d¡ d S )NZTestr&   )r   r   r   r0   ÚbuttonframeZmake_buttonr   r!   )r   Zbtnr   r   r   Útest_make_buttonŽ   s   z%SearchDialogBaseTest.test_make_buttonc                 C   sR   t | jƒ| j_| j ¡  d}| jj ¡ D ]}|d dkr |d }q|  d|¡ d S )Nr7   r&   ÚCloseZcommandr   )r   r   r   r0   r+   rH   Zwinfo_childrenr1   )r   ZclosebuttoncommandÚchildr   r   r   Útest_create_command_buttons”   s   
€z0SearchDialogBaseTest.test_create_command_buttonsN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r   r'   r,   r5   r6   r:   r<   rE   rG   rI   rL   r   r   r   r   r
      s"    

r
   Ú__main__é   )Ú	verbosityÚexit)Ú__doc__ZunittestZtest.supportr   Útkinterr   r   r   Ztkinter.ttkr   Zidlelibr   r   r   r   Zidlelib.idle_test.mock_idler	   ZTestCaser
   rM   Úmainr   r   r   r   Ú<module>   s     ÿ