Your IP : 18.223.170.253


Current Path : /opt/alt/python36/lib64/python3.6/idlelib/idle_test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/idlelib/idle_test/__pycache__/test_squeezer.cpython-36.pyc

3

� feU�@s�ddlmZddlmZmZddlZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZmZddlmZdd	lmZdd
lmZddlmZe
jZdd
�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!e"dkr�ej#dd�dS)�)�
namedtuple)�Text�TkN)�Mock�NonCallableMagicMock�patch�sentinel�ANY)�requires)�idleConf)�count_lines_with_wrapping�ExpandingButton�Squeezer)�macosx)�	view_text)�Hovertip)�PyShellcs0td�t���j��fdd�}|j|��S)z*Helper for tests: Create a root Tk object.Zguics�j��j�dS)N)Zupdate_idletasksZdestroy�)�rootr�D/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_squeezer.py�cleanup_rootsz&get_test_tk_root.<locals>.cleanup_root)r
rZwithdraw�
addCleanup)Z
test_instancerr)rr�get_test_tk_roots
rc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�CountLinesTestz1Tests for the count_lines_with_wrapping function.cCs|j|t|||��S)N)�assertEqualr)�self�expected�text�	linewidth�tabwidthrrr�check#szCountLinesTest.checkcCs|jtd�d�dS)zTest with an empty string.�rN)rr)rrrr�test_count_empty)szCountLinesTest.test_count_emptycCs|jtd�d�dS)z/Test with a string which begins with a newline.z
text�N)rr)rrrr�!test_count_begins_with_empty_line-sz0CountLinesTest.test_count_begins_with_empty_linecCs|jtd�d�dS)z-Test with a string which ends with a newline.ztext
�N)rr)rrrr�test_count_ends_with_empty_line1sz.CountLinesTest.test_count_ends_with_empty_linecCs|jtd�d�dS)z Test with several lines of text.z1
2
3
�N)rr)rrrr�test_count_several_lines5sz'CountLinesTest.test_count_several_linescCs|jddddd�|jddddd�|jddddd�|jddddd�|jddddd�|jddd
dd�|jd	dd
dd�|jddd	dd�|jddddd�|jddddd�|jddddd�|jddd
dd�|jddddd�|jddddd�dS)z-Test with various tab widths and line widths.r%�	��)rrrrr#r'��
��	���
Nr)z		z			z				z					z
										z
										z				z										z
										z											z						z						z						)r )rrrr�test_tab_width9szCountLinesTest.test_tab_widthN)
�__name__�
__module__�__qualname__�__doc__r r"r$r&r(r3rrrrr!src@s�eZdZdZdd�Zd%dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd�Zeejejejejfdd ��Zed!d"��Zd#d$�ZdS)&�SqueezerTestzTests for the Squeezer class.cCst�}t|_|S)z$Create a mock EditorWindow instance.)rr�	__class__)r�editwinrrr�make_mock_editor_windowSsz$SqueezerTest.make_mock_editor_windowNcCs|dkr|j�}t|�S)z<Create an actual Squeezer instance with a mock EditorWindow.N)r;r)rZ
editor_windowrrr�make_squeezer_instance[sz#SqueezerTest.make_squeezer_instancecCs$xdD]\}}|j||d�qWd	S)z�Test Squeezer.count_lines() with various inputs.

        This checks that Squeezer.count_lines() calls the
        count_lines_with_wrapping() function with the appropriate parameters.
        r+�Pr%�Or*r'�x)rrN�r+r=�r%r>�r*r=�r'r?)r@rArBrC)�_test_count_lines_helper)rrrrrr�test_count_linesaszSqueezerTest.test_count_linesc	s�d�d}d}||j_|�d|||jj_||dd���fdd�|j_t�}�fdd	�}||j_td
|�}|j�|j	|j
�dS)z<Prepare a mock EditorWindow object for Squeezer.count_lines.r-r#r%N)ZborderZpadxZfontcs�|S)Nr)Zopt)�	text_optsrr�<lambda>|szDSqueezerTest._prepare_mock_editwin_for_count_lines.<locals>.<lambda>cs|dkr�Std��dS)N�0z%measure should only be called on '0'!)�
ValueError)�char)�
CHAR_WIDTHrr�measure�szCSqueezerTest._prepare_mock_editwin_for_count_lines.<locals>.measurezidlelib.squeezer.Font)Zget_tk_tabwidth�return_valuerZwinfo_width�cgetrrLr�startr�stop)	rr:rrZBORDER_WIDTHZ
PADDING_WIDTHZ	mock_fontrLZpatcherr)rKrFr�%_prepare_mock_editwin_for_count_linesks
z2SqueezerTest._prepare_mock_editwin_for_count_linescCsh|j�}|j|||�|j|�}ttd�}d}td|��&|j|j|�t�|j|||�WdQRXdS)zHelper for test_count_lines.)rM�TEXTz*idlelib.squeezer.count_lines_with_wrappingN)	r;rQr<r�SENTINEL_VALUEr�assertIs�count_lines�assert_called_with)rrrr:�squeezerZmock_count_linesrrrrrD�s

