3 ง fq ใ@s”dZddlmZddlZddlmZedƒddlmZmZddl m Z ddl m Z ddl jZejZe jZGd d „d ejƒZed krejd d dS)zTest replace, coverage 78%.้)ฺ ReplaceDialogN)ฺrequiresZgui)ฺTkฺText)ฺMock)ฺMboxc@steZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)ฺReplaceDialogTestcCsztƒ|_|jjƒtt_tj|jƒ|_t|j|jƒ|_ dd„|j _ t ƒ|j _ t |jƒ|_t ƒ|j_t ƒ|j_|j|j _dS)NcSsdS)Nฉr r r ๚C/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_replace.pyฺsz.ReplaceDialogTest.setUpClass..)rฺrootZwithdrawrฺseฺ tkMessageBoxZ SearchEngineฺenginerฺdialogZbellrฺokrฺtextZundo_block_startZundo_block_stop)ฺclsr r r ฺ setUpClasss      zReplaceDialogTest.setUpClasscCs$tt_|`|`|`|jjƒ|`dS)N)ฺ orig_mboxr rrrrr Zdestroy)rr r r ฺ tearDownClass!s  zReplaceDialogTest.tearDownClasscCs|jjddƒdS)NฺinsertzThis is a sample sTring)rr)ฺselfr r r ฺsetUp(szReplaceDialogTest.setUpcCs€|jjjdƒ|jjjdƒ|jjjdƒ|jjjdƒ|jjjdƒ|jjjdƒ|jj jdƒdt _ dt _ |j jddƒdS)NฺFTz1.0ฺend)rฺpatvarฺsetrฺreplvarฺwordvarฺcasevarฺrevarฺwrapvarฺbackvarฺ showerrorฺtitleฺmessagerฺdelete)rr r r ฺtearDown+szReplaceDialogTest.tearDowncCs๔|j}|j}|jj}|jj}|jj}|jjdƒ||jjƒ|j ƒƒ|j dƒ|j dƒ|ƒ||j ddƒdƒ|j ddƒ|j dƒ|j dƒ|ƒ||j d d ƒdƒ|j d ƒ|j d ƒ|ƒ||j d dƒd ƒ|j ddƒ|j ddƒ|j ddƒ}|j dƒ|ƒ|j ddƒ}|||ƒ|j ddƒ|j dƒ|j dƒ|ƒ||j dƒdƒ||j dƒdƒ|ƒ||j dƒdƒ||j dƒdƒ|j ddƒ}|ƒ|j ddƒ}|||ƒ|j ddƒ}|j dƒ|ƒ|j ddƒ}|||ƒ|jj dƒdS)NZasdfฺaz1.8z1.12rz1.0ฺisฺhelloz1.2z1.7ฺstringZworldz1.23z1.28rz line42:z [a-z][\d]+z1.9ฺiฺjz2.1ฺfoobarr)rฺ assertEqualrrrrฺ replace_itZsetpatZgetpatฺgetrฺmark_setrZfind_it)rrฺequalฺpvฺrvฺreplaceฺ before_textฺ after_textr r r ฺtest_replace_simple7s\                        z%ReplaceDialogTest.test_replace_simplecCs๖|j}|j}|jj}|jj}|jj}|jjjdƒ|j ddƒ|jdƒ|jdƒ|ƒ||j dƒdƒ||j dƒdƒ|ƒ||j dƒdƒ||j dƒdƒ|ƒ||j dƒdƒ|j dd ƒ|jd ƒ|j d d ƒ}|ƒ|j d d ƒ}|||ƒdS) NFrz1.4r-r.z1.2z1.5z1.20z1.8r*z1.0r) rr0rrrrr1r"rr3r2)rrr4r5r6r7r8r9r r r ฺtest_replace_wrap_around}s.       z*ReplaceDialogTest.test_replace_wrap_aroundcCst|j}|j}|jj}|jj}|jj}|jjjdƒ|jdƒ|jdƒ|ƒ||j ddƒdƒ||j ddƒdƒdS) NTr*r+z1.0z1.4ฺThisz1.5z1.10) rr0rrrrr1rrr2)rrr4r5r6r7r r r ฺtest_replace_whole_wordšs  z)ReplaceDialogTest.test_replace_whole_wordcCs˜|j}|j}|jj}|jj}|jj}|jjjdƒ|jj ddƒ}|jdƒ|jdƒ|ƒ|jj ddƒ}|||ƒ|jdƒ|ƒ||j ddƒdƒdS)NTz1.0rฺthisฺthatr<z1.4) r0rrrrrr1r rr2)rr4rr5r6r7r8r9r r r ฺtest_replace_match_caseจs    z)ReplaceDialogTest.test_replace_match_casecCsJ|j}|j}|jj}|jj}|jj}|jjjdƒ|j ddƒ}|jdƒ|jdƒ|ƒ|j ddƒ}|||ƒ|j ddƒ|ƒ||j dd ƒd ƒ|jd ƒ|ƒ|j d t j ƒ|j d t jƒ|jdƒ|ƒ|j d t j ƒ|j dt jƒd t _ d t _|jdƒ|jdƒ|ƒ|j d t j ƒ|j dt jƒ|jjdƒ||j ƒdƒdS)NTz1.0rz [a-z][\d]+r+rz line42z2.0z2.8ZlinhellorฺerrorฺEmptyz[\dฺPatternz[a]ztest\zInvalid Replace Expression๚?z\?)r0rrrrrr1r!rr2rฺassertInr$r%r&Z setcookedpat)rr4rr5r6r7r8r9r r r ฺtest_replace_regexปs@           z$ReplaceDialogTest.test_replace_regexcCsฐ|j}|j}|jj}|jj}|jj}|jjjdƒ|j ddƒ|jdƒ|jdƒ|ƒ||j ddƒdƒ||j dd ƒdƒ|ƒ||j d d ƒdƒ|ƒ||j dd ƒdƒdS) NTrz is as r*ฺwasz1.2z1.4z2.0z2.3z1.5z1.8) r0rrrrrr1r#rrr2)rr4rr5r6r7r r r ฺtest_replace_backwardsไs    z(ReplaceDialogTest.test_replace_backwardscCs๐|j}|jj}|jj}|jj}|jddƒ|jd|jddƒdƒ|jdƒ|jdƒ|ƒ|j d|jddƒƒ|jj jdƒ|jd ƒ|ƒ|j d t j ƒ|j d t jƒ|jd ƒ|jd ƒ|ƒ|jj jdƒ|jdƒ|jdƒ|ƒdS)Nrฺ z1.0r้dr*rGTrrArBz[s][T]๚\Fztext which is not presentr/)rrrrrฺ replace_allrr2rZ assertNotInr!rEr$r%r&)rrr5r6rLr r r ฺtest_replace_all๘s,        z"ReplaceDialogTest.test_replace_allcCsr|j}|jj}|jj}|jj}|j}|jdƒ|jdƒ|ƒ||jddƒdƒ|jj jdƒ|jdƒ|ƒdS)Nr<rGz sel.firstzsel.lastTr) rrrrrZdefault_commandr0rr2r!)rrr5r6Z replace_findr4r r r ฺtest_default_commands   z&ReplaceDialogTest.test_default_commandN)ฺ__name__ฺ __module__ฺ __qualname__ฺ classmethodrrrr(r:r;r=r@rFrHrMrNr r r r rs   F)rฺ__main__้)ฺ verbosity)ฺ__doc__Zidlelib.replacerZunittestZ test.supportrZtkinterrrZ unittest.mockrZidlelib.idle_test.mock_tkrZidlelib.searchengineZ searchenginer rrr$ZTestCaserrOฺmainr r r r ฺs