Your IP : 18.222.13.30


Current Path : /opt/alt/python37/lib64/python3.7/idlelib/idle_test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/idlelib/idle_test/__pycache__/test_codecontext.cpython-37.pyc

B

� f�>�@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�Zedkr�ejdd�dS)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�G/opt/alt/python37/lib64/python3.7/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_label1szDummyEditwin.update_menu_labelN)�__name__�
__module__�__qualname__rrrrrrrr&src@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)NZguiz1.0�leftZboth�)ZsideZfill�expand)�row�columnZsticky)rrrZwithdrawrrrr�insert�code_sampleZpackZgridrr�editor�testcfgr�idleConf�userCfg)�clsrrrrrr�
setUpClass7szCodeContextTest.setUpClasscCs@ttj_|jj�dd�|`|`|`|j�	�|j�
�|`dS)Nz1.0�end)�usercfgrr,r-r*r�deleterrZupdate_idletasks�destroy)r.rrr�
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)ZthemeZelement)�orig_idleConf_GetHighlightrrr�mock_idleconf_GetHighlightVsz9CodeContextTest.setUp.<locals>.mock_idleconf_GetHighlight�GetHighlightcs�jS)N)�
font_override)rZ
configTypeZsection)rrr�mock_idleconf_GetFont`sz4CodeContextTest.setUp.<locals>.mock_idleconf_GetFontZGetFont)r�yviewr�CodeContextr*�ccr9r,r<�unittestr	�patch�object�startZ
addCleanup�stopr=)rr;ZGetHighlight_patcherr>ZGetFont_patcherr)r:rr�setUpNs"

zCodeContextTest.setUpcCs,|jjr|jj��|j��|j`|`dS)N)rAr8r3�__del__)rrrr�tearDowngs
zCodeContextTest.tearDowncCsz|j}|j}|j}||j|�||j|j�||jd|jd�|�|j�||jdg�||jd�|�|jj	�dS)Nr5)r���rFr$)
�assertEqualr*rA�editwinr�assertIsNoner8�info�
topvisible�t1)r�eqZedrArrr�	test_initnszCodeContextTest.test_initcCs|j��dS)N)rArH)rrrr�test_del{szCodeContextTest.test_delc	Csb|j�ddd��}|j_|j��|�t��}|jj�	dd|�WdQRX|�
dt|j��dS)Ni'cSsdS)Nrrrrr�<lambda>�z5CodeContextTest.test_del_with_timer.<locals>.<lambda>�afterrNz
doesn't exist)
rrVrArPrH�assertRaisesrr�tk�callZassertIn�strZ	exception)r�timer�cmrrr�test_del_with_timer~s

z#CodeContextTest.test_del_with_timercCstj��|�|jjd�dS)N�)rr@�reloadrKrA�
context_depth)rrrr�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)Nr5Zfgr7Zbgr6z1.0zend-1crzHide Code ContextrVrNr$r[zShow Code Context�
css|]}|dVqdS)�Nr)�.0�xrrr�	<genexpr>�szACodeContextTest.test_toggle_code_context_event.<locals>.<genexpr>�r)rKrA�toggle_code_context_eventr8ZassertIsNotNonerr9�getrLrrrXrYrPrM�join�get_contextr?)rrQrAZtoggleZline11_contextrrr�test_toggle_code_context_event�s0 z.CodeContextTest.test_toggle_code_context_eventc	Cs.|j}|jj}|�t��|ddd�WdQRX||d�dgdf�||d�dgdf�||d�ddgdf�||d	�dd
dgdf�||d�dd
dd
gdf�||ddd�dd
dd
gdf�||ddd�d
dd
gdf�||ddd�dd
gdf�||ddd�d
dd
gdf�||ddd�dd
gdf�dS)Nr$r)Zstopline�)rcrzclass C1():�class��)roroz    def __init__(self, a, b):�def�
)�roz    def compare(self):rq)�rtz        if a > b:�ifrg)rrrtz        elif a < b:�elifrcrt)Z
stopindent)rKrArkrW�AssertionError)rrQZgcrrr�test_get_context�s:


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
�|��||jdddg�||jd�||j�
dd�d
�|j�	d�|��||jdddddg�||jd�||j�
dd�d�|��d|_||jdddddg�||jd�||j�
dd�d�|j�	d�|��||jdddg�||jd�||j�
dd�d�dS)N)rrJrFr$rcz1.0zend-1cr)rcrzclass C1():rnrmzclass C1():ro)roroz    def __init__(self, a, b):rqrpz)class C1():
    def __init__(self, a, b):rg)rsroz    def compare(self):rq)rtrtz        if a > b:ru)rrrtz        elif a < b:rv�zHclass C1():
    def compare(self):
        if a > b:
        elif a < b:�z    def __init__(self, a, b):)rKrAr8rhrM�update_code_contextrNrOrr?rir`)rrQrArrr�test_update_code_context�sl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.0rcr(z1.5r$z12.0ryz3.0rtz1.0z5.0Zselrp)rKrAZ
jumptoliner8rhrr?r{rOZmark_setr`Ztag_add)rrQrAZjumprrr�test_jumptoline.s<zCodeContextTest.test_jumptoliner{cCsD|jjr|j��|j��|��|j��|j��|��dS)N)rAr8rhZtimer_eventZassert_not_calledZ
assert_called)rZmock_updaterrr�test_timer_eventWs



z CodeContextTest.test_timer_eventcCs�|j}|j}|jd}d}|�||�|jdk	r8|��||_|��|��||jd|�||_|��||jd|�dS)Nr5Z
TkTextFont)rKrArZassertNotEqualr8rhr=Zupdate_font)rrQrAZ	orig_font�	test_fontrrrrds

zCodeContextTest.test_fontcs�|j�|j�t|j�}ddd�}��fdd�}�jr<���||_������||����||�||_���||�dS)Nz#222222z#ffff00)r6r7cs,��jd|d���jd|d�dS)Nr6r7)r8)Zcolors)rArQrr�assert_colors_are_equal�szFCodeContextTest.test_highlight_colors.<locals>.assert_colors_are_equal)rKrA�dictr9r8rhZupdate_highlight_colors)rZorig_colorsZtest_colorsr�r)rArQr�test_highlight_colors}s 

z%CodeContextTest.test_highlight_colorsN)rr r!�classmethodr/r4rGrIrRrSr]rarlrxr|r}r	rCrDrr@r~rr�rrrrr"5s	
$0Q)
r"c@seZdZdd�Zdd�ZdS)�HelperFunctionTextcCsJtj}d}x |D]\}}|�||�|�qW|�|dt�d�d�d�dS)N))z    first word)z    �first)z	first word)�	r�)u
  ᧔᧒: )z  u᧔᧒)z	no spaces)rZno)r)rr)z# TEST COMMENT)rr)z    (continuation))z    rz    (continuation)z^(\s*)([^\s]*))�c)z    z(continuation))rZget_spaces_firstwordrK�re�compile)rriZ
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$)rzclass C1():rnrcz    # Class comment.rm)roz    def __init__(self, a, b):rqrs)rtz        if a > b:ruz	if a == b:)r$z	if a == b:ru)rKrZ
get_line_infor)�
splitlinesZINFINITY)rrQZgli�linesrrr�test_get_line_info�sz%HelperFunctionText.test_get_line_infoN)rr r!r�r�rrrrr��sr��__main__rc)�	verbosity)�__doc__ZidlelibrrBZ
unittest.mockZtest.supportrZtkinterrrrrrr	r�r
r,r-r1ZIdleUserConfParserr+r)rZTestCaser"r�rrrrrr�<module>s*k(

?>