B 0‘c<\ã@s<ddlmZddlZddlmZddlmZddlmZm Z ddl m Z ddl m ZGdd „d ejƒZGd d „d ejƒZGd d „d ejƒZGdd„dejƒZGdd„dejƒZGdd„dƒZGdd„dƒZ Gdd„dejƒZGdd„dƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZed kr8ejd!d!d"dS)#é)ÚformatN)Úmock)Úrequires)ÚTkÚText)Ú EditorWindow)ÚEditorc@s8eZdZdZdZdZdZdZdd„Zdd „Z d d „Z d S) Ú Is_Get_Testz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentcCs6| t d¡¡| t d¡¡| t |j¡¡dS)NÚz )Z assertTrueÚftZ is_all_whiteZ assertFalseÚ test_comment)Úself©rúB/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_format.pyÚtest_is_all_whiteszIs_Get_Test.test_is_all_whitecCsR|j}|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒdS)Nr z )Ú assertEqualr Z get_indentr Útrailingws_commentÚleadingws_commentÚleadingws_nocomment)r ÚEqualrrrÚtest_get_indents zIs_Get_Test.test_get_indentcCsd|j}|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒ|t |j¡dƒdS)Nú#z #z r )rr Zget_comment_headerr rrrÚtest_nocomment)r rrrrÚtest_get_comment_header s z#Is_Get_Test.test_get_comment_headerN) Ú__name__Ú __module__Ú __qualname__r rrrrrrrrrrrr sr c@s0eZdZedd„ƒZdd„Zdd„Zdd„Zd S) ÚFindTestcCsddlm}|ƒ|_dS)Nr)r)Zidlelib.idle_test.mock_tkrÚtext)ÚclsrrrrÚ setUpClass5s zFindTest.setUpClassc CsŠ|j}| d|¡xftd|ƒD]X}t| d|¡ d¡dƒ}x6d|d|fD]$}d||f}| t ||¡|¡qNWqW|  dd¡dS) Nz1.0éz%d.endÚ.réz%d.%dÚend) rÚinsertÚrangeÚintÚindexÚsplitrr Zfind_paragraphÚdelete) r Z inserttextZstoplineÚexpectedrÚlineZ linelengthÚcolZ tempindexrrrÚruncase:s  zFindTest.runcasec Csd}| |dddd|dd…f¡d}| |d d d d|d d …f¡d}| |d d d d|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡dS)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 ÚcommentrrrÚtest_find_commentGs zFindTest.test_find_commentc Cs®d}| |dddd|dd…f¡d}| |d d d d|d d …f¡d}| |d d d d|d d…f¡d}| |dd dd|d d…f¡d}| |dd dd|d d…f¡dS)Nz6"""String with no blank lines before String line """ r1z1.0z4.0r rr7zC """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.0éz8 """Single line string with leading whitespace.""" é7)r.)r Z teststringrrrÚtest_find_paragraph}szFindTest.test_find_paragraphN)rrrÚ classmethodr r.r:r@rrrrr+s  6rc@seZdZdd„ZdS)ÚReformatFunctionTestcCsØ|j}tj}d}||ddƒdƒ||ddƒdƒ|||dƒdƒ|||dƒdƒ|||d ƒd ƒ|||d ƒd ƒ|||d ƒdƒd }|||dƒdƒ|||dƒdƒ|||d ƒdƒ|||d ƒdƒ|||d ƒd ƒdS)Nz O hello worldú r!zHello worldéz Hello worldz O hello worldééz O hello worldé é z O hello worldz O hello worldz O hello world)rr Zreformat_paragraph)r rZreformZhwrrrÚtest_reformat_paragraph¥s z,ReformatFunctionTest.test_reformat_paragraphN)rrrrIrrrrrB¢srBc@seZdZdd„ZdS)ÚReformatCommentTestcCsJ|j}d}t |dd¡}d}|||ƒd}t |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?"""r2z 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_stringÚresultr+r rrrÚtest_reformat_comment¿s z)ReformatCommentTest.test_reformat_commentN)rrrrMrrrrrJ¼srJc@seZdZdd„ZdS)ÚFormatClassTestcCs2t d¡}| |jd¡| ¡| |jd¡dS)NÚeditor)r ÚFormatParagraphrZeditwinÚclose)r ÚinstancerrrÚtest_init_close×s zFormatClassTest.test_init_closeN)rrrrSrrrrrNÖsrNc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú TextWrappercCst|d|_dS)N)Úmaster)rr)r rUrrrÚ__init__êszTextWrapper.__init__cCs t|j|ƒS)N)Úgetattrr)r ÚnamerrrÚ __getattr__ìszTextWrapper.__getattr__cCsdS)Nr)r rrrÚundo_block_startîózTextWrapper.undo_block_startcCsdS)Nr)r rrrÚundo_block_stopïr[zTextWrapper.undo_block_stopN)rrrrVrYrZr\rrrrrTésrTc@seZdZdd„ZejZdS)rcCst|ƒ|_dS)N)rTr)r ÚrootrrrrVòszEditor.__init__N)rrrrVrÚget_selection_indicesrrrrrñsrc@sPeZdZdZdZdZedd„ƒZedd„ƒZdd „Z d d „Z d d „Z dd„Z dS)ÚFormatEventTestzv '''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.cCsBtdƒtƒ|_|j ¡t|jd}|jj|_t |¡j|_ dS)NÚgui)r]) rrr]Úwithdrawrrr rPZformat_paragraph_eventÚ formatter)rrOrrrr s    zFormatEventTest.setUpClasscCs$|`|`|j ¡|j ¡|`dS)N)rrbr]Úupdate_idletasksÚdestroy)rrrrÚ tearDownClasss  zFormatEventTest.tearDownClasscCs@|j dd¡| d¡| |j dd¡d¡|j dd¡dS)Nz1.0z Short line ZDummyr%r$)rr%rbrÚgetr*)r rrrÚtest_short_line s zFormatEventTest.test_short_linecCs¬|j}| d|j¡| dd¡|jddd| dd¡}d}| ||¡| dd¡| d|j¡| dd d ¡|jddd| dd¡}d }| ||¡| dd¡dS) Nz1.0r%ÚParameterDoesNothingr2)Ú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%rKZmark_setrbrfrr*Útag_add)r rrLr+rrrÚtest_long_line&s      zFormatEventTest.test_long_linecCs\|j}| d|j¡| ddd¡|jddd| dd¡}d }| ||¡| dd ¡dS) Nz1.0rjz2.0z4.0rhr2)rir%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_stringrkrbrfrr*)r rrLr+rrrÚtest_multiple_linesAs  z#FormatEventTest.test_multiple_linescCs |j}| d|j¡|jddd| dd¡}d}| ||¡| dd¡| d|j¡| dd d ¡|jddd| dd¡}d }| ||¡| dd¡dS) Nz1.0rhr2)rir%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$rjz2.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_commentrbrfrr*rk)r rrLr+rrrÚtest_comment_blockPs     z"FormatEventTest.test_comment_blockN) rrrrKrmrorAr rergrlrnrprrrrr_ös r_c@s eZdZdd„ZejZejZdS)Ú DummyEditwincCs(||_||_d|_d|_d|_d|_dS)Nr1FT)r]rÚ indentwidthZtabwidthÚusetabsZcontext_use_ps1)r r]rrrrrV}s zDummyEditwin.__init__N)rrrrVrZ _make_blanksr^rrrrrq|srqc@s®eZdZedd„ƒZedd„ƒZdd„Zdd„Zd Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zej ejd¡dd„ƒZej ejd¡dd„ƒZej ed¡dd„ƒZdS)ÚFormatRegionTestcCs`tdƒtƒ|_|j ¡t|jƒ|_t ¡|j_t ¡|j_ t |j|jƒ|_ t   |j ¡|_dS)Nr`)rrr]rarrrÚMockrZr\rqrOr Ú FormatRegionrb)rrrrr ‹s    zFormatRegionTest.setUpClasscCs(|`|`|`|j ¡|j ¡|`dS)N)rrbrOr]rcrd)rrrrre–s   zFormatRegionTest.tearDownClasscCs|j d|j¡dS)Nz1.0)rr%Ú code_sample)r rrrÚsetUpszFormatRegionTest.setUpcCs|j dd¡dS)Nz1.0r$)rr*)r rrrÚtearDown szFormatRegionTest.tearDowna# WS line needed for test. 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 cCsr|jj}|j}|j}| ddd¡ddddg}||ƒddd |¡|fƒ| ddd ¡||ƒd d dddgfƒdS) Nrjz7.0z10.0r z def compare(self):z if a > b:Ú z1.0r$z15.0z16.0)rbÚ get_regionrrrkÚjoinÚ tag_remove)r rfrÚeqZexpected_linesrrrÚtest_get_region´sz FormatRegionTest.test_get_regionc Cs&|jj}|j}|j}|j}t ¡|_|j ¡d}|j ¡d}|  ddd¡|j  ¡\}}} } |||| | ƒ|j  ¡||  dd¡| ƒ||  dd¡| ƒ|  ddd ¡d } |  d ¡} |d d | | ƒ||  dd¡| ƒ||  d d¡| ƒ||  dd¡|ƒ||  dd¡|ƒ|  ddd ¡||_dS)Nr;é rjz6.0z11.0z sel.firstzsel.lastz1.0r$zadded line 1 rzz7.0z10.0z7.0-1cz12.0-1c)rbÚ set_regionrrZbellrrurwÚ splitlinesrkr{Zassert_called_oncerfr}r)) r Zset_rr~Z save_bellZline6Zline10ÚheadÚtailÚcharsÚlinesZ newstringÚnewlinesrrrÚtest_set_regionÅs.   z FormatRegionTest.test_set_regioncCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrjz7.0z10.0z2 def compare(self): if a > b: )rbZindent_region_eventrrrkrf)r Úindentrr~rrrÚtest_indent_region_eventès z)FormatRegionTest.test_indent_region_eventcCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrjz7.0z10.0z" def compare(self): if a > b: )rbZdedent_region_eventrrrkrf)r Údedentrr~rrrÚtest_dedent_region_eventòs z)FormatRegionTest.test_dedent_region_eventcCs>|jj}|j}|j}| ddd¡|ƒ|| dd¡dƒdS)Nrjz7.0z10.0z0## ## def compare(self): ## if a > b: )rbÚcomment_region_eventrrrkrf)r r9rr~rrrÚtest_comment_region_eventüs z*FormatRegionTest.test_comment_region_eventcCs®|jj}|jj}|j}|j}| ddd¡|ƒ|ƒ|| dd¡dƒ| ddd¡| ddd¡|ƒ|| dd ¡d ƒ|j ddd d d g¡|ƒ|| dd ¡d ƒdS)Nrjz7.0z10.0z* def compare(self): if a > b: z1.0r$z3.0z4.0z3.endz # Class comment.r z# Class comment.z Class comment.) rbrZuncomment_region_eventrrrkrfr}r)r r9Z uncommentrr~rrrÚtest_uncomment_region_eventsz,FormatRegionTest.test_uncomment_region_eventÚ _asktabwidthcCs\|jj}|j}|j}| ddd¡d|_| |ƒ¡d|_| |ƒ¡|| dd¡dƒdS)Nrjz7.0z10.0r/z$ def compare(self): if a > b: ) rbÚtabify_region_eventrrrkÚ return_valueÚ assertIsNoneÚassertIsNotNonerf)r rZtabifyrr~rrrÚtest_tabify_region_events  z)FormatRegionTest.test_tabify_region_eventcCsl|jj}|j}|j}| ddd¡d|_| |ƒ¡d|_|j ¡d|_| |ƒ¡||  dd¡dƒdS)Nrjz7.0z10.0r#r/z0 def compare(self): if a > b: ) rbZuntabify_region_eventrrrkr’r“r‘r”rf)r rZuntabifyrr~rrrÚtest_untabify_region_event)s   z+FormatRegionTest.test_untabify_region_eventÚ askintegercCs |jj}d|_| |ƒd¡dS)Né )rbrr’r)r r—ZaskrrrÚtest_ask_tabwidth:sz"FormatRegionTest.test_ask_tabwidthN)rrrrAr rerxryrwrrˆrŠrŒrŽrrÚpatchÚobjectr rvr•r–r™rrrrrt‰s #   rtc@s8eZdZej ed¡dd„ƒZej ed¡dd„ƒZdS)Ú IndentsTestÚaskyesnocCsjtddƒ}t |¡}d|_| d¡| |jd¡| |jd¡| d¡| |jd¡| |jd¡dS)NTéF)rqr ÚIndentsr’Ztoggle_tabs_eventrrsrr)r rrOÚindentsrrrÚtest_toggle_tabsCs    zIndentsTest.test_toggle_tabsr—cCsxtddƒ}t |¡}d|_| d¡| |jd¡d|_| d¡| |jd¡d|_d|_| d¡| |jd¡dS)Nr1r/r;T)rqr rŸr’Zchange_indentwidth_eventrrrrs)r r—rOr rrrÚtest_change_indentwidthQs     z#IndentsTest.test_change_indentwidthN) rrrrršr›r r¡r¢rrrrrœAsrœc@s<eZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd S) Ú RstripTestcCsHtdƒtƒ|_|j ¡t|jƒ|_t|jd|_t  |j¡j |_ dS)Nr`)r) rrr]rarrÚ MockEditorrOr ZRstripÚ do_rstrip)rrrrr fs   zRstripTest.setUpClasscCs(|`|`|`|j ¡|j ¡|`dS)N)rr¥rOr]rcrd)rrrrreos   zRstripTest.tearDownClasscCs|j dd¡dS)Nz1.0zend-1c)rr*)r rrrryvszRstripTest.tearDowncCs8d}d}|j d|¡| ¡| |j dd¡|¡dS)NzˆLine with an ending tab Line ending in 5 spaces Linewithnospaces indented line indented line with trailing space zyLine with an ending tab Line ending in 5 spaces Linewithnospaces indented line indented line with trailing space z1.0r%)rr%r¥rrf)r ZoriginalÚstrippedrrrÚtest_rstrip_linesys zRstripTest.test_rstrip_linesc Cs²|j}xLdD]D}|j|d.| d|¡| ¡| | dd¡d¡WdQRXq WxXdD]P}|j|d:| dd¡| d|¡| ¡| | dd¡d¡WdQRXqZWdS)N)r rzz )Úcodez1.0zend-1cr )za za za za )rZsubTestr%r¥rrfr*)r rr¨rrrÚtest_rstrip_endŒs  "   zRstripTest.test_rstrip_endN) rrrrAr reryr§r©rrrrr£ds  r£Ú__main__r#)Ú verbosityÚexit)Zidlelibrr ZunittestrZ test.supportrZtkinterrrZidlelib.editorrZidlelib.idle_test.mock_idlerr¤ZTestCaser rrBrJrNrTr_rqrtrœr£rÚmainrrrrÚs,     w 9#7