a
    åze	  ã                   @   s´   d Z ddlmZmZ ddlmZ edƒ ddlmZ ddlZddl	m
Z
mZmZ ddlZdd	„ Zd
d„ Zdd„ Zdd„ ZG dd„ dejƒZG dd„ dejƒZedkr°ejdd dS )zßTest tooltip, coverage 100%.

Coverage is 100% after excluding 6 lines with "# pragma: no cover".
They involve TclErrors that either should or should not happen in a
particular situation, and which are 'pass'ed if they do.
é    )ÚTooltipBaseÚHovertip)ÚrequiresZgui)ÚwrapsN)ÚButtonÚTkÚToplevelc                   C   s
   t ƒ ad S ©N)r   Úroot© r   r   ú4/usr/lib/python3.9/idlelib/idle_test/test_tooltip.pyÚsetUpModule   s    r   c                   C   s   t  ¡  t  ¡  b d S r	   )r
   Zupdate_idletasksÚdestroyr   r   r   r   ÚtearDownModule   s    r   c                    s    t ˆ ƒ‡ ‡fdd„ƒ‰g ˆ_ˆS )Nc                     s   ˆj  | |f¡ ˆ | i |¤ŽS r	   )Úcall_args_listÚappend)ÚargsÚkwargs©ÚfuncÚwrapped_funcr   r   r      s    z'add_call_counting.<locals>.wrapped_func)r   r   )r   r   r   r   Úadd_call_counting   s    r   c                 C   sN   t tƒ}|  |j¡ | d¡ t|dd}| ¡  |  |j¡ | ¡  ||fS )NzTest tooltipúToolTip test button©Útext)r   r
   Ú
addCleanupr   Útitler   ÚpackZlift)ZtestobjÚtopÚbuttonr   r   r   Ú_make_top_and_button&   s    
r    c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚToolTipBaseTestc                 C   s   t | ƒ\| _| _d S r	   ©r    r   r   ©Úselfr   r   r   ÚsetUp3   s    zToolTipBaseTest.setUpc                 C   sr   t tƒ}|  |j¡ t|dd}| ¡  |  |j¡ |  t¡  t|ƒ}| 	¡  W d   ƒ n1 sd0    Y  d S )Nr   r   )
r   r
   r   r   r   r   ZassertRaisesÚNotImplementedErrorr   Úshowtip)r$   r   r   Útooltipr   r   r   Útest_base_class_is_unusable6   s    z+ToolTipBaseTest.test_base_class_is_unusableN)Ú__name__Ú
__module__Ú__qualname__r%   r)   r   r   r   r   r!   2   s   r!   c                   @   sL   e Z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 )ÚHovertipTestc                 C   s   t | ƒ\| _| _d S r	   r"   r#   r   r   r   r%   E   s    zHovertipTest.setUpc                 C   s   |j o|j  ¡ S r	   )Ú	tipwindowZwinfo_viewable©r$   r(   r   r   r   Úis_tipwindow_shownH   s    zHovertipTest.is_tipwindow_shownc                 C   sD   t | jdƒ}|  |j¡ |  |  |¡¡ | ¡  |  |  |¡¡ d S ©NúToolTip text)r   r   r   ÚhidetipÚassertFalser0   r'   Ú
assertTruer/   r   r   r   Útest_showtipK   s
    zHovertipTest.test_showtipc                 C   sp   t | jdƒ}|  |j¡ |  |  |¡¡ | ¡  |  |  |¡¡ |j}| ¡  |  |  |¡¡ |  	|j|¡ d S r1   )
r   r   r   r3   r4   r0   r'   r5   r.   ZassertIs)r$   r(   Zorig_tipwindowr   r   r   Útest_showtip_twiceR   s    zHovertipTest.test_showtip_twicec                 C   s<   t | jdƒ}|  |j¡ | ¡  | ¡  |  |  |¡¡ d S r1   )r   r   r   r3   r'   r4   r0   r/   r   r   r   Útest_hidetip]   s
    zHovertipTest.test_hidetipc                 C   s‚   t | jdd d}|  |j¡ t|jƒ|_t ¡  |  |  	|¡¡ | jj
dddd t ¡  |  |  	|¡¡ |  t|jjƒd¡ d S )Nr2   ©Zhover_delayú<Enter>r   ©ÚxÚy)r   r   r   r3   r   r'   r
   Úupdater4   r0   Úevent_generater5   ÚassertGreaterÚlenr   r/   r   r   r   Ú$test_showtip_on_mouse_enter_no_delayd   s    z1HovertipTest.test_showtip_on_mouse_enter_no_delayc                 C   s(  t | jddd}|  |j¡ t|jƒ|_t ¡  |  |  	|¡¡ | jj
dddd t ¡  |  |  	|¡¡ t | jddd}|  |j¡ t|jƒ|_t ¡  | jj
dddd t ¡  | jj
dddd t ¡  t d¡ t ¡  |  |  	|¡¡ |  t|jjƒd¡ |  |  	|¡¡ |  |jjg ¡ d S )	Nr2   éd   r9   r:   r   r;   ú<Leave>g333333Ã?)r   r   r   r3   r   r'   r
   r>   r4   r0   r?   ÚtimeÚsleepr5   r@   rA   r   ZassertEqual)r$   Ztooltip1Ztooltip2r   r   r   Útest_hover_with_delayo   s,    
z"HovertipTest.test_hover_with_delayc                 C   sŒ   t | jdd d}|  |j¡ t|jƒ|_t ¡  | jjdddd t ¡  | jjdddd t ¡  |  	|  
|¡¡ |  t|jjƒd¡ d S )Nr2   r9   r:   r   r;   rD   )r   r   r   r3   r   r'   r
   r>   r?   r4   r0   r@   rA   r   r/   r   r   r   Útest_hidetip_on_mouse_leave“   s    z(HovertipTest.test_hidetip_on_mouse_leaveN)r*   r+   r,   r%   r0   r6   r7   r8   rB   rG   rH   r   r   r   r   r-   D   s   $r-   Ú__main__é   )Ú	verbosity)Ú__doc__Zidlelib.tooltipr   r   Ztest.supportr   Ú	functoolsr   rE   Útkinterr   r   r   Zunittestr   r   r   r    ZTestCaser!   r-   r*   Úmainr   r   r   r   Ú<module>   s   	\