
    ;e>                        d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlZddlmZ ej        j        Z ej        d           ej        d           ej        d           ej        d          d	Zd
Z G d d          Z G d dej                  Z G d dej                  Zedk    r ej        d           dS dS )zTest codecontext, coverage 100%    )codecontextN)requires)NSEWTkFrameTextTclError)mock)config )main	highlightkeys
extensionsz
class C1:
    # Class comment.
    def __init__(self, a, b):
        self.a = a
        self.b = b
    def compare(self):
        if a > b:
            return a
        elif a < b:
            return b
        else:
            return None
c                        e Zd Zd Zd Zd ZdS )DummyEditwinc                 L    || _         || _        || _        || _        d| _        d S )Nr   )roottop
text_frametextlabel)selfr   framer   s       9/usr/lib/python3.11/idlelib/idle_test/test_codecontext.py__init__zDummyEditwin.__init__'   s)    		


    c                 j    t          t          | j                            |                              S N)intfloatr   index)r   r"   s     r   	getlinenozDummyEditwin.getlineno.   s&    5//00111r   c                      |d         | _         d S )Nr   )r   )r   kwargss     r   update_menu_labelzDummyEditwin.update_menu_label1   s    G_


r   N)__name__
__module____qualname__r   r#   r&    r   r   r   r   &   sA          2 2 2% % % % %r   r   c                       e Zd Zed             Zed             Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zej                            ej        d          d             Zd Zd ZdS )CodeContextTestc                    t          d           t                      x}| _        |                                 t	          |          x}| _        t          |          x}| _        |                    dt                     |
                    ddd           |                    ddt                     t          |||          | _        t          t           j        _        d S )Ngui1.0leftboth   )sidefillexpand)rowcolumnsticky)r   r   r   withdrawr   r   r   r   insertcode_samplepackgridr   r   editortestcfgr   idleConfuserCfg)clsr   r   r   s       r   
setUpClasszCodeContextTest.setUpClass7   s    $$sx!$KK'	u++%sxE;'''

VA
666		a$	///!$t44
'.$$$r   c                     t           t          j        _        | j        j                            dd           | `| `| `| j        	                                 | j        
                                 | `d S )Nr/   end)usercfgr   r@   rA   r>   r   deleter   r   update_idletasksdestroy)rB   s    r   tearDownClasszCodeContextTest.tearDownClassE   se    '.$
ue,,,J	38!!###HHHr   c                 `     j                             d           d j         d<   t          j         j                   _        ddd _        t          j        j         fd}t          j
        j                            t          j        d|          }|                                                      |j                   d _         fd	}t          j
        j                            t          j        d
|          }|                                                      |j                   d S )Nr   TkFixedFontfontz#abcdefz#123456
background
foregroundc                 6    |dk    rj         S  | |          S )Ncontext)highlight_cfg)themeelementorig_idleConf_GetHighlightr   s     r   mock_idleconf_GetHighlightz9CodeContextTest.setUp.<locals>.mock_idleconf_GetHighlightV   s*    )##))--eW===r   GetHighlightc                     j         S r   )font_override)r   
configTypesectionr   s      r   mock_idleconf_GetFontz4CodeContextTest.setUp.<locals>.mock_idleconf_GetFont`   s    %%r   GetFont)r   yviewr   CodeContextr>   ccrS   r@   rX   unittestr
   patchobjectstart
addCleanupstoprZ   )r   rW   GetHighlight_patcherr]   GetFont_patcherrV   s   `    @r   setUpzCodeContextTest.setUpN   s>   	)	&)$+66,5,57 7%0%9%F"	> 	> 	> 	> 	> 	>  (}299 .2L N  N""$$$,1222*	& 	& 	& 	& 	&"--44 )-BD D,-----r   c                     | j         j        r| j         j                                         | j                                          | j         `| ` d S r   )ra   rR   rI   __del__r   s    r   tearDownzCodeContextTest.tearDowng   sE    7? 	&GO##%%%GOTWWWr   c                 z   | j         }| j        }| j        } ||j        |            ||j        |j                    ||j        d         |j        d                    |                     |j                    ||j        dg            ||j        d           |                     | j        j	                   d S )NrM   r   r   Fr2   )
assertEqualr>   ra   editwinr   assertIsNonerR   info
topvisiblet1)r   eqedra   s       r   	test_initzCodeContextTest.test_initn   s    [W
2:r
27BG
276?BGFO,,,"*%%%
27'()))
2=!$'*%%%%%r   c                 8    | j                                          d S r   )ra   rl   rm   s    r   test_delzCodeContextTest.test_del{   s    r   c                 ~   | j                             dd           x}| j        _        | j                                         |                     t                    5 }| j        j        	                    dd|           d d d            n# 1 swxY w Y   | 
                    dt          |j                             d S )Ni'  c                      d S r   r*   r*   r   r   <lambda>z5CodeContextTest.test_del_with_timer.<locals>.<lambda>   s    D r   afterru   zdoesn't exist)r   r   ra   rw   rl   assertRaisesr	   r   tkcallassertInstr	exception)r   timercms      r   test_del_with_timerz#CodeContextTest.test_del_with_timer~   s    !Y__ULLAAA