z%SqueezerTest._test_count_lines_helpercCs2|j�}|j|�}|j|j|�|j|jg�dS)z(Test the creation of Squeezer instances.N)r;r<rTr:r�expandingbuttons)rr:rWrrr�	test_init�s
zSqueezerTest.test_initcCs�|j�}xxddddddgD]`}ttd�|_}|j|�}|j|jj|f�t�|j|jd�|j|f�|jt	|j
�d	�qWd
S)z@Test Squeezer's overriding of the EditorWindow's write() method.r!rRz	LONG TEXTi�zMANY_LINES
�d)rMr%rN)r;rrS�writer<rr:�
call_countrV�lenrX)rr:r�
orig_writerWrrr�test_write_no_tags�s
zSqueezerTest.test_write_no_tagscCs�x~ddddddgD]f}|j�}t|j_|j}|j|�}|j|jj|d�t�|j|jd�|j|d�|jt	|j
�d	�qWd
S)z@Test Squeezer's overriding of the EditorWindow's write() method.r!rRz	LONG TEXTi�zMANY_LINES
rZ�stderrr%rN)r;rSr[rMr<rr:r\rVr]rX)rrr:r^rWrrr�test_write_not_stdout�s
z"SqueezerTest.test_write_not_stdoutcCs�|j�}|j|ddd�xndD]f}ttd�|_}|j|�}d|_|j|jj|d�t�|j|j	d	�|j
|d�|jt|j�d
�qWxnddd
dgD]Z}ttd�|_}|j|�}d|_|j|jj|d�d�|j|j	d
�|jt|j�d	�q�WdS)z@Test Squeezer's overriding of the EditorWindow's write() method.r=r*)rrr!rR)rM�2�stdoutr%rz	LONG TEXTi�zMANY_LINES
rZN)r!rR)
r;rQrrSr[r<�auto_squeeze_min_linesrr:r\rVr]rX)rr:rr^rWrrr�test_write_stdout�s&



zSqueezerTest.test_write_stdoutcCs�t|�}t|�}|jdd�|j�}||_|j|�}d|_tdd�|_|j	ddd�|j
|jdd�d	�|j
t|j
�d
�dS)zATest that the auto-squeezing creates an ExpandingButton properly.�iomarkz1.0r,r1)rMzTEXT
rc�end�
r%N)rr�mark_setr;rr<rdrrUr[r�getr]rX)rr�text_widgetr:rWrrr�test_auto_squeeze�s
zSqueezerTest.test_auto_squeezecCs,t|�}�xdD�]}t|�}|jdd�|j�}||_|j_|j|�}tdd�|_	|j
dd|�|jdd�|j|jdd	�d
�|jt
|j�d�|jt�d�}|j|d
�|j|jdd	�d�|jt
|j�d�|j|jdjd�|jdjt�d�|j|jdd	�d
�|jt
|j�d�qWdS)z$Test the squeeze_current_text event.rcr`rfz1.0r1)rMz
SOME
TEXT
�insertrgzSOME
TEXT

r)�event�breakz

