HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/idlelib/idle_test/__pycache__/test_codecontext.cpython-310.pyc
o

�i�>�@s�dZddlmZddlZddlZddlmZddlmZm	Z	m
Z
mZmZddlm
Z
ddlZddlmZejjZe�d�e�d�e�d�e�d�d	�Zd
ZGdd�d�ZGd
d�dej�ZGdd�dej�Zedkrrejdd�dSdS)zTest codecontext, coverage 100%�)�codecontextN)�requires)�NSEW�Tk�Frame�Text�TclError)�mock)�config�)�mainZ	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@s$eZdZdd�Zdd�Zdd�ZdS)�DummyEditwincCs"||_||_||_||_d|_dS)Nr)�root�topZ
text_frame�text�label)�selfr�framer�r�?/usr/local/lib/python3.10/idlelib/idle_test/test_codecontext.py�__init__'s

zDummyEditwin.__init__cCstt|j�|���S�N)�int�floatr�index)rrrrr�	getlineno.szDummyEditwin.getlinenocKs|d|_dS)Nr)r)r�kwargsrrr�update_menu_label1�zDummyEditwin.update_menu_labelN)�__name__�
__module__�__qualname__rrrrrrrr&src@s�eZdZedd��Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zej�ejd�dd��Zdd�Zdd�Zd S)!�CodeContextTestcCs~td�t�}|_|��t|�}|_t|�}|_|�dt	�|j
dddd�|jddtd�t
|||�|_ttj_dS)NZgui�1.0�leftZboth�)Zside�fill�expand)�row�columnZsticky)rrrZwithdrawrrrr�insert�code_sample�packZgridrr�editor�testcfgr�idleConf�userCfg)�clsrrrrrr�
setUpClass7szCodeContextTest.setUpClasscCs@ttj_|jj�dd�|`|`|`|j�	�|j�
�|`dS)Nr%�end)�usercfgrr1r2r/r�deleterrZupdate_idletasks�destroy)r3rrr�
tearDownClassEs

zCodeContextTest.tearDownClasscs��j�d�d�jd<t��j��_ddd��_tjj���fdd�}t	j
j�tjd	|�}|�
���|j�d�_�fd
d�}t	j
j�tjd|�}|�
���|j�dS)
NrZTkFixedFont�fontz#abcdefz#123456��
background�
foregroundcs|dkr�jS�||�S)N�context)�
highlight_cfg)Ztheme�element�Zorig_idleConf_GetHighlightrrr�mock_idleconf_GetHighlightVs
z9CodeContextTest.setUp.<locals>.mock_idleconf_GetHighlight�GetHighlightcs�jSr)�
font_override)rZ
configType�section�rrr�mock_idleconf_GetFont`sz4CodeContextTest.setUp.<locals>.mock_idleconf_GetFontZGetFont)r�yviewr�CodeContextr/�ccr?r1rC�unittestr	�patch�object�startZ
addCleanup�stoprD)rrBZGetHighlight_patcherrGZGetFont_patcherrrAr�setUpNs(
���zCodeContextTest.setUpcCs,|jjr
|jj��|j��|j`|`dSr)rJr>r8�__del__rFrrr�tearDowngs
zCodeContextTest.tearDowncCsz|j}|j}|j}||j|�||j|j�||jd|jd�|�|j�||jdg�||jd�|�|jj	�dS)Nr:�r���rFr')
�assertEqualr/rJ�editwinr�assertIsNoner>�info�
topvisible�t1)r�eqZedrJrrr�	test_initnszCodeContextTest.test_initcCs|j��dSr)rJrQrFrrr�test_del{r zCodeContextTest.test_delcCsv|j�ddd��}|j_|j��|�t��}|jj�	dd|�Wd�n1s+wY|�
dt|j��dS)Ni'cSsdSrrrrrr�<lambda>sz5CodeContextTest.test_del_with_timer.<locals>.<lambda>�afterrXz
doesn't exist)
rr_rJrZrQ�assertRaisesrr�tk�callZassertIn�str�	exception)r�timer�cmrrr�test_del_with_timer~s
�z#CodeContextTest.test_del_with_timercCstj��|�|jjd�dS)N�)rrI�reloadrUrJ�
context_depthrFrrr�test_reload�s
zCodeContextTest.test_reloadcCsJ|j}|j}|j}|jr|�|�|�|j�||jd|jd�||jd|jd�||jd|jd�||j�dd�d�||jj	d	�||j
j�d
d|jj
�dd
�|�|�|j�||jj	d�|�|jj
�d�dd�|�d�dD��}|j�d�|�||j�dd�|�|�|�||j�dd�|�dS)Nr:Zfgr=�bgr<r%�end-1crzHide Code Contextr_rXr'rezShow Code Context�
css�|]}|dVqdS)�Nr)�.0�xrrr�	<genexpr>�s�zACodeContextTest.test_toggle_code_context_event.<locals>.<genexpr>�r)rUrJ�toggle_code_context_eventr>ZassertIsNotNonerr?�getrVrrrarbrZrW�join�get_contextrH)rr[rJZtoggleZline11_contextrrr�test_toggle_code_context_event�s0 z.CodeContextTest.test_toggle_code_context_eventcCs4|j}|jj}|�t��|ddd�Wd�n1swY||d�dgdf�||d�dgdf�||d�ddgdf�||d	�gd
�df�||d�gd�df�||dd
d�gd�df�||ddd�gd�df�||ddd�ddgdf�||ddd�gd�df�||ddd�ddgdf�dS)Nr'r)Zstopline��ror�	class C1:�class���r}r}�    def __init__(self, a, b):�def�
)rz��r}z    def compare(self):r���r��        if a > b:�ifrs)rzr�r��r�r�z        elif a < b:�elifro)r�r�r�r�r�r�)Z
stopindent)rUrJrwr`�AssertionError)rr[�gcrrr�test_get_context�sJ�
����������
�z CodeContextTest.test_get_contextcCs|j}|j}|js
|��|�|���||jdg�||jd�|j�	d�|��||jdg�||jd�||j�
dd�d�|j�	d�|��||jddg�||jd�||j�
dd�d	�|j�	d�|��||jddg�||jd
�||j�
dd�d	�|j�	d
�|��||jgd��||jd�||j�
dd�d
�|j�	d�|��||jgd��||jd�||j�
dd�d�|��d|_||jgd��||jd�||j�
dd�d�|j�	d�|��||jgd��||jd�||j�
dd�d�dS)NrSr'ror%rmrrzryr{r})rSrzrr~z'class C1:
    def __init__(self, a, b):rs)rSrzr�r�r��zFclass C1:
    def compare(self):
        if a > b:
        elif a < b:�r�)rUrJr>rtrW�update_code_contextrXrYrrHrurj)rr[rJrrr�test_update_code_context�sTz(CodeContextTest.test_update_code_contextcCs.|j}|j}|j}|js|��|j�d�|��||jd�|j�	dd�|�||jd�|j�d�|��||jd�|j�	dd�|�||jd	�d|_
