3 2a%@sJddlmZddlZddlZddlZddlmZmZddlZddlm Z ddlZddl m Z ej Z e j ZiZejdZed<ejdZed<ejdZed <ejdZed <d d Zd dZGdddejZGdddejZGdddejZGdddejZGdddejZGdddejZedkrFejdddS))configN)captured_stderrfindfile)mock)Funcmain highlightkeys extensionscCstt_dt_dS)NT)testcfgidleConfuserCfgidlelibtestingrr0/opt/alt/python36/lib64/python3.6/test_config.py setUpModulesrcCstt_dt_dS)NF)usercfgr rrrrrrrtearDownModule!src@s0eZdZdZddZddZddZdd Zd S) IdleConfParserTestz [one] one = false two = true three = 10 [two] one = a string two = true three = false cCstjd}|j|j|j}|j|jddddd|j|jddddd||jddd dd ||jddd |j|jddddd|j|jddddd||jddd ||jddd |j|jdd||jddddddS)Nronebool)typeFtwoTthreeint za stringtruefalsenotZexistZDEFAULT)default)rIdleConfParser read_string assertEqualZassertIsGetZ assertIsNone)selfparsereqrrrtest_get5s  zIdleConfParserTest.test_getcCs\tjd}|j|j|j}|j|ddddg|j|ddddg|j|dgdS)Nrrrrz not exist)rr"r# GetOptionListassertCountEqualr$)r&r'Zget_listrrrtest_get_option_listJs   z'IdleConfParserTest.test_get_option_listcCs&tjd}|j|j|jgdS)Nr)rr"Loadr$sections)r&r'rrrtest_load_nothingRs z$IdleConfParserTest.test_load_nothingcCsFtd}tj|}|j|j|jddd|j|jddgdS)Nz cfgparser.1zFoo Barfoonewbar)rrr"r-r$r%r*)r& config_pathr'rrrtest_load_fileWs  z!IdleConfParserTest.test_load_fileN)__name__ __module__ __qualname__rr)r,r/r3rrrrr&s  rc@sNeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ dS)IdleUserConfParserTestrcCs tj|S)N)rIdleUserConfParser)r&pathrrr new_parserdsz!IdleUserConfParserTest.new_parsercCs|j}|jd|j|jddd|j|jddd|j|jddd|j|jddd|j|jddd|j|jddg|j|jddddS)NFoobarrrBar) r: add_section assertTrue SetOption assertFalser$r%r+r.)r&r'rrrtest_set_optiongs z&IdleUserConfParserTest.test_set_optioncCsZ|j}|jd|jddd|j|jdd|j|jdd|j|jdddS)Nr;r<rZNotZExist)r: AddSectionr@r?Z RemoveOptionrA)r&r'rrrtest_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN|j}|j|jg|jd|jd|jd|j|jddgdS)Nr;r=)r:r$r.rCr+)r&r'rrrtest_add_sections    z'IdleUserConfParserTest.test_add_sectioncCs^|j}|jd|jd|jddd|j|jdddg|j|j|jdgdS)Nr;r=ZIdlenameval)r:rCr@r+r.ZRemoveEmptySectionsr$)r&r'rrrtest_remove_empty_sectionss  z1IdleUserConfParserTest.test_remove_empty_sectionscCsv|j}|jd|jd|j|j|j|jg|jddd|jd|j|j|j|jdgdS)Nr;r=r<r) r:rCr?ZIsEmptyr$r.r@rAr+)r&r'rrr test_is_emptys   z$IdleUserConfParserTest.test_is_emptyc Cstjr}tjj|d}|j|}|j|jd|jddd|j |j tjj ||j|j tjj |WdQRXdS)Nztest.cfgr;r<r) tempfileTemporaryDirectoryosr9joinr:Z RemoveFilerCr@Saver?existsrA)r&tdirr9r'rrrtest_remove_files   z'IdleUserConfParserTest.test_remove_filec Cstj}tjj|d}|j|}|jd|jddd|jtjj ||j |j tjj ||j d|j |jtjj |WdQRXdS)Nztest.cfgr;r<r) rJrKrLr9rMr:rCr@rArOrNr?remove_section)r&rPr9r'rrr test_saves    z IdleUserConfParserTest.test_saveN)r) r4r5r6r:rBrDrErHrIrQrSrrrrr7as      r7c@s(eZdZeddZeddZd@ddZdd Zej e j j d d d d Z ej e j j d  dddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z d5d6Z!d7d8Z"d9d:Z#d;d<Z$d=d>Z%d?S)A IdleConfTestc Csi|_tjdd}tdkr(tjjt}ntjjt jd}xD|j D]:}tjj |d|}t |d}|j |j|<WdQRXqBWtj|_tt_dS)NT)_utest__main__rz../config-%s.defr) config_stringrIdleConfr4rLr9dirname__file__abspathsys config_typesrMopenread_warn orig_warnr)clsconfidle_dirctyper2frrr setUpClasss   zIdleConfTest.setUpClasscCs |jt_dS)N)rbrra)rcrrr tearDownClassszIdleConfTest.tearDownClassFcCs tj|dS)N)rU)rrY)r&rUrrr new_configszIdleConfTest.new_configcCsltjdd}xZ|jD]P}tjd|j|<|j|j|j|tjd|j|<|j|j|j|qW|S)NT)rUr) rrYr^r" defaultCfgr#rXr8r)r&rdrfrrr mock_configs  zIdleConfTest.mock_configwinzthis is test for unix systemc:Cs|jdd}tjddd0tjddd|j|jdWdQRXWdQRXtjdddFtjd d d,tjd |j|jd WdQRXWdQRXWdQRXtjd dd:|jt$|jt|jWdQRXWdQRXWdQRXdS)NT)rUzos.path.expanduserz /home/foo) return_valuezos.path.existsz/home/foo/.idlerc~z os.getcwdz/home/foo/cpythonzos.mkdirz/home/foo/cpython/.idlercz os.path.joinz/path/not/exists)rjrpatchr$ GetUserCfgDir assertRaises SystemExitFileNotFoundError)r&rdrrrtest_get_user_cfg_dir_unixs $  $  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc:Cs|jdd}tjddd0tjddd|j|jdWdQRXWdQRXtjdddFtjd d d,tjd |j|jd WdQRXWdQRXWdQRXtjd dd:|jt$|jt|jWdQRXWdQRXWdQRXdS)NT)rUzos.path.expanduserzC:\foo)rnzos.path.existszC:\foo\.idlercroz os.getcwdzC:\foo\cpythonzos.mkdirzC:\foo\cpython\.idlercz os.path.joinz/path/not/exists)rjrrpr$rqrrrsrt)r&rdrrrtest_get_user_cfg_dir_windowss $  $  z*IdleConfTest.test_get_user_cfg_dir_windowscCs(|jdd}d}tjjddi(tjd|d|jWdQRXWdQRX|j|jj|j|j|j j|jx |jj D]}|j |t j qWx |j j D]}|j |t jqWx2|jjD]$\}}|j|jtjj|d|qWx4|j jD]&\}}|j|jtjj|jd |qWdS) NT)rUz /home/foor4Z__foo__zos.path.dirname)rnz config-%s.defz config-%s.cfg)rjrrpdictZCreateConfigHandlersr+rkr r^rvaluesZassertIsInstancerr"r8itemsr$filerLr9rMZuserdir)r&rdreZdefault_parserZ user_parserZ config_typer'rrrtest_create_config_handlerss" z(IdleConfTest.test_create_config_handlerscCs|jdd}td}tj||jd<tj||jd<|j|j}||jdj ddd||jdj ddg||jdj ddd||jdj ddgdS)NT)rUz cfgparser.1r0zFoo Barr1) rjrrr"rkr8rZ LoadCfgFilesr$r%r*)r&rdr2r(rrrtest_load_cfg_files3s z IdleConfTest.test_load_cfg_filesc Cs>|j}tjd"}|j|j|jt|jWdQRXdS)Nz&idlelib.config.IdleUserConfParser.Save)rlrrpZSaveUserCfgFilesr$ call_countlenr)r&rdmrrrtest_save_user_cfg_filesHs z%IdleConfTest.test_save_user_cfg_filescCs|j}|j}||jdddd||jddddddtjdV}||jddd ddd||jddd d||jddd d d d ||jd WdQRXdS)Nr EditorWindowwidthZ80r)rPzidlelib.config._warnZfont NotExistsZNE)r!)rlr$ GetOptionrrpr})r&rdr(rarrrtest_get_optionOs zIdleConfTest.test_get_optioncCs2|j}|jdddd|j|jdddddS)Nrr;r<r1)rlr@r$r)r&rdrrrrB[szIdleConfTest.test_set_optioncCs|j}|j|jddddddddd d g|j|jd dddddddd d g|jtj|jd dWdQRX|jtj|jdd WdQRXdS)Nr!rZGeneralrZPyShellIndentThemeKeysZHistory HelpFilesuserZfoobarZ notexists)rlr+GetSectionListrrrInvalidConfigSetZInvalidConfigType)r&rdrrrtest_get_section_listas      z"IdleConfTest.test_get_section_listcCs|j}|j}||jddddd||jdddd||jdddd|jtj|jdddWdQRX||jdd d dd|jd d d d|jd d ddtjd||jd ddddWdQRXdS)Nz IDLE ClassicZnormalz#000000z#ffffff)Z foregroundZ backgroundZfgbgZfbZcursorZblackr Foobarznormal-foregroundz#747474znormal-backgroundz#171717zidlelib.config._warn) rlr$Z GetHighlightrrrZ InvalidFgBgr@rrp)r&rdr(rrrtest_get_highlightrs   zIdleConfTest.test_get_highlightc CsL|j}|j|jdd|jdd|jtj|jddWdQRXdS)Nr!z IDLE Classicrbad)rlr$Z GetThemeDictrrrZ InvalidTheme)r&rdrrrtest_get_theme_dicts  z IdleConfTest.test_get_theme_dictcCs8|j}|j|j|jd|j|j|jddS)Nrr)rlr$Z CurrentThemecurrent_colors_and_keys CurrentKeys)r&rdrrrtest_get_current_theme_and_keyssz,IdleConfTest.test_get_current_theme_and_keyscCs|j}|j|jdddS)Nrz IDLE Classic)rlr$r)r&rdrrrtest_current_colors_and_keyssz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd}dt_|j|jddt_|j|jddt_|j|jd|t_dS) NT)rUwin32zIDLE Classic WindowsdarwinzIDLE Classic OSXz some-linuxzIDLE Modern Unix)r]platformrjr$ default_keys)r&current_platformrdrrrtest_default_keyss zIdleConfTest.test_default_keyscCstjd|j}tj}||ddg||dg||dddg||ddddg||ddd ddgtjdtjddS) Nzn [ZzDummy] enable = True [DISABLE] enable = False T)Z shell_onlyZzDummy) editor_onlyF) active_onlyZDISABLE)rr)userextnr#r$r Z GetExtensionsrR)r&r(ZiGErrrtest_get_extensionss z IdleConfTest.test_get_extensionscCs0|j}|j|j|jdddddddgdS)Nr!r Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr)rlr+ZRemoveKeyBindNamesr)r&rdrrrtest_remove_key_bind_namessz'IdleConfTest.test_remove_key_bind_namescCs>tjd|j}|tjdd|tjddtjddS)Nz= [ZzDummy] enable = True zz-inrzz-out)rr#r$r ZGetExtnNameForEventrR)r&r(rrrtest_get_extn_name_for_events z)IdleConfTest.test_get_extn_name_for_eventcCs0tjd|jtjdddgitjddS)Nz= [ZzDummy] enable = True rz<>z!)rr#r$r ZGetExtensionKeysrR)r&rrrtest_get_extension_keyss   z$IdleConfTest.test_get_extension_keyscCsNtjd|j}tj}||didgdgd}||d|tjddS)Nz= [ZzDummy] enable = True rz!z!)z<>z <>r)rr#r$r ZGetExtensionBindingsrR)r&r(ZiGEBexpectrrrtest_get_extension_bindingss z(IdleConfTest.test_get_extension_bindingscCs|j}|j}||jddddg||jddddg||jddd d g||jd dd g||jd dd g||jddg||jddgdS)NzIDLE Modern Unixz<>zzzIDLE Classic Unixz z zIDLE Classic WindowszzzIDLE Classic MaczzIDLE Classic OSXz NOT EXISTS)rlr$Z GetKeyBinding)r&rdr(rrrtest_get_keybindings      z IdleConfTest.test_get_keybindingcCs8tj}|j}dt_|j|j|j|j|t_dS)Nz some-linux)r]rrlr$ZGetCurrentKeySet GetKeySetr)r&rrdrrrtest_get_current_keysets  z$IdleConfTest.test_get_current_keysetcCsj|j}|jdjd|jdjd|jdjddd|jdjddd|j|jdd d dS) Nr rZFoobar_cfgBindingsenableTrueZnewfoozzIDLE Modern Unixz <>r)rlrkr>setr$r)r&rdrrrtest_get_keyset s zIdleConfTest.test_get_keysetcCsL|j}|j|jd|j|jd|j|jd|j|jddS)NcopyZcutzdel-word-rightz not-exists)rlr?Z IsCoreBindingrA)r&rdrrrtest_is_core_bindings z!IdleConfTest.test_is_core_bindingcCs|j}|j|jdg|j|jdg|jtj|j|jdgWdQRX|j|j|jd|jd|jdj ddd|jdj ddd |jdj dd d |jdj dd d |j|jddddg|j|j|jd|jddS)Nr!rrrr4zPython;https://python.org3zPython:https://python.org2z/Pillow;https://pillow.readthedocs.io/en/latest/1z/IDLE;C:/Programs/Python36/Lib/idlelib/help.htmlIDLE*C:/Programs/Python36/Lib/idlelib/help.htmlPillow(https://pillow.readthedocs.io/en/latest/Pythonhttps://python.org)rrr)rrr)rrr) rlr$ZGetExtraHelpSourceListrrrrr+ZGetAllExtraHelpSourcesListrr@)r&rdrrrtest_extra_help_source_list s& z(IdleConfTest.test_extra_help_source_listcCsddlm}ddlm}ddlm}|j}|d|}|j|j|dd|d}|j |j |d d |d |d dkr|d n|d |df|j ~dS)Nr)requires)Tk)FontZguiZ TkFixedFontT)rFrOrootrrZfamilysizerZweight) test.supportrZtkinterrZ tkinter.fontrrlZwithdrawactualr$ZGetFontZdestroy)r&rrrrdrrgrrr test_get_font;s    (zIdleConfTest.test_get_fontcCs|j}|j}||jddg||jdddg||jddg||jddd d g||jd dd g||jd dddg||jddddgdS)Nz<>z z<>z z z<>zzIDLE Classic WindowszzzIDLE Classic OSXzzIDLE Classic Unixz z zIDLE Modern Unix)rlr$Z GetCoreKeys)r&rdr(rrrtest_get_core_keysNs  zIdleConfTest.test_get_core_keysN)F)&r4r5r6 classmethodrhrirjrlunittestZskipIfr]r startswithrurvr{r|rrrBrrrrrrrrrrrrrrrrrrrrrrrTs:          rTc@sNeZdZejZdZejZddZddZ ddZ dd Z d d Z d d Z dS)CurrentColorKeysTestz IDLE ClassiccCs~|j|jd|jtjd|j|jd|jdtdd<|j|jdddtdd<|j|jd|jtjddS)Nrz< [Theme] default = True zIDLE NewrFz non-existent)r$ colorkeys default_themeusermainr#rR)r&rrrtest_old_builtin_themeis  z+CurrentColorKeysTest.test_old_builtin_themecCshtjd|j|jdddtdd<|j|jdddtdd<|j|jd|jtjddS)NzZ [Theme] default = True name2 = IDLE Dark rz IDLE DarkzIDLE NewrFz non-existentname2)rr#r$rrrR)r&rrrtest_new_builtin_theme{s  z+CurrentColorKeysTest.test_new_builtin_themecCsptjd|j|jd|jtjd|j|jdddtdd<|j|jddtjdtjddS)Nz\ [Theme] default = False name = Custom Dark rz[Custom Dark] a=bz Custom Darkz non-existentr)rr#r$rruserhighrR)r&rrrtest_user_override_themes   z-CurrentColorKeysTest.test_user_override_themecCs^|j|jd|jtjd|j|jdddtdd<|j|jd|jtjddS)Nrz` [Keys] default = True name = IDLE Classic Unix zIDLE Classic Unixz non-existentrF)r$rrrr#rR)r&rrrtest_old_builtin_keyss z*CurrentColorKeysTest.test_old_builtin_keyscCshtjd|j|jdddtdd<|j|jdddtdd<|j|jd|jtjddS)Nz` [Keys] default = True name2 = IDLE Modern Unix rzIDLE Modern UnixzIDLE Classic UnixrFz non-existentr)rr#r$rrrR)r&rrrtest_new_builtin_keyss  z*CurrentColorKeysTest.test_new_builtin_keyscCsptjd|j|jd|jtjd|j|jdddtdd<|j|jddtjdtjddS)Nz[ [Keys] default = False name = Custom Keys rz[Custom Keys] a=bz Custom Keysz non-existentr)rr#r$rruserkeysrR)r&rrrtest_user_override_keyss   z,CurrentColorKeysTest.test_user_override_keysN)r4r5r6r rrrrrrrrrrrrrrr^src@seZdZiiiidZddZdddiiddd iid d d iiidZd dZddZddZddZ ddZ ddZ ddZ ddZ ddZdS) ChangesTest)rr r r cCs:|j}|jdddd|jdddd|jd d d d |S) NrMsecmitemmvalr Hsechitemhvalr Kseckitemkval)changes add_option)r&rrrrloads zChangesTest.loadrrrrrrrrrcCstj|_dS)N)rZ ConfigChangesr)r&rrrsetUpszChangesTest.setUpcCs|j|j|jdS)N)r$rempty)r&rrr test_initszChangesTest.test_initcCs8|j}|j||j|jdddd|j||jdS)Nrrrr)rr$loadedr)r&rrrrtest_add_optionszChangesTest.test_add_optioncCs|jj}|j|dddd|j|dddd|jtddd|j|dddd|jtddd|j|dddd|jtjddtjddS)NrrZwhat0z use-spacesr)r save_optionr?rAr$r has_optionrR)r&rrrrtest_save_optionszChangesTest.test_save_optioncCs|j}|j|j|jtddd|jtddd|jtddd |jd ddd|j|jtj dtj dtj ddS) Nrrrrrrrrrr) rr?save_allr$rrrrrArR)r&rrrrtest_save_addeds  zChangesTest.test_save_addedcCsV|j}|jdddd|jdddd|j|jtjdd|jtjdddS)NrrrZidledocZELDIZcodeldi)rrrrrArrr?)r&rrrrtest_save_helps zChangesTest.test_save_helpcCs|j}|jdddddS)Nrrz use-spacesr)rr)r&rrrrtest_save_default szChangesTest.test_save_defaultc Cs|j}|jdd|j||jx\d D]T\}}t|j|dd|j|||jt|||t||WdQRXq(WdS) NrZfakerr rrFvaluerrr r)rr)rZdelete_sectionr$rr r@rrKeyError)r&rZcfgtypesectionrrrtest_delete_sections    zChangesTest.test_delete_sectioncCs"|j}|j|j||jdS)N)rclearr$r)r&rrrr test_clearszChangesTest.test_clearN)r4r5r6rrrrrrrrrrrrrrrrrs       rc@seZdZddZdS) WarningTestcCs|j}tt_t}tjddWdQRX|tjdh||jdt}tjddWdQRX||jdt}tjddWdQRX|tjd d h||jd dS) Nwarningkey rwarn2yek)rrzwarning )rr)rrzwarn2 )r$rrZ_warnedrragetvalue)r&ZEqualstderrrrr test_warn%szWarningTest.test_warnN)r4r5r6rrrrrr#srrV) verbosity) rrr]rLrJrrrrrZidlelib.idle_test.mock_idlerr rrr r8rrrrrrZTestCaserr7rTrrrr4rrrrrs8   ;` oV