
    z%i                        	 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       yy)    )textview)requiresguiN)TkTclErrorCHARNONEWORD)Button)Func)	Mbox_funcc                  @    t               at        j                          y Nr   rootwithdraw     S/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_textview.pysetUpModuler      s    4DMMOr   c                  V    t         j                          t         j                          b y r   r   update_idletasksdestroyr   r   r   tearDownModuler      s    LLNr   c                   6    e Zd Z e       Z e       Z e       Zy)VWN)__name__
__module____qualname__r   	transientgrab_setwait_windowr   r   r   r   r   #   s    IvH&Kr   r   c                   $    e Zd Zd Zd Zd Zd Zy)ViewWindowTestc                     t         j                  j                          t         j                  j                          t         j                  j                          y r   )r   r!   __init__r"   r#   selfs    r   setUpzViewWindowTest.setUp,   s2    


!r   c                 <   t        t        dd      }| j                  t         j                  j                         | j                  t         j
                  j                         | j                  t         j                  j                         |j                          y )NTitle	test text)r   r   
assertTruer!   calledr"   r#   okr)   views     r   test_init_modalzViewWindowTest.test_init_modal1   s[    $-++,**+--.	r   c                 @   t        t        ddd      }| j                  t         j                  j                         | j                  t         j
                  j                         | j                  t         j                  j                         |j                          y Nr,   r-   Fmodal)r   r   assertFalser!   r/   r"   r#   r0   r1   s     r   test_init_nonmodalz!ViewWindowTest.test_init_nonmodal8   sc    $E:,,-++,../	r   c                     t        t        ddd      }t               |_        |j	                          | j                  |j                  j                         |`|j                          y r5   )r   r   r   r   r0   r.   r/   r1   s     r   test_okzViewWindowTest.test_ok?   sH    $E:v	++,Lr   N)r   r   r    r*   r3   r9   r;   r   r   r   r%   r%   *   s    "
r   r%   c                       e Zd Zd Zy)AutoHideScrollbarTestc                     t        j                  t              }| j                  t        |j
                         | j                  t        |j                         y r   )tvAutoHideScrollbarr   assertRaisesr   packplace)r)   scrolls     r   test_forbidden_geometryz-AutoHideScrollbarTest.test_forbidden_geometryJ   s:    %%d+(FKK0(FLL1r   N)r   r   r    rE   r   r   r   r=   r=   H   s    2r   r=   c                   B    e Zd Zed        Zed        ZefdZd Zd Z	y)ScrollableTextFrameTestc                 F    t               x| _        }|j                          y r   r   clsr   s     r   
setUpClassz"ScrollableTextFrameTest.setUpClassR   s    $4r   c                 p    | j                   j                          | j                   j                          | ` y r   r   rJ   s    r   tearDownClassz%ScrollableTextFrameTest.tearDownClassW   s'    !!#Hr   c                 x    t        j                  | j                  fd|i|fd}| j                  |       S )Nwrapc                  F     j                           j                          y r   )r   r   )frames   r   cleanup_framez9ScrollableTextFrameTest.make_frame.<locals>.cleanup_frame_   s    ""$MMOr   )r?   ScrollableTextFramer   
addCleanup)r)   rP   kwargsrS   rR   s       @r   
make_framez"ScrollableTextFrameTest.make_frame]   s9    &&tyyFtFvF	 	&r   c                     | j                         }|j                  j                  dd       | j                  |j                  j	                  dd      d       y )N1.0r-   1.end)rW   textinsertassertEqualget)r)   rR   s     r   
test_line1z"ScrollableTextFrameTest.test_line1e   sA    !

%-w7Er   c                    | j                  t              }| j                  |j                  j	                  d      t               | j                  |j                         t        t        fD ]u  }| j                  |      5  | j                  |      }| j                  |j                  j	                  d      |       | j                  |j                         d d d        w y # 1 sw Y   xY w)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$7U]]+ 4L 	1D4( 1T2  !8$?!!%--01 1	11 1s   AC&&C/	N)
r   r   r    classmethodrK   rN   r	   rW   r_   rf   r   r   r   rG   rG   P   s=       
 # F
