B „ f°;ã@s~dZddlmZddlZddlmZddlmZmZddl Z ddlm Z ddl m Z Gdd „d ej ƒZGd d „d ej ƒZGd d „d ej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGd d!„d!ej ƒZGd"d#„d#ej ƒZGd$d%„d%ej ƒZed&k�rzejd'd(d)�dS)*a½Test query, coverage 93%). Non-gui tests for Query, SectionName, ModuleName, and HelpSource use dummy versions that extract the non-gui methods and add other needed attributes. GUI tests create an instance of each class and simulate entries and button clicks. Subclass tests only target the new code in the subclass definition. The appearance of the widgets is checked by the Query and HelpSource htests. These are run by running query.py. é)ÚqueryN)Úrequires)ÚTkÚEND)Úmock)ÚVarc@sFeZdZdZGdd„dƒZdd„Zdd„Zdd „Zd d „Zd d „Z dS)Ú QueryTestzTest Query base class.c@s<eZdZejjZejjZejjZdd„Zdd„Z dd„Z dS)zQueryTest.Dummy_QuerycCs&t|d�|_ddi|_d|_d|_dS)N)ÚvalueÚtextÚF)rÚentryÚ entry_errorÚresultÚ destroyed)ÚselfÚ dummy_entry©rúA/opt/alt/python37/lib64/python3.7/idlelib/idle_test/test_query.pyÚ__init__!s  zQueryTest.Dummy_Query.__init__cCs||jd<dS)Nr )r )rÚmessagerrrÚ showerror&szQueryTest.Dummy_Query.showerrorcCs d|_dS)NT)r)rrrrÚdestroy(szQueryTest.Dummy_Query.destroyN) Ú__name__Ú __module__Ú __qualname__rÚQueryÚentry_okÚokÚcancelrrrrrrrÚ Dummy_Querys rcCsD| d¡}| | ¡d¡| |j|jfd¡| d|jd¡dS)Nú )NFz blank liner )rÚ assertEqualrrrÚassertInr )rÚdialogrrrÚtest_entry_ok_blank+s zQueryTest.test_entry_ok_blankcCsD| d¡}|j}|| ¡dƒ||j|jfdƒ||jddƒdS)Nz good Úgood)NFr r )rr!rrrr )rr#ÚEqualrrrÚtest_entry_ok_good1s  zQueryTest.test_entry_ok_goodcCsT| d¡}t ¡|j_| | ¡d¡| |jjj¡|j`| |j |j fd¡dS)Nr )NF) rrÚMockr Z focus_setr!rÚ assertTrueÚcalledrr)rr#rrrÚ test_ok_blank8s   zQueryTest.test_ok_blankcCs2| d¡}| | ¡d¡| |j|jfd¡dS)Nr%)r%T)rr!rrr)rr#rrrÚ test_ok_good@s zQueryTest.test_ok_goodcCs2| d¡}| | ¡d¡| |j|jfd¡dS)Nzdoes not matter)NT)rr!rrr)rr#rrrÚ test_cancelEs zQueryTest.test_cancelN) rrrÚ__doc__rr$r'r+r,r-rrrrrsrc@s>eZdZdZGdd„dƒZdd„Zdd„Zdd „Zd d „Zd S) ÚSectionNameTestz#Test SectionName subclass of Query.c@s*eZdZejjZdgZdd„Zdd„ZdS)z!SectionNameTest.Dummy_SectionNameÚusedcCst|d�|_ddi|_dS)N)r r r )rr r )rrrrrrQs z*SectionNameTest.Dummy_SectionName.__init__cCs||jd<dS)Nr )r )rrrrrrTsz+SectionNameTest.Dummy_SectionName.showerrorN) rrrrÚ SectionNamerÚ used_namesrrrrrrÚDummy_SectionNameNsr3cCs0| d¡}| | ¡d¡| d|jd¡dS)Nr zno namer )r3r!rr"r )rr#rrrÚtest_blank_section_nameWs z'SectionNameTest.test_blank_section_namecCs0| d¡}| | ¡d¡| d|jd¡dS)Nr0Zuser )r3r!rr"r )rr#rrrÚtest_used_section_name\s z&SectionNameTest.test_used_section_namecCs0| d¡}| | ¡d¡| d|jd¡dS)NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r )r3r!rr"r )rr#rrrÚtest_long_section_nameas z&SectionNameTest.test_long_section_namecCs0| d¡}| | ¡d¡| |jdd¡dS)Nz good r%r r )r3r!rr )rr#rrrÚtest_good_section_namefs z&SectionNameTest.test_good_section_nameN) rrrr.r3r4r5r6r7rrrrr/Ks  r/c@s>eZdZdZGdd„dƒZdd„Zdd„Zdd „Zd d „Zd S) ÚModuleNameTestz"Test ModuleName subclass of Query.c@s(eZdZejjZdZdd„Zdd„ZdS)zModuleNameTest.Dummy_ModuleNamer cCst|d�|_ddi|_dS)N)r r r )rr r )rrrrrrrs z(ModuleNameTest.Dummy_ModuleName.__init__cCs||jd<dS)Nr )r )rrrrrrusz)ModuleNameTest.Dummy_ModuleName.showerrorN) rrrrÚ ModuleNamerÚtext0rrrrrrÚDummy_ModuleNameosr;cCs0| d¡}| | ¡d¡| d|jd¡dS)Nr zno namer )r;r!rr"r )rr#rrrÚtest_blank_module_namexs z%ModuleNameTest.test_blank_module_namecCs0| d¡}| | ¡d¡| d|jd¡dS)NZ __name_xyz123_should_not_exist__z not foundr )r;r!rr"r )rr#rrrÚtest_bogus_module_name}s z%ModuleNameTest.test_bogus_module_namecCs0| d¡}| | ¡d¡| d|jd¡dS)NÚ itertoolsz source-basedr )r;r!rr"r )rr#rrrÚtest_c_source_name‚s z!ModuleNameTest.test_c_source_namecCs4| d¡}| | ¡ d¡¡| |jdd¡dS)NÚidlelibz __init__.pyr r )r;r)rÚendswithr!r )rr#rrrÚtest_good_module_name‡s z$ModuleNameTest.test_good_module_nameN) rrrr.r;r<r=r?rBrrrrr8ls  r8c@s6eZdZdZGdd„dƒZdd„Zdd„Zdd „Zd S) ÚGotoTestzTest Goto subclass of Query.c@s$eZdZejjZdd„Zdd„ZdS)zGotoTest.Dummy_ModuleNamecCst|d�|_ddi|_dS)N)r r r )rr r )rrrrrr’s z"GotoTest.Dummy_ModuleName.__init__cCs||jd<dS)Nr )r )rrrrrr•sz#GotoTest.Dummy_ModuleName.showerrorN)rrrrÚGotorrrrrrrr;�sr;cCs0| d¡}| | ¡d¡| d|jd¡dS)NÚaznot a base 10 integerr )r;r!rr"r )rr#rrrÚtest_bogus_goto˜s zGotoTest.test_bogus_gotocCs0| d¡}| | ¡d¡| d|jd¡dS)NÚ0znot a positive integerr )r;r!rr"r )rr#rrrÚ test_bad_goto�s zGotoTest.test_bad_gotocCs0| d¡}| | ¡d¡| |jdd¡dS)NÚ1ér r )r;r!rr )rr#rrrÚtest_good_goto¢s zGotoTest.test_good_gotoN)rrrr.r;rFrHrKrrrrrC�s rCc@s&eZdZdZGdd„dƒZdd„ZdS)ÚHelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c@seZdZejjZeƒZdS)z)HelpsourceBrowsefileTest.Dummy_HelpSourceN)rrrrÚ HelpSourceÚ browse_filerÚpathvarrrrrÚDummy_HelpSource­srPc Cs�| ¡}x‚ddd„dfddd„tfddd„dfddd„tffD]J\}}}| ¡�2|j |¡||_| ¡| |j ¡|¡WdQRXq>WdS)Nr cSsdS)Nr r)rEÚbÚcrrrÚ¸ózBHelpsourceBrowsefileTest.test_file_replaces_path..cSstS)N)Ú__file__)rErQrRrrrrS¹rTZhtestcSsdS)Nr r)rErQrRrrrrSºrTcSstS)N)rU)rErQrRrrrrS»rT) rPrUÚsubTestrOÚsetZ askfilenamerNr!Úget)rr#ÚpathÚfuncrrrrÚtest_file_replaces_path±s     z0HelpsourceBrowsefileTest.test_file_replaces_pathN)rrrr.rPr[rrrrrLªsrLc@sPeZdZdZGdd„dƒZejZedd„ƒZ dd„Z dd „Z d d „Z d d „Z dS)ÚHelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c@s&eZdZejjZdd„Zddd„ZdS)z%HelpsourcePathokTest.Dummy_HelpSourcecCst|d�|_ddi|_dS)N)r r r )rrYÚ path_error)rZ dummy_pathrrrrÈs z.HelpsourcePathokTest.Dummy_HelpSource.__init__NcCs||jd<dS)Nr )r])rrZwidgetrrrrËsz/HelpsourcePathokTest.Dummy_HelpSource.showerror)N)rrrrrMÚpath_okrrrrrrrPÆsrPcCs |jt_dS)N)Ú orig_platformrÚplatform)ÚclsrrrÚ tearDownClassÏsz"HelpsourcePathokTest.tearDownClasscCs0| d¡}| | ¡d¡| d|jd¡dS)Nr z no help filer )rPr!r^r"r])rr#rrrÚtest_path_ok_blankÓs z'HelpsourcePathokTest.test_path_ok_blankcCs4| td¡}| | ¡d¡| d|jd¡dS)Nz bad-bad-badz not existr )rPrUr!r^r"r])rr#rrrÚtest_path_ok_badØsz%HelpsourcePathokTest.test_path_ok_badc Csd| d¡}|j}xNdD]F}| ¡�4|j |¡| | ¡|¡| |jdd¡WdQRXqWdS)Nr )z www.py.orgz http://py.orgr )rPr!rVrYrWr^r])rr#r&ZurlrrrÚtest_path_ok_webÝs    z%HelpsourcePathokTest.test_path_ok_webc Csl| d¡}x\dD]T\}}| ¡�>|t_|j t¡| | ¡|t¡| |j dd¡WdQRXqWdS)Nr ))Údarwinzfile://)Úotherr r ) rPrVrr`rYrWrUr!r^r])rr#r`ÚprefixrrrÚtest_path_ok_fileæs   z&HelpsourcePathokTest.test_path_ok_fileN)rrrr.rPrr`r_Ú classmethodrbrcrdrerirrrrr\Ãs  r\c@s&eZdZdZGdd„dƒZdd„ZdS)ÚHelpsourceEntryokTestz5Test entry_ok method of HelpSource subclass of Query.c@s,eZdZejjZiZiZdd„Zdd„Z dS)z&HelpsourceEntryokTest.Dummy_HelpSourcecCs|jS)N)Úname)rrrrÚitem_ok÷sz.HelpsourceEntryokTest.Dummy_HelpSource.item_okcCs|jS)N)rY)rrrrr^ùsz.HelpsourceEntryokTest.Dummy_HelpSource.path_okN) rrrrrMrr r]rmr^rrrrrPós rPc CsR| ¡}xDdD]<\}}}| ¡�$|||_|_| | ¡|¡WdQRXqWdS)N))NNN)Nzdoc.txtN)ÚdocNN)rnzdoc.txt)rnzdoc.txt)rPrVrlrYr!r)rr#rlrYrrrrÚtest_entry_ok_helpsourceüs  z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)rrrr.rProrrrrrkðs rkc@s6eZdZdZGdd„dƒZdd„Zdd„Zdd „Zd S) ÚCustomRunCLIargsokTestz6Test cli_ok method of the CustomRun subclass of Query.c@s$eZdZejjZdd„Zdd„ZdS)z&CustomRunCLIargsokTest.Dummy_CustomRuncCst|d�|_ddi|_dS)N)r r r )rr r )rrrrrrs z/CustomRunCLIargsokTest.Dummy_CustomRun.__init__cCs||jd<dS)Nr )r )rrrrrrsz0CustomRunCLIargsokTest.Dummy_CustomRun.showerrorN)rrrrÚ CustomRunÚ cli_args_okrrrrrrÚDummy_CustomRun srscCs| d¡}| | ¡g¡dS)Nr )rsr!rr)rr#rrrÚtest_blank_argss z&CustomRunCLIargsokTest.test_blank_argscCs0| d¡}| | ¡d¡| d|jd¡dS)Nz'no-closing-quotez No closingr )rsr!rrr"r )rr#rrrÚtest_invalid_argss z(CustomRunCLIargsokTest.test_invalid_argscCsPddddddg}| d |¡d¡}| | ¡|d g¡| |jd d ¡dS) Nz-nZ10z --verbosez-pz/pathz--namer z "my name"zmy namer r )rsÚjoinr!rrr )rÚargsr#rrrÚtest_good_argssz%CustomRunCLIargsokTest.test_good_argsN)rrrr.rsrtrurxrrrrrp s rpc@s&eZdZdZGdd„dƒZdd„ZdS)ÚCustomRunEntryokTestz8Test entry_ok method of the CustomRun subclass of Query.c@s&eZdZejjZiZeƒZdd„Z dS)z$CustomRunEntryokTest.Dummy_CustomRuncCs|jS)N)Úcli_args)rrrrrr+sz0CustomRunEntryokTest.Dummy_CustomRun.cli_args_okN) rrrrrqrr rÚ restartvarrrrrrrrs'srsc Csx| ¡}xjdD]b}|j |¡xPddgdg|fffD]8\}}|j||d��||_| | ¡|¡WdQRXq4WqWdS)N>FT)NNzmy arg)Úrestartrz)rsr{rWrVrzr!r)rr#r|rzrrrrÚtest_entry_ok_customrun.s  z,CustomRunEntryokTest.test_entry_ok_customrunN)rrrr.rsr}rrrrry$sryc@sDeZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d S)Ú QueryGuiTestcCsBtdƒtƒ|_}|j ¡tj|dddd�|_t ¡|j_ dS)NÚguiZTESTZtestT)Ú_utest) rrÚrootÚwithdrawrrr#rr(r)rar�rrrÚ setUpClass=s   zQueryGuiTest.setUpClasscCs|j`|`|j ¡|`dS)N)r#rr�)rarrrrbEs zQueryGuiTest.tearDownClasscCs(|jj dd¡d|j_|jj ¡dS)NrÚend)r#r ÚdeleterrZ reset_mock)rrrrÚsetUpLszQueryGuiTest.setUpcCs>|j}|j dd¡|j ¡| |jd¡| |jj ¡dS)NrÚabc) r#r ÚinsertÚ button_okÚinvoker!rr)rr*)rr#rrrÚ test_click_okQs  zQueryGuiTest.test_click_okcCs0|j}|j ¡| |jd¡| |jj¡dS)N)r#r‰rŠr!rZ assertFalserr*)rr#rrrÚtest_click_blankXs zQueryGuiTest.test_click_blankcCs>|j}|j dd¡|j ¡| |jd¡| |jj ¡dS)Nrr‡) r#r rˆZ button_cancelrŠr!rr)rr*)rr#rrrÚtest_click_cancel^s  zQueryGuiTest.test_click_cancelN) rrrrjrƒrbr†r‹rŒr�rrrrr~;s   r~c@s eZdZedd„ƒZdd„ZdS)ÚSectionnameGuiTestcCs tdƒdS)Nr)r)rarrrrƒhszSectionnameGuiTest.setUpClasscCsltƒ}| ¡tj|dddhdd�}|j}| |jdh¡|j dd¡|j  ¡| |j d¡|  ¡dS)NÚTÚtr‡T)r€rZokay) rr‚rr1r!r2r rˆr‰rŠrr)rr�r#r&rrrÚtest_click_section_namels z*SectionnameGuiTest.test_click_section_nameN)rrrrjrƒr‘rrrrrŽfs rŽc@s eZdZedd„ƒZdd„ZdS)ÚModulenameGuiTestcCs tdƒdS)Nr)r)rarrrrƒzszModulenameGuiTest.setUpClasscCsjtƒ}| ¡tj|ddddd�}| |jd¡| |j ¡d¡|j  ¡|  |j   d¡¡|  ¡dS)Nr�r�r@T)r€z __init__.py)rr‚rr9r!r:r rXr‰rŠr)rrAr)rr�r#rrrÚtest_click_module_name~s z(ModulenameGuiTest.test_click_module_nameN)rrrrjrƒr“rrrrr’xs r’c@s eZdZedd„ƒZdd„ZdS)Ú GotoGuiTestcCs tdƒdS)Nr)r)rarrrrƒ‹szGotoGuiTest.setUpClasscCsRtƒ}| ¡tj|dddd�}|j dd¡|j ¡| |j d¡|  ¡dS)Nr�r�T)r€rZ22é) rr‚rrDr rˆr‰rŠr!rr)rr�r#rrrr“�s z"GotoGuiTest.test_click_module_nameN)rrrrjrƒr“rrrrr”‰s r”c@s eZdZedd„ƒZdd„ZdS)ÚHelpsourceGuiTestcCs tdƒdS)Nr)r)rarrrrƒ›szHelpsourceGuiTest.setUpClasscCs„tƒ}| ¡tj|ddtdd�}|j}||j ¡dƒ||j ¡tƒ|j   ¡t j dkr`dnd}||j d|tfƒ| ¡dS)Nr�Z__test__T)ZmenuitemÚfilepathr€rfzfile://r )rr‚rrMrUr!r rXrYr‰rŠÚsysr`rr)rr�r#r&rhrrrÚtest_click_help_sourceŸs   z(HelpsourceGuiTest.test_click_help_sourceN)rrrrjrƒr™rrrrr–™s r–c@s eZdZedd„ƒZdd„ZdS)ÚCustomRunGuiTestcCs tdƒdS)Nr)r)rarrrrƒ¯szCustomRunGuiTest.setUpClasscCsrtƒ}| ¡tj|dddgdd�}| |j ¡d¡|j td¡|j   ¡| |j dddgdf¡|  ¡dS) NZTitlerEzb=1T)rzr€za b=1z crR) rr‚rrqr!r rXrˆrr‰rŠrr)rr�r#rrrÚtest_click_args³s z CustomRunGuiTest.test_click_argsN)rrrrjrƒr›rrrrrš­s ršÚ__main__éF)Ú verbosityÚexit)r.r@rZunittestZ test.supportrZtkinterrrr˜rZidlelib.idle_test.mock_tkrZTestCaserr/r8rCrLr\rkrpryr~rŽr’r”r–ršrÚmainrrrrÚ s0    3!!-+