<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
B
    „ fÄ  ã               @   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   úD/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_textview.pyÚsetUpModule   s    r   c               C   s   t  ¡  t  ¡  b d S )N)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 )N)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ÚTitlez	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   z	test textF)Úmodal)r   r   ZassertFalser   r!   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 )Nr   z	test textF)r%   )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 )N)ÚtvZAutoHideScrollbarr   ZassertRaisesr   ZpackZplace)r   Zscrollr   r   r   Útest_forbidden_geometryJ   s    
z-AutoHideScrollbarTest.test_forbidden_geometryN)r   r   r   r*   r   r   r   r   r(   H   s   r(   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 )N)r   r   r   )Úclsr   r   r   r   Ú
setUpClassR   s    z"ScrollableTextFrameTest.setUpClassc             C   s   | j  ¡  | j  ¡  | ` d S )N)r   r   r   )r,   r   r   r   ÚtearDownClassW   s    

z%ScrollableTextFrameTest.tearDownClassc                s2   t j| jfd|i|—Ž‰ ‡ fdd„}|  |¡ ˆ S )NÚwrapc                  s   ˆ   ¡  ˆ  ¡  d S )N)r   r   r   )Úframer   r   Úcleanup_frame_   s    z9ScrollableTextFrameTest.make_frame.<locals>.cleanup_frame)r)   ZScrollableTextFramer   Ú
addCleanup)r   r/   Úkwargsr1   r   )r0   r   Ú
make_frame]   s    
z"ScrollableTextFrameTest.make_framec             C   s0   |   ¡ }|j dd¡ |  |j dd¡d¡ d S )Nz1.0z	test textz1.end)r4   ÚtextÚinsertÚassertEqualÚget)r   r0   r   r   r   Ú
test_line1e   s    z"ScrollableTextFrameTest.test_line1c          
   C   s†   | j td}|  |j d¡t¡ |  |j¡ xTttgD ]H}| j	|d2 | j |d}|  |j d¡|¡ |  
|j¡ W d Q R X q6W d S )N)r/   r/   )r4   r   r7   r5   ÚcgetZassertIsNotNoneZxscrollr   r   ZsubTestÚassertIsNone)r   r0   r/   r   r   r   Útest_horiz_scrollbarj   s    z,ScrollableTextFrameTest.test_horiz_scrollbarN)
r   r   r   Úclassmethodr-   r.   r   r4   r9   r<   r   r   r   r   r+   P   s
   r+   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 )Nz	test text)r   r   r   r)   Ú	ViewFramer0   )r,   r   r   r   r   r-   ~   s    zViewFrameTest.setUpClassc             C   s    | ` | j ¡  | j ¡  | `d S )N)r0   r   r   r   )r,   r   r   r   r.   „   s    

zViewFrameTest.tearDownClassc             C   s    | j jj}|  |ddƒd¡ d S )Nz1.0z1.endz	test text)r0   r5   r8   r7   )r   r8   r   r   r   r9   ‹   s    
zViewFrameTest.test_line1N)r   r   r   r=   r-   r.   r9   r   r   r   r   r>   |   s   r>   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 )N)r)   Ú	showerrorÚ
orig_errorr   )r,   r   r   r   r-   “   s    zViewFunctionTest.setUpClassc             C   s   | j t_| ` d S )N)rB   r)   rA   )r,   r   r   r   r.   ˜   s    zViewFunctionTest.tearDownClassc             C   s>   t jtdddd}|  |t j¡ |  |jt j¡ |j ¡  d S )Nr   z	test textF)r%   )r)   Ú	view_textr   ÚassertIsInstanceÚ
ViewWindowÚ	viewframer?   r"   )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   ÚasciiF)r%   ZTestz1.0z1.end)r)   Ú	view_filer   Ú__file__rD   rE   rF   r?   Ú	textframer5   r8   ZassertInr"   )r   r#   r8   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.xyzrH   F)r%   zFile Load Error)r)   rI   r   r;   r7   rA   Útitle)r   r#   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   rH   F)r%   zUnicode Decode Error)ÚosÚpathÚabspathÚjoinÚdirnamerJ   r)   rI   r   r;   r7   rA   rM   )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   ZtestFZnone)r%   r/   r/   )r)   rC   r   rF   rK   r5   r7   r:   )r   r#   Ztext_widgetr   r   r   Útest_nowrap¸   s    
zViewFunctionTest.test_nowrapN)r   r   r   r=   r-   r.   rG   rL   rN   rV   rW   r   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 )
Ú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 )N)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!   r)   rC   r   r#   r   )r   r   r   Ú_commandÊ   s    zAButtonClickTest.test_view_text_bind_with_button.<locals>._commandÚBUTTON)r5   ÚcommandTrZ   z1.0z1.endr[   )r	   r   Úinvoker2   r   r7   r!   r#   rM   rF   rK   r5   r8   )r   r]   Ú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ƒB}ˆ  |ddƒ| ¡  ¡ ¡ | ¡  ˆ  |d	d
ƒ| ¡  ¡ ¡ W d Q R X d S )Nc                  s    dˆ _ tjtdtdddˆ _d S )NTÚ
TITLE_FILErH   )Úencodingr\   )r!   r)   rI   r   rJ   r#   r   )r   r   r   r]   ×   s    
zAButtonClickTest.test_view_file_bind_with_button.<locals>._commandr^   )r5   r_   Trc   z1.0z1.endz3.0z3.end)r	   r   r`   r2   r   r7   r!   r#   rM   rF   rK   r5   r8   ÚopenrJ   ÚreadlineÚstrip)r   r]   ra   r8   Úfr   )r   r   Útest_view_file_bind_with_buttonÖ   s    
z/ButtonClickTest.test_view_file_bind_with_buttonN)r   r   r   r   rY   rb   ri   r   r   r   r   rX   ¿   s   rX   Ú__main__é   )Ú	verbosity)!Ú__doc__Zidlelibr   r)   Ztest.supportr   rO   ZunittestZtkinterr   r   r   r   r   Ztkinter.ttkr	   Zidlelib.idle_test.mock_idler
   Zidlelib.idle_test.mock_tkr   r   r   rE   r   ZTestCaser   r(   r+   r>   r@   rX   r   Úmainr   r   r   r   Ú<module>   s(   ,.)