1r   rG   c                   2    e Zd Zed        Zed        Zd Zy)ViewFrameTestc                 |    t               x| _        }|j                          t        j                  |d      | _        y )Nr-   )r   r   r   r?   	ViewFramerR   rI   s     r   rK   zViewFrameTest.setUpClass~   s+    $4LL{3	r   c                 t    | ` | j                  j                          | j                  j                          | `y r   )rR   r   r   r   rM   s    r   rN   zViewFrameTest.tearDownClass   s,    I!!#Hr   c                 v    | j                   j                  j                  }| j                   |dd      d       y )NrY   rZ   r-   )rR   r[   r^   r]   )r)   r^   s     r   r_   zViewFrameTest.test_line1   s,    jjoo!!UG,k:r   N)r   r   r    rg   rK   rN   r_   r   r   r   ri   ri   |   s-    4 4
  ;r   ri   c                   J    e Zd Zed        Zed        Zd Zd Zd Zd Z	d Z
y)	ViewFunctionTestc                 T    t         j                  | _        t               t         _        y r   )r?   	showerror
orig_errorr   rM   s    r   rK   zViewFunctionTest.setUpClass   s     {r   c                 2    | j                   t        _        | ` y r   )rr   r?   rq   rM   s    r   rN   zViewFunctionTest.tearDownClass   s    ~~Nr   c                    t        j                  t        ddd      }| j                  |t         j                         | j                  |j
                  t         j                         |j
                  j                          y r5   )r?   	view_textr   assertIsInstance
ViewWindow	viewframerk   r0   r1   s     r   test_view_textzViewFunctionTest.test_view_text   sR    ||D';eDdBMM2dnnbll;r   c                    t        j                  t        dt        dd      }| j	                  |t         j
                         | j	                  |j                  t         j                         |j                  j                  j                  j                  }| j                  d |dd             |j                          y )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dBMM2dnnbll;nn&&++//fc%12	r   c                     t        j                  t        dddd      }| j                  |       | j	                  t         j
                  j                  d       y )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   sA    ||D'9gUK$++->?r   c                 @   t         j                  }|j                  |j                  |j	                  t
              dd            }t        j                  t        d|dd      }| j                  |       | j                  t        j                  j                  d       y )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   sn    GGYYqvvaii14GH||D'2weD$++-CDr   c                     t        j                  t        dddd      }|j                  j                  j
                  }| j                  |j                  d      d       y )Nr,   testFnone)r7   rP   rP   )r?   ru   r   rx   r   r[   r]   ra   )r)   r2   text_widgets      r   test_nowrapzViewFunctionTest.test_nowrap   sH    ||D'6VLnn..33))&16:r   N)r   r   r    rg   rK   rN   ry   r   r   r   r   r   r   r   ro   ro      sC    # #  @E;r   ro   c                   $    e Zd Zd Zd Zd Zd Zy)ButtonClickTestc                      d | _         d| _        y )NF)r2   r/   r(   s    r   r*   zButtonClickTest.setUp   s    	r   c                 R    | j                   r| j                   j                          y y r   )r2   r   r(   s    r   tearDownzButtonClickTest.tearDown   s    99II r   c                      fd}t        t        d|      }|j                           j                  |j                          j                   j                  d        j                   j                  j                         d        j                   j                  j                  j                  j                  j                  dd      d       y )	Nc                  X    d _         t        j                  t        ddd       _        y )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PDIr   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 8X>'d+*L9,,66;;??wO"	$r   c                      fd}t        t        d|      }|j                           j                  |j                          j                   j                  d        j                   j                  j                         d        j                  j                  j                  j                  j                  }t        t              5 } j                   |dd      |j                         j!                                |j                           j                   |dd	      |j                         j!                                d d d        y # 1 sw Y   y xY w)
Nc                  b    d _         t        j                  t        dt        dd       _        y )NT
TITLE_FILEr{   )encodingr   )r/   r?   r}   r   r~   r2   r(   s   r   r   zAButtonClickTest.test_view_file_bind_with_button.<locals>._command   s&    DKT<.5dDDIr   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 8X>'d+*L9ii!!++0044(^ 	HqS0!**,2D2D2FGJJLS0!**,2D2D2FG	H 	H 	Hs   A;EEN)r   r   r    r*   r   r   r   r   r   r   r   r      s     $Hr   r   __main__   )	verbosity) 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      s    # !  	  2 2  , /
 X&& <2H-- 2)1h// )1X;H%% ;**;x(( *;\&Hh'' &HR zHMMA r   