B  f;@s~dZddlmZddlZddlmZddlmZmZddl Z ddlm Z ddl m Z Gdd d ej ZGd d d ej ZGd d d ej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGdddej ZGd d!d!ej ZGd"d#d#ej ZGd$d%d%ej Zed&krzejd'd(d)dS)*aTest 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)TkEND)mock)Varc@sFeZdZdZGdddZddZddZdd Zd d Zd d Z dS) QueryTestzTest Query base class.c@s<eZdZejjZejjZejjZddZddZ ddZ dS)zQueryTest.Dummy_QuerycCs&t|d|_ddi|_d|_d|_dS)N)valuetextF)rentry entry_errorresult destroyed)self dummy_entryrA/opt/alt/python37/lib64/python3.7/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_okokcancelrrrrrrr Dummy_Querys rcCsD|d}||d||j|jfd|d|jddS)N )NFz blank liner )r assertEqualrrrassertInr )rdialogrrrtest_entry_ok_blank+s zQueryTest.test_entry_ok_blankcCsD|d}|j}||d||j|jfd||jdddS)Nz good good)NFr r )rr!rrrr )rr#Equalrrrtest_entry_ok_good1s  zQueryTest.test_entry_ok_goodcCsT|d}t|j_||d||jjj|j`||j |j fddS)Nr )NF) rrMockr Z focus_setr!r assertTruecalledrr)rr#rrr test_ok_blank8s   zQueryTest.test_ok_blankcCs2|d}||d||j|jfddS)Nr%)r%T)rr!rrr)rr#rrr test_ok_good@s zQueryTest.test_ok_goodcCs2|d}||d||j|jfddS)Nzdoes not matter)NT)rr!rrr)rr#rrr test_cancelEs zQueryTest.test_cancelN) rrr__doc__rr$r'r+r,r-rrrrrsrc@s>eZdZdZGdddZddZddZdd Zd d Zd S) SectionNameTestz#Test SectionName subclass of Query.c@s*eZdZejjZdgZddZddZdS)z!SectionNameTest.Dummy_SectionNameusedcCst|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_namesrrrrrrDummy_SectionNameNsr3cCs0|d}||d|d|jddS)Nr zno namer )r3r!rr"r )rr#rrrtest_blank_section_nameWs z'SectionNameTest.test_blank_section_namecCs0|d}||d|d|jddS)Nr0Zuser )r3r!rr"r )rr#rrrtest_used_section_name\s z&SectionNameTest.test_used_section_namecCs0|d}||d|d|jddS)NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r )r3r!rr"r )rr#rrrtest_long_section_nameas z&SectionNameTest.test_long_section_namecCs0|d}||d||jdddS)Nz good r%r r )r3r!rr )rr#rrrtest_good_section_namefs z&SectionNameTest.test_good_section_nameN) rrrr.r3r4r5r6r7rrrrr/Ks  r/c@s>eZdZdZGdddZddZddZdd Zd d Zd S) ModuleNameTestz"Test ModuleName subclass of Query.c@s(eZdZejjZdZddZddZdS)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 ModuleNamertext0rrrrrrDummy_ModuleNameosr;cCs0|d}||d|d|jddS)Nr zno namer )r;r!rr"r )rr#rrrtest_blank_module_namexs z%ModuleNameTest.test_blank_module_namecCs0|d}||d|d|jddS)NZ __name_xyz123_should_not_exist__z not foundr )r;r!rr"r )rr#rrrtest_bogus_module_name}s z%ModuleNameTest.test_bogus_module_namecCs0|d}||d|d|jddS)N itertoolsz source-basedr )r;r!rr"r )rr#rrrtest_c_source_names z!ModuleNameTest.test_c_source_namecCs4|d}||d||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?rBrrrrr8ls  r8c@s6eZdZdZGdddZddZddZdd Zd S) GotoTestzTest Goto subclass of Query.c@s$eZdZejjZddZddZdS)zGotoTest.Dummy_ModuleNamecCst|d|_ddi|_dS)N)r r r )rr r )rrrrrrs z"GotoTest.Dummy_ModuleName.__init__cCs||jd<dS)Nr )r )rrrrrrsz#GotoTest.Dummy_ModuleName.showerrorN)rrrrGotorrrrrrrr;sr;cCs0|d}||d|d|jddS)Naznot a base 10 integerr )r;r!rr"r )rr#rrrtest_bogus_gotos zGotoTest.test_bogus_gotocCs0|d}||d|d|jddS)N0znot a positive integerr )r;r!rr"r )rr#rrr test_bad_gotos zGotoTest.test_bad_gotocCs0|d}||d||jdddS)N1r r )r;r!rr )rr#rrrtest_good_gotos zGotoTest.test_good_gotoN)rrrr.r;rFrHrKrrrrrCs rCc@s&eZdZdZGdddZddZdS)HelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c@seZdZejjZeZdS)z)HelpsourceBrowsefileTest.Dummy_HelpSourceN)rrrr HelpSource browse_filerpathvarrrrrDummy_HelpSourcesrPc Cs|}xddddfdddtfddddfdddtffD]J\}}}|2|j|||_|||j|WdQRXq>WdS)Nr cSsdS)Nr r)rEbcrrrzBHelpsourceBrowsefileTest.test_file_replaces_path..cSstS)N)__file__)rErQrRrrrrSrTZhtestcSsdS)Nr r)rErQrRrrrrSrTcSstS)N)rU)rErQrRrrrrSrT) rPrUsubTestrOsetZ askfilenamerNr!get)rr#pathfuncrrrrtest_file_replaces_paths     z0HelpsourceBrowsefileTest.test_file_replaces_pathN)rrrr.rPr[rrrrrLsrLc@sPeZdZdZGdddZejZeddZ ddZ dd Z d d Z d d Z dS)HelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c@s&eZdZejjZddZdddZdS)z%HelpsourcePathokTest.Dummy_HelpSourcecCst|d|_ddi|_dS)N)r r r )rrY path_error)rZ dummy_pathrrrrs z.HelpsourcePathokTest.Dummy_HelpSource.__init__NcCs||jd<dS)Nr )r])rrZwidgetrrrrsz/HelpsourcePathokTest.Dummy_HelpSource.showerror)N)rrrrrMpath_okrrrrrrrPsrPcCs |jt_dS)N) orig_platformrplatform)clsrrr tearDownClasssz"HelpsourcePathokTest.tearDownClasscCs0|d}||d|d|jddS)Nr z no help filer )rPr!r^r"r])rr#rrrtest_path_ok_blanks z'HelpsourcePathokTest.test_path_ok_blankcCs4|td}||d|d|jddS)Nz bad-bad-badz not existr )rPrUr!r^r"r])rr#rrrtest_path_ok_badsz%HelpsourcePathokTest.test_path_ok_badc Csd|d}|j}xNdD]F}|4|j||||||jddWdQRXqWdS)Nr )z www.py.orgz http://py.orgr )rPr!rVrYrWr^r])rr#r&Zurlrrrtest_path_ok_webs    z%HelpsourcePathokTest.test_path_ok_webc Csl|d}x\dD]T\}}|>|t_|jt|||t||j ddWdQRXqWdS)Nr ))darwinzfile://)otherr r ) rPrVrr`rYrWrUr!r^r])rr#r`prefixrrrtest_path_ok_files   z&HelpsourcePathokTest.test_path_ok_fileN)rrrr.rPrr`r_ classmethodrbrcrdrerirrrrr\s  r\c@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)rY)rrrrr^sz.HelpsourceEntryokTest.Dummy_HelpSource.path_okN) rrrrrMrr r]rmr^rrrrrPs rPc CsR|}xDdD]<\}}}|$|||_|_|||WdQRXqWdS)N))NNN)Nzdoc.txtN)docNN)rnzdoc.txt)rnzdoc.txt)rPrVrlrYr!r)rr#rlrYrrrrtest_entry_ok_helpsources  z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)rrrr.rProrrrrrks rkc@s6eZdZdZGdddZddZddZdd Zd S) CustomRunCLIargsokTestz6Test cli_ok method of the CustomRun subclass of Query.c@s$eZdZejjZddZddZdS)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_okrrrrrrDummy_CustomRun srscCs|d}||gdS)Nr )rsr!rr)rr#rrrtest_blank_argss z&CustomRunCLIargsokTest.test_blank_argscCs0|d}||d|d|jddS)Nz'no-closing-quotez No closingr )rsr!rrr"r )rr#rrrtest_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 )rsjoinr!rrr )rargsr#rrrtest_good_argssz%CustomRunCLIargsokTest.test_good_argsN)rrrr.rsrtrurxrrrrrp s rpc@s&eZdZdZGdddZddZdS)CustomRunEntryokTestz8Test entry_ok method of the CustomRun subclass of Query.c@s&eZdZejjZiZeZddZ 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|rzrrrrtest_entry_ok_customrun.s  z,CustomRunEntryokTest.test_entry_ok_customrunN)rrrr.rsr}rrrrry$sryc@sDeZdZeddZeddZddZddZd d Zd d Z d S) QueryGuiTestcCsBtdt|_}|jtj|dddd|_t|j_ dS)NguiZTESTZtestT)_utest) rrrootwithdrawrrr#rr(r)rarrrr setUpClass=s   zQueryGuiTest.setUpClasscCs|j`|`|j|`dS)N)r#rr)rarrrrbEs zQueryGuiTest.tearDownClasscCs(|jjddd|j_|jjdS)Nrend)r#r deleterrZ reset_mock)rrrrsetUpLszQueryGuiTest.setUpcCs>|j}|jdd|j||jd||jj dS)Nrabc) r#r insert button_okinvoker!rr)rr*)rr#rrr test_click_okQs  zQueryGuiTest.test_click_okcCs0|j}|j||jd||jjdS)N)r#rrr!rZ assertFalserr*)rr#rrrtest_click_blankXs zQueryGuiTest.test_click_blankcCs>|j}|jdd|j||jd||jj dS)Nrr) r#r rZ button_cancelrr!rr)rr*)rr#rrrtest_click_cancel^s  zQueryGuiTest.test_click_cancelN) rrrrjrrbrrrrrrrrr~;s   r~c@s eZdZeddZddZdS)SectionnameGuiTestcCs tddS)Nr)r)rarrrrhszSectionnameGuiTest.setUpClasscCslt}|tj|dddhdd}|j}||jdh|jdd|j ||j d| dS)NTtrT)rrZokay) rrrr1r!r2r rrrrr)rrr#r&rrrtest_click_section_namels z*SectionnameGuiTest.test_click_section_nameN)rrrrjrrrrrrrfs rc@s eZdZeddZddZdS)ModulenameGuiTestcCs tddS)Nr)r)rarrrrzszModulenameGuiTest.setUpClasscCsjt}|tj|ddddd}||jd||jd|j | |j d| dS)Nrrr@T)rz __init__.py)rrrr9r!r:r rXrrr)rrAr)rrr#rrrtest_click_module_name~s z(ModulenameGuiTest.test_click_module_nameN)rrrrjrrrrrrrxs rc@s eZdZeddZddZdS) GotoGuiTestcCs tddS)Nr)r)rarrrrszGotoGuiTest.setUpClasscCsRt}|tj|dddd}|jdd|j||j d| dS)NrrT)rrZ22) rrrrDr rrrr!rr)rrr#rrrrs z"GotoGuiTest.test_click_module_nameN)rrrrjrrrrrrrs rc@s eZdZeddZddZdS)HelpsourceGuiTestcCs tddS)Nr)r)rarrrrszHelpsourceGuiTest.setUpClasscCst}|tj|ddtdd}|j}||jd||jt|j t j dkr`dnd}||j d|tf|dS)NrZ__test__T)Zmenuitemfilepathrrfzfile://r )rrrrMrUr!r rXrYrrsysr`rr)rrr#r&rhrrrtest_click_help_sources   z(HelpsourceGuiTest.test_click_help_sourceN)rrrrjrrrrrrrs rc@s eZdZeddZddZdS)CustomRunGuiTestcCs tddS)Nr)r)rarrrrszCustomRunGuiTest.setUpClasscCsrt}|tj|dddgdd}||jd|jtd|j ||j dddgdf| dS) NZTitlerEzb=1T)rzrza b=1z crR) rrrrqr!r rXrrrrrr)rrr#rrrtest_click_argss z CustomRunGuiTest.test_click_argsN)rrrrjrrrrrrrs r__main__F) verbosityexit)r.r@rZunittestZ test.supportrZtkinterrrrrZidlelib.idle_test.mock_tkrZTestCaserr/r8rCrLr\rkrpryr~rrrrrrmainrrrr s0    3!!-+