|j�d�|��||jd�|j�	dd
�|�||jd	�|j�d�|��|j�dd
d�|j�	dd
�|�||jd
�dS)Nz2.0ror,z1.5r'z12.0r�z3.0r�r%z5.0Zselr~)rUrJZ
jumptoliner>rtrrHr�rYZmark_setrjZtag_add)rr[rJZjumprrr�test_jumptoline.s<zCodeContextTest.test_jumptoliner�cCsD|jjr	|j��|j��|��|j��|j��|��dSr)rJr>rtZtimer_eventZassert_not_calledZ
assert_called)rZmock_updaterrr�test_timer_eventWs



z CodeContextTest.test_timer_eventcCs�|j}|j}|jd}d}|�||�|jdur|��||_|��|��||jd|�||_|��||jd|�dS)Nr:Z
TkTextFont)rUrJrZassertNotEqualr>rtrDZupdate_font)rr[rJZ	orig_font�	test_fontrrrr�ds

zCodeContextTest.test_fontcs�|j�|j�t|j�}ddd�}��fdd�}�jr���||_������||����||�||_���||�dS)Nz#222222z#ffff00r;cs,��jd|d���jd|d�dS)Nr<r=)r>)Zcolors�rJr[rr�assert_colors_are_equal�szFCodeContextTest.test_highlight_colors.<locals>.assert_colors_are_equal)rUrJ�dictr?r>rtZupdate_highlight_colors)rZorig_colorsZtest_colorsr�rr�r�test_highlight_colors}s 

z%CodeContextTest.test_highlight_colorsN)r!r"r#�classmethodr4r9rPrRr\r]rgrkrxr�r�r�r	rLrMrrIr�r�r�rrrrr$5s&


$0Q)
r$c@seZdZdd�Zdd�ZdS)�HelperFunctionTextcCsFtj}d}|D]\}}|�||�|�q|�|dt�d�d�d�dS)N))z    first word)�    �first)z	first word)�	r�)u
  ᧔᧒: )z  u᧔᧒)z	no spaces)r�no)r�rr)z# TEST COMMENTr�)�    (continuation))r�rr�z^(\s*)([^\s]*))�c)r�z(continuation))rZget_spaces_firstwordrU�re�compile)rruZ
test_lines�lineZexpected_outputrrr�test_get_spaces_firstword�s	��z,HelperFunctionText.test_get_spaces_firstwordcCs�|j}tj}t��}|||d�tjddf�|||d�d�|||d�tjddf�|||d�d	�|||d
�d�||d�d
�dS)NrrFr')rr{r|roz    # Class comment.ry)r}r�r�r�)r�r�r��	if a == b:)r'r�r�)rUrZ
get_line_infor-�
splitlinesZINFINITY)rr[Zgli�linesrrr�test_get_line_info�sz%HelperFunctionText.test_get_line_infoN)r!r"r#r�r�rrrrr��sr��__main__ro)�	verbosity)�__doc__ZidlelibrrKZ
unittest.mockZtest.supportr�tkinterrrrrrr	r�r
r1r2r6ZIdleUserConfParserr0r-rZTestCaser$r�r!rrrrr�<module>s0�k(