B
    \                 @   s   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ G d	d
 d
ejZG dd dejZedkrejdd dS )zTest outwin, coverage 76%.    )outwinN)requires)TkText)	Mbox_func)Func)mockc               @   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S )OutputWindowTestc             C   sF   t d t  }| _|  td d d | }| _t| | _|_d S )NZgui)	r   r   rootZwithdrawr   ZOutputWindowwindowr   text)clsr
   w r   .lib/python3.7/idlelib/idle_test/test_outwin.py
setUpClass   s
    zOutputWindowTest.setUpClassc             C   s$   | j   | `| ` | j  | `d S )N)r   closer   r
   Zdestroy)r   r   r   r   tearDownClass   s    

zOutputWindowTest.tearDownClassc             C   s   | j dd d S )Nz1.0end)r   delete)selfr   r   r   setUp   s    zOutputWindowTest.setUpc             C   s*   | j }| |d | |t d S )Nztest.txt)r   ZassertFalseZispythonsource__file__)r   r   r   r   r   test_ispythonsource    s    z$OutputWindowTest.test_ispythonsourcec             C   s   |  | jj d d S )NZOutput)assertEqualr   toptitle)r   r   r   r   test_window_title&   s    z"OutputWindowTest.test_window_titlec             C   sd   | j }| j}t |_d|j_|| d ||jjd d|j_|| d ||jjd |`d S )NFZno   TZyes   )r   r   r   Z	get_savedresultZ	maybesavecalled)r   r   eqr   r   r   test_maybesave)   s    zOutputWindowTest.test_maybesavec             C   s  | j }| jj}| jj}| jj}d}|||t| ||dd|  |dd d}|||t| ||ddd ||ddd |dd d}|||t| ||ddd ||ddd	 |dd d
}|||t| ||ddd ||ddd ||ddd |dd d}d}|||ddt| |||ddt| ||dd| ||dd| ||dd|d ||dd|d d S )Ns   Test bytes.z1.0z1.endr   z	test textzinsert linestartzinsert lineendz
test text
 ztest text
Line 2z2.0z2.endzLine 2zLine 2
Zmytag)ZtagsZ	secondtagzmytag.firstz
mytag.lastzsecondtag.firstzsecondtag.last
)	r   r   r   getr   writelendecoderstrip)r   r"   r   r&   r'   bZ	test_textZ
test_text2r   r   r   
test_write7   s@    



zOutputWindowTest.test_writec             C   sb   | j }| jj}| jj}|d ||ddd ||ddd ||dd	d
 ||ddd d S )N)zLine 1
zLine 2
zLine 3
z1.0z1.endzLine 1z2.0z2.endzLine 2z3.0z3.endzLine 3zinsert linestartzinsert lineendr$   )r   r   r&   r   
writelines)r   r"   r&   r-   r   r   r   test_writelinesc   s    z OutputWindowTest.test_writelinesc             C   s
  | j }| j}| j}t |_t  }|j_t  }|_	|
d | |  ||jd ||jd |
tt d |
tt d | |  ||jttdf |dd |
tt d |
d | |  ||jttd	f |j`|`	d S )
NzNot a file liner   zNo special linez: 42: spam
z
: 21: spam   z1.0r   *   )r   r   r   r   ZMockZflistr   Zgotofileliner   	showerrorr'   ZassertIsNoneZgoto_file_liner!   r   strr   argsr   )r   r"   r   r   Zgflr1   r   r   r   test_goto_file_linen   s(    


z$OutputWindowTest.test_goto_file_lineN)__name__
__module____qualname__classmethodr   r   r   r   r   r#   r,   r.   r4   r   r   r   r   r	      s   ,r	   c               @   s2   e Zd Zedd Zdd Zeddd ZdS )	ModuleFunctionTestc             C   s
   d t _d S )N)r   file_line_progs)r   r   r   r   r      s    zModuleFunctionTest.setUpc             C   s6   t   x(tt jt jD ]\}}| |j| qW d S )N)r   Zcompile_progszipZfile_line_patsr:   r   pattern)r   ZpatZregexr   r   r   test_compile_progs   s    z%ModuleFunctionTest.test_compile_progszbuiltins.openc             C   sD   t j}d}x4|D ],\}}| ||| |r||d d qW d S )N))z"foo file "testfile1", line 42, bar)Z	testfile1r0   )zfoo testfile2(21) bar)Z	testfile2r/   )z  testfile3  : 42: foo bar\n)z  testfile3  r0   )zfoo testfile4.py :1: )zfoo testfile4.py r   )u   testfile5: ᧔᧒: )Z	testfile5r0   )ztestfile6: 42N)ztestfile7 42 textNr   r)r   Zfile_line_helperr   Zassert_called_with)r   Z	mock_openZflhZ
test_lineslineZexpected_outputr   r   r   test_file_line_helper   s    z(ModuleFunctionTest.test_file_line_helperN)	r5   r6   r7   r8   r   r=   r   Zpatchr@   r   r   r   r   r9      s   r9   __main__r   )	verbosity)__doc__Zidlelibr   ZunittestZtest.supportr   Ztkinterr   r   Zidlelib.idle_test.mock_tkr   Zidlelib.idle_test.mock_idler   r   ZTestCaser	   r9   r5   mainr   r   r   r   <module>   s    