B YI~d.}@sJddlmZddlZddlZddlZddlmZmZddlZddlm Z ddlZddl m Z ej Z e j ZiZedZed<edZed<edZed <edZed <d d Zd dZGdddejZGdddejZGdddejZGdddejZGdddejZGdddejZedkrFejdddS))configN)captured_stderrfindfile)mock)Funcmain highlightkeys extensionscCstt_dt_dS)NT)testcfgidleConfuserCfgidlelibtestingrrB/opt/alt/python37/lib64/python3.7/idlelib/idle_test/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 cCstd}||j|j}||jddddd||jddddd||jddd dd ||ddd ||jddddd||jddddd||ddd ||ddd ||dd||jddddddS)Nronebool)typeFtwoTthreeint za stringtruefalsenotZexistZDEFAULT)default)rIdleConfParser read_string assertEqualZassertIsGetZ assertIsNone)selfparsereqrrrtest_get5s  zIdleConfParserTest.test_getcCs\td}||j|j}||ddddg||ddddg||dgdS)Nrrrrz not exist)rr"r# GetOptionListassertCountEqualr$)r&r'Zget_listrrrtest_get_option_listJs   z'IdleConfParserTest.test_get_option_listcCs&td}|||gdS)Nr)rr"Loadr$sections)r&r'rrrtest_load_nothingRs z$IdleConfParserTest.test_load_nothingcCsFtd}t|}|||ddd||ddgdS)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@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)IdleUserConfParserTestrcCs t|S)N)rIdleUserConfParser)r&pathrrr new_parserdsz!IdleUserConfParserTest.new_parsercCs|}|d||ddd||ddd||ddd||ddd||ddd||ddg||ddddS)NFoobarrrBar) r: add_section assertTrue SetOption assertFalser$r%r+r.)r&r'rrrtest_set_optiongs z&IdleUserConfParserTest.test_set_optioncCsZ|}|d|ddd||dd||dd||dddS)Nr;r<rZNotZExist)r: AddSectionr@r?Z RemoveOptionrA)r&r'rrrtest_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN|}||g|d|d|d||ddgdS)Nr;r=)r:r$r.rCr+)r&r'rrrtest_add_sections    z'IdleUserConfParserTest.test_add_sectioncCs^|}|d|d|ddd||dddg|||dgdS)Nr;r=ZIdlenameval)r:rCr@r+r.ZRemoveEmptySectionsr$)r&r'rrrtest_remove_empty_sectionss  z1IdleUserConfParserTest.test_remove_empty_sectionscCsv|}|d|d||||g|ddd|d||||dgdS)Nr;r=r<r) r:rCr?ZIsEmptyr$r.r@rAr+)r&r'rrr test_is_emptys   z$IdleUserConfParserTest.test_is_emptyc Cst}tj|d}||}|d|ddd|tj || | tj || d| |tj |WdQRXdS)Nztest.cfgr;r<r) tempfileZTemporaryDirectoryosr9joinr:rCr@rAexistsZSaver?remove_section)r&Ztdirr9r'rrr test_saves    z IdleUserConfParserTest.test_saveN)r) r4r5r6r:rBrDrErHrIrOrrrrr7as     r7c@s(eZdZeddZeddZd@ddZdd Ze e j d d d d Z e e 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(tjt}ntjt jd}xD|j D]:}tj |d|}t |d}| |j|<WdQRXqBWtj|_tt_dS)NT)_utest__main__rz../config-%s.defr) config_stringrIdleConfr4rKr9dirname__file__abspathsys config_typesrLopenread_warn orig_warnr)clsconfidle_dirctyper2frrr setUpClasss   zIdleConfTest.setUpClasscCs |jt_dS)N)r^rr])r_rrr tearDownClassszIdleConfTest.tearDownClassFcCs tj|dS)N)rQ)rrU)r&rQrrr new_configszIdleConfTest.new_configcCsltjdd}xZ|jD]P}td|j|<|j||j|td|j|<|j||j|qW|S)NT)rQr) rrUrZr" defaultCfgr#rTr8r)r&r`rbrrr mock_configs  zIdleConfTest.mock_configwinzthis is test for unix systemc Cs|jdd}tjddd0tjddd||dWdQRXWdQRXtjdddFtjd d d,td ||d WdQRXWdQRXWdQRXtjd dd:|t$|t|WdQRXWdQRXWdQRXdS)NT)rQzos.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)rfrpatchr$ GetUserCfgDir assertRaises SystemExitFileNotFoundError)r&r`rrrtest_get_user_cfg_dir_unixs $  $  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc Cs|jdd}tjddd0tjddd||dWdQRXWdQRXtjdddFtjd d d,td ||d WdQRXWdQRXWdQRXtjd dd:|t$|t|WdQRXWdQRXWdQRXdS)NT)rQzos.path.expanduserzC:\foo)rjzos.path.existszC:\foo\.idlercrkz os.getcwdzC:\foo\cpythonzos.mkdirzC:\foo\cpython\.idlercz os.path.joinz/path/not/exists)rfrrlr$rmrnrorp)r&r`rrrtest_get_user_cfg_dir_windowss $  $  z*IdleConfTest.test_get_user_cfg_dir_windowsc Cs6|jdd}d}tjddi(tjd|d|WdQRXWdQRX||j|j||j |jx |j D]}| |t j qWx |j D]}| |t jqWx6|jD](\}}||jtj|d|d qWx>|j D]0\}}||jtj|jpd d|d qWdS) NT)rQz /home/foor4Z__foo__zos.path.dirname)rjzconfig-z.def#z.cfg)rfrrldictZCreateConfigHandlersr+rgr rZrvaluesZassertIsInstancerr"r8itemsr$filerKr9rLZuserdir)r&r`raZdefault_parserZ user_parserZcfg_typer'rrrtest_create_config_handlers s" z(IdleConfTest.test_create_config_handlerscCs|jdd}td}t||jd<t||jd<||j}||jd ddd||jd ddg||jd ddd||jd ddgdS)NT)rQz cfgparser.1r0zFoo Barr1) rfrrr"rgr8rZ LoadCfgFilesr$r%r*)r&r`r2r(rrrtest_load_cfg_files&s z IdleConfTest.test_load_cfg_filesc Cs>|}td"}|||jt|jWdQRXdS)Nz&idlelib.config.IdleUserConfParser.Save)rhrrlZSaveUserCfgFilesr$ call_countlenr)r&r`mrrrtest_save_user_cfg_files;s z%IdleConfTest.test_save_user_cfg_filesc Cs|}|j}||dddd||jddddddtdV}||jddd ddd||ddd d||jddd d d d ||jd WdQRXdS)Nr EditorWindowwidthZ80r)rPzidlelib.config._warnZfont NotExistsZNE)r!)rhr$ GetOptionrrlrz)r&r`r(r]rrrtest_get_optionBs zIdleConfTest.test_get_optioncCs2|}|dddd||dddddS)Nrr;r<r1)rhr@r$r)r&r`rrrrBNszIdleConfTest.test_set_optionc Cs|}||ddddddddd d g||d dddddddd d g|tj|d dWdQRX|tj|dd WdQRXdS)Nr!rZGeneralr~ZPyShellIndentThemeKeysZHistory HelpFilesuserZfoobarZ notexists)rhr+GetSectionListrnrInvalidConfigSetZInvalidConfigType)r&r`rrrtest_get_section_listTs      z"IdleConfTest.test_get_section_listc Cs|}|j}||ddddd||ddddd|dd d d |dd d d td||d dd d dWdQRXdS)Nz IDLE ClassicZnormalz#000000z#ffffff)Z foregroundZ backgroundZcursorZblackr Foobarznormal-foregroundz#747474znormal-backgroundz#171717zidlelib.config._warn)rhr$Z GetHighlightr@rrl)r&r`r(rrrtest_get_highlightes   zIdleConfTest.test_get_highlightc CsL|}||dd|dd|tj|ddWdQRXdS)Nr!z IDLE Classicrbad)rhr$Z GetThemeDictrnrZ InvalidTheme)r&r`rrrtest_get_theme_dictws  z IdleConfTest.test_get_theme_dictcCs8|}|||d|||ddS)Nrr)rhr$Z CurrentThemecurrent_colors_and_keys CurrentKeys)r&r`rrrtest_get_current_theme_and_keyssz,IdleConfTest.test_get_current_theme_and_keyscCs|}||dddS)Nrz IDLE Classic)rhr$r)r&r`rrrtest_current_colors_and_keyssz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd}dt_||ddt_||ddt_||d|t_dS) NT)rQwin32zIDLE Classic WindowsdarwinzIDLE Classic OSXz some-linuxzIDLE Modern Unix)rYplatformrfr$ default_keys)r&current_platformr`rrrtest_default_keyss zIdleConfTest.test_default_keyscCstd|j}tj}||ddg||dg||dddg||ddddg||ddd ddgtdtddS) Nzn [ZzDummy] enable = True [DISABLE] enable = False T)Z shell_onlyZzDummy) editor_onlyF) active_onlyZDISABLE)rr)userextnr#r$r Z GetExtensionsrN)r&r(ZiGErrrtest_get_extensionss z IdleConfTest.test_get_extensionscCs0|}|||dddddddgdS)Nr!r Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr)rhr+ZRemoveKeyBindNamesr)r&r`rrrtest_remove_key_bind_namessz'IdleConfTest.test_remove_key_bind_namescCs>td|j}|tdd|tddtddS)Nz= [ZzDummy] enable = True zz-inrzz-out)rr#r$r ZGetExtnNameForEventrN)r&r(rrrtest_get_extn_name_for_events z)IdleConfTest.test_get_extn_name_for_eventcCs0td|tdddgitddS)Nz= [ZzDummy] enable = True rz<>z!)rr#r$r ZGetExtensionKeysrN)r&rrrtest_get_extension_keyss   z$IdleConfTest.test_get_extension_keyscCsNtd|j}tj}||didgdgd}||d|tddS)Nz= [ZzDummy] enable = True rz!z!)z<>z <>r)rr#r$r ZGetExtensionBindingsrN)r&r(ZiGEBexpectrrrtest_get_extension_bindingss z(IdleConfTest.test_get_extension_bindingscCs|}|j}||ddddg||ddddg||ddd d g||d dd g||d dd g||ddg||ddgdS)NzIDLE Modern Unixz<>zzzIDLE Classic Unixz z zIDLE Classic WindowszzzIDLE Classic MaczzIDLE Classic OSXz NOT EXISTS)rhr$Z GetKeyBinding)r&r`r(rrrtest_get_keybindings      z IdleConfTest.test_get_keybindingcCs8tj}|}dt_|||||t_dS)Nz some-linux)rYrrhr$ZGetCurrentKeySet GetKeySetr)r&rr`rrrtest_get_current_keysets  z$IdleConfTest.test_get_current_keysetcCsj|}|jdd|jdd|jdddd|jdddd||dd d dS) Nr rZFoobar_cfgBindingsZenableTrueZnewfoozzIDLE Modern Unixz <>r)rhrgr>setr$r)r&r`rrrtest_get_keysets zIdleConfTest.test_get_keysetcCsL|}||d||d||d||ddS)NcopyZcutzdel-word-rightz not-exists)rhr?Z IsCoreBindingrA)r&r`rrrtest_is_core_bindings z!IdleConfTest.test_is_core_bindingc Cs|}||dg||dg|tj||dgWdQRX|||d|d|jd ddd|jd ddd |jd dd d |jd dd d ||ddddg|||d|ddS)Nr!rrrr4zPython;https://python.org3zPython:https://python.org2z/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) rhr$ZGetExtraHelpSourceListrnrrr+ZGetAllExtraHelpSourcesListrr@)r&r`rrrtest_extra_help_source_lists& z(IdleConfTest.test_extra_help_source_listcCsddlm}ddlm}ddlm}|}|d|}|||dd|d}| | |d d |d |d dkr|d n|d |df| ~dS)Nr)requires)Tk)FontZguiZ TkFixedFontT)rFrMrootrr~ZfamilysizerZweight) test.supportrZtkinterrZ tkinter.fontrrhZwithdrawactualr$ZGetFontZdestroy)r&rrrr`rrcrrr test_get_font*s    (zIdleConfTest.test_get_fontcCs|}|j}||ddg||dddg||ddg||ddd d g||d dd g||d dddg||ddddgdS)Nz<>z z<>z z z<>zzIDLE Classic WindowszzzIDLE Classic OSXzzIDLE Classic Unixz z zIDLE Modern Unix)rhr$Z GetCoreKeys)r&r`r(rrrtest_get_core_keys=s  zIdleConfTest.test_get_core_keysN)F)&r4r5r6 classmethodrdrerfrhunittestZskipIfrYr startswithrqrrrxryr}rrBrrrrrrrrrrrrrrrrrrrrrrrPs:          rPc@sNeZdZejZdZeZddZddZ ddZ dd Z d d Z d d Z dS)CurrentColorKeysTestz IDLE ClassiccCs~||d|jtd||d|jdtdd<||dddtdd<||d|jtddS)Nrz< [Theme] default = True zIDLE NewrFz non-existent)r$ colorkeys default_themeusermainr#rN)r&rrrtest_old_builtin_themeXs  z+CurrentColorKeysTest.test_old_builtin_themecCshtd||dddtdd<||dddtdd<||d|jtddS)NzZ [Theme] default = True name2 = IDLE Dark rz IDLE DarkzIDLE NewrFz non-existentname2)rr#r$rrrN)r&rrrtest_new_builtin_themejs  z+CurrentColorKeysTest.test_new_builtin_themecCsptd||d|jtd||dddtdd<||ddtdtddS)Nz\ [Theme] default = False name = Custom Dark rz[Custom Dark] a=bz Custom Darkz non-existentr)rr#r$rruserhighrN)r&rrrtest_user_override_themezs   z-CurrentColorKeysTest.test_user_override_themecCs^||d|jtd||dddtdd<||d|jtddS)Nrz` [Keys] default = True name = IDLE Classic Unix zIDLE Classic Unixz non-existentrF)r$rrrr#rN)r&rrrtest_old_builtin_keyss z*CurrentColorKeysTest.test_old_builtin_keyscCshtd||dddtdd<||dddtdd<||d|jtddS)Nz` [Keys] default = True name2 = IDLE Modern Unix rzIDLE Modern UnixzIDLE Classic UnixrFz non-existentr)rr#r$rrrN)r&rrrtest_new_builtin_keyss  z*CurrentColorKeysTest.test_new_builtin_keyscCsptd||d|jtd||dddtdd<||ddtdtddS)Nz[ [Keys] default = False name = Custom Keys rz[Custom Keys] a=bz Custom Keysz non-existentr)rr#r$rruserkeysrN)r&rrrtest_user_override_keyss   z,CurrentColorKeysTest.test_user_override_keysN)r4r5r6r rrrrrrrrrrrrrrrMsrc@seZdZiiiidZddZdddiiddd iid d d iiidZd dZddZddZddZ ddZ ddZ ddZ ddZ ddZdS) ChangesTest)rr r r cCs:|j}|dddd|dddd|d d d d |S) NrMsecmitemmvalr Hsechitemhvalr Kseckitemkval)changes add_option)r&rrrrloads zChangesTest.loadrrrrrrrrrcCst|_dS)N)rZ ConfigChangesr)r&rrrsetUpszChangesTest.setUpcCs||j|jdS)N)r$rempty)r&rrr test_initszChangesTest.test_initcCs8|}|||j|dddd|||jdS)Nrrrr)rr$loadedr)r&rrrrtest_add_optionszChangesTest.test_add_optioncCs|jj}||dddd||dddd|tddd||dddd|tddd||dddd|tddtddS)NrrZwhat0z use-spacesr)r save_optionr?rAr$r has_optionrN)r&rrrrtest_save_optionszChangesTest.test_save_optioncCs|}|||tddd|tddd|tddd |d ddd||t dt dt ddS) Nrrrrrrrrrr) rr?save_allr$rrrrrArN)r&rrrrtest_save_addeds  zChangesTest.test_save_addedcCsV|j}|dddd|dddd||tdd|tdddS)NrrrZidledocZELDIZcodeldi)rrrrrArrr?)r&rrrrtest_save_helps zChangesTest.test_save_helpcCs|j}|dddddS)Nrrz use-spacesr)rr)r&rrrrtest_save_defaultszChangesTest.test_save_defaultc Cs|}|dd|||jx\dD]T\}}t||dd||||t|||t||WdQRXq(WdS)NrZfake))rr)r rrFvalue)rZdelete_sectionr$rr r@rnKeyError)r&rZcfgtypesectionrrrtest_delete_sections    zChangesTest.test_delete_sectioncCs"|}||||jdS)N)rclearr$r)r&rrrr test_clear szChangesTest.test_clearN)r4r5r6rrrrrrrrrrrrrrrrrs       rc@seZdZddZdS) WarningTestc Cs|j}tt_t}tddWdQRX|tjdh||dt}tddWdQRX||dt}tddWdQRX|tjddh||d dS) Nwarningkey)rrzwarning rwarn2yek)rrzwarn2 )r$rrZ_warnedrr]getvalue)r&ZEqualstderrrrr test_warnszWarningTest.test_warnN)r4r5r6rrrrrrsrrR) verbosity) rrrYrKrJrrrrrZidlelib.idle_test.mock_idlerr rrr r8rrrrrrZTestCaserr7rPrrrr4rrrrrs8   ;SoV