r%z	SOME
TEXTN)rcr`)rrrir;r�per�bottomr<rrUrmrrjr]rX�squeeze_current_text_event�s�expand)rrZtag_namerkr:rW�retvalrrr�test_squeeze_current_text_event�s(
z,SqueezerTest.test_squeeze_current_text_eventcCs�t|�}t|�}|jdd�|j�}||_|j_|j|�}tdd�|_	|j
ddd�|jdd�|j|jdd�d	�|jt
|j�d
�|jt�d�}|j|d�|j|jdd�d	�|jt
|j�d
�d
S)z@Test that the event doesn't squeeze text without a relevant tag.rfz1.0r1)rMz
SOME
TEXT
ZTAGrmrgzSOME
TEXT

r)rnroN)rrrir;rrprqr<rrUrmrrjr]rXrr)rrrkr:rWrurrr�/test_squeeze_current_text_event_no_allowed_tagss
z<SqueezerTest.test_squeeze_current_text_event_no_allowed_tagscCst|�}t|�}|jdd�|j�}||_|j_|j|�}tdd�|_	|j
ddd�|jdd�|jt�d�|jt
|j�d	�|j
dd
d�|jdd�|jt�d�}|j|d�|j|jdd�d
�|jt
|j�d�|j|j|jdd|jd	��dS)z2Test squeezing text before existing squeezed text.rfz1.0r1)rMz
SOME
TEXT
rcrm)rnr%zMORE
STUFF
rorgz


r#r�<N)rrrir;rrprqr<rrUrmrrrr]rXrj�
assertTrueZcompare)rrrkr:rWrurrr�/test_squeeze_text_before_existing_squeezed_texts*
z<SqueezerTest.test_squeeze_text_before_existing_squeezed_text�GetOptionSignaturez:configType section option default type warn_on_default rawcCs|j|||||||�S)N)r{)�clsZ
configTypeZsectionZoption�default�typeZwarn_on_default�rawrrr�	_make_sig>szSqueezerTest._make_sigcCs|dd�\}}|j||�S)Nr#���)r�)r|Z
mock_call_obj�args�kwargsrrr�get_GetOption_signatureFsz$SqueezerTest.get_GetOption_signaturecCs8|jtjt�tjdddd�tj�|jtjd�dS)zTest the reload() class-method.�mainrzauto-squeeze-min-linesZ42�*N)ZassertIsInstancerrd�intrZ	SetOption�reloadr)rrrr�test_reloadKszSqueezerTest.test_reload)N)r4r5r6r7r;r<rErQrDrYr_rarerlrvrwrzrr{�classmethodrZ	NOT_GIVENr�r�r�rrrrr8Qs.


"r8c@sTeZdZdZdd�Zeded�dd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�ExpandingButtonTestz$Tests for the ExpandingButton class.cCs$t|�}t�}t|�|j_d|_|S)z0Helper for tests: Create a mock Squeezer object.rb)rrrr:rrd)rrrWrrr�make_mock_squeezerWs
z&ExpandingButtonTest.make_mock_squeezerzidlelib.squeezer.Hovertip)�autospeccCs�|j�}|jj}tddd|�}|j|jd�|j|j|�|jd|jd�k�|j|j	dd�d�|j
d	|j��d
tj
�r�dnd}|j
||j��|j|jd
�|j|ttd�|jdd
}|j
d|j��dS)z1Test the simplest creation of an ExpandingButton.rR�TAGSrbz50 linesrz1.0rgrhz<Double-Button-1>z<Button-%s>�2�3r%)Zhover_delayrzright-clickN)r�r:rr
rrsZmasterryrNrjZassertInZbindrZisAquaTkr\rVr	�	call_args�lower)rZMockHovertiprWrk�expandingbuttonZright_button_codeZtooltip_textrrrrYaszExpandingButtonTest.test_initcCs�|j�}tddd|�}|j}|jd|d�|j|_|jt�d�}|j|d�|j|jdd�d	�|j	d
�}|j|jd|�d�|j|j
dd�d|f�|j|jjj
d�|jjj|�dS)zTest the expand event.rRr�rbz1.0)�window)rnNrgzTEXT
zend-1cr%)r�r
r�
window_create�	base_textrtrrrj�indexZ
tag_nextrangerX�remover\rV)rrWr�rkruZtext_end_indexrrr�test_expand~s

zExpandingButtonTest.test_expandcCs�|j�}dd}t|dd|�}|j�|j|j�|j}|jd|d�|j|_td��$}d	|j	_
d	|j_
|jt
�d
�}WdQRX|j|d�|j|jjdd
�d�td��$}d|j	_
d|j_
|jt
�d
�}WdQRX|j|d�|j|jjdd
�|�dS)z@Test that expanding very long output asks user for confirmation.�ar-r,r�rbz1.0)r�zidlelib.squeezer.tkMessageBoxF)rnNrozend-1cr!Ti��)r�r
Zset_is_dangerousryZis_dangerousrr�r�rZaskokcancelrMZaskyesnortrrrj)rrWrr�rkZmock_msgboxrurrr�test_expand_dangerous_oupput�s(

z0ExpandingButtonTest.test_expand_dangerous_oupputcCsp|j�}tddd|�}t�|_t�|_|jt�d�}|j|d�|j|jjd�|j|jjd�|jjd�dS)zTest the copy event.rRr�rb)rnNr%)	r�r
rZclipboard_clearZclipboard_append�copyrr\rV)rrWr�rurrr�	test_copy�szExpandingButtonTest.test_copyc
Csl|j�}tddd|�}t�|_tdtd��8}|jt�d�|j|jd�|j|j	dd	d�Wd
QRXd
S)zTest the view event.rRr�rbzidlelib.squeezer.view_text)r�)rnr%rr#N)
r�r
rZ
selection_ownrrZviewrr\r�)rrWr�Zmock_view_textrrr�	test_view�szExpandingButtonTest.test_viewcCs�|j�}tddd|�}td��j}t�}||_t�}d|_d|_|j|d�|j|j	j
t|j��x"|jD]^}}|j	j
|td�qhWWdQRXdS)	zTest the context menu.rRr�rbztkinter.Menur-)rn)�labelZcommandN)r�r
rrrM�x�yZcontext_menu_eventrZadd_commandr\r]Zrmenu_specsZassert_any_callr	)rrWr�Z	mock_MenuZ	mock_menuZ
mock_eventr��datarrr�
test_rmenu�s

zExpandingButtonTest.test_rmenuN)
r4r5r6r7r�rrrYr�r�r�r�r�rrrrr�Ss
)r��__main__r#)�	verbosity)$�collectionsrZtkinterrrZunittestZ
unittest.mockrrrrr	Ztest.supportr
Zidlelib.configrZidlelib.squeezerrr
rZidlelibrZidlelib.textviewrZidlelib.tooltiprZidlelib.pyshellrrSrZTestCaserr8r�r4r�rrrr�<module>s(0*

?>