B
    v9a  ã               @   sæ   d Z ddlmZ ddlZddlmZ edƒ ddlZddl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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.
é    )ÚtextviewN)ÚrequiresZgui)ÚTk)ÚButton)ÚFunc)Ú	Mbox_funcc               C   s   t ƒ at ¡  d S )N)r   ÚrootÚwithdraw© r
   r
   ú#/usr/lib/python3.7/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edd„ ƒZedd„ ƒZdd„ ZdS )ÚTextFrameTestc             C   s&   t ƒ  | _}| ¡  t |d¡| _d S )Nz	test text)r   r   r	   ÚtvZ	TextFrameÚframe)Úclsr   r
   r
   r   Ú
setUpClassJ   s    zTextFrameTest.setUpClassc             C   s    | ` | j ¡  | j ¡  | `d S )N)r&   r   r   r   )r'   r
   r
   r   ÚtearDownClassP   s    

zTextFrameTest.tearDownClassc             C   s    | j jj}|  |ddƒd¡ d S )Nz1.0z1.endz	test text)r&   ÚtextÚgetÚassertEqual)r   r+   r
   r
   r   Ú
test_line1W   s    
zTextFrameTest.test_line1N)r   r   r   Úclassmethodr(   r)   r-   r
   r
   r
   r   r$   H   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)r1   r%   r0   )r'   r
   r
   r   r)   d   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Ú	viewframeÚ	ViewFramer   )r   r   r
   r
   r   Útest_view_texti   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__r3   r4   r5   r6   Ú	textframer*   r+   ZassertInr   )r   r   r+   r
   r
   r   Útest_view_fileo   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.xyzr8   F)r!   zFile Load Error)r%   r9   r   ÚassertIsNoner,   r0   Útitle)r   r   r
   r
   r   Útest_bad_filew   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   r8   F)r!   zUnicode Decode Error)ÚosÚpathÚabspathÚjoinÚdirnamer:   r%   r9   r   r=   r,   r0   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   ZtestFZnone)r!   ÚwraprH   )r%   r2   r   r5   r;   r*   r,   Zcget)r   r   Ztext_widgetr
   r
   r   Útest_nowrap„   s    
zViewFunctionTest.test_nowrapN)r   r   r   r.   r(   r)   r7   r<   r?   rG   rI   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%   r2   r   r   r
   )r   r
   r   Ú_command–   s    zAButtonClickTest.test_view_text_bind_with_button.<locals>._commandÚBUTTON)r*   ÚcommandTrL   z1.0z1.endrM   )r   r   ÚinvokeÚ
addCleanupr   r,   r   r   r>   r5   r;   r*   r+   )r   rO   Ú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_FILEr8   )ÚencodingrN   )r   r%   r9   r   r:   r   r
   )r   r
   r   rO   £   s    
zAButtonClickTest.test_view_file_bind_with_button.<locals>._commandrP   )r*   rQ   TrV   z1.0z1.endz3.0z3.end)r   r   rR   rS   r   r,   r   r   r>   r5   r;   r*   r+   Úopenr:   ÚreadlineÚstrip)r   rO   rT   r+   Úfr
   )r   r   Útest_view_file_bind_with_button¢   s    
z/ButtonClickTest.test_view_file_bind_with_buttonN)r   r   r   r   rK   rU   r\   r
   r
   r
   r   rJ   ‹   s   rJ   Ú__main__é   )Ú	verbosity)Ú__doc__Zidlelibr   r%   ZunittestZtest.supportr   r@   Ztkinterr   Ztkinter.ttkr   Zidlelib.idle_test.mock_idler   Zidlelib.idle_test.mock_tkr   r   r   r4   r   ZTestCaser   r$   r/   rJ   r   Úmainr
   r
   r
   r   Ú<module>   s$   .)