a
    åzeÄ  ã                   @   s  d Z ddlmZ ddlmZ edƒ ddlZddlZddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ dd	lmZ d
d„ Zdd„ 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S )a  Test textview, coverage 100%.

Since all methods and functions create (or destroy) a ViewWindow, which
is a widget containing a widget, etcetera, all tests must be gui tests.
Using mock Text would not change this.  Other mocks are used to retrieve
information about calls.
é    )Útextview)ÚrequiresZguiN)ÚTkÚTclErrorÚCHARÚNONEÚWORD)ÚButton)ÚFunc)Ú	Mbox_funcc                   C   s   t ƒ at ¡  d S ©N©r   ÚrootÚwithdraw© r   r   ú5/usr/lib/python3.9/idlelib/idle_test/test_textview.pyÚsetUpModule   s    r   c                   C   s   t  ¡  t  ¡  b d S r   ©r   Úupdate_idletasksÚdestroyr   r   r   r   ÚtearDownModule   s    r   c                   @   s   e Zd Zeƒ Zeƒ Zeƒ ZdS )ÚVWN)Ú__name__Ú
__module__Ú__qualname__r
   Ú	transientÚgrab_setÚwait_windowr   r   r   r   r   #   s   r   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚViewWindowTestc                 C   s"   t j ¡  t j ¡  t j ¡  d S r   )r   r   Ú__init__r   r   ©Úselfr   r   r   ÚsetUp,   s    

zViewWindowTest.setUpc                 C   sB   t tddƒ}|  t jj¡ |  t jj¡ |  t jj¡ | ¡  d S )NÚTitleú	test text)r   r   Ú
assertTruer   Úcalledr   r   Úok©r!   Úviewr   r   r   Útest_init_modal1   s
    zViewWindowTest.test_init_modalc                 C   sF   t tdddd}|  t jj¡ |  t jj¡ |  t jj¡ | ¡  d S ©Nr#   r$   F©Úmodal)r   r   ZassertFalser   r&   r   r   r'   r(   r   r   r   Útest_init_nonmodal8   s
    z!ViewWindowTest.test_init_nonmodalc                 C   s>   t tdddd}tƒ |_| ¡  |  |jj¡ |`| ¡  d S r+   )r   r   r
   r   r'   r%   r&   r(   r   r   r   Útest_ok?   s    zViewWindowTest.test_okN)r   r   r   r"   r*   r.   r/   r   r   r   r   r   *   s   r   c                   @   s   e Zd Zdd„ ZdS )ÚAutoHideScrollbarTestc                 C   s*   t  t¡}|  t|j¡ |  t|j¡ d S r   )ÚtvZAutoHideScrollbarr   ZassertRaisesr   ÚpackZplace)r!   Zscrollr   r   r   Útest_forbidden_geometryJ   s    
z-AutoHideScrollbarTest.test_forbidden_geometryN)r   r   r   r3   r   r   r   r   r0   H   s   r0   c                   @   s@   e Zd Zedd„ ƒZedd„ ƒZefdd„Zdd„ Zd	d
„ Z	dS )ÚScrollableTextFrameTestc                 C   s   t ƒ  | _}| ¡  d S r   r   ©Úclsr   r   r   r   Ú
setUpClassR   s    z"ScrollableTextFrameTest.setUpClassc                 C   s   | j  ¡  | j  ¡  | ` d S r   r   ©r6   r   r   r   ÚtearDownClassW   s    

z%ScrollableTextFrameTest.tearDownClassc                    s2   t j| jfd|i|¤Ž‰ ‡ fdd„}|  |¡ ˆ S )NÚwrapc                      s   ˆ   ¡  ˆ  ¡  d S r   )r   r   r   ©Úframer   r   Úcleanup_frame_   s    z9ScrollableTextFrameTest.make_frame.<locals>.cleanup_frame)r1   ZScrollableTextFramer   Ú
addCleanup)r!   r:   Úkwargsr=   r   r;   r   Ú
make_frame]   s    
z"ScrollableTextFrameTest.make_framec                 C   s0   |   ¡ }|j dd¡ |  |j dd¡d¡ d S )Nú1.0r$   ú1.end)r@   ÚtextÚinsertÚassertEqualÚget)r!   r<   r   r   r   Ú
test_line1e   s    z"ScrollableTextFrameTest.test_line1c              	   C   s–   | j td}|  |j d¡t¡ |  |j¡ ttfD ]\}| j	|d< | j |d}|  |j d¡|¡ |  
|j¡ W d   ƒ q41 s†0    Y  q4d S )N)r:   r:   )r@   r   rE   rC   ÚcgetZassertIsNotNoneZxscrollr   r   ZsubTestÚassertIsNone)r!   r<   r:   r   r   r   Útest_horiz_scrollbarj   s    z,ScrollableTextFrameTest.test_horiz_scrollbarN)
r   r   r   Úclassmethodr7   r9   r   r@   rG   rJ   r   r   r   r   r4   P   s   

r4   c                   @   s,   e Zd Zedd„ ƒZedd„ ƒZdd„ ZdS )ÚViewFrameTestc                 C   s&   t ƒ  | _}| ¡  t |d¡| _d S )Nr$   )r   r   r   r1   Ú	ViewFramer<   r5   r   r   r   r7   ~   s    zViewFrameTest.setUpClassc                 C   s    | ` | j ¡  | j ¡  | `d S r   )r<   r   r   r   r8   r   r   r   r9   „   s    

