3 *ja-@s&dZddlmZddlZddlmZddlmZddlZddlm Z ddl m Z Gdd d ej Z Gd d d ej ZGd d d ej ZejZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej Zedkr"ejddddS) aTest 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@sFeZdZdZGdddZddZddZdd Zd d Zd d Z dS) QueryTestzTest Query base class.c@sFeZdZejjZejjZejjZeZ iZ ddZ ddZ ddZ dS)zQueryTest.Dummy_QuerycCs&|jj|d|jd<d|_d|_dS)NtextF)entryset entry_errorresult destroyed)self dummy_entryrA/opt/alt/python36/lib64/python3.6/idlelib/idle_test/test_query.py__init__#s  zQueryTest.Dummy_Query.__init__cCs||jd<dS)Nr )r )rmessagerrr showerror(szQueryTest.Dummy_Query.showerrorcCs d|_dS)NT)r)rrrrdestroy*szQueryTest.Dummy_Query.destroyN)__name__ __module__ __qualname__rQueryentry_okokcancelrr r rrrrrrr Dummy_QuerysrcCsD|jd}|j|jd|j|j|jfd|jd|jddS)N Fz blank liner )NF)r assertEqualrr rassertInr )rdialogrrrtest_entry_ok_blank-s zQueryTest.test_entry_ok_blankcCsD|jd}|j}||jd||j|jfd||jdddS)Nz good goodFr r)NF)rr rr rr )rr"Equalrrrtest_entry_ok_good3s  zQueryTest.test_entry_ok_goodcCsT|jd}tj|j_|j|jd|j|jjj|j`|j|j |j fddS)NrF)NF) rrMockr Z focus_setr r assertTruecalledr r)rr"rrr test_ok_blank:s   zQueryTest.test_ok_blankcCs2|jd}|j|jd|j|j|jfddS)Nr$T)r$T)rr rr r)rr"rrr test_ok_goodBs zQueryTest.test_ok_goodcCs2|jd}|j|jd|j|j|jfddS)Nzdoes not matterT)NT)rr rr r)rr"rrr test_cancelGs zQueryTest.test_cancelN) rrr__doc__rr#r&r*r+r,rrrrrsrc@s>eZdZdZGdddZddZddZdd Zd d Zd S) SectionNameTestz#Test SectionName subclass of Query.c@s4eZdZejjZdgZeZiZ ddZ ddZ dS)z!SectionNameTest.Dummy_SectionNameusedcCs|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 rrrrrrDummy_SectionNamePs r2cCs0|jd}|j|jd|jd|jddS)Nrzno namer )r2r rr!r )rr"rrrtest_blank_section_name[s z'SectionNameTest.test_blank_section_namecCs0|jd}|j|jd|jd|jddS)Nr/Zuser )r2r rr!r )rr"rrrtest_used_section_name`s z&SectionNameTest.test_used_section_namecCs4|jdd}|j|jd|jd|jddS)Nr$zlonger than 30r )r2r rr!r )rr"rrrtest_long_section_nameesz&SectionNameTest.test_long_section_namecCs0|jd}|j|jd|j|jdddS)Nz good r$r r)r2r rr )rr"rrrtest_good_section_namejs z&SectionNameTest.test_good_section_nameN) rrrr-r2r3r4r6r7rrrrr.Ms  r.c@s>eZdZdZGdddZddZddZdd Zd d Zd S) ModuleNameTestz"Test ModuleName subclass of Query.c@s2eZdZejjZdZeZiZ ddZ ddZ 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 ModuleNamertext0rr r rrrrrrDummy_ModuleNamess r;cCs0|jd}|j|jd|jd|jddS)Nrzno namer )r;r rr!r )rr"rrrtest_blank_module_name~s z%ModuleNameTest.test_blank_module_namecCs0|jd}|j|jd|jd|jddS)NZ __name_xyz123_should_not_exist__z not foundr )r;r rr!r )rr"rrrtest_bogus_module_names z%ModuleNameTest.test_bogus_module_namecCs0|jd}|j|jd|jd|jddS)N itertoolsz source-basedr )r;r rr!r )rr"rrrtest_c_source_names z!ModuleNameTest.test_c_source_namecCs4|jd}|j|jjd|j|jdddS)Nidlelibz __init__.pyr r)r;r(rendswithr r )rr"rrrtest_good_module_names z$ModuleNameTest.test_good_module_nameN) rrrr-r;r<r=r?rBrrrrr8ps  r8c@s&eZdZdZGdddZddZdS)HelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c@seZdZejjZeZdS)z)HelpsourceBrowsefileTest.Dummy_HelpSourceN)rrrr HelpSource browse_filerpathvarrrrrDummy_HelpSourcesrGc Cs|j}xddddfdddtfddddfdddtffD]J\}}}|j2|jj|||_|j|j|jj|WdQRXq>WdS)NrcSsdS)Nrr)abcrrrszBHelpsourceBrowsefileTest.test_file_replaces_path..cSstS)N)__file__)rHrIrJrrrrKsZhtestcSsdS)Nrr)rHrIrJrrrrKscSstS)N)rL)rHrIrJrrrrKs) rGrLsubTestrFr Z askfilenamerEr get)rr"pathfuncr rrrtest_file_replaces_paths     z0HelpsourceBrowsefileTest.test_file_replaces_pathN)rrrr-rGrQrrrrrCsrCc@sJeZdZdZGdddZeddZddZdd Zd d Z d d Z dS)HelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c@s0eZdZejjZeZiZddZ dddZ dS)z%HelpsourcePathokTest.Dummy_HelpSourcecCs|jj|d|jd<dS)Nrr )rOr path_error)rZ dummy_pathrrrrs z.HelpsourcePathokTest.Dummy_HelpSource.__init__NcCs||jd<dS)Nr )rS)rrZwidgetrrrrsz/HelpsourcePathokTest.Dummy_HelpSource.showerror)N) rrrrrDpath_okrrOrSrrrrrrrGs rGcCs tt_dS)N) orig_platformrplatform)clsrrr tearDownClasssz"HelpsourcePathokTest.tearDownClasscCs0|jd}|j|jd|jd|jddS)Nrz no help filer )rGr rTr!rS)rr"rrrtest_path_ok_blanks z'HelpsourcePathokTest.test_path_ok_blankcCs4|jtd}|j|jd|jd|jddS)Nz bad-bad-badz not existr )rGrLr rTr!rS)rr"rrrtest_path_ok_badsz%HelpsourcePathokTest.test_path_ok_badc Csd|jd}|j}xNdD]F}|j4|jj||j|j||j|jddWdQRXqWdS)Nr www.py.org http://py.orgr )r[r\)rGr rMrOr rTrS)rr"r%Zurlrrrtest_path_ok_webs    z%HelpsourcePathokTest.test_path_ok_webc Csl|jd}x\dD]T\}}|j>|t_|jjt|j|j|t|j|j ddWdQRXqWdS) Nrdarwinfile://otherr r^r_r`r)rarb) rGrMrrVrOr rLr rTrS)rr"rVprefixrrrtest_path_ok_files   z&HelpsourcePathokTest.test_path_ok_fileN) rrrr-rG classmethodrXrYrZr]rdrrrrrRs  rRc@s&eZdZdZGdddZddZdS)HelpsourceEntryokTestz5Test entry_ok method of HelpSource subclass of Query.c@s,eZdZejjZiZiZddZddZ dS)z&HelpsourceEntryokTest.Dummy_HelpSourcecCs|jS)N)name)rrrritem_oksz.HelpsourceEntryokTest.Dummy_HelpSource.item_okcCs|jS)N)rO)rrrrrTsz.HelpsourceEntryokTest.Dummy_HelpSource.path_okN) rrrrrDrr rSrhrTrrrrrGs rGc CsR|j}xDdD]<\}}}|j$|||_|_|j|j|WdQRXqWdS) Ndoc.txtdocNNNNriNrjNNrjrirjrirn)rkrlrmro)rGrMrgrOr r)rr"rgrOr rrrtest_entry_ok_helpsources z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)rrrr-rGrprrrrrfs rfc@sDeZdZeddZeddZddZddZd d Zd d Z d S) QueryGuiTestcCsBtdt|_}|jjtj|dddd|_tj|j_ dS)NguiZTESTZtestT)_utest) rrrootwithdrawrrr"rr'r)rWrtrrr setUpClasss   zQueryGuiTest.setUpClasscCs|j`|`|jj|`dS)N)r"rrt)rWrrrrXs zQueryGuiTest.tearDownClasscCs(|jjjddd|j_|jjjdS)Nrend)r"r deleter rZ reset_mock)rrrrsetUpszQueryGuiTest.setUpcCs>|j}|jjdd|jj|j|jd|j|jj dS)Nrabc) r"r insert button_okinvoker r r(rr))rr"rrr test_click_ok s  zQueryGuiTest.test_click_okcCs0|j}|jj|j|jd|j|jjdS)N)r"r|r}r r Z assertFalserr))rr"rrrtest_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"rrrtest_click_cancels  zQueryGuiTest.test_click_cancelN) rrrrervrXryr~rrrrrrrqs   rqc@s eZdZeddZddZdS)SectionnameGuiTestcCs tddS)Nrr)r)rWrrrrv$szSectionnameGuiTest.setUpClasscCspt}|jtj|dddhdd}|j}|j|jdh|jjdd|jj |j|j d~|j ~dS)NTtrzT)rsrZokay) rrurr0r r1r r{r|r}r r)rrtr"r%rrrtest_click_section_name(s z*SectionnameGuiTest.test_click_section_nameN)rrrrervrrrrrr"s rc@s eZdZeddZddZdS)ModulenameGuiTestcCs tddS)Nrr)r)rWrrrrv8szModulenameGuiTest.setUpClasscCsnt}|jtj|ddddd}|j|jd|j|jjd|jj |j |j j d~|j ~dS)Nrrr@T)rsz __init__.py)rrurr9r r:r rNr|r}r(r rAr)rrtr"rrrtest_click_module_name<s z(ModulenameGuiTest.test_click_module_nameN)rrrrervrrrrrr6s rc@s eZdZeddZddZdS)HelpsourceGuiTestcCs tddS)Nrr)r)rWrrrrvKszHelpsourceGuiTest.setUpClasscCst}|jtj|ddtdd}|j}||jjd||jjt|j j t j dkr`dnd}||j d|tf~|j~dS)NrZ__test__T)Zmenuitemfilepathrsr^zfile://r)rrurrDrLr r rNrOr|r}sysrVr r)rrtr"r%rcrrrtest_click_help_sourceOs   z(HelpsourceGuiTest.test_click_help_sourceN)rrrrervrrrrrrIs r__main__F) verbosityexit)r-r@rZunittestZ test.supportrZtkinterrrrZidlelib.idle_test.mock_tkrZTestCaserr.r8rVrUrCrRrfrqrrrrmainrrrr s(     5#%.+