3  f8@sdZddlmZddlZddlmZddlmZm Z ddl m Z Gdddej Z Gd d d ej ZGd d d ej ZGd ddej ZGdddej ZGdddZGdddZGdddej ZedkrejddddS)zTest paragraph, coverage 76%.) paragraphN)requires)TkText) EditorWindowc@s<eZdZdZdZdZdZdZdZddZ d d Z d d Z d S) Is_Get_TestzTest the is_ and get_ functionsz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentcCs6|jtjd|jtjd|jtj|jdS)Nz )Z assertTruepgZ is_all_whiteZ assertFalse test_comment)selfr E/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_paragraph.pytest_is_all_whiteszIs_Get_Test.test_is_all_whitecCsR|j}|tj|jd|tj|jd|tj|jd|tj|jddS)Nrz ) assertEqualr Z get_indentr trailingws_commentleadingws_commentleadingws_nocomment)r Equalr r r test_get_indents zIs_Get_Test.test_get_indentcCsd|j}|tj|jd|tj|jd|tj|jd|tj|jd|tj|jddS)N#z #z r)rr Zget_comment_headerr rrrtest_nocomment)r rr r r test_get_comment_headers z#Is_Get_Test.test_get_comment_headerN) __name__ __module__ __qualname____doc__r rrrrrrrr r r r r src@s4eZdZdZeddZddZddZdd Zd S) FindTestaaTest the find_paragraph function in paragraph module. Using the runcase() function, find_paragraph() is called with 'mark' set at multiple indexes before and inside the test paragraph. It appears that code with the same indentation as a quoted string is grouped as part of the same paragraph, which is probably incorrect behavior. cCsddlm}||_dS)Nr)r)Zidlelib.idle_test.mock_tkrtext)clsrr r r setUpClass3s zFindTest.setUpClassc Cs|j}|jd|xftd|D]X}t|jd|jdd}x6d|d|fD]$}d||f}|jtj|||qNWqW|j dddS) Nz1.0z%d.end.rz%d.%dend) rinsertrangeintindexsplitrr Zfind_paragraphdelete) r Z inserttextZstoplineexpectedrlineZ linelengthcolZ tempindexr r r runcase8s  zFindTest.runcasec Csd}|j|dddd|ddfd}|j|d d d d|d d fd}|j|d d d d|d dfd}|j|dd dd|d dfd}|j|dd dd|d dfd}|j|dd dd|d dfd}|j|dd dd|d dfd}|j|dd dd|d dfdS)Nz;# Comment block with no blank lines before # Comment line z1.0z3.0rr:zG # Comment block with whitespace line before and after # Comment line z2.0z4.0r FzS # Indented comment block with whitespace before and after # Comment line z #Rz # Single line comment z4 # Single line comment with leading whitespace 3z0 # Comment immediately followed by code x = 42 (z= # Indented comment immediately followed by code x = 42 5z= # Comment immediately followed by indented code x = 42 1)r-)r Zcommentr r r test_find_commentEs zFindTest.test_find_commentc Csd}|j|dddd|ddfd}|j|d d d d|d d fd}|j|d d d d|d dfd}|j|dd dd|d dfd}|j|dd dd|d dfdS)Nz6"""String with no blank lines before String line """ r0z1.0z4.0rrr6zC """String with whitespace line before and after String line. """ z2.0z5.0r BzV """Indented string with whitespace before and after Comment string. """ z Uz """Single line string.""" r.z3.0z8 """Single line string with leading whitespace.""" 7)r-)r Z teststringr r r test_find_paragraph{szFindTest.test_find_paragraphN) rrrr classmethodrr-r8r>r r r r r)s   6rc@seZdZdZddZdS)ReformatFunctionTestz?Test the reformat_paragraph function without the editor window.cCs|j}tj}d}||ddd||ddd|||dd|||dd|||d d |||d d |||d dd }|||dd|||dd|||d d|||d d|||d d dS)Nz O hello world r zHello worldz Hello worldz O hello worldz O hello world z O hello worldz O hello worldz O hello world)rr Zreformat_paragraph)r rZreformZhwr r r test_reformat_paragraphs z,ReformatFunctionTest.test_reformat_paragraphN)rrrrrGr r r r r@sr@c@seZdZdZddZdS)ReformatCommentTestz=Test the reformat_comment function without the editor window.cCsJ|j}d}tj|dd}d}|||d}tj|dd}d}|||dS)Nzu """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r1z zy """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""zm# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?rzo# this is a test of a reformat for a triple quoted string will it # reformat to less than 70 characters for me?)rr Zreformat_comment)r r test_stringresultr*r r r r test_reformat_comments z)ReformatCommentTest.test_reformat_commentN)rrrrrKr r r r rHsrHc@seZdZddZdS)FormatClassTestcCs2tjd}|j|jd|j|j|jddS)Neditor)r FormatParagraphrZeditwinclose)r instancer r r test_init_closes zFormatClassTest.test_init_closeN)rrrrQr r r r rLsrLc@s,eZdZddZddZddZddZd S) TextWrappercCst|d|_dS)N)master)rr)r rSr r r __init__szTextWrapper.__init__cCs t|j|S)N)getattrr)r namer r r __getattr__szTextWrapper.__getattr__cCsdS)Nr )r r r r undo_block_startszTextWrapper.undo_block_startcCsdS)Nr )r r r r undo_block_stopszTextWrapper.undo_block_stopN)rrrrTrWrXrYr r r r rRsrRc@seZdZddZejZdS)EditorcCst||_dS)N)rRr)r rootr r r rTszEditor.__init__N)rrrrTrZget_selection_indicesr r r r rZsrZc@sTeZdZdZdZdZdZeddZeddZ d d Z d d Z d dZ ddZ dS)FormatEventTestzTest the formatting of text inside a Text widget. This is done with FormatParagraph.format.paragraph_event, which calls functions in the module as appropriate. zv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''' a '''The first line is under the max width. The second line's length is way over the max width. It goes on and on until it is over 100 characters long. Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. ''' a,# The first line is under the max width. # The second line's length is way over the max width. It goes on and on until it is over 100 characters long. # Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. # The fourth line is short like the first line.cCsBtdt|_|jjt|jd}|jj|_tj|j|_ dS)NZgui)r[) rrr[ZwithdrawrZrr rNZformat_paragraph_event formatter)rrMr r r r s    zFormatEventTest.setUpClasscCs$|`|`|jj|jj|`dS)N)rr]r[Zupdate_idletasksZdestroy)rr r r tearDownClasss  zFormatEventTest.tearDownClasscCs@|jjdd|jd|j|jjddd|jjdddS)Nz1.0z Short line ZDummyr$r#)rr$r]rgetr))r r r r test_short_lines zFormatEventTest.test_short_linecCs|j}|jd|j|jdd|jddd|jdd}d}|j|||jdd|jd|j|jdd d |jddd|jdd}d }|j|||jdddS) Nz1.0r$ParameterDoesNothingr1)limitzz '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''' r#selz1.11z1.endzv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?''') rr$rIZmark_setr]r_rr)tag_add)r rrJr*r r r test_long_line$s      zFormatEventTest.test_long_linecCs\|j}|jd|j|jddd|jddd|jdd}d }|j|||jdd dS) Nz1.0rcz2.0z4.0rar1)rbr$z The second line's length is way over the max width. It goes on and on until it is over 100 characters long. Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it. r#)rr$multiline_test_stringrdr]r_rr))r rrJr*r r r test_multiple_lines?s  z#FormatEventTest.test_multiple_linescCs|j}|jd|j|jddd|jdd}d}|j|||jdd|jd|j|jdd d |jddd|jdd}d }|j|||jdddS) Nz1.0rar1)rbr$a/# The first line is under the max width. The second line's length is # way over the max width. It goes on and on until it is over 100 # characters long. Same thing with the third line. It is also way over # the max width, but FormatParagraph will fix it. The fourth line is # short like the first line. r#rcz2.0z3.0z# The first line is under the max width. # The second line's length is way over the max width. It goes on and # on until it is over 100 characters long. )rr$multiline_test_commentr]r_rr)rd)r rrJr*r r r test_comment_blockNs     z"FormatEventTest.test_comment_blockN)rrrrrIrfrhr?rr^r`rergrir r r r r\s r\__main__r") verbosityexit)rZidlelibrr ZunittestZ test.supportrZtkinterrrZidlelib.editorrZTestCaserrr@rHrLrRrZr\rmainr r r r s    w