3 § fž8ã@sØdZddlmZddlZddlmZddlmZmZm Z m Z ddlm Z ddl Z ddlm Z ejjZe jdƒe jdƒe jdƒe jdƒd œZd ZGd d „d ƒZGd d„dejƒZGdd„dejƒZedkrÔejdd�dS)zTest codecontext, coverage 100%é)Ú codecontextN)Úrequires)ÚTkÚFrameÚTextÚTclError)Úmock)ÚconfigÚ)ÚmainZ highlightÚkeysÚ extensionszó 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 c@seZdZdd„ZdS)Ú DummyEditwincCs||_||_||_||_dS)N)ÚrootÚtopZ text_frameÚtext)ÚselfrÚframer©rúG/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_codecontext.pyÚ__init__&szDummyEditwin.__init__N)Ú__name__Ú __module__Ú __qualname__rrrrrr%src@sŒeZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zejjejdƒdd„ƒZdd„ZdS)ÚCodeContextTestcCs~tdƒtƒ}|_|jƒt|ƒ}|_t|ƒ}|_|jdt ƒ|j dddd�|j dddd�t |||ƒ|_ t tj_dS)NZguiz1.0ÚleftZbothé)ZsideZfillÚexpandr)rrrZwithdrawrrrrÚinsertÚ code_sampleZpackrÚeditorÚtestcfgrÚidleConfÚuserCfg)ÚclsrrrrrrÚ setUpClass/s  zCodeContextTest.setUpClasscCs@ttj_|jjjddƒ|`|`|`|jj ƒ|jj ƒ|`dS)Nz1.0Úend) Úusercfgrr"r#r rÚdeleterrZupdate_idletasksÚdestroy)r$rrrÚ tearDownClass=s    zCodeContextTest.tearDownClasscCs|jjdƒtj|jƒ|_dS)Nr)rÚyviewrÚ CodeContextr Úcc)rrrrÚsetUpFs zCodeContextTest.setUpcCs,|jjr|jjjƒ|jjƒ|j`|`dS)N)r-Úcontextr)Ú__del__)rrrrÚtearDownJs  zCodeContextTest.tearDowncCs¨|j}|j}|j}||j|ƒ||j|jƒ||j|jdƒ|j|jƒ||jd gƒ||j dƒ||j j j dd|jj ƒddƒ||j j j dd|jjƒddƒdS) NÚfontrrr FÚafterÚinfoZtimeréÿÿÿÿ)rr5r F)Ú assertEqualr r-ZeditwinrÚtextfontÚ assertIsNoner/r4Ú topvisiblerÚtkÚcallÚt1Út2)rÚeqZedr-rrrÚ test_initQs    zCodeContextTest.test_initcCs”|jjƒ|jtƒ�(}|jjjdd|jjƒ|jd|ƒWdQRX|jtƒ�(}|jjjdd|jj ƒ|jd|ƒWdQRX|j`|j` |jjƒdS)Nr3r4z doesn't exist) r-r0Ú assertRaisesrrr:r;r<ZassertInr=)rÚmsgrrrÚtest_del_s    zCodeContextTest.test_delcCs4tjjƒ|j|jjdddœƒ|j|jjdƒdS)NZ lightgrayz#000000)Ú backgroundÚ foregroundé)rr,Úreloadr6r-ÚcolorsÚ context_depth)rrrrÚ test_reloadls   zCodeContextTest.test_reloadcCs¤|j}|j}|j}|jr|ƒ||ƒdƒ|j|jƒ||jd|jƒ||jd|jdƒ||jd|jdƒ||jjddƒd ƒ||ƒdƒ|j|jƒdS) NÚbreakr2ZfgrDZbgrCz1.0zend-1cr ) r6r-Útoggle_code_context_eventr/ZassertIsNotNoner7rGÚgetr8)rr>r-ZtogglerrrÚtest_toggle_code_context_eventrs   z.CodeContextTest.test_toggle_code_context_eventcCs.|j}|jj}|jtƒ�|ddd�WdQRX||dƒdgdfƒ||dƒdgdfƒ||d ƒddgdfƒ||d ƒdddgdfƒ||dƒdddd gdfƒ||ddd�d!d"d#d$gdfƒ||ddd�d%d&d'gdfƒ||ddd�d(d)gdfƒ||ddd�d*d+d,gdfƒ||ddd�d-d.gdfƒdS)/Nrr)Zstoplineééú class C1():Úclassééú def __init__(self, a, b):Údefé éú def compare(self):éú if a > b:Úifé ú elif a < b:Úelif)Z stopindent)rOrrPrQ)rOrrPrQ)rOrrPrQ)rRrRrTrU)rOrrPrQ)rWrRrXrU)rYrYrZr[)rOrrPrQ)rWrRrXrU)rYrYrZr[)rVrYr]r^)rOrrPrQ)rWrRrXrU)rYrYrZr[)rVrYr]r^)rWrRrXrU)rYrYrZr[)rVrYr]r^)rYrYrZr[)rVrYr]r^)rWrRrXrU)rYrYrZr[)rVrYr]r^)rYrYrZr[)rVrYr]r^)r6r-Z get_contextr@ÚAssertionError)rr>ÚgcrrrÚtest_get_context‡s:           z CodeContextTest.test_get_contextc Cs*|j}|j}|js|jƒ|j|jƒƒ||jdgƒ||jdƒ|jj dƒ|jƒ||jdgƒ||jdƒ||jj ddƒdƒ|jj dƒ|jƒ||jd!d"gƒ||jd ƒ||jj ddƒdƒ|jj d ƒ|jƒ||jd$d%gƒ||jd ƒ||jj ddƒdƒ|jj d ƒ|jƒ||jd'd(d)gƒ||jdƒ||jj ddƒdƒ|jj dƒ|jƒ||jd+d,d-d.d/gƒ||jdƒ||jj ddƒdƒ|jƒd|_ ||jd1d2d3d4d5gƒ||jdƒ||jj ddƒdƒ|jj dƒ|jƒ||jd7d8d9gƒ||jdƒ||jj ddƒd ƒdS):Nrrr FrOz1.0zend-1cú class C1():rQrNrRú def __init__(self, a, b):rUrSz)class C1(): def __init__(self, a, b):r\rWú def compare(self):rYú if a > b:r[rVú elif a < b:r^é zHclass C1(): def compare(self): if a > b: elif a < b:ér5)rr5r Fr5)rr5r Fr5)rr5r F)rOrrbrQr5)rr5r F)rOrrbrQr5)rr5r F)rOrrbrQ)rRrRrcrUr5)rr5r F)rOrrbrQ)rWrRrdrU)rYrYrer[)rVrYrfr^r5)rr5r F)rOrrbrQ)rWrRrdrU)rYrYrer[)rVrYrfr^r5)rr5r F)rOrrbrQ)rRrRrcrU) r6r-r/rKr8Úupdate_code_contextr4r9rr+rLrH)rr>r-rrrÚtest_update_code_context·sl              z(CodeContextTest.test_update_code_contextcCsü|j}|j}|j}|js |jƒ|jjd›d�ƒ|jƒ||jdƒ|jj ddƒ|ƒ||jdƒ|jjd›d�ƒ|jƒ||jdƒ|jj ddƒ|ƒ||jdƒd|_ |jjd›d�ƒ|jƒ||jdƒ|jj dd ƒ|ƒ||jdƒdS) NrOz.0rz1.5rrgz3.0rYz1.0) r6r-Z jumptoliner/rKrr+rir9Zmark_setrH)rr>r-ZjumprrrÚtest_jumptolines0     zCodeContextTest.test_jumptolinericCsD|jjr|jjƒ|jjƒ|jƒ|jjƒ|jjƒ|jƒdS)N)r-r/rKZ timer_eventZassert_not_calledZ assert_called)rZ mock_updaterrrÚtest_timer_event)s    z CodeContextTest.test_timer_eventcCs¾|j}|j}|jd}tjj}d}dddœ}|jr:|jƒ||jd<|tj_|jƒ||j |ƒ||j |ƒ|jƒ||jd<|tj_|jƒ||j |ƒ||j |ƒ||jd|ƒ||jd|dƒ||jd|dƒ||jd<|jƒ||j |ƒ||j |ƒ||jd|ƒ||jd|dƒ||jd|dƒ||jd<|tj_|jƒ||j |ƒ||j |ƒ||jd|ƒ||jd|dƒ||jd|dƒ|tj_|jƒdS)Nr2ZFakeFontz#222222z#ffff00)rCrDrCrD) r6r-rrr,rGr/rKZconfig_timer_eventr7Z contextcolors)rr>r-Z save_fontZ save_colorsZ test_fontZ test_colorsrrrÚtest_config_timer_event6sN              z'CodeContextTest.test_config_timer_eventN)rrrÚ classmethodr%r*r.r1r?rBrIrMrarjrkrZpatchÚobjectrr,rlrmrrrrr-s   0Q! rc@seZdZdd„Zdd„ZdS)ÚHelperFunctionTextc CsJtj}d}x |D]\}}|j||ƒ|ƒqW|j|d tjdƒd�d ƒdS)!Nú first wordú Úfirstú first wordú õ ᧔᧒: ú õ᧔᧒ú no spacesr Únoú# TEST COMMENTú (continuation)z^(\s*)([^\s]*))Úcú(continuation)©rrrs©rqr©rurs©rtr�©rwrx©rvrƒ©r rz©ryr…©r r ©r r‡©r r ©r{r‰©rrr ©r|r‹)r€r‚r„r†rˆrŠrŒ)rrr~)rZget_spaces_firstwordr6ÚreÚcompile)rrLZ test_linesÚlineZexpected_outputrrrÚtest_get_spaces_firstwordls z,HelperFunctionText.test_get_spaces_firstwordcCs�|j}tj}tjƒ}|||dƒtjddfƒ|||dƒdƒ|||dƒtjddfƒ|||d ƒdƒ|||d ƒdƒ||dƒdƒdS)Nrr Frú class C1():rQrOz # Class comment.rNrRú def __init__(self, a, b):rUrWrYú if a > b:r[ú if a == b:)rr‘rQ)rRr’rU)rYr“r[)rr”r[)r6rZ get_line_inforÚ splitlinesZINFINITY)rr>ZgliÚlinesrrrÚtest_get_line_infosz%HelperFunctionText.test_get_line_infoN)rrrr�r—rrrrrpjsrpÚ__main__rO)Ú verbosity)Ú__doc__ZidlelibrZunittestZ test.supportrZtkinterrrrrrr�r r"r#r'ZIdleUserConfParserr!rrZTestCaserrprr rrrrÚs(    ?(