zViewFrameTest.tearDownClassc                 C   s    | j jj}|  |ddƒd¡ d S )NrA   rB   r$   )r<   rC   rF   rE   )r!   rF   r   r   r   rG   ‹   s    
zViewFrameTest.test_line1N)r   r   r   rK   r7   r9   rG   r   r   r   r   rL   |   s
   

rL   c                   @   sL   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S )ÚViewFunctionTestc                 C   s   t j| _tƒ t _d S r   )r1   Ú	showerrorÚ
orig_errorr   r8   r   r   r   r7   “   s    zViewFunctionTest.setUpClassc                 C   s   | j t_| ` d S r   )rP   r1   rO   r8   r   r   r   r9   ˜   s    zViewFunctionTest.tearDownClassc                 C   s>   t jtdddd}|  |t j¡ |  |jt j¡ |j ¡  d S r+   )r1   Ú	view_textr   ÚassertIsInstanceÚ
ViewWindowÚ	viewframerM   r'   r(   r   r   r   Útest_view_text   s    zViewFunctionTest.test_view_textc                 C   s\   t jtdtddd}|  |t j¡ |  |jt j¡ |jjj	j
}|  d|ddƒ¡ | ¡  d S )Nr#   ÚasciiFr,   ZTestrA   rB   )r1   Ú	view_filer   Ú__file__rR   rS   rT   rM   Ú	textframerC   rF   ZassertInr'   )r!   r)   rF   r   r   r   Útest_view_file£   s    zViewFunctionTest.test_view_filec                 C   s2   t jtddddd}|  |¡ |  t jjd¡ d S )Nr#   zabc.xyzrV   Fr,   zFile Load Error)r1   rW   r   rI   rE   rO   Útitler(   r   r   r   Útest_bad_file«   s    
zViewFunctionTest.test_bad_filec                 C   sR   t j}| | | t¡dd¡¡}tjtd|ddd}|  	|¡ |  
tjjd¡ d S )Nz..zCREDITS.txtr#   rV   Fr,   zUnicode Decode Error)ÚosÚpathÚabspathÚjoinÚdirnamerX   r1   rW   r   rI   rE   rO   r[   )r!   ÚpÚfnr)   r   r   r   Útest_bad_encoding±   s
    
z"ViewFunctionTest.test_bad_encodingc                 C   s4   t jtddddd}|jjj}|  | d¡d¡ d S )Nr#   ÚtestFZnone)r-   r:   r:   )r1   rQ   r   rT   rY   rC   rE   rH   )r!   r)   Ztext_widgetr   r   r   Útest_nowrap¸   s    
zViewFunctionTest.test_nowrapN)r   r   r   rK   r7   r9   rU   rZ   r\   rd   rf   r   r   r   r   rN   ‘   s   

rN   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚButtonClickTestc                 C   s   d | _ d| _d S )NF)r)   r&   r    r   r   r   r"   Á   s    zButtonClickTest.setUpc                 C   s   | j r| j  ¡  d S r   )r)   r   r    r   r   r   ÚtearDownÅ   s    zButtonClickTest.tearDownc                    sn   ‡ fdd„}t td|d}| ¡  ˆ  |j¡ ˆ  ˆ jd¡ ˆ  ˆ j ¡ d¡ ˆ  ˆ jj	j
j dd¡d	¡ d S )
Nc                      s   dˆ _ tjtddddˆ _d S )NTÚ
TITLE_TEXTÚCOMMAND)Ú_utest)r&   r1   rQ   r   r)   r   r    r   r   Ú_commandÊ   s    zAButtonClickTest.test_view_text_bind_with_button.<locals>._commandÚBUTTON©rC   ZcommandTri   rA   rB   rj   )r	   r   Úinvoker>   r   rE   r&   r)   r[   rT   rY   rC   rF   )r!   rl   Úbuttonr   r    r   Útest_view_text_bind_with_buttonÉ   s    ÿz/ButtonClickTest.test_view_text_bind_with_buttonc                    sÄ   ‡ fdd„}t td|d}| ¡  ˆ  |j¡ ˆ  ˆ jd¡ ˆ  ˆ j ¡ d¡ ˆ jj	j
jj}ttƒL}ˆ  |ddƒ| ¡  ¡ ¡ | ¡  ˆ  |d	d
ƒ| ¡  ¡ ¡ W d   ƒ n1 s¶0    Y  d S )Nc                      s    dˆ _ tjtdtdddˆ _d S )NTÚ
TITLE_FILErV   )Úencodingrk   )r&   r1   rW   r   rX   r)   r   r    r   r   rl   ×   s    
ÿzAButtonClickTest.test_view_file_bind_with_button.<locals>._commandrm   rn   Trr   rA   rB   z3.0z3.end)r	   r   ro   r>   r   rE   r&   r)   r[   rT   rY   rC   rF   ÚopenrX   ÚreadlineÚstrip)r!   rl   rp   rF   Úfr   r    r   Útest_view_file_bind_with_buttonÖ   s    
z/ButtonClickTest.test_view_file_bind_with_buttonN)r   r   r   r"   rh   rq   rx   r   r   r   r   rg   ¿   s   rg   Ú__main__é   )Ú	verbosity)!Ú__doc__Zidlelibr   r1   Ztest.supportr   r]   ZunittestÚtkinterr   r   r   r   r   Ztkinter.ttkr	   Zidlelib.idle_test.mock_idler
   Zidlelib.idle_test.mock_tkr   r   r   rS   r   ZTestCaser   r0   r4   rL   rN   rg   r   Úmainr   r   r   r   Ú<module>   s(   ,.)
