a  ze>@sdZddlmZddlZddlZddlmZddlmZm Z m Z m Z m Z ddlm Z ddlZddlmZejjZededededd Zd ZGd d d ZGd ddejZGdddejZedkrejdddS)zTest codecontext, coverage 100%) codecontextN)requires)NSEWTkFrameTextTclError)mock)config)mainZ highlightkeys 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@s$eZdZddZddZddZdS) DummyEditwincCs"||_||_||_||_d|_dS)Nr )roottopZ text_frametextlabel)selfrframerrV/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/idle_test/test_codecontext.py__init__'s zDummyEditwin.__init__cCstt|j|SN)intfloatrindex)rrrrr getlineno.szDummyEditwin.getlinenocKs|d|_dS)Nr)r)rkwargsrrrupdate_menu_label1szDummyEditwin.update_menu_labelN)__name__ __module__ __qualname__rrrrrrrr&src@seZdZeddZeddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZejejdddZddZddZd S)!CodeContextTestcCs~tdt}|_|t|}|_t|}|_|dt |j dddd|j ddt dt ||||_ttj_dS)NZgui1.0leftZboth)Zsidefillexpand)rowcolumnZsticky)rrrZwithdrawrrrrinsert code_samplepackZgridrreditortestcfgridleConfuserCfg)clsrrrrrr setUpClass7s  zCodeContextTest.setUpClasscCs@ttj_|jjdd|`|`|`|j |j |`dS)Nr$end) usercfgrr0r1r.rdeleterrZupdate_idletasksdestroy)r2rrr tearDownClassEs    zCodeContextTest.tearDownClasscsjddjd<tj_ddd_tjjfdd}t j j tjd |}| |jd_fd d }t j j tjd |}| |jdS) NrZ TkFixedFontfontz#abcdefz#123456 background foregroundcs|dkrjS||S)Ncontext) highlight_cfg)ZthemeelementZorig_idleConf_GetHighlightrrrmock_idleconf_GetHighlightVsz9CodeContextTest.setUp..mock_idleconf_GetHighlight GetHighlightcsjSr) font_override)rZ configTypesectionrrrmock_idleconf_GetFont`sz4CodeContextTest.setUp..mock_idleconf_GetFontZGetFont)ryviewr CodeContextr.ccr>r0rBunittestr patchobjectstartZ addCleanupstoprC)rrAZGetHighlight_patcherrFZGetFont_patcherrr@rsetUpNs(    zCodeContextTest.setUpcCs,|jjr|jj|j|j`|`dSr)rIr=r7__del__rErrrtearDowngs  zCodeContextTest.tearDowncCsz|j}|j}|j}||j|||j|j||jd|jd||j||jdg||jd||jj dS)Nr9rr Fr&) assertEqualr.rIeditwinr assertIsNoner=info topvisiblet1)reqZedrIrrr test_initns   zCodeContextTest.test_initcCs|jdSr)rIrPrErrrtest_del{szCodeContextTest.test_delcCsv|jddd}|j_|j|t"}|jj dd|Wdn1sV0Y| dt |j dS)Ni'cSsdSrrrrrrz5CodeContextTest.test_del_with_timer..afterrWz doesn't exist) rr_rIrYrP assertRaisesrrtkcallZassertInstr exception)rtimercmrrrtest_del_with_timer~s   0z#CodeContextTest.test_del_with_timercCstj||jjddS)N)rrHreloadrTrI context_depthrErrr test_reloads zCodeContextTest.test_reloadcCsJ|j}|j}|j}|jr||||j||jd|jd||jd|jd||jd|jd||jddd||jj d ||j j d d |jj d d |||j||jj d||jj ddd|ddD}|jd|||jdd|||||jdd|dS)Nr9Zfgr<bgr;r$end-1cr zHide Code Contextr_rWr&rezShow Code Context css|]}|dVqdS)Nr).0xrrr r^zACodeContextTest.test_toggle_code_context_event.. r)rTrItoggle_code_context_eventr=ZassertIsNotNonerr>getrUrrrarbrYrVjoin get_contextrG)rrZrIZtoggleZline11_contextrrrtest_toggle_code_context_events0    z.CodeContextTest.test_toggle_code_context_eventcCs4|j}|jj}|t|dddWdn1s:0Y||ddgdf||ddgdf||dddgdf||d gd df||d gd df||d d dgd df||d ddgddf||d ddddgdf||d ddgddf||d ddddgdfdS)Nr&r)Zstoplineror class C1:classr}r} def __init__(self, a, b):def )rzr}z def compare(self):rr if a > b:ifrs)rzrrrrz elif a < b:elifro)rrrrrr)Z stopindent)rTrIrwr`AssertionError)rrZgcrrrtest_get_contextsH * z CodeContextTest.test_get_contextcCs|j}|j}|js|||||jdg||jd|j d|||jdg||jd||j ddd|j d|||jddg||jd||j ddd |j d|||jddg||jd ||j ddd |j d |||jgd ||jd ||j ddd |j d|||jgd||jd||j ddd|d|_ ||jgd||jd||j ddd|j d |||jgd ||jd||j ddddS)NrRr&ror$rmr rzryr{r})rRrzrr~z'class C1: def __init__(self, a, b):rs)rRrzrrr zFclass C1: def compare(self): if a > b: elif a < b:r) rTrIr=rtrVupdate_code_contextrWrXrrGrurj)rrZrIrrrtest_update_code_contextsT              z(CodeContextTest.test_update_code_contextcCs.|j}|j}|j}|js ||jd|||jd|j dd|||jd|jd|||jd|j dd|||jd d|_ |jd|||jd|j dd |||jd |jd ||j d d d|j dd |||jd dS)Nz2.0ror+z1.5r&z12.0rz3.0rr$z5.0Zselr~) rTrIZ jumptoliner=rtrrGrrXZmark_setrjZtag_add)rrZrIZjumprrrtest_jumptoline.s<          zCodeContextTest.test_jumptolinercCsD|jjr|j|j||j|j|dSr)rIr=rtZ timer_eventZassert_not_calledZ assert_called)rZ mock_updaterrrtest_timer_eventWs    z CodeContextTest.test_timer_eventcCs|j}|j}|jd}d}||||jdur8|||_||||jd|||_|||jd|dS)Nr9Z TkTextFont)rTrIrZassertNotEqualr=rtrCZ update_font)rrZrIZ orig_font test_fontrrrrds   zCodeContextTest.test_fontcs|j|jt|j}ddd}fdd}jr<||_||||||_||dS)Nz#222222z#ffff00r:cs,jd|djd|ddS)Nr;r<)r=)ZcolorsrIrZrrassert_colors_are_equalszFCodeContextTest.test_highlight_colors..assert_colors_are_equal)rTrIdictr>r=rtZupdate_highlight_colors)rZ orig_colorsZ test_colorsrrrrtest_highlight_colors}s   z%CodeContextTest.test_highlight_colorsN)r r!r" classmethodr3r8rOrQr[r\rgrkrxrrrr rKrLrrHrrrrrrrr#5s$   $0Q) r#c@seZdZddZddZdS)HelperFunctionTextcCsFtj}d}|D]\}}||||q||dtddddS)N))z first word) first)z first word) r)u ᧔᧒: )z u᧔᧒)z no spaces)r no)r r r )z# TEST COMMENTr) (continuation))rr rz^(\s*)([^\s]*))c)rz(continuation))rZget_spaces_firstwordrTrecompile)rruZ test_lineslineZexpected_outputrrrtest_get_spaces_firstwords z,HelperFunctionText.test_get_spaces_firstwordcCs|j}tj}t}|||dtjddf|||dd|||dtjddf|||dd |||d d ||d d dS)Nrr Fr&)rr{r|roz # Class comment.ry)r}rrr)rrr if a == b:)r&rr)rTrZ get_line_infor, splitlinesZINFINITY)rrZZglilinesrrrtest_get_line_infosz%HelperFunctionText.test_get_line_infoN)r r!r"rrrrrrrsr__main__ro) verbosity)__doc__ZidlelibrrJZ unittest.mockZ test.supportrtkinterrrrrrr rr r0r1r5ZIdleUserConfParserr/r,rZTestCaser#rr r rrrrs,    k(