x(( 	6BILgvu555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6os2<'8'899999s   "B

BBc                     t           j                                         |                     | j        j        d           d S )N   )r   r`   reloadrr   ra   context_depthrm   s    r   test_reloadzCodeContextTest.test_reload   s8    &&(((.33333r   c                 x   | j         }| j        }|j        }|j        r
 |              |             |                     |j                    ||j        d         | j        d                     ||j        d         | j        d                     ||j        d         | j        d                     ||j                            dd          d            ||j        j	        d	            || j
        j                            d
d| j        j                  d         d            |             |                     |j                    ||j        j	        d           |                     | j        j                   d                    d |                    d          d         D                       }|j                            d            |              ||j                            dd          |            |              |              ||j                            dd          |           d S )NrM   fgrP   bgrO   r/   end-1cr   zHide Code Contextr   ru   r2   r   zShow Code Context
c              3   &   K   | ]}|d          V  dS )   Nr*   ).0xs     r   	<genexpr>zACodeContextTest.test_toggle_code_context_event.<locals>.<genexpr>   s&      "G"GA1Q4"G"G"G"G"G"Gr      r   )rr   ra   toggle_code_context_eventrR   assertIsNotNoner   rS   getrs   r   r   r   r   rw   rt   joinget_contextr_   )r   rx   ra   toggleline11_contexts        r   test_toggle_code_context_eventz.CodeContextTest.test_toggle_code_context_event   s'   W- : 	FHHH 	RZ(((
2:fty0111
2:dT/=>>>
2:dT/=>>>
2:>>%**B///
2:0111
49<Wfdgj99!<gFFF 	"*%%%
2:0111$'*%%% "G"G1C1CA1F"G"G"GGG
b
2:>>%**N;;; 	
2:>>%**N;;;;;r   c                    | j         }| j        j        }|                     t                    5   |dd           d d d            n# 1 swxY w Y    | |d          dgdf            | |d          dgdf            | |d          ddgdf            | |d	          g d
df            | |d          g ddf            | |dd          g ddf            | |dd          g ddf            | |dd          ddgdf            | |dd          g ddf            | |dd          ddgdf           d S )Nr2   r   )stopline   r   r   	class C1:class      r   r       def __init__(self, a, b):def
   )r      r   z    def compare(self):r      r           if a > b:ifr   )r   r   r   r   r   z        elif a < b:elifr   )r   r   r   r   r   r   )
stopindent)rr   ra   r   r   AssertionError)r   rx   gcs      r   test_get_contextz CodeContextTest.test_get_context   s   W  ~.. 	 	Bq1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	22a550115666 	22a550115666 	22a550BDEFH 	I 	I 	I 	22b66 8 8 89:< 	= 	= 	=
 	22b66 = = = ?@A 	B 	B 	B 	22b1 !I !I !I KL M 	N 	N 	N 	22b1 !I !I !IJK M 	N 	N 	N 	22b1!B!G!IJK M 	N 	N 	N 	22bQ #K #K #KLM"O 	P 	P 	P 	22bQ#D#I#KLM"O 	P 	P 	P 	P 	Ps   AAAc                 F   | j         }| j        }|j        s|                                 |                     |                                            ||j        dg            ||j        d           |j        	                    d           |                                  ||j        dg            ||j        d            ||j        
                    dd          d           |j        	                    d           |                                  ||j        ddg            ||j        d            ||j        
                    dd          d	           |j        	                    d           |                                  ||j        ddg            ||j        d
            ||j        
                    dd          d	           |j        	                    d
           |                                  ||j        g d            ||j        d            ||j        
                    dd          d           |j        	                    d           |                                  ||j        g d            ||j        d            ||j        
                    dd          d           |                                 d|_         ||j        g d            ||j        d            ||j        
                    dd          d           |j        	                    d           |                                  ||j        g d            ||j        d            ||j        
                    dd          d           d S )Nrp   r2   r   r/   r   r   r   r   r   r   )rp   r   r   r   z'class C1:
    def __init__(self, a, b):r   )rp   r   r   r   r      zFclass C1:
    def compare(self):
        if a > b:
        elif a < b:   r   )rr   ra   rR   r   rt   update_code_contextru   rv   r   r_   r   r   )r   rx   ra   s      r   test_update_code_contextz(CodeContextTest.test_update_code_context   s-   Wz 	+((*** 	"0022333
27'()))
2=! 	a
   
27'()))
2=!
2:>>%**B/// 	a
   
27')EFGGG
2=!
2:>>%**K888 	a
   
27')EFGGG
2=!
2:>>%**K888 	a
   
27 E E E 	F 	F 	F 	2=!
2:>>%** -L 	M 	M 	M 	b
   
27 = = = 	> 	> 	>
 	2="
2:>>%** -B 	C 	C 	C 	   
27 = = = 	> 	> 	>
 	2="
2:>>%** -B 	C 	C 	C 	a
   
27 E E E 	F 	F 	F 	2=!
2:>>%**,KLLLLLr   c                 2   | j         }| j        }|j        }|j        s|                                 |j                            d           |                                  ||j        d           |j        	                    dd            |              ||j        d           |j                            d           |                                  ||j        d           |j        	                    dd            |              ||j        d	           d|_
        |j                            d           |                                  ||j        d           |j        	                    dd
            |              ||j        d	           |j                            d           |                                 |j                            dd
d           |j        	                    dd
            |              ||j        d           d S )Nz2.0r   r:   z1.5r2   z12.0r   z3.0r   r/   z5.0selr   )rr   ra   
jumptolinerR   r   r   r_   r   rv   mark_setr   tag_add)r   rx   ra   jumps       r   test_jumptolinezCodeContextTest.test_jumptoline.  s   W}z 	+((*** 	e
   
2=!

He,,,
2=! 	f
   
2="

He,,,
2=! 
f
   
2="

He,,,
2=! 	e
   

5%///

He,,,
2=!r   r   c                 6   | j         j        r| j                                          | j                                          |                                 | j                                          | j                                          |                                 d S r   )ra   rR   r   timer_eventassert_not_calledassert_called)r   mock_updates     r   test_timer_eventz CodeContextTest.test_timer_eventW  s     7? 	0G--///%%''' 	))+++!!#####r   c                    | j         }| j        }|j        d         }d}|                     ||           |j        |                                 || _        |                                 |                                  ||j        d         |           || _        |                                  ||j        d         |           d S )NrM   
TkTextFont)rr   ra   r   assertNotEqualrR   r   rZ   update_font)r   rx   ra   	orig_font	test_fonts        r   r   zCodeContextTest.test_fontd  s    WGFO	 	Iy111 :!((***&
 	$$&&&
2:fy))) '

2:fy)))))r   c                    | j         | j        t          | j                  }ddd}fd}j        r                                 || _                                                                           ||                                             ||           || _                                          ||           d S )Nz#222222z#ffff00rN   c                 |     j         d         | d                     j         d         | d                    d S )NrO   rP   )rR   )colorsra   rx   s    r   assert_colors_are_equalzFCodeContextTest.test_highlight_colors.<locals>.assert_colors_are_equal  sE    Brz,')=>>>Brz,')=>>>>>r   )rr   ra   dictrS   rR   r   update_highlight_colors)r   orig_colorstest_colorsr   ra   rx   s       @@r   test_highlight_colorsz%CodeContextTest.test_highlight_colors}  s   W4-..%.iHH	? 	? 	? 	? 	? 	?
 : 	+((***(
""$$$ 	$$&&&,,, 	""$$$,,, )
""$$$,,,,,r   N)r'   r(   r)   classmethodrC   rJ   rj   rn   rz   r|   r   r   r   r   r   r   r
   rc   rd   r   r`   r   r   r   r*   r   r   r,   r,   5   s<       / / [/   [. . .2% % %& & &  : : :4 4 4"< "< "<H.P .P .P`OM OM OMb' ' 'R 
Z{.0EFF
$ 
$ GF
$* * *2- - - - -r   r,   c                       e Zd Zd Zd ZdS )HelperFunctionTextc                     t           j        }d}|D ]$\  }}|                      ||          |           %|                      |dt          j        d                    d           d S )N))z    first word)    first)z	first word)	r   )u
     ᧔᧒: )z  u   ᧔᧒)z	no spaces)r   no)r   r   r   )z# TEST COMMENTr   )    (continuation))r   r   r   z^(\s*)([^\s]*))c)r   z(continuation))r   get_spaces_firstwordrr   recompile)r   r   
