o
    JAf.                     @   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rJejdd dS 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   4/usr/lib/python3.10/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 )N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titler   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 )NF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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 )Nr   r   z	test text1.endinsert linestartinsert lineendz
test text
 ztest text
Line 22.02.endLine 2Line 2
Zmytag)tagsZ	secondtagzmytag.firstz
mytag.lastzsecondtag.firstzsecondtag.last
)r   r   r   getr   writelenrstrip)r   r'   r   r3   r4   Z	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
r0   zLine 3
r   r)   zLine 1r-   r.   r/   z3.0z3.endzLine 3r*   r+   r,   )r   r   r3   r   
writelines)r   r'   r3   r8   r   r   r   test_writelines^   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   r   r   *   )r   r   r   r   ZMockflistr   Zgotofileliner   	showerrorr4   ZassertIsNoneZgoto_file_liner&   r    strr   argsr   )r   r'   r   r   Zgflr=   r   r   r   test_goto_file_linei   s(   


z$OutputWindowTest.test_goto_file_lineN)__name__
__module____qualname__classmethodr   r   r   r   r!   r(   r7   r9   r@   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 r   )r   file_line_progsr   r   r   r   r      s   
zModuleFunctionTest.setUpc                 C   s2   t   tt jt jD ]\}}| |j| qd S r   )r   Zcompile_progszipZfile_line_patsrF   r   pattern)r   patZregexr   r   r   test_compile_progs   s   z%ModuleFunctionTest.test_compile_progszbuiltins.openc                 C   s@   t j}d}|D ]\}}| ||| |r||d d qd S )N))z"foo file "testfile1", line 42, bar)Z	testfile1r;   )zfoo testfile2(21) bar)Z	testfile2r:   )z  testfile3  : 42: foo bar\n)z  testfile3  r;   )zfoo testfile4.py :1: )zfoo testfile4.py r#   )u   testfile5: ᧔᧒: )Z	testfile5r;   )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)	rA   rB   rC   rD   r   rJ   r   ZpatchrM   r   r   r   r   rE      s    
rE   __main__r$   )	verbosity)__doc__Zidlelibr   ZunittestZtest.supportr   tkinterr   r   Zidlelib.idle_test.mock_tkr   Zidlelib.idle_test.mock_idler   r   ZTestCaser	   rE   rA   mainr   r   r   r   <module>   s    |