
    ;e                        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
 Zd Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Zedk    r ej         d           dS 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)requiresguiN)TkTclErrorCHARNONEWORD)Button)Func)	Mbox_funcc                  T    t                      at                                           d S Nr   rootwithdraw     6/usr/lib/python3.11/idlelib/idle_test/test_textview.pysetUpModuler      s    44DMMOOOOOr   c                  l    t                                            t                                            b d S r   r   update_idletasksdestroyr   r   r   tearDownModuler      s(    LLNNNr   c                   J    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/        ItvvH$&&KKKr   r   c                   &    e Zd Zd Zd Zd Zd ZdS )ViewWindowTestc                     t           j                                         t           j                                         t           j                                         d S r   )r   r!   __init__r"   r#   selfs    r   setUpzViewWindowTest.setUp,   sD    


!!!!!r   c                 2   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)   views     r   test_init_modalzViewWindowTest.test_init_modal1   si    $--+,,,*+++-...					r   c                 6   t          t          ddd          }|                     t           j        j                   |                     t           j        j                   |                     t           j        j                   |                                 d S Nr,   r-   Fmodal)r   r   assertFalser!   r/   r"   r#   r0   r1   s     r   test_init_nonmodalz!ViewWindowTest.test_init_nonmodal8   st    $E:::,---+,,,.///					r   c                     t          t          ddd          }t                      |_        |                                 |                     |j        j                   |`|                                 d S r5   )r   r   r   r   r0   r.   r/   r1   s     r   test_okzViewWindowTest.test_ok?   s]    $E:::vv			+,,,Lr   N)r   r   r    r*   r3   r9   r;   r   r   r   r%   r%   *   sP        " " "
        r   r%   c                       e Zd Zd ZdS )AutoHideScrollbarTestc                     t          j        t                    }|                     t          |j                   |                     t          |j                   d S r   )tvAutoHideScrollbarr   assertRaisesr   packplace)r)   scrolls     r   test_forbidden_geometryz-AutoHideScrollbarTest.test_forbidden_geometryJ   sH    %d++(FK000(FL11111r   N)r   r   r    rE   r   r   r   r=   r=   H   s#        2 2 2 2 2r   r=   c                   P    e Zd Zed             Zed             ZefdZd Zd Z	dS )ScrollableTextFrameTestc                 X    t                      x| _        }|                                 d S r   r   clsr   s     r   
setUpClassz"ScrollableTextFrameTest.setUpClassR   s#    $$4r   c                 n    | j                                          | j                                          | ` d S r   r   rJ   s    r   tearDownClassz%ScrollableTextFrameTest.tearDownClassW   s3    !!###HHHr   c                 n    t          j        | j        fd|i|fd}|                     |           S )Nwrapc                  X                                                                         d S r   )r   r   )frames   r   cleanup_framez9ScrollableTextFrameTest.make_frame.<locals>.cleanup_frame_   s&    ""$$$MMOOOOOr   )r?   ScrollableTextFramer   
addCleanup)r)   rP   kwargsrS   rR   s       @r   
make_framez"ScrollableTextFrameTest.make_frame]   sT    &tyFFtFvFF	 	 	 	 	 	&&&r   c                     |                                  }|j                            dd           |                     |j                            dd          d           d S )N1.0r-   1.end)rW   textinsertassertEqualget)r)   rR   s     r   
test_line1z"ScrollableTextFrameTest.test_line1e   sU    !!
%---w77EEEEEr   c                    |                      t                    }|                     |j                            d          t                     |                     |j                   t          t          fD ]}| 	                    |          5  |                      |          }|                     |j                            d          |           | 
                    |j                   d d d            n# 1 swxY w Y   d S )N)rP   rP   )rW   r	   r]   r[   cgetassertIsNotNonexscrollr   r
   subTestassertIsNone)r)   rR   rP   s      r   test_horiz_scrollbarz,ScrollableTextFrameTest.test_horiz_scrollbarj   s'    T**00$777U]+++ 4L 	1 	1D4(( 1 1T22  !8!8$???!!%-0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1	1 	1s   AC::C>	C>	N)
