3 § fø-ã@s&dZddlmZddlZddlmZddlmZddlZddlm Z ddl m Z Gdd „d ej ƒZ Gd d „d ej ƒZGd d „d ej ƒZejZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZedk�r"ejddd�dS) a½Test query, coverage 91%). 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)Úmock)ÚVarc@sFeZdZdZGdd„dƒZdd„Zdd„Zdd „Zd d „Zd d „Z dS)Ú QueryTestzTest Query base class.c@sFeZdZejjZejjZejjZeƒZ iZ dd„Z dd„Z dd„Z dS)zQueryTest.Dummy_QuerycCs&|jj|ƒd|jd<d|_d|_dS)NÚÚtextF)ÚentryÚsetÚ entry_errorÚresultÚ destroyed)ÚselfÚ dummy_entry©rúA/opt/alt/python36/lib64/python3.6/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Úcancelrr r rrrrrrrÚ Dummy_QuerysrcCsD|jdƒ}|j|jƒdƒ|j|j|jfdƒ|jd|jdƒdS)Nú Fz blank liner )NF)rÚ assertEqualrr rÚassertInr )rÚdialogrrrÚtest_entry_ok_blank-s zQueryTest.test_entry_ok_blankcCsD|jdƒ}|j}||jƒdƒ||j|jfdƒ||jddƒdS)Nz good ÚgoodFr r)NF)rr rr rr )rr"ÚEqualrrrÚtest_entry_ok_good3s  zQueryTest.test_entry_ok_goodcCsT|jdƒ}tjƒ|j_|j|jƒdƒ|j|jjjƒ|j`|j|j |j fdƒdS)NrF)NF) rrÚMockr Z focus_setr rÚ assertTrueÚcalledr r)rr"rrrÚ test_ok_blank:s   zQueryTest.test_ok_blankcCs2|jdƒ}|j|jƒdƒ|j|j|jfdƒdS)Nr$T)r$T)rr rr r)rr"rrrÚ test_ok_goodBs zQueryTest.test_ok_goodcCs2|jdƒ}|j|jƒdƒ|j|j|jfdƒdS)Nzdoes not matterT)NT)rr rr r)rr"rrrÚ test_cancelGs 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@s4eZdZejjZdgZeƒZiZ dd„Z dd„Z dS)z!SectionNameTest.Dummy_SectionNameÚusedcCs|jj|ƒd|jd<dS)Nrr )r r r )rrrrrrUs z*SectionNameTest.Dummy_SectionName.__init__cCs||jd<dS)Nr )r )rrrrrrXsz+SectionNameTest.Dummy_SectionName.showerrorN) rrrrÚ SectionNamerÚ used_namesrr r rrrrrrÚDummy_SectionNamePs r2cCs0|jdƒ}|j|jƒdƒ|jd|jdƒdS)Nrzno namer )r2r rr!r )rr"rrrÚtest_blank_section_name[s z'SectionNameTest.test_blank_section_namecCs0|jdƒ}|j|jƒdƒ|jd|jdƒdS)Nr/Zuser )r2r rr!r )rr"rrrÚtest_used_section_name`s z&SectionNameTest.test_used_section_namecCs4|jddƒ}|j|jƒdƒ|jd|jdƒdS)Nr$ézlonger than 30r )r2r rr!r )rr"rrrÚtest_long_section_nameesz&SectionNameTest.test_long_section_namecCs0|jdƒ}|j|jƒdƒ|j|jddƒdS)Nz good r$r r)r2r rr )rr"rrrÚtest_good_section_namejs z&SectionNameTest.test_good_section_nameN) rrrr-r2r3r4r6r7rrrrr.Ms  r.c@s>eZdZdZGdd„dƒZdd„Zdd„Zdd „Zd d „Zd S) ÚModuleNameTestz"Test ModuleName subclass of Query.c@s2eZdZejjZdZeƒZiZ dd„Z dd„Z dS)zModuleNameTest.Dummy_ModuleNamercCs|jj|ƒd|jd<dS)Nrr )r r r )rrrrrrxs z(ModuleNameTest.Dummy_ModuleName.__init__cCs||jd<dS)Nr )r )rrrrrr{sz)ModuleNameTest.Dummy_ModuleName.showerrorN) rrrrÚ ModuleNamerÚtext0rr r rrrrrrÚDummy_ModuleNamess r;cCs0|jdƒ}|j|jƒdƒ|jd|jdƒdS)Nrzno namer )r;r rr!r )rr"rrrÚtest_blank_module_name~s z%ModuleNameTest.test_blank_module_namecCs0|jdƒ}|j|jƒdƒ|jd|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|jdƒ}|j|jƒdƒ|jd|jdƒdS)NÚ itertoolsz source-basedr )r;r rr!r )rr"rrrÚtest_c_source_nameˆs z!ModuleNameTest.test_c_source_namecCs4|jdƒ}|j|jƒjdƒƒ|j|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?rBrrrrr8ps  r8c@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šsrGc Cs�|jƒ}x‚ddd„dfddd„tfddd„dfddd„tffD]J\}}}|jƒ�2|jj|ƒ||_|jƒ|j|jjƒ|ƒWdQRXq>WdS)NrcSsdS)Nrr)ÚaÚbÚcrrrÚ¥szBHelpsourceBrowsefileTest.test_file_replaces_path..cSstS)N)Ú__file__)rHrIrJrrrrK¦sZhtestcSsdS)Nrr)rHrIrJrrrrK§scSstS)N)rL)rHrIrJrrrrK¨s) rGrLÚsubTestrFr Z askfilenamerEr Úget)rr"ÚpathÚfuncr rrrÚtest_file_replaces_pathžs     z0HelpsourceBrowsefileTest.test_file_replaces_pathN)rrrr-rGrQrrrrrC—srCc@sJeZdZdZGdd„dƒZedd„ƒZdd„Zdd „Zd d „Z d d „Z dS)ÚHelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c@s0eZdZejjZeƒZiZdd„Z ddd„Z dS)z%HelpsourcePathokTest.Dummy_HelpSourcecCs|jj|ƒd|jd<dS)Nrr )rOr Ú path_error)rZ dummy_pathrrrr·s z.HelpsourcePathokTest.Dummy_HelpSource.__init__NcCs||jd<dS)Nr )rS)rrZwidgetrrrrºsz/HelpsourcePathokTest.Dummy_HelpSource.showerror)N) rrrrrDÚpath_okrrOrSrrrrrrrG³s rGcCs tt_dS)N)Ú orig_platformrÚplatform)ÚclsrrrÚ tearDownClass½sz"HelpsourcePathokTest.tearDownClasscCs0|jdƒ}|j|jƒdƒ|jd|jdƒdS)Nrz no help filer )rGr rTr!rS)rr"rrrÚtest_path_ok_blankÁs z'HelpsourcePathokTest.test_path_ok_blankcCs4|jtdƒ}|j|jƒdƒ|jd|jdƒdS)Nz bad-bad-badz not existr )rGrLr rTr!rS)rr"rrrÚtest_path_ok_badÆsz%HelpsourcePathokTest.test_path_ok_badc Csd|jdƒ}|j}xNdD]F}|jƒ�4|jj|ƒ|j|jƒ|ƒ|j|jddƒWdQRXqWdS)Nrú www.py.orgú http://py.orgr )r[r\)rGr rMrOr rTrS)rr"r%ZurlrrrÚtest_path_ok_webËs    z%HelpsourcePathokTest.test_path_ok_webc Csl|jdƒ}x\dD]T\}}|jƒ�>|t_|jjtƒ|j|jƒ|tƒ|j|j ddƒWdQRXqWdS) NrÚdarwinúfile://Úotherr ©r^r_©r`r)rarb) rGrMrrVrOr rLr rTrS)rr"rVÚprefixrrrÚtest_path_ok_fileÔs   z&HelpsourcePathokTest.test_path_ok_fileN) rrrr-rGÚ classmethodrXrYrZr]rdrrrrrR°s  rRc@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)rO)rrrrrTçsz.HelpsourceEntryokTest.Dummy_HelpSource.path_okN) rrrrrDrr rSrhrTrrrrrGás rGc CsR|jƒ}xDdD]<\}}}|jƒ�$|||_|_|j|jƒ|ƒWdQRXqWdS) Núdoc.txtÚdoc©NNN©NriN©rjNN©rjri©rjrirn)rkrlrmro)rGrMrgrOr r)rr"rgrOr rrrÚtest_entry_ok_helpsourceês z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)rrrr-rGrprrrrrfÞs rfc@sDeZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d S)Ú QueryGuiTestcCsBtdƒtƒ|_}|jjƒtj|dddd�|_tjƒ|j_ dS)NÚguiZTESTZtestT)Ú_utest) rrÚrootÚwithdrawrrr"rr'r)rWrtrrrÚ setUpClassùs   zQueryGuiTest.setUpClasscCs|j`|`|jjƒ|`dS)N)r"rrt)rWrrrrXs zQueryGuiTest.tearDownClasscCs(|jjjddƒd|j_|jjjƒdS)NrÚend)r"r Údeleter rZ reset_mock)rrrrÚsetUpszQueryGuiTest.setUpcCs>|j}|jjddƒ|jjƒ|j|jdƒ|j|jj ƒdS)NrÚabc) r"r ÚinsertÚ button_okÚinvoker r r(rr))rr"rrrÚ test_click_ok s  zQueryGuiTest.test_click_okcCs0|j}|jjƒ|j|jdƒ|j|jjƒdS)N)r"r|r}r r Z assertFalserr))rr"rrrÚtest_click_blanks zQueryGuiTest.test_click_blankcCs>|j}|jjddƒ|jjƒ|j|jdƒ|j|jj ƒdS)Nrrz) r"r r{Z button_cancelr}r r r(rr))rr"rrrÚtest_click_cancels  zQueryGuiTest.test_click_cancelN) rrrrervrXryr~rr€rrrrrq÷s   rqc@s eZdZedd„ƒZdd„ZdS)ÚSectionnameGuiTestcCs tdƒdS)Nrr)r)rWrrrrv$szSectionnameGuiTest.setUpClasscCsptƒ}|jƒtj|dddhdd�}|j}|j|jdhƒ|jjddƒ|jj ƒ|j|j dƒ~|j ƒ~dS)NÚTÚtrzT)rsrZokay) rrurr0r r1r r{r|r}r r)rrtr"r%rrrÚtest_click_section_name(s z*SectionnameGuiTest.test_click_section_nameN)rrrrervr„rrrrr�"s r�c@s eZdZedd„ƒZdd„ZdS)ÚModulenameGuiTestcCs tdƒdS)Nrr)r)rWrrrrv8szModulenameGuiTest.setUpClasscCsntƒ}|jƒtj|ddddd�}|j|jdƒ|j|jjƒdƒ|jj ƒ|j |j j dƒƒ~|j ƒ~dS)Nr‚rƒr@T)rsz __init__.py)rrurr9r r:r rNr|r}r(r rAr)rrtr"rrrÚtest_click_module_name<s z(ModulenameGuiTest.test_click_module_nameN)rrrrervr†rrrrr…6s r…c@s eZdZedd„ƒZdd„ZdS)ÚHelpsourceGuiTestcCs tdƒdS)Nrr)r)rWrrrrvKszHelpsourceGuiTest.setUpClasscCsˆtƒ}|jƒtj|ddtdd�}|j}||jjƒdƒ||jjƒtƒ|j j ƒt j dkr`dnd}||j d|tfƒ~|jƒ~dS)Nr‚Z__test__T)ZmenuitemÚfilepathrsr^zfile://r)rrurrDrLr r rNrOr|r}ÚsysrVr r)rrtr"r%rcrrrÚtest_click_help_sourceOs   z(HelpsourceGuiTest.test_click_help_sourceN)rrrrervrŠrrrrr‡Is r‡Ú__main__éF)Ú verbosityÚexit)r-r@rZunittestZ test.supportrZtkinterrr‰rZidlelib.idle_test.mock_tkrZTestCaserr.r8rVrUrCrRrfrqr�r…r‡rÚmainrrrrÚ s(     5#%.+