a  ze.}@sNdZddlmZddlZddlZddlZddlmZmZddl Z ddl m Z ddlZddl m Z ej Z e jZiZedZed<edZed <edZed <edZed <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)testcfgidleConfuserCfgidlelibtestingrrQ/opt/bitninja-python-dojo/embedded/lib/python3.9/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 cCstd}||j|j}||jddddd||jddddd||jddd dd ||ddd ||jddddd||jddddd||ddd ||ddd ||dd||jddddddS)NronebooltypeFtwoTthreeint za stringtruefalsenotZexistZDEFAULTdefault)rIdleConfParser read_string assertEqualZassertIsGetZ assertIsNone)selfparsereqrrrtest_get5s  zIdleConfParserTest.test_getcCsXtd}||j|j}||dgd||dgd||dgdS)Nrr)rrrrz not exist)rr$r% GetOptionListassertCountEqualr&)r(r)Zget_listrrrtest_get_option_listJs   z'IdleConfParserTest.test_get_option_listcCs&td}|||gdS)Nr)rr$Loadr&sectionsr(r)rrrtest_load_nothingRs z$IdleConfParserTest.test_load_nothingcCsFtd}t|}|||ddd||ddgdS)N cfgparser.1Foo Barfoonewbar)rrr$r/r&r'r,)r( config_pathr)rrrtest_load_fileWs  z!IdleConfParserTest.test_load_fileN) __name__ __module__ __qualname____doc__rr+r.r2r8rrrrr&s  rc@sJeZdZdZdddZddZddZd d Zd d Zd dZ ddZ dS)IdleUserConfParserTestz"Test that IdleUserConfParser worksrcCs t|SN)rIdleUserConfParser)r(pathrrr new_parserdsz!IdleUserConfParserTest.new_parsercCs|}|d||ddd||ddd||ddd||ddd||ddd||ddg||ddddS)NFoobarrr Bar) rA add_section assertTrue SetOption assertFalser&r'r-r0r1rrrtest_set_optiongs z&IdleUserConfParserTest.test_set_optioncCsZ|}|d|ddd||dd||dd||dddS)NrBrCrZNotZExist)rA AddSectionrGrFZ RemoveOptionrHr1rrrtest_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN|}||g|d|d|d||ddgdS)NrBrD)rAr&r0rJr-r1rrrtest_add_sections    z'IdleUserConfParserTest.test_add_sectioncCs\|}|d|d|ddd||gd|||dgdS)NrBrDIdlenameval)rDrBrM)rArJrGr-r0ZRemoveEmptySectionsr&r1rrrtest_remove_empty_sectionss  z1IdleUserConfParserTest.test_remove_empty_sectionscCsv|}|d|d||||g|ddd|d||||dgdS)NrBrDrCr ) rArJrFZIsEmptyr&r0rGrHr-r1rrr test_is_emptys   z$IdleUserConfParserTest.test_is_emptycCst}tj|d}||}|d|ddd|tj || | tj || d| |tj |Wdn1s0YdS)Nztest.cfgrBrCr) tempfileTemporaryDirectoryosr@joinrArJrGrHexistsZSaverFremove_section)r(Ztdirr@r)rrr test_saves    z IdleUserConfParserTest.test_saveN)r) r9r:r;r<rArIrKrLrPrQrXrrrrr=as     r=c@s,eZdZdZeddZeddZdAddZd d Ze e j d d d dZe e 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(tjt}ntjt jd}|j D]N}tj |d|}t |d}| |j|<Wdq@1s0Yq@tj|_tt_dS)NT_utest__main__rz../config-%s.defr) config_stringrIdleConfr9rTr@dirname__file__abspathsys config_typesrUopenread_warn orig_warnr)clsconfidle_dirctyper7frrr setUpClasss   .zIdleConfTest.setUpClasscCs |jt_dSr>)rhrrg)rirrr tearDownClassszIdleConfTest.tearDownClassFcCs tj|dS)NrZ)rr_)r(r[rrr new_configszIdleConfTest.new_configcCshtjdd}|jD]P}td|j|<|j||j|td|j|<|j||j|q|S)zbReturn a mocked idleConf Both default and user config used the same config-*.def TrZr) rr_rdr$ defaultCfgr%r^r?r)r(rjrlrrr mock_configs  zIdleConfTest.mock_configwinzthis is test for unix systemc Cs|jdd}tjdddNtjddd ||dWdn1sP0YWdn1sn0Ytjdddxtjd d dJtd  ||d Wdn1s0YWdn1s0YWdn1s0Ytjd ddp|tD|t|Wdn1sV0YWdn1sv0YWdn1s0YdS)NTrZos.path.expanduser /home/fooZ return_valueos.path.existsz/home/foo/.idlerc~ os.getcwdz/home/foo/cpythonos.mkdirz/home/foo/cpython/.idlerc os.path.join/path/not/existsrprpatchr&Z GetUserCfgDir assertRaises SystemExitFileNotFoundErrorr(rjrrrtest_get_user_cfg_dir_unixs L  `  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc Cs|jdd}tjdddNtjddd ||dWdn1sP0YWdn1sn0Ytjdddxtjd d dJtd  ||d Wdn1s0YWdn1s0YWdn1s0Ytjd ddp|tD|t|Wdn1sV0YWdn1sv0YWdn1s0YdS)NTrZrtzC:\foorvrwzC:\foo\.idlercrxryzC:\foo\cpythonrzzC:\foo\cpython\.idlercr{r|r}rrrrtest_get_user_cfg_dir_windowss L  `  z*IdleConfTest.test_get_user_cfg_dir_windowsc CsP|jdd}d}tjddiFtjd|d|Wdn1sN0YWdn1sl0Y||j|j||j |j|j D]}| |t j q|j D]}| |t jq|jD](\}}||jtj|d|d q|j D]2\}}||jtj|jp8d d|d qdS) NTrZrur9Z__foo__zos.path.dirnamervzconfig-z.def#z.cfg)rprr~dictZCreateConfigHandlersr-rqr rdrvaluesZassertIsInstancerr$r?itemsr&filerTr@rUZuserdir)r(rjrkZdefault_parserZ user_parserZcfg_typer)rrrtest_create_config_handlers s& Dz(IdleConfTest.test_create_config_handlerscCs|jdd}td}t||jd<t||jd<||j}||jd ddd||jd ddg||jd ddd||jd ddgdS)NTrZr3r5r4r6) rprrr$rqr?rZ LoadCfgFilesr&r'r,)r(rjr7r*rrrtest_load_cfg_files&s z IdleConfTest.test_load_cfg_filescCsR|}td,}|||jt|jWdn1sD0YdS)Nz&idlelib.config.IdleUserConfParser.Save)rrrr~ZSaveUserCfgFilesr& call_countlenr)r(rjmrrrtest_save_user_cfg_files;s z%IdleConfTest.test_save_user_cfg_filescCs|}|j}||dddd||jddddddtd`}||jddd ddd||ddd d||jddd d d d ||jd Wdn1s0YdS)Nr EditorWindowwidthZ80rrPidlelib.config._warnZfont NotExistsZNEr")rrr& GetOptionrr~r)r(rjr*rgrrrtest_get_optionBs zIdleConfTest.test_get_optioncCs2|}|dddd||dddddS)NrrBrCr6)rrrGr&rrrrrrINszIdleConfTest.test_set_optioncCs|}||ddgd||ddgd|tj|ddWdn1sf0Y|tj|ddWdn1s0YdS)Nr#r)ZGeneralrZPyShellIndentThemeKeysZHistory HelpFilesuserZfoobarZ notexists)rrr-GetSectionListrrInvalidConfigSetZInvalidConfigTyperrrrtest_get_section_listTs  *z"IdleConfTest.test_get_section_listcCs|}|j}||ddddd||ddddd|dd d d |dd d d td(||d dd d dWdn1s0YdS)N IDLE ClassicZnormalz#000000z#ffffff)Z foregroundZ backgroundZcursorZblackr Foobarznormal-foregroundz#747474znormal-backgroundz#171717r)rrr&Z GetHighlightrGrr~r(rjr*rrrtest_get_highlightes zIdleConfTest.test_get_highlightcCs`|}||dd|dd|tj|ddWdn1sR0YdS)Nr#rrbad)rrr&Z GetThemeDictrrZ InvalidThemerrrrtest_get_theme_dictws  z IdleConfTest.test_get_theme_dictcCs8|}|||d|||ddS)Nrr)rrr&Z CurrentThemecurrent_colors_and_keys CurrentKeysrrrrtest_get_current_theme_and_keyssz,IdleConfTest.test_get_current_theme_and_keyscCs|}||dddS)Nrr)rrr&rrrrrtest_current_colors_and_keyssz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd}dt_||ddt_||ddt_||d|t_dS) NTrZwin32IDLE Classic WindowsdarwinIDLE Classic OSX some-linuxIDLE Modern Unix)rcplatformrpr& default_keysr(Zcurrent_platformrjrrrtest_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 GetExtensionsrW)r(r*ZiGErrrtest_get_extensionss  z IdleConfTest.test_get_extensionscCs*|}|||ddgddS)Nr#r )Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr)rrr-ZRemoveKeyBindNamesrrrrrtest_remove_key_bind_namess z'IdleConfTest.test_remove_key_bind_namescCs>td|j}|tdd|tddtddS)N= [ZzDummy] enable = True zz-inrzz-out)rr%r&r ZGetExtnNameForEventrW)r(r*rrrtest_get_extn_name_for_events  z)IdleConfTest.test_get_extn_name_for_eventcCs0td|tdddgitddS)Nrr<>!)rr%r&r ZGetExtensionKeysrWr(rrrtest_get_extension_keyss   z$IdleConfTest.test_get_extension_keyscCsNtd|j}tj}||didgdgd}||d|tddS)Nrrrz!)rz <>r)rr%r&r ZGetExtensionBindingsrW)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)Nr<>zzIDLE Classic Unixz z rzzzIDLE Classic Macrz NOT EXISTS)rrr&Z GetKeyBindingrrrrtest_get_keybindings   z IdleConfTest.test_get_keybindingcCs8tj}|}dt_|||||t_dS)Nr)rcrrrr&ZGetCurrentKeySet GetKeySetrrrrrtest_get_current_keysets  z$IdleConfTest.test_get_current_keysetcCsj|}|jdd|jdd|jdddd|jdddd||dd d dS) Nr rZFoobar_cfgBindingsenableTrueZnewfoozrz <>r)rrrqrEsetr&rrrrrtest_get_keysets zIdleConfTest.test_get_keysetcCsL|}||d||d||d||ddS)NcopyZcutzdel-word-rightz not-exists)rrrFZ IsCoreBindingrHrrrrtest_is_core_bindings z!IdleConfTest.test_is_core_bindingcCs|}||dg||dg|tj"||dgWdn1s`0Y|||d|d|jd ddd|jd ddd |jd dd d |jd dd d ||dgd|||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) rrr&ZGetExtraHelpSourceListrrrr-ZGetAllExtraHelpSourcesListrrGrrrrtest_extra_help_source_lists(0 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)rNrVrootrrfamilysizerZweight) test.supportrtkinterrZ tkinter.fontrrrZwithdrawactualr&ZGetFontZdestroy)r(rrrrjrrmrrr test_get_font*s    $zIdleConfTest.test_get_fontcCs|}|j}||ddg||dddg||ddg||ddd d g||d dd g||d dddg||ddddgdS)Nz<>z rz z z<>zrzzrrrz z r)rrr&Z GetCoreKeysrrrrtest_get_core_keys=szIdleConfTest.test_get_core_keysN)F)'r9r:r;r< classmethodrnrorprrunittestZskipIfrcr startswithrrrrrrrIrrrrrrrrrrrrrrrrrrrrrrrYsD            rYc@sReZdZdZejZdZeZddZ 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). rcCs~||d|jtd||d|jdtdd<||dddtdd<||d|jtddS)Nrz< [Theme] default = True IDLE NewrN non-existent)r& colorkeys default_themeusermainr%rWrrrrtest_old_builtin_themeXs   z+CurrentColorKeysTest.test_old_builtin_themecCshtd||dddtdd<||dddtdd<||d|jtddS)NzZ [Theme] default = True name2 = IDLE Dark rz IDLE DarkrrNrname2)rr%r&rrrWrrrrtest_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 Darkrr)rr%r&rruserhighrWrrrrtest_user_override_themezs    z-CurrentColorKeysTest.test_user_override_themecCs^||d|jtd||dddtdd<||d|jtddS)Nrz` [Keys] default = True name = IDLE Classic Unix rrrN)r&rrrr%rWrrrrtest_old_builtin_keyss   z*CurrentColorKeysTest.test_old_builtin_keyscCshtd||dddtdd<||dddtdd<||d|jtddS)Nz` [Keys] default = True name2 = IDLE Modern Unix rrrrNrr)rr%r&rrrWrrrrtest_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 Keysrr)rr%r&rruserkeysrWrrrrtest_user_override_keyss    z,CurrentColorKeysTest.test_user_override_keysN)r9r:r;r<r 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 Kseckitemkvalchanges add_optionr(rrrrloads zChangesTest.loadrrrrrrrrrcCst|_dSr>)rZ ConfigChangesrrrrrsetUpszChangesTest.setUpcCs||j|jdSr>)r&remptyrrrr test_initszChangesTest.test_initcCs8|}|||j|dddd|||jdS)Nrrrr)rr&loadedrrrrrtest_add_optionszChangesTest.test_add_optioncCs|jj}||dddd||dddd|tddd||dddd|tddd||dddd|tddtddS)NrrZwhat0 use-spacesr)r save_optionrFrHr&r has_optionrW)r(rrrrtest_save_optionszChangesTest.test_save_optioncCs|}|||tddd|tddd|tddd |d ddd||t dt dt ddS) Nrrrrrrrrrr) rrFsave_allr&rrrrrHrWrrrrtest_save_addeds  zChangesTest.test_save_addedcCsV|j}|dddd|dddd||tdd|tdddS)NrrrZidledocZELDIZcodeldi)rrrr rHrr rFrrrrtest_save_helps zChangesTest.test_save_helpcCs|j}|dddddS)Nrrrrrrrrrtest_save_defaultszChangesTest.test_save_defaultc Cs|}|dd|||jdD]h\}}t||dd||||t(|||t||Wdq&1s0Yq&dS)NrZfake))rr)r rrNvalue)rZdelete_sectionr&rr rGrKeyError)r(rZcfgtypesectionrrrtest_delete_sections     zChangesTest.test_delete_sectioncCs"|}||||jdSr>)rclearr&rrrrr test_clear szChangesTest.test_clearN)r9r:r;rrrrrrr r r rrrrrrrrs        rc@seZdZddZdS) WarningTestcCs|j}tt_t}tddWdn1s60Y|tjdh||dt}tddWdn1s0Y||dt}tddWdn1s0Y|tjddh||d dS) Nwarningkey)rrzwarning rwarn2yek)rrzwarn2 )r&rrZ_warnedrrggetvalue)r(ZEqualstderrrrr test_warns***zWarningTest.test_warnN)r9r:r;rrrrrrsrr\) verbosity)!r<rrrcrTrRrrrrrZidlelib.idle_test.mock_idlerr rrr r?rrrrrrZTestCaserr=rYrrrr9rrrrrs:   ;SoV