r   r   r    classmethodrK   rN   r	   rW   r_   rf   r   r   r   rG   rG   P   s          [   [
 #    F F F
1 1 1 1 1r   rG   c                   @    e Zd Zed             Zed             Zd ZdS )ViewFrameTestc                     t                      x| _        }|                                 t          j        |d          | _        d S )Nr-   )r   r   r   r?   	ViewFramerR   rI   s     r   rK   zViewFrameTest.setUpClass~   s6    $$4L{33			r   c                 r    | ` | j                                         | j                                         | `d S r   )rR   r   r   r   rM   s    r   rN   zViewFrameTest.tearDownClass   s8    I!!###HHHr   c                 h    | j         j        j        }|                      |dd          d           d S )NrY   rZ   r-   )rR   r[   r^   r]   )r)   r^   s     r   r_   zViewFrameTest.test_line1   s6    jo!UG,,k:::::r   N)r   r   r    rg   rK   rN   r_   r   r   r   ri   ri   |   sW        4 4 [4
   [; ; ; ; ;r   ri   c                   X    e Zd Zed             Zed             Zd Zd Zd Zd Z	d Z
dS )	ViewFunctionTestc                 X    t           j        | _        t                      t           _        d S r   )r?   	showerror
orig_errorr   rM   s    r   rK   zViewFunctionTest.setUpClass   s     {{r   c                 ,    | j         t          _        | ` d S r   )rr   r?   rq   rM   s    r   rN   zViewFunctionTest.tearDownClass   s    ~NNNr   c                     t          j        t          ddd          }|                     |t           j                   |                     |j        t           j                   |j                                         d S r5   )r?   	view_textr   assertIsInstance
ViewWindow	viewframerk   r0   r1   s     r   test_view_textzViewFunctionTest.test_view_text   sf    |D';eDDDdBM222dnbl;;;r   c                 j   t          j        t          dt          dd          }|                     |t           j                   |                     |j        t           j                   |j        j        j	        j
        }|                     d |dd                     |                                 d S )Nr,   asciiFr6   TestrY   rZ   )r?   	view_filer   __file__rv   rw   rx   rk   	textframer[   r^   assertInr0   )r)   r2   r^   s      r   test_view_filezViewFunctionTest.test_view_file   s    |D'8WEJJJdBM222dnbl;;;n&+/fcc%11222					r   c                     t          j        t          dddd          }|                     |           |                     t           j        j        d           d S )Nr,   zabc.xyzr{   Fr6   zFile Load Error)r?   r}   r   re   r]   rq   titler1   s     r   test_bad_filezViewFunctionTest.test_bad_file   sR    |D'9gUKKK$+->?????r   c                 R   t           j        }|                    |                    |                    t
                    dd                    }t          j        t          d|dd          }| 	                    |           | 
                    t          j        j        d           d S )Nz..zCREDITS.txtr,   r{   Fr6   zUnicode Decode Error)ospathabspathjoindirnamer~   r?   r}   r   re   r]   rq   r   )r)   pfnr2   s       r   test_bad_encodingz"ViewFunctionTest.test_bad_encoding   s    GYYqvvaii114GGHH|D'2weDDD$+-CDDDDDr   c                     t          j        t          dddd          }|j        j        j        }|                     |                    d          d           d S )Nr,   testFnone)r7   rP   rP   )r?   ru   r   rx   r   r[   r]   ra   )r)   r2   text_widgets      r   test_nowrapzViewFunctionTest.test_nowrap   sS    |D'6VLLLn.3))&116:::::r   N)r   r   r    rg   rK   rN   ry   r   r   r   r   r   r   r   ro   ro      s        # # [#   [    @ @ @E E E; ; ; ; ;r   ro   c                   &    e Zd Zd Zd Zd Zd ZdS )ButtonClickTestc                 "    d | _         d| _        d S )NF)r2   r/   r(   s    r   r*   zButtonClickTest.setUp   s    	r   c                 J    | j         r| j                                          d S d S r   )r2   r   r(   s    r   tearDownzButtonClickTest.tearDown   s0    9 	 I	  	 r   c                      fd}t          t          d|          }|                                                      |j                                         j        d                                 j                                        d                                 j        j	        j
        j                            dd          d           d S )	Nc                  Z    d _         t          j        t          ddd           _        d S )NT
TITLE_TEXTCOMMAND)_utest)r/   r?   ru   r   r2   r(   s   r   _commandzAButtonClickTest.test_view_text_bind_with_button.<locals>._command   s(    DKT<4PPPDIIIr   BUTTONr[   commandTr   rY   rZ   r   )r   r   invokerU   r   r]   r/   r2   r   rx   r   r[   r^   )r)   r   buttons   `  r   test_view_text_bind_with_buttonz/ButtonClickTest.test_view_text_bind_with_button   s    	Q 	Q 	Q 	Q 	Q 8X>>>'''d+++**L999,6;??wOO"	$ 	$ 	$ 	$ 	$r   c                      fd}t          t          d|          }|                                                      |j                                         j        d                                 j                                        d            j        j	        j
        j        j        }t          t                    5 }                      |dd          |                                                                           |                                                       |dd	          |                                                                           d d d            d S # 1 swxY w Y   d S )
Nc                  f    d _         t          j        t          dt          dd           _        d S )NT
TITLE_FILEr{   )encodingr   )r/   r?   r}   r   r~   r2   r(   s   r   r   zAButtonClickTest.test_view_file_bind_with_button.<locals>._command   s4    DKT<.5dD D DDIIIr   r   r   Tr   rY   rZ   z3.0z3.end)r   r   r   rU   r   r]   r/   r2   r   rx   r   r[   r^   openr~   readlinestrip)r)   r   r   r^   fs   `    r   test_view_file_bind_with_buttonz/ButtonClickTest.test_view_file_bind_with_button   s   	D 	D 	D 	D 	D 8X>>>'''d+++**L999i!+04(^^ 	HqSS00!**,,2D2D2F2FGGGJJLLLSS00!**,,2D2D2F2FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   BE--E14E1N)r   r   r    r*   r   r   r   r   r   r   r   r      sU               $ $ $H H H H Hr   r   __main__   )	verbosity)!__doc__idlelibr   r?   test.supportr   r   unittesttkinterr   r   r   r	   r
   tkinter.ttkr   idlelib.idle_test.mock_idler   idlelib.idle_test.mock_tkr   r   r   rw   r   TestCaser%   r=   rG   ri   ro   r   r   mainr   r   r   <module>r      sG    # " " " " " ! ! ! ! ! !  				  2 2 2 2 2 2 2 2 2 2 2 2 2 2       , , , , , , / / / / / /  
             X&   <2 2 2 2 2H- 2 2 2)1 )1 )1 )1 )1h/ )1 )1 )1X; ; ; ; ;H% ; ; ;**; *; *; *; *;x( *; *; *;\&H &H &H &H &Hh' &H &H &HR zHMA r   