test_lineslineexpected_outputs        r   test_get_spaces_firstwordz,HelperFunctionText.test_get_spaces_firstword  s    .
 &0 	9 	9!D/SSYY8888 	1!z*;<<> > >3	5 	5 	5 	5 	5r   c                    | j         }t          j        }t                                          } | ||d                   t          j        ddf            | ||d                   d            | ||d                   t          j        ddf            | ||d                   d	            | ||d
                   d            | |d          d           d S )Nr   r   Fr2   )r   r   r   r   z    # Class comment.r   )r   r   r   r   )r   r   r   	if a == b:)r2   r   r   )rr   r   get_line_infor;   
splitlinesINFINITY)r   rx   gliliness       r   test_get_line_infoz%HelperFunctionText.test_get_line_info  s    '&&(( 	33uQx==;/U;<<<
33uQx==3444
33uQx==;/1GOPPP
33uQx==EFFF
33uQx==8999
33~ 9:::::r   N)r'   r(   r)   r   r   r*   r   r   r   r     s2        5 5 5&; ; ; ; ;r   r   __main__r   )	verbosity)__doc__idlelibr   rb   unittest.mocktest.supportr   tkinterr   r   r   r   r	   r
   r   r   r@   rA   rF   IdleUserConfParserr?   r;   r   TestCaser,   r   r'   r   r*   r   r   <module>r      s   ! !            ! ! ! ! ! ! 3 3 3 3 3 3 3 3 3 3 3 3 3 3       				       

&%F%b))**2..%F%b))+&+B//	 "% % % % % % % %f- f- f- f- f-h' f- f- f-R%; %; %; %; %;* %; %; %;P zHMA r   