a 9êdg.}ã@sJddlmZddlZddlZddlZddlmZmZddlZddlm Z ddlZddl m Z ej Z e j ZiZe d¡Zed<e d¡Zed<e d¡Zed <e d¡Zed <d d „Zd d„ZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZedkrFejdddS)é)ÚconfigN)Úcaptured_stderrÚfindfile)Úmock)ÚFuncÚÚmainÚ highlightÚkeysÚ extensionscCstt_dt_dS)NT)ÚtestcfgÚidleConfÚuserCfgÚidlelibÚtesting©rrú9/usr/local/lib/python3.9/idlelib/idle_test/test_config.pyÚ setUpModulesrcCstt_dt_dS)NF)Úusercfgr rrrrrrrÚtearDownModule!src@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚIdleConfParserTestzœ [one] one = false two = true three = 10 [two] one = a string two = true three = false cCsôt d¡}| |j¡|j}| |jddddd¡| |jddddd¡||jddd dd ƒ|| dd¡d ƒ| |jddddd¡| |jddddd¡|| dd¡d ƒ|| dd¡d ƒ| | dd¡¡||jdddddƒdS)NrÚoneÚbool©ÚtypeFÚtwoTÚthreeÚinté za stringÚtrueÚfalseÚnotZexistZDEFAULT©Údefault)rÚIdleConfParserÚ read_stringÚ assertEqualZassertIsÚGetZ assertIsNone)ÚselfÚparserÚeqrrrÚtest_get5s  zIdleConfParserTest.test_getcCsXt d¡}| |j¡|j}| |dƒgd¢¡| |dƒgd¢¡| |dƒg¡dS)Nrr)rrrrz not exist)rr$r%Ú GetOptionListÚassertCountEqualr&)r(r)Zget_listrrrÚtest_get_option_listJs   z'IdleConfParserTest.test_get_option_listcCs&t d¡}| ¡| | ¡g¡dS)Nr)rr$ÚLoadr&Úsections©r(r)rrrÚtest_load_nothingRs z$IdleConfParserTest.test_load_nothingcCsFtdƒ}t |¡}| ¡| | dd¡d¡| | d¡dg¡dS)Nú cfgparser.1úFoo BarÚfooÚnewbar)rrr$r/r&r'r,)r(Ú config_pathr)rrrÚtest_load_fileWs  z!IdleConfParserTest.test_load_fileN)Ú__name__Ú __module__Ú __qualname__rr+r.r2r8rrrrr&s  rc@sFeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dS)ÚIdleUserConfParserTestrcCs t |¡S©N)rÚIdleUserConfParser)r(ÚpathrrrÚ new_parserdsz!IdleUserConfParserTest.new_parsercCs¢| ¡}| d¡| | ddd¡¡| | ddd¡¡| | ddd¡¡| | dd¡d¡| | ddd¡¡| | ¡ddg¡| | dd¡d¡dS)NÚFooÚbarrr ÚBar) r@Ú add_sectionÚ assertTrueÚ SetOptionÚ assertFalser&r'r-r0r1rrrÚtest_set_optiongs z&IdleUserConfParserTest.test_set_optioncCsZ| ¡}| d¡| ddd¡| | dd¡¡| | dd¡¡| | dd¡¡dS)NrArBrZNotZExist)r@Ú AddSectionrFrEZ RemoveOptionrGr1rrrÚtest_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN| ¡}| | ¡g¡| d¡| d¡| d¡| | ¡ddg¡dS)NrArC)r@r&r0rIr-r1rrrÚtest_add_section€s    z'IdleUserConfParserTest.test_add_sectioncCs\| ¡}| d¡| d¡| ddd¡| | ¡gd¢¡| ¡| | ¡dg¡dS)NrArCÚIdleÚnameÚval)rCrArL)r@rIrFr-r0ZRemoveEmptySectionsr&r1rrrÚtest_remove_empty_sections‹s  z1IdleUserConfParserTest.test_remove_empty_sectionscCsv| ¡}| d¡| d¡| | ¡¡| | ¡g¡| ddd¡| d¡| | ¡¡| | ¡dg¡dS)NrArCrBr ) r@rIrEZIsEmptyr&r0rFrGr-r1rrrÚ test_is_empty•s   z$IdleUserConfParserTest.test_is_emptycCs¬t ¡}tj |d¡}| |¡}| d¡| ddd¡| tj  |¡¡|  ¡|  tj  |¡¡|  d¡|  ¡| tj  |¡¡Wdƒn1sž0YdS)Nztest.cfgrArBr) ÚtempfileÚTemporaryDirectoryÚosr?Újoinr@rIrFrGÚexistsZSaverEÚremove_section)r(Ztdirr?r)rrrÚ test_save¢s    z IdleUserConfParserTest.test_saveN)r) r9r:r;r@rHrJrKrOrPrWrrrrr<as     r<c@s(eZdZedd„ƒZedd„ƒZd@dd„Zdd „Ze  e j   d ¡d ¡d d „ƒZ e  e j   d ¡ d¡dd„ƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Z d5d6„Z!d7d8„Z"d9d:„Z#d;d<„Z$d=d>„Z%d?S)AÚ IdleConfTestc Cs¤i|_tjdd}tdkr(tj t¡}ntj t jd¡}|j D]N}tj  |d|¡}t |dƒ}|  ¡|j|<Wdƒq@1s„0Yq@tj|_tƒt_dS)NT©Ú_utestÚ__main__rz../config-%s.defÚr)Ú config_stringrÚIdleConfr9rSr?ÚdirnameÚ__file__ÚabspathÚsysÚ config_typesrTÚopenÚreadÚ_warnÚ orig_warnr)ÚclsÚconfÚidle_dirÚctyper7ÚfrrrÚ setUpClass·s   .zIdleConfTest.setUpClasscCs |jt_dSr=)rgrrf)rhrrrÚ tearDownClassÈszIdleConfTest.tearDownClassFcCs tj|dS)NrY)rr^)r(rZrrrÚ new_configÌszIdleConfTest.new_configcCshtjdd}|jD]P}t d¡|j|<|j| |j|¡t d¡|j|<|j| |j|¡q|S)NTrYr) rr^rcr$Ú defaultCfgr%r]r>r)r(rirkrrrÚ mock_configÏs  zIdleConfTest.mock_configÚwinzthis is test for unix systemc Cs¤|jdd}tjdddNtjddd | | ¡d¡Wdƒn1sP0YWdƒn1sn0Ytjdddxtjd d dJt d ¡ | | ¡d ¡Wdƒn1sÈ0YWdƒn1sæ0YWdƒn1s0Ytjd ddp| t¡D| t¡| ¡Wdƒn1sV0YWdƒn1sv0YWdƒn1s–0YdS)NTrYúos.path.expanduserú /home/foo©Z return_valueúos.path.existsz/home/foo/.idlercú~ú os.getcwdz/home/foo/cpythonúos.mkdirz/home/foo/cpython/.idlercú os.path.joinú/path/not/exists©rorÚpatchr&Z GetUserCfgDirÚ assertRaisesÚ SystemExitÚFileNotFoundError©r(rirrrÚtest_get_user_cfg_dir_unixÝs L  ÿ`  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc Cs¤|jdd}tjdddNtjddd | | ¡d¡Wdƒn1sP0YWdƒn1sn0Ytjdddxtjd d dJt d ¡ | | ¡d ¡Wdƒn1sÈ0YWdƒn1sæ0YWdƒn1s0Ytjd ddp| t¡D| t¡| ¡Wdƒn1sV0YWdƒn1sv0YWdƒn1s–0YdS)NTrYrszC:\foorurvzC:\foo\.idlercrwrxzC:\foo\cpythonryzC:\foo\cpython\.idlercrzr{r|rrrrÚtest_get_user_cfg_dir_windowsôs L  ÿ`  z*IdleConfTest.test_get_user_cfg_dir_windowsc CsP|jdd}d}tj ddi¡Ftjd|d| ¡Wdƒn1sN0YWdƒn1sl0Y| |j ¡|j¡| |j  ¡|j¡|j  ¡D]}|  |t j ¡q¨|j   ¡D]}|  |t j¡qÆ|j ¡D](\}}| |jtj |d|›d ¡¡qä|j  ¡D]2\}}| |jtj |jp8d d|›d ¡¡qdS) NTrYrtr9Z__foo__zos.path.dirnameruzconfig-z.defú#z.cfg)rorr}ÚdictZCreateConfigHandlersr-rpr rcrÚvaluesZassertIsInstancerr$r>Úitemsr&ÚfilerSr?rTZuserdir)r(rirjZdefault_parserZ user_parserZcfg_typer)rrrÚtest_create_config_handlers s& Dÿÿz(IdleConfTest.test_create_config_handlerscCs¦|jdd}tdƒ}t |¡|jd<t |¡|jd<| ¡|j}||jd  dd¡dƒ||jd  d¡dgƒ||jd  dd¡dƒ||jd  d¡dgƒdS)NTrYr3r5r4r6) rorrr$rpr>rZ LoadCfgFilesr&r'r,)r(rir7r*rrrÚtest_load_cfg_files&s z IdleConfTest.test_load_cfg_filescCsR| ¡}t d¡,}| ¡| |jt|jƒ¡Wdƒn1sD0YdS)Nz&idlelib.config.IdleUserConfParser.Save)rqrr}ZSaveUserCfgFilesr&Ú call_countÚlenr)r(riÚmrrrÚtest_save_user_cfg_files;s z%IdleConfTest.test_save_user_cfg_filescCs¸| ¡}|j}|| ddd¡dƒ||jddddddƒt d¡`}||jddd dddƒ|| ddd ¡dƒ||jddd d d d ƒ||jd ƒWdƒn1sª0YdS)NrÚ EditorWindowÚwidthZ80rréPúidlelib.config._warnZfontÚ NotExistsZNEr"é)rqr&Ú GetOptionrr}r‹)r(rir*rfrrrÚtest_get_optionBs zIdleConfTest.test_get_optioncCs2| ¡}| dddd¡| | ddd¡d¡dS)NrrArBr6)rqrFr&r•rrrrrHNszIdleConfTest.test_set_optioncCs¬| ¡}| | dd¡gd¢¡| | dd¡gd¢¡| tj¡| dd¡Wdƒn1sf0Y| tj¡| dd¡Wdƒn1sž0YdS)Nr#r)ZGeneralrZPyShellÚIndentÚThemeÚKeysZHistoryÚ HelpFilesÚuserZfoobarZ notexists)rqr-ÚGetSectionListr~rÚInvalidConfigSetZInvalidConfigTyperrrrÚtest_get_section_listTs þ þ*z"IdleConfTest.test_get_section_listcCs¤| ¡}|j}|| dd¡dddœƒ|| dd¡dddœƒ| dd d d ¡| dd d d ¡t d¡(|| d d¡d d dœƒWdƒn1s–0YdS)Nú IDLE ClassicZnormalz#000000z#ffffff)Z foregroundZ backgroundZcursorZblackr ÚFoobarznormal-foregroundz#747474znormal-backgroundz#171717r’)rqr&Z GetHighlightrFrr}©r(rir*rrrÚtest_get_highlightesÿÿ ÿzIdleConfTest.test_get_highlightcCs`| ¡}| | dd¡| dd¡¡| tj¡| dd¡Wdƒn1sR0YdS)Nr#rŸr›Úbad)rqr&Z GetThemeDictr~rZ InvalidThemerrrrÚtest_get_theme_dictws  þz IdleConfTest.test_get_theme_dictcCs8| ¡}| | ¡| d¡¡| | ¡| d¡¡dS)Nr˜r™)rqr&Z CurrentThemeÚcurrent_colors_and_keysÚ CurrentKeysrrrrÚtest_get_current_theme_and_keysƒsz,IdleConfTest.test_get_current_theme_and_keyscCs| ¡}| | d¡d¡dS)Nr˜rŸ)rqr&r¥rrrrÚtest_current_colors_and_keys‰sz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd}dt_| | ¡d¡dt_| | ¡d¡dt_| | ¡d¡|t_dS) NTrYÚwin32úIDLE Classic WindowsÚdarwinúIDLE Classic OSXú some-linuxúIDLE Modern Unix)rbÚplatformror&Ú default_keys©r(Zcurrent_platformrirrrÚtest_default_keysŽs zIdleConfTest.test_default_keyscCsˆt d¡|j}tj}||ddgƒ||ƒdgƒ||dddgƒ||ddddgƒ||ddd ddgƒt d¡t d¡dS) Nzn [ZzDummy] enable = True [DISABLE] enable = False T)Z shell_onlyÚZzDummy)Ú editor_onlyF)Ú active_onlyZDISABLE)rµr´)Úuserextnr%r&r Z GetExtensionsrV)r(r*ZiGErrrÚtest_get_extensionsžs  z IdleConfTest.test_get_extensionscCs*| ¡}| | | dd¡¡gd¢¡dS)Nr#r )Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr³)rqr-ZRemoveKeyBindNamesrœrrrrÚtest_remove_key_bind_names°s þz'IdleConfTest.test_remove_key_bind_namescCs>t d¡|j}|t d¡dƒ|t d¡dƒt d¡dS)Nú= [ZzDummy] enable = True zz-inr³zz-out)r¶r%r&r ZGetExtnNameForEventrV)r(r*rrrÚtest_get_extn_name_for_event·s  z)IdleConfTest.test_get_extn_name_for_eventcCs0t d¡| t d¡ddgi¡t d¡dS)Nr¹r³ú<>ú!)r¶r%r&r ZGetExtensionKeysrV©r(rrrÚtest_get_extension_keysÁs   ÿz$IdleConfTest.test_get_extension_keyscCsNt d¡|j}tj}||dƒiƒdgdgdœ}||dƒ|ƒt d¡dS)Nr¹r“r¼z!)r»z <>r³)r¶r%r&r ZGetExtensionBindingsrV)r(r*ZiGEBÚexpectrrrÚtest_get_extension_bindingsÍs ÿz(IdleConfTest.test_get_extension_bindingscCs | ¡}|j}|| dd¡ddgƒ|| dd¡ddgƒ|| dd¡d d gƒ|| d d¡d gƒ|| d d¡d gƒ|| dd¡gƒ|| dd¡gƒdS)Nr®ú<>zzúIDLE Classic Unixz z rªzzzIDLE Classic Macúr¬z NOT EXISTS)rqr&Z GetKeyBindingr¡rrrÚtest_get_keybindingÚs ÿ ÿ ÿz IdleConfTest.test_get_keybindingcCs8tj}| ¡}dt_| | ¡| | ¡¡¡|t_dS)Nr­)rbr¯rqr&ZGetCurrentKeySetÚ GetKeySetr¦r±rrrÚtest_get_current_keysetës  z$IdleConfTest.test_get_current_keysetcCsj| ¡}|jd d¡|jd d¡|jd ddd¡|jd ddd¡| | d¡d d ¡dS) Nr r ZFoobar_cfgBindingsÚenableÚTrueZnewfoozr®z <>r)rqrprDÚsetr&rÅrrrrÚtest_get_keysetüs zIdleConfTest.test_get_keysetcCsL| ¡}| | d¡¡| | d¡¡| | d¡¡| | d¡¡dS)NÚcopyZcutzdel-word-rightz not-exists)rqrEZ IsCoreBindingrGrrrrÚtest_is_core_bindings z!IdleConfTest.test_is_core_bindingcCs| ¡}| | d¡g¡| | d¡g¡| tj¡"| | d¡g¡Wdƒn1s`0Y| | ¡| d¡| d¡¡|jd  ddd¡|jd  ddd ¡|jd  dd d ¡|jd  dd d ¡| | d¡gd¢¡| | ¡| d¡| d¡¡dS)Nr#r›r£rršÚ4zPython;https://python.orgÚ3zPython:https://python.orgÚ2z/Pillow;https://pillow.readthedocs.io/en/latest/Ú1z/IDLE;C:/Programs/Python36/Lib/idlelib/help.html))ÚIDLEz*C:/Programs/Python36/Lib/idlelib/help.htmlrÐ)ZPillowz(https://pillow.readthedocs.io/en/latest/rÏ)ÚPythonzhttps://python.orgrÍ) rqr&ZGetExtraHelpSourceListr~rrr-ZGetAllExtraHelpSourcesListrrFrrrrÚtest_extra_help_source_lists(0þ ÿþz(IdleConfTest.test_extra_help_source_listcCsœddlm}ddlm}ddlm}| ¡}|dƒ|ƒ}| ¡| |dd|d¡}|  |  |d d ¡|d |d dkr|d n|d |df¡|  ¡~dS)Nr)Úrequires)ÚTk)ÚFontZguiZ TkFixedFontT)rMrUÚrootrrÚfamilyÚsizerZweight) Ú test.supportrÔÚtkinterrÕZ tkinter.fontrÖrqZwithdrawÚactualr&ZGetFontZdestroy)r(rÔrÕrÖrir×rlrrrÚ test_get_font*s    $þzIdleConfTest.test_get_fontcCs®| ¡}|j}|| ¡ddgƒ|| ¡dddgƒ|| ¡ddgƒ|| d¡dd d gƒ|| d ¡dd gƒ|| d ¡dddgƒ|| d¡dddgƒdS)Nz<>z rÁz z z<>zrªzzr¬rÃrÂz z r®)rqr&Z GetCoreKeysr¡rrrÚtest_get_core_keys=sÿÿÿzIdleConfTest.test_get_core_keysN)F)&r9r:r;Ú classmethodrmrnrorqÚunittestZskipIfrbr¯Ú startswithr‚rƒr‰rŠrŽr–rHržr¢r¤r§r¨r²r·r¸rºr¾rÀrÄrÆrÊrÌrÓrÝrÞrrrrrX´sB            rXc@sNeZdZejZdZe ¡Zdd„Zdd„Z dd„Z dd „Z d d „Z d d „Z dS)ÚCurrentColorKeysTestrŸcCs~| | d¡|j¡t d¡| | d¡|j¡dtdd<| | d¡d¡dtdd<| | d¡|j¡t d¡dS)Nr˜z< [Theme] default = True úIDLE NewrMú non-existent)r&Ú colorkeysÚ default_themeÚusermainr%rVr½rrrÚtest_old_builtin_themeXs   z+CurrentColorKeysTest.test_old_builtin_themecCsht d¡| | d¡d¡dtdd<| | d¡d¡dtdd<| | d¡|j¡t d¡dS)NzZ [Theme] default = True name2 = IDLE Dark r˜z IDLE DarkrãrMräÚname2)rçr%r&rårærVr½rrrÚtest_new_builtin_themejs   z+CurrentColorKeysTest.test_new_builtin_themecCspt d¡| | d¡|j¡t d¡| | d¡d¡dtdd<| | d¡d¡t d¡t d¡dS)Nz\ [Theme] default = False name = Custom Dark r˜z[Custom Dark] a=bz Custom Darkräré)rçr%r&råræÚuserhighrVr½rrrÚtest_user_override_themezs    z-CurrentColorKeysTest.test_user_override_themecCs^| | d¡|j¡t d¡| | d¡d¡dtdd<| | d¡|j¡t d¡dS)Nr™z` [Keys] default = True name = IDLE Classic Unix rÂrärM)r&rår°rçr%rVr½rrrÚtest_old_builtin_keys‹s   z*CurrentColorKeysTest.test_old_builtin_keyscCsht d¡| | d¡d¡dtdd<| | d¡d¡dtdd<| | d¡|j¡t d¡dS)Nz` [Keys] default = True name2 = IDLE Modern Unix r™r®rÂrMräré)rçr%r&rår°rVr½rrrÚtest_new_builtin_keysšs   z*CurrentColorKeysTest.test_new_builtin_keyscCspt d¡| | d¡|j¡t d¡| | d¡d¡dtdd<| | d¡d¡t d¡t d¡dS)Nz[ [Keys] default = False name = Custom Keys r™z[Custom Keys] a=bz Custom Keysräré)rçr%r&rår°ÚuserkeysrVr½rrrÚtest_user_override_keysªs    z,CurrentColorKeysTest.test_user_override_keysN)r9r:r;r r¥rårær°rèrêrìrírîrðrrrrrâMsrâc@seZdZiiiidœZdd„Zdddiiddd iid d d iiidœZd d„Zdd„Zdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„ZdS) Ú ChangesTest)rr r r cCs:|j}| dddd¡| dddd¡| d d d d ¡|S) NrÚMsecÚmitemÚmvalr ÚHsecÚhitemÚhvalr ÚKsecÚkitemÚkval©ÚchangesÚ add_option©r(rürrrÚloadÀs zChangesTest.loadròrórôrõrör÷rørùrúcCst ¡|_dSr=)rZ ConfigChangesrür½rrrÚsetUpÌszChangesTest.setUpcCs| |j|j¡dSr=)r&rüÚemptyr½rrrÚ test_initÏszChangesTest.test_initcCs8| ¡}| ||j¡| dddd¡| ||j¡dS)Nrròrórô)rÿr&ÚloadedrýrþrrrÚtest_add_optionÒszChangesTest.test_add_optioncCs |jj}| |ddddƒ¡| |ddddƒ¡| tddd¡| |ddddƒ¡| tddd¡| |ddddƒ¡| t dd¡¡t d¡dS)Nrr—ZwhatÚ0ú use-spacesrÐ)rüÚ save_optionrErGr&rçÚ has_optionrV)r(rrrrÚtest_save_optionØszChangesTest.test_save_optioncCs’| ¡}| | ¡¡| tddd¡| tddd¡| tddd ¡| d ddd¡| | ¡¡t  d¡t  d¡t  d¡dS) Nròrórôrõrör÷rørùrúr) rÿrEÚsave_allr&rçrërïrýrGrVrþrrrÚtest_save_addedäs  zChangesTest.test_save_addedcCsV|j}| dddd¡| dddd¡| ¡| t dd¡¡| t dd¡¡dS)NrršrÑZidledocZELDIZcodeldi)rürrýr rGrçrrErþrrrÚtest_save_helpðs zChangesTest.test_save_helpcCs|j}| dddd¡dS)Nrr—rrÐrûrþrrrÚtest_save_defaultùszChangesTest.test_save_defaultc Cs”| ¡}| dd¡| ||j¡dD]h\}}t| |dd¡| ||¡| t¡(|||t||Wdƒq&1s„0Yq&dS)NrZfake))rrò)r rørMÚvalue)rÿZdelete_sectionr&rr rFr~ÚKeyError)r(rüZcfgtypeÚsectionrrrÚtest_delete_sections     zChangesTest.test_delete_sectioncCs"| ¡}| ¡| ||j¡dSr=)rÿÚclearr&rrþrrrÚ test_clear szChangesTest.test_clearN)r9r:r;rrÿrrrrr r r r rrrrrrrñ¼s    ý    rñc@seZdZdd„ZdS)Ú WarningTestcCsð|j}tƒt_tƒ}t dd¡Wdƒn1s60Y|tjdhƒ|| ¡dƒtƒ}t dd¡Wdƒn1s„0Y|| ¡dƒtƒ}t dd¡Wdƒn1sÄ0Y|tjddhƒ|| ¡d ƒdS) NÚwarningÚkey)rrzwarning rÚwarn2Úyek)rrzwarn2 )r&rÉrZ_warnedrrfÚgetvalue)r(ZEqualÚstderrrrrÚ test_warns***zWarningTest.test_warnN)r9r:r;rrrrrrsrr[é)Ú verbosity) rrrbrSrQrÚrrràrZidlelib.idle_test.mock_idlerr rrr r>rçrërïr¶rrZTestCaserr<rXrârñrr9rrrrrÚs8   ;SoV