B YI~d.}�@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�Zedk�rFejdd�dS)�)�configN)�captured_stderr�findfile)�mock)�Func��main� highlight�keys� extensionscCstt_dt_dS)NT)�testcfg�idleConf�userCfg�idlelib�testing�rr�B/opt/alt/python37/lib64/python3.7/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}|�|jdddd�d�|�|jdddd�d�||jddd d�d �||�dd�d �|�|jdddd�d�|�|jdddd�d�||�dd�d �||�dd�d �|�|�dd��||jdddd�d�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_getcCs\t�d�}|�|j�|j}|�|d�dddg�|�|d�dddg�|�|d�g�dS)Nrrrrz 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)Nz cfgparser.1zFoo 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,r/r3rrrrr&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+r.)r&r'rrr�test_set_optiongs z&IdleUserConfParserTest.test_set_optioncCsZ|��}|�d�|�ddd�|�|�dd��|�|�dd��|�|�dd��dS)Nr;r<rZNotZExist)r:� AddSectionr@r?Z RemoveOptionrA)r&r'rrr�test_remove_optionws  z)IdleUserConfParserTest.test_remove_optioncCsN|��}|�|��g�|�d�|�d�|�d�|�|��ddg�dS)Nr;r=)r:r$r.rCr+)r&r'rrr�test_add_section�s    z'IdleUserConfParserTest.test_add_sectioncCs^|��}|�d�|�d�|�ddd�|�|��dddg�|��|�|��dg�dS)Nr;r=ZIdle�name�val)r:rCr@r+r.ZRemoveEmptySectionsr$)r&r'rrr�test_remove_empty_sections�s  z1IdleUserConfParserTest.test_remove_empty_sectionscCsv|��}|�d�|�d�|�|���|�|��g�|�ddd�|�d�|�|���|�|��dg�dS)Nr;r=r<r) r:rCr?ZIsEmptyr$r.r@rAr+)r&r'rrr� test_is_empty�s   z$IdleUserConfParserTest.test_is_emptyc Cs�t����}tj�|d�}|�|�}|�d�|�ddd�|�tj� |��|� �|� tj� |��|� d�|� �|�tj� |��WdQRXdS)Nztest.cfgr;r<r) �tempfileZTemporaryDirectory�osr9�joinr:rCr@rA�existsZSaver?�remove_section)r&Ztdirr9r'rrr� test_save�s    z IdleUserConfParserTest.test_saveN)r) r4r5r6r:rBrDrErHrIrOrrrrr7as     r7c@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�}xD|j D]:}tj� |d|�}t |d��}|� �|j|<WdQRXqBWtj|_t�t_dS)NT)�_utest�__main__rz../config-%s.def�r)� config_stringr�IdleConfr4rKr9�dirname�__file__�abspath�sys� config_typesrL�open�read�_warn� orig_warnr)�cls�conf�idle_dir�ctyper2�frrr� setUpClass�s   zIdleConfTest.setUpClasscCs |jt_dS)N)r^rr])r_rrr� tearDownClass�szIdleConfTest.tearDownClassFcCs tj|d�S)N)rQ)rrU)r&rQrrr� new_config�szIdleConfTest.new_configcCsltjdd�}xZ|jD]P}t�d�|j|<|j|�|j|�t�d�|j|<|j|�|j|�qW|S)NT)rQr) rrUrZr"� defaultCfgr#rTr8r)r&r`rbrrr� mock_config�s  zIdleConfTest.mock_config�winzthis is test for unix systemc Cs�|jdd�}tjddd��0tjddd��|�|��d�WdQRXWdQRXtjddd��Ftjd d d��,t�d ��|�|��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)rfr�patchr$� GetUserCfgDir� assertRaises� SystemExit�FileNotFoundError)r&r`rrr�test_get_user_cfg_dir_unix�s $  $  z'IdleConfTest.test_get_user_cfg_dir_unixzthis is test for Windows systemc Cs�|jdd�}tjddd��0tjddd��|�|��d�WdQRXWdQRXtjddd��Ftjd d d��,t�d ��|�|��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`rrr�test_get_user_cfg_dir_windows�s $  $  z*IdleConfTest.test_get_user_cfg_dir_windowsc Cs6|jdd�}d}tj�ddi��(tjd|d��|��WdQRXWdQRX|�|j��|j�|�|j ��|j�x |j� �D]}|� |t j �q�Wx |j � �D]}|� |t j�q�Wx6|j��D](\}}|�|jtj�|d|�d ���q�Wx>|j ��D]0\}}|�|jtj�|j�pd d|�d ���q�WdS) NT)rQz /home/foor4Z__foo__zos.path.dirname)rjzconfig-z.def�#z.cfg)rfrrl�dictZCreateConfigHandlersr+rgr rZr�valuesZassertIsInstancerr"r8�itemsr$�filerKr9rLZuserdir)r&r`raZdefault_parserZ user_parserZcfg_typer'rrr�test_create_config_handlers s" 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)NT)rQz cfgparser.1r0zFoo Barr1) rfrrr"rgr8rZ LoadCfgFilesr$r%r*)r&r`r2r(rrr�test_load_cfg_files&s z IdleConfTest.test_load_cfg_filesc Cs>|��}t�d��"}|��|�|jt|j��WdQRXdS)Nz&idlelib.config.IdleUserConfParser.Save)rhrrlZSaveUserCfgFilesr$� call_count�lenr)r&r`�mrrr�test_save_user_cfg_files;s z%IdleConfTest.test_save_user_cfg_filesc Cs�|��}|j}||�ddd�d�||jddddd�d�t�d��V}||jddd dd�d�||�ddd �d�||jddd d d �d �||jd �WdQRXdS)Nr� EditorWindow�widthZ80r)r�Pzidlelib.config._warnZfont� NotExistsZNE)r!�)rhr$� GetOptionrrlrz)r&r`r(r]rrr�test_get_optionBs zIdleConfTest.test_get_optioncCs2|��}|�dddd�|�|�ddd�d�dS)Nrr;r<r1)rhr@r$r�)r&r`rrrrBNszIdleConfTest.test_set_optionc Cs�|��}|�|�dd�ddddddd d g�|�|�d d�ddddddd d g�|�tj��|�d d�WdQRX|�tj��|�dd �WdQRXdS)Nr!rZGeneralr~ZPyShell�Indent�Theme�KeysZHistory� HelpFiles�userZfoobarZ notexists)rhr+�GetSectionListrnr�InvalidConfigSetZInvalidConfigType)r&r`rrr�test_get_section_listTs      z"IdleConfTest.test_get_section_listc Cs�|��}|j}||�dd�ddd��||�dd�ddd��|�dd d d �|�dd d d �t�d��||�d d�d d d��WdQRXdS)Nz IDLE ClassicZnormalz#000000z#ffffff)Z foregroundZ backgroundZcursorZblackr �Foobarznormal-foregroundz#747474znormal-backgroundz#171717zidlelib.config._warn)rhr$Z GetHighlightr@rrl)r&r`r(rrr�test_get_highlightes   zIdleConfTest.test_get_highlightc CsL|��}|�|�dd�|�dd��|�tj��|�dd�WdQRXdS)Nr!z IDLE Classicr��bad)rhr$Z GetThemeDictrnrZ InvalidTheme)r&r`rrr�test_get_theme_dictws  z IdleConfTest.test_get_theme_dictcCs8|��}|�|��|�d��|�|��|�d��dS)Nr�r�)rhr$Z CurrentTheme�current_colors_and_keys� CurrentKeys)r&r`rrr�test_get_current_theme_and_keys�sz,IdleConfTest.test_get_current_theme_and_keyscCs|��}|�|�d�d�dS)Nr�z IDLE Classic)rhr$r�)r&r`rrr�test_current_colors_and_keys�sz)IdleConfTest.test_current_colors_and_keyscCs^tj}|jdd�}dt_|�|��d�dt_|�|��d�dt_|�|��d�|t_dS) NT)rQ�win32zIDLE Classic Windows�darwinzIDLE Classic OSXz some-linuxzIDLE Modern Unix)rY�platformrfr$� default_keys)r&�current_platformr`rrr�test_default_keys�s zIdleConfTest.test_default_keyscCs�t�d�|j}tj}||dd�g�||�dg�||dd�dg�||dd�ddg�||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 GetExtensionsrN)r&r(ZiGErrr�test_get_extensions�s z IdleConfTest.test_get_extensionscCs0|��}|�|�|�dd��dddddg�dS)Nr!r Z AutoCompleteZ CodeContextZFormatParagraphZ ParenMatchr�)rhr+ZRemoveKeyBindNamesr�)r&r`rrr�test_remove_key_bind_names�sz'IdleConfTest.test_remove_key_bind_namescCs>t�d�|j}|t�d�d�|t�d�d�t�d�dS)Nz= [ZzDummy] enable = True zz-inr�zz-out)r�r#r$r ZGetExtnNameForEventrN)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)Nz= [ZzDummy] enable = True r�z<>z!)r�r#r$r ZGetExtensionKeysrN)r&rrr�test_get_extension_keys�s   z$IdleConfTest.test_get_extension_keyscCsNt�d�|j}tj}||d�i�dgdgd�}||d�|�t�d�dS)Nz= [ZzDummy] enable = True r�z!z!)z<>z <>r�)r�r#r$r ZGetExtensionBindingsrN)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)NzIDLE Modern Unixz<>zzzIDLE Classic Unixz z zIDLE Classic WindowszzzIDLE Classic MaczzIDLE Classic OSXz NOT EXISTS)rhr$Z GetKeyBinding)r&r`r(rrr�test_get_keybinding�s      z IdleConfTest.test_get_keybindingcCs8tj}|��}dt_|�|��|�|����|t_dS)Nz some-linux)rYr�rhr$ZGetCurrentKeySet� GetKeySetr�)r&r�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_cfgBindingsZenable�TrueZnewfoozzIDLE Modern Unixz <>r)rhrgr>�setr$r�)r&r`rrr�test_get_keyset�s zIdleConfTest.test_get_keysetcCsL|��}|�|�d��|�|�d��|�|�d��|�|�d��dS)N�copyZcutzdel-word-rightz not-exists)rhr?Z IsCoreBindingrA)r&r`rrr�test_is_core_bindings z!IdleConfTest.test_is_core_bindingc Cs|��}|�|�d�g�|�|�d�g�|�tj��|�|�d�g�WdQRX|�|��|�d�|�d��|jd� ddd�|jd� ddd �|jd� dd d �|jd� dd d �|�|�d�dddg�|�|��|�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�) rhr$ZGetExtraHelpSourceListrnrr�r+ZGetAllExtraHelpSourcesListrr@)r&r`rrr�test_extra_help_source_lists& 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)rFrM�rootrr~Zfamily�sizerZweight) � test.supportr�Ztkinterr�Z tkinter.fontr�rhZwithdraw�actualr$ZGetFontZdestroy)r&r�r�r�r`r�rcrrr� 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 z<>z z z<>zzIDLE Classic WindowszzzIDLE Classic OSXzzIDLE Classic Unixz z zIDLE Modern Unix)rhr$Z GetCoreKeys)r&r`r(rrr�test_get_core_keys=s  zIdleConfTest.test_get_core_keysN)F)&r4r5r6� classmethodrdrerfrh�unittestZskipIfrYr�� startswithrqrrrxryr}r�rBr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrP�s:          rPc@sNeZdZejZdZe��Zdd�Zdd�Z dd�Z dd �Z d d �Z d d �Z dS)�CurrentColorKeysTestz IDLE ClassiccCs~|�|�d�|j�t�d�|�|�d�|j�dtdd<|�|�d�d�dtdd<|�|�d�|j�t�d�dS)Nr�z< [Theme] default = True zIDLE NewrFz non-existent)r$� colorkeys� default_theme�usermainr#rN)r&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 DarkzIDLE NewrFz non-existent�name2)r�r#r$r�r�rN)r&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 Darkz non-existentr�)r�r#r$r�r��userhighrN)r&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 zIDLE Classic Unixz non-existentrF)r$r�r�r�r#rN)r&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�zIDLE Modern UnixzIDLE Classic UnixrFz non-existentr�)r�r#r$r�r�rN)r&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 Keysz non-existentr�)r�r#r$r�r��userkeysrN)r&rrr�test_user_override_keys�s   z,CurrentColorKeysTest.test_user_override_keysN)r4r5r6r r�r�r�r�r�r�r�r�r�r�rrrrr�Msr�c@s�eZdZiiiid�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��|_dS)N)rZ ConfigChangesr�)r&rrr�setUp�szChangesTest.setUpcCs|�|j|j�dS)N)r$r��empty)r&rrr� test_init�szChangesTest.test_initcCs8|��}|�||j�|�dddd�|�||j�dS)Nrr�r�r�)r�r$�loadedr�)r&r�rrr�test_add_option�szChangesTest.test_add_optioncCs�|jj}|�|dddd��|�|dddd��|�tddd�|�|dddd��|�tddd�|�|dddd��|�t�dd��t�d�dS)Nrr�Zwhat�0z use-spacesr�)r�� save_optionr?rAr$r�� has_optionrN)r&r�rrr�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�r?�save_allr$r�r�r�r�rArN)r&r�rrr�test_save_added�s  zChangesTest.test_save_addedcCsV|j}|�dddd�|�dddd�|��|�t�dd��|�t�dd��dS)Nrr�r�ZidledocZELDIZcodeldi)r�r�r�r�rAr�r�r?)r&r�rrr�test_save_help�s zChangesTest.test_save_helpcCs|j}|�dddd�dS)Nrr�z use-spacesr�)r�r�)r&r�rrr�test_save_default�szChangesTest.test_save_defaultc Cs�|��}|�dd�|�||j�x\dD]T\}}t|�|dd�|�||�|�t��|||t||WdQRXq(WdS)NrZfake))rr�)r r�rF�value)r�Zdelete_sectionr$r�r r@rn�KeyError)r&r�Zcfgtype�sectionrrr�test_delete_sections    zChangesTest.test_delete_sectioncCs"|��}|��|�||j�dS)N)r��clearr$r�)r&r�rrr� test_clear szChangesTest.test_clearN)r4r5r6r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s       r�c@seZdZdd�ZdS)� WarningTestc Cs�|j}t�t_t��}t�dd�WdQRX|tjdh�||��d�t��}t�dd�WdQRX||��d�t��}t�dd�WdQRX|tjddh�||��d �dS) N�warning�key)r�r�zwarning r�warn2�yek)r�r�zwarn2 )r$r�rZ_warnedrr]�getvalue)r&ZEqual�stderrrrr� test_warnszWarningTest.test_warnN)r4r5r6r�rrrrr�sr�rR�)� verbosity) rrrYrKrJr�rrr�rZidlelib.idle_test.mock_idlerr rrr r8r�r�r�r�rrZTestCaserr7rPr�r�r�r4rrrrr�s8   ;SoV