B � f�:�@sdZddlmZddlmZddlZddlmZddlmZddl m Z m Z ddlm Z dd l mZejjZe �d �e �d �e �d �e �d �d �Zd Zd d�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zedk�rejdd�dS)zTest colorizer, coverage 93%.�)� colorizer)�requiresN)�mock)�partial)�Tk�Text)�config)� Percolator�)�main� highlight�keys� extensionsa+if True: int ('1') # keyword, builtin, string, comment elif False: print(0) # 'string' in comment else: float(None) # if in comment if iF + If + IF: 'keyword matching must respect case' if'': x or'' # valid string-keyword no-space combinations async def f(): await g() 'x', '''x''', "x", """x""" cCs ttj_dS)N)�testcfgr�idleConf�userCfg�rr�E/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_colorizer.py� setUpModule!srcCs ttj_dS)N)�usercfgrrrrrrr�tearDownModule%src@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) � FunctionTestcCs|�t�dd�d�dS)NZtest)�a�bZcdz(?Pa|b|cd))� assertEqualr�any)�selfrrr�test_any+szFunctionTest.test_anycCs|�t���dS)N)� assertTruerZmake_pat)rrrr� test_make_pat/szFunctionTest.test_make_patcCs�tj}|j}d}|�|�}||��dd�|�||���}||��dd�|�||���}||��dd�|�||���}||��dd �|�||���}||��dd�dS) Nzdef f(): print("hello") �KEYWORD�def�SYNC� �BUILTIN�print�STRINGz"hello")r�progr�search� groupdict�end)rr'�eq�line�mrrr� test_prog3s zFunctionTest.test_progcCs:tj}|�d�}|�|�|�d�}|�|�d�d�dS)NZnospacez spacer)r�idprog�match� assertIsNoner�group)rr/r-rrr� test_idprogBs    zFunctionTest.test_idprogN)�__name__� __module__� __qualname__rrr.r3rrrrr)src@s,eZdZedd��Zedd��Zdd�ZdS)�ColorConfigTestcCs*td�t�}|_|��t|�|_dS)N�gui)rr�root�withdrawr�text)�clsr9rrr� setUpClassLs zColorConfigTest.setUpClasscCs |`|j��|j��|`dS)N)r;r9�update_idletasks�destroy)r<rrr� tearDownClassSs  zColorConfigTest.tearDownClasscCsn|j}|j}t�|�||dd�||dd�||dd�||dd�||dd �||d d�dS) N� backgroundz#ffffff� foregroundz#000000ZselectbackgroundZgrayZselectforegroundZinsertbackgroundZblackZinactiveselectbackground)r;rrZ color_config)rr;r+rrr�test_color_configZs z!ColorConfigTest.test_color_configN)r4r5r6� classmethodr=r@rCrrrrr7Js  r7c@sDeZdZedd��Zedd��Zdd�Zdd�Zd d �Zd d �Z d S)�ColorDelegatorInstantiationTestcCs.td�t�}|_|��t|�}|_dS)Nr8)rrr9r:rr;)r<r9r;rrrr=is z*ColorDelegatorInstantiationTest.setUpClasscCs |`|j��|j��|`dS)N)r;r9r>r?)r<rrrr@ps  z-ColorDelegatorInstantiationTest.tearDownClasscCst��|_dS)N)r�ColorDelegator�color)rrrr�setUpwsz%ColorDelegatorInstantiationTest.setUpcCs*|j��|j�dd�|j��|`dS)Nz1.0r*)rG�closer;�delete� resetcache)rrrr�tearDownzs  z(ColorDelegatorInstantiationTest.tearDowncCs|j}|�|tj�dS)N)rG�assertIsInstancerrF)rrGrrr� test_init�sz)ColorDelegatorInstantiationTest.test_initcCs:|j}|�|j�|�|j�|�|j�|�|j�dS)N)rGr1�after_idr�allow_colorizing� assertFalse� colorizing�stop_colorizing)rrGrrr�test_init_state�s    z/ColorDelegatorInstantiationTest.test_init_stateN) r4r5r6rDr=r@rHrLrNrTrrrrrEgs   rEc@s�eZdZedd��Zedd��Zdd�Zdd�Zd d �Zd d �Z d d�Z e j � ejd�dd��Ze j � ejd�dd��Zdd�Zdd�Ze j � ejd�dd��Ze j � ejd�dd��Ze j � ejd�e j � ejd�dd���Zd S)!�ColorDelegatorTestcCs8td�t�}|_|��t|�}|_t|�|_dS)Nr8)rrr9r:rr;r � percolator)r<r9r;rrrr=�s  zColorDelegatorTest.setUpClasscCs0|jj��|`|`|j��|j��|`dS)N)rVZredirrIr;r9r>r?)r<rrrr@�s    z ColorDelegatorTest.tearDownClasscCst��|_|j�|j�dS)N)rrFrGrVZ insertfilter)rrrrrH�s zColorDelegatorTest.setUpcCs8|j��|j�|j�|j�dd�|j��|`dS)Nz1.0r*)rGrIrVZ removefilterr;rJrK)rrrrrL�s   zColorDelegatorTest.tearDowncCs:|j}|�|jtj�|�|jj�dd|j �dd�dS)N�after�info��timer) rGrM�delegaterZ Delegatorrr9�tk�callrO)rrGrrr�test_setdelegate�s z#ColorDelegatorTest.test_setdelegatec Cs|ttjjdd�}xf|jj��D]V\}}|j|d��<|�d|�|�d|�|dkrj|� |||� �d��WdQRXqWdS)Nz IDLE Classic)�theme)�tagrArB)r"�TODO)�element) rrr� GetHighlightrG�tagdefs�items�subTestZassertInr�lower)rr r`Zcolorsrrr�test_LoadTagDefs�s  z#ColorDelegatorTest.test_LoadTagDefsc Cs�|j}ttjjdd�}xx|jjD]l}xfdD]^}|j||d��F|dkr\|�|� ||�d�n"|�|� ||�||� �d�|�WdQRXq*Wq W|�|� �dd �dS) Nz IDLE Classic)r_)rArB)r`�plane)r"rar )rb�����Zsel) r;rrrrcrGrdrfrZtag_cgetrg� tag_names)rr;r r`rirrr�test_config_colors�s &z%ColorDelegatorTest.test_config_colors� notify_rangecCsb|j}|�dd�|�|�dd�d�|�dd�|�dd�|�|�dd�d�|�d d �dS) N�insertZfooz1.0r*zfoo z1.0+3cZbarbazz foobarbaz z1.3z1.3+6c)r;rnr�get�assert_called_with)r� mock_notifyr;rrr� test_insert�s   zColorDelegatorTest.test_insertcCs||j}|�dd�|�|�dd�d�|�d�|�|�dd�d�|�d�|�dd �|�|�dd�d �|�d�dS) NrnZ abcdefghiz1.0r*z abcdefghi z1.7z abcdefgi z1.3z1.6zabcgi )r;rnrrorJrp)rrqr;rrr� test_delete�s    zColorDelegatorTest.test_deletecCs|j}|j}|j}|j}||jj�dd|�dd�|�|j�|�|j �|� |j �d|_|� dd�|�|j �||j|�|� |�d|_|� dd�|� |j �|�|j�||jj�dd|j�dd�|�|j|�|� |j�d|_d |_ |� d d �|�|j�dS) NrWrXrYrZTz1.0r*z1.0+3cFz1.4z1.4+10c)r;rGrrOr9r\r]rQrRrSrrPrm� after_cancelZassertIsNotNone�assertNotEqualr1)rr;rGr+Zsave_idrrr�test_notify_range�s0            z$ColorDelegatorTest.test_notify_rangecCsP|j}|j}|�|j�|�|j�|�|j�||jj� dd|j �dd�|� �|� |j �|�|j�|�|j�|�|j�d|_|� �|� |j �|�|j�|�|j�|�|j�|� �|� |j �|�|j�|�|j�|�|j�d|_|� �||jj� dd|j �dd�|�|j�|�|j�|�|j�dS)NrWrXrYrZTF) rGrrQrRrSrrPr9r\r]rOZtoggle_colorize_eventr1)rrGr+rrr�test_toggle_colorize_event s8                 z-ColorDelegatorTest.test_toggle_colorize_event�recolorize_maincCs|j}|j}|j}|�|j�|j}d|_|��|��||_d|_|��|��d|_d|_ |��|��d|_ |��|� |j �|� |j �|� �||j d�||jj�dd|j�dd�|�ddd �|��|� |j �|� |j �|� �||j d �|�|j�dS) NFTrYrWrXrZraz1.0r*�)r;rGrrtrOr[� recolorizeZassert_not_calledrPrRrQrSZ assert_calledZ call_countr9r\r]� tag_remover1)rZ mock_recmainr;rGr+Z save_delegaterrr�test_recolorize3s<       z"ColorDelegatorTest.test_recolorizec Csz|j}|j}|j}|�dt�d}|�ddd�|��x8|��D],}|j|d��||� |�d�WdQRXqBW|� ddd�|��x8|D]0\}}|j|d��||�|�|�WdQRXq�W||� dd�d�||� d d�d �||� d d �d �||� dd �d�||� dd �d�||� dd�d�||� dd�d�||� dd�d�||� dd�d�||� dd�d�dS)Nrn))z1.0)r )z1.2r)z1.3)r )z1.7r)z1.9)r$)z1.14)r&)z1.19)�COMMENT)z2.1)r )z2.18r)z2.25)r})z3.6)r$)z3.12)r )z3.21)r})z4.0)r )z4.3r)z4.6r)z5.2)r&)z5.8)r )z5.10)r&)z6.0)r )z6.10)Z DEFINITION)z6.11r)z7.0)r&)z7.4r)z7.5)r&)z7.12r)z7.14)r&)z1.55)r")z2.50)r")z3.34)r"raz1.0r*)r`r)�indexr )z1.0z1.2r}z2.0)z2.22z2.43r")z2.43z3.0r&)z4.17z4.53z7.0)z7.0z7.3z7.3)z7.5z7.12z7.12)z7.14z7.17z7.17)z7.19z7.26)z7.26z9.0) r;rGrrn�sourcer{rxrkrf� tag_ranges�tag_addZ tag_nextrange) rrqr;rGr+Zexpectedr`r~Z expected_tagsrrr�test_recolorize_main`s2 z'ColorDelegatorTest.test_recolorize_mainrzc Cs�|j}|j}|�dt�|��|�dd�|�dd�|�dd�x8|jD].}|j|d��|�|� |�d�WdQRXqLW|� �x8|jD].}|j|d��|� |� |�d�WdQRXq�WdS)NrnZERRORz1.0raZhit)r`r) r;rGrnrrxr�rdrfrur�Z removecolorsr)rrqZmock_recolorizer;rGr`rrr�test_removecolors�s       z$ColorDelegatorTest.test_removecolorsN)r4r5r6rDr=r@rHrLr^rhrlrZpatch�objectrrFrrrsrvrwr|r�r�rrrrrU�s   $(-0rU�__main__ry)� verbosity)�__doc__ZidlelibrZ test.supportrZunittestr� functoolsrZtkinterrrrZidlelib.percolatorr rrrZIdleUserConfParserrrrrZTestCaserr7rErUr4r rrrr�s0       !'