3  f%@sNdZddlmZddlZddlZddlZddlmZmZddl Z ddl m Z ddlZddl m Z ej Z e jZiZejdZed<ejdZed <ejdZed <ejdZed <d d ZddZGddde jZGddde jZGddde jZGddde jZGddde jZGddde jZedkrJe j dddS)zTest config, coverage 93%. (100% for IdleConfParser, IdleUserConfParser*, ConfigChanges). * Exception is OSError clause in Save method. Much of IdleConf is also exercised by ConfigDialog and test_configdialog. )configN)captured_stderrfindfile)mock)Funcmain highlightkeys extensionscCstt_dt_dS)NT)testcfgidleConfuserCfgidlelibtestingrrB/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_config.py setUpModulesrcCstt_dt_dS)NF)usercfgr rrrrrrrtearDownModule!src@s4eZdZdZdZddZddZddZd d Zd S) IdleConfParserTestzTest that IdleConfParser worksz [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____doc__rr)r,r/r3rrrrr&s  rc@sReZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ dS)IdleUserConfParserTestz"Test that IdleUserConfParser worksrcCs 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; AddSectionrAr@Z RemoveOptionrB)r&r'rrrtest_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN|j}|j|jg|jd|jd|jd|j|jddgdS)Nr<r>)r;r$r.rDr+)r&r'rrrtest_add_sections    z'IdleUserConfParserTest.test_add_sectioncCs^|j}|jd|jd|jddd|j|jdddg|j|j|jdgdS)Nr<r>ZIdlenameval)r;rDrAr+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;rDr@ZIsEmptyr$r.rArBr+)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) tempfileTemporaryDirectoryosr:joinr;Z RemoveFilerDrASaver@existsrB)r&tdirr:r'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) rKrLrMr:rNr;rDrArBrPrOr@remove_section)r&rQr:r'rrr test_saves    z IdleUserConfParserTest.test_saveN)r) r4r5r6r7r;rCrErFrIrJrRrTrrrrr8as      r8c@s,eZdZdZeddZeddZdAddZd d Ze j e j j d d d dZe j e j j d  dddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Z d4d5Z!d6d7Z"d8d9Z#d:d;Z$dd?Z&d@S)B IdleConfTestzTest for idleConfc 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_stringrIdleConfr4rMr:dirname__file__abspathsys config_typesrNopenread_warn orig_warnr)clsconfidle_dirctyper2frrr setUpClasss   zIdleConfTest.setUpClasscCs |jt_dS)N)rcrrb)rdrrr tearDownClassszIdleConfTest.tearDownClassFcCs tj|dS)N)rV)rrZ)r&rVrrr new_configszIdleConfTest.new_configcCsltjdd}xZ|jD]P}tjd|j|<|j|j|j|tjd|j|<|j|j|j|qW|S)zbReturn a mocked idleConf Both default and user config used the same config-*.def T)rVr) rrZr_r" defaultCfgr#rYr9r)r&rergrrr mock_configs  zIdleConfTest.mock_configwinzthis is test for unix systemc:Cs|jdd}tjddd0tjddd|j|jdWdQRXWdQRXtjdd dFtjd d d,tjd |j|jd WdQRXWdQRXWdQRXtjddd:|jt$|jt|jWdQRXWdQRXWdQRXdS)z,Test to get user config directory under unixT)rVzos.path.expanduserz /home/foo) return_valuezos.path.existsz/home/foo/.idlercN~z os.getcwdz/home/foo/cpythonzos.mkdirz/home/foo/cpython/.idlercz os.path.joinz/path/not/exists)rkrpatchr$ GetUserCfgDir assertRaises SystemExitFileNotFoundError)r&rerrrtest_get_user_cfg_dir_unixs $  $  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc:Cs|jdd}tjddd0tjddd|j|jdWdQRXWdQRXtjdd dFtjd d d,tjd |j|jd WdQRXWdQRXWdQRXtjddd:|jt$|jt|jWdQRXWdQRXWdQRXdS)z/Test to get user config directory under WindowsT)rVzos.path.expanduserzC:\foo)rozos.path.existszC:\foo\.idlercNrpz os.getcwdzC:\foo\cpythonzos.mkdirzC:\foo\cpython\.idlercz os.path.joinz/path/not/exists)rkrrqr$rrrsrtru)r&rerrrtest_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)rVz /home/foor4Z__foo__zos.path.dirname)roz config-%s.defz config-%s.cfg)rkrrqdictZCreateConfigHandlersr+rlr r_rvaluesZassertIsInstancerr"r9itemsr$filerMr:rNZuserdir)r&rerfZdefault_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)rVz cfgparser.1r0zFoo Barr1) rkrrr"rlr9rZ LoadCfgFilesr$r%r*)r&rer2r(rrrtest_load_cfg_files3s z IdleConfTest.test_load_cfg_filesc Cs>|j}tjd"}|j|j|jt|jWdQRXdS)Nz&idlelib.config.IdleUserConfParser.Save)rmrrqZSaveUserCfgFilesr$ call_countlenr)r&remrrrtest_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!)rmr$ GetOptionrrqr~)r&rer(rbrrrtest_get_optionOs zIdleConfTest.test_get_optioncCs2|j}|jdddd|j|jdddddS)Nrr<r=r1)rmrAr$r)r&rerrrrC[szIdleConfTest.test_set_optioncCs|j}|j|jddddddddd d g|j|jd dddddddd d g|jtj|jd dWdQRX|jtj|jdd WdQRXdS)Nr!rZGeneralrZPyShellIndentThemeKeysZHistory HelpFilesuserZfoobarZ notexists)rmr+GetSectionListrsrInvalidConfigSetZInvalidConfigType)r&rerrrtest_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 backgroundZfgZbgZfbZcursorZblackr Foobarznormal-foregroundz#747474znormal-backgroundz#171717zidlelib.config._warn) rmr$Z GetHighlightrsrZ InvalidFgBgrArrq)r&rer(rrrtest_get_highlightrs   zIdleConfTest.test_get_highlightc CsL|j}|j|jdd|jdd|jtj|jddWdQRXdS)zXXX: NOT YET DONEr!z IDLE ClassicrbadN)rmr$Z GetThemeDictrsrZ InvalidTheme)r&rerrrtest_get_theme_dicts  z IdleConfTest.test_get_theme_dictcCs8|j}|j|j|jd|j|j|jddS)Nrr)rmr$Z CurrentThemecurrent_colors_and_keys CurrentKeys)r&rerrrtest_get_current_theme_and_keyssz,IdleConfTest.test_get_current_theme_and_keyscCs|j}|j|jdddS)Nrz IDLE Classic)rmr$r)r&rerrrtest_current_colors_and_keyssz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd}dt_|j|jddt_|j|jddt_|j|jd|t_dS) NT)rVZwin32zIDLE Classic WindowsdarwinzIDLE Classic OSXz some-linuxzIDLE Modern Unix)r^platformrkr$ default_keys)r&current_platformrerrrtest_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 GetExtensionsrS)r&r(ZiGErrrtest_get_extensionss z IdleConfTest.test_get_extensionscCs0|j}|j|j|jdddddddgdS)Nr!r Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr)rmr+ZRemoveKeyBindNamesr)r&rerrrtest_remove_key_bind_namessz'IdleConfTest.test_remove_key_bind_namescCs>tjd|j}|tjdd|tjddtjddS)Nz= [ZzDummy] enable = True zz-inrzz-out)rr#r$r ZGetExtnNameForEventrS)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 ZGetExtensionKeysrS)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 ZGetExtensionBindingsrS)r&r(ZiGEBZexpectrrrtest_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)rmr$Z GetKeyBinding)r&rer(rrrtest_get_keybindings      z IdleConfTest.test_get_keybindingcCs8tj}|j}dt_|j|j|j|j|t_dS)Nz some-linux)r^rrmr$ZGetCurrentKeySet GetKeySetr)r&rrerrrtest_get_current_keysets  z$IdleConfTest.test_get_current_keysetcCsj|j}|jdjd|jdjd|jdjddd|jdjddd|j|jdd d dS) Nr rZFoobar_cfgBindingsenableTrueZnewfoozzIDLE Modern Unixz <>r)rmrlr?setr$r)r&rerrrtest_get_keyset s zIdleConfTest.test_get_keysetcCsL|j}|j|jd|j|jd|j|jd|j|jddS)NcopyZcutzdel-word-rightz not-exists)rmr@Z IsCoreBindingrB)r&rerrrtest_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) rmr$ZGetExtraHelpSourceListrsrrr+ZGetAllExtraHelpSourcesListrrA)r&rerrrtest_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)rGrProotrrZfamilysizerZweight) test.supportrZtkinterrZ tkinter.fontrrmZwithdrawZactualr$ZGetFontZdestroy)r&rrrrerrhrrr 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)rmr$Z GetCoreKeys)r&rer(rrrtest_get_core_keysNs  zIdleConfTest.test_get_core_keysN)F)'r4r5r6r7 classmethodrirjrkrmunittestZskipIfr^r startswithrvrwr|r}rrrCrrrrrrrrrrrrrrrrrrrrrrrUs<          rUc@sReZdZdZejZdZejZddZ ddZ ddZ d d Z d d Z d dZdS)CurrentColorKeysTesta Test colorkeys function with user config [Theme] and [Keys] patterns. colorkeys = config.IdleConf.current_colors_and_keys Test all patterns written by IDLE and some errors Item 'default' should really be 'builtin' (versus 'custom). z IDLE ClassiccCs~|j|jd|jtjd|j|jd|jdtdd<|j|jdddtdd<|j|jd|jtjddS)Nrz< [Theme] default = True zIDLE NewrGz non-existent)r$ colorkeys default_themeusermainr#rS)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 NewrGz non-existentname2)rr#r$rrrS)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$rruserhighrS)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-existentrG)r$rrrr#rS)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 UnixrGz non-existentr)rr#r$rrrS)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$rruserkeysrS)r&rrrtest_user_override_keyss   z,CurrentColorKeysTest.test_user_override_keysN)r4r5r6r7r 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@rBr$r has_optionrS)r&rrrrtest_save_optionszChangesTest.test_save_optioncCs|j}|j|j|jtddd|jtddd|jtddd |jd ddd|j|jtj dtj dtj ddS) Nrrrrrrrrrr) rr@save_allr$rrrrrBrS)r&rrrrtest_save_addeds  zChangesTest.test_save_addedcCsV|j}|jdddd|jdddd|j|jtjdd|jtjdddS)NrrrZidledocZELDIZcodeldi)rrrrrBrrr@)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 rrGvaluerrr r)rr)rZdelete_sectionr$rr rArsKeyError)r&rZcfgtypeZsectionrrrtest_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_warnedrrbgetvalue)r&ZEqualstderrrrr test_warn%szWarningTest.test_warnN)r4r5r6rrrrrr#srrW) verbosity)!r7rrr^rMrKrrrrrZidlelib.idle_test.mock_idlerr rrr r9rrrrrrZTestCaserr8rUrrrr4rrrrrs:   ;` oV