a  ze^<@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. )queryNrequires)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)NvaluetextF)rentry entry_errorresult destroyedselfZ dummy_entryrP/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/idle_test/test_query.py__init__!s  zQueryTest.Dummy_Query.__init__cCs||jd<dSNr rrmessagerrr showerror&szQueryTest.Dummy_Query.showerrorcCs d|_dSNT)rrrrrdestroy(szQueryTest.Dummy_Query.destroyN) __name__ __module__ __qualname__rQueryentry_okokcancelrrrrrrr Dummy_Querys r&cCsD|d}||d||j|jfd|d|jddS)N NFz blank liner )r& assertEqualr#rrassertInrrdialogrrrtest_entry_ok_blank+s zQueryTest.test_entry_ok_blankcCsD|d}|j}||d||j|jfd||jdddS)N good goodr(r r )r&r)r#rrr)rr,Equalrrrtest_entry_ok_good1s  zQueryTest.test_entry_ok_goodcCsT|d}t|j_||d||jjj|j`||j |j fddS)Nr r() r&rMockrZ focus_setr)r$ assertTruecalledrrr+rrr test_ok_blank8s   zQueryTest.test_ok_blankcCs2|d}||d||j|jfddS)Nr/)r/T)r&r)r$rrr+rrr test_ok_good@s zQueryTest.test_ok_goodcCs2|d}||d||j|jfddS)Nzdoes not matterr)r&r)r%rrr+rrr test_cancelEs zQueryTest.test_cancelN) rr r!__doc__r&r-r1r5r6r7rrrrr sr c@s>eZdZdZGdddZddZddZdd Zd d Zd S) SectionNameTestz#Test SectionName subclass of Query.c@s*eZdZejjZdgZddZddZdS)z!SectionNameTest.Dummy_SectionNameusedcCst|d|_ddi|_dSNr r r rrrrrrrrQs z*SectionNameTest.Dummy_SectionName.__init__cCs||jd<dSrrrrrrrTsz+SectionNameTest.Dummy_SectionName.showerrorN) rr r!r SectionNamer# used_namesrrrrrrDummy_SectionNameNsr?cCs0|d}||d|d|jddSNr'zno namer r?r)r#r*rr+rrrtest_blank_section_nameWs z'SectionNameTest.test_blank_section_namecCs0|d}||d|d|jddS)Nr:Zuser rAr+rrrtest_used_section_name\s z&SectionNameTest.test_used_section_namecCs0|d}||d|d|jddS)NZ goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r rAr+rrrtest_long_section_nameas z&SectionNameTest.test_long_section_namecCs0|d}||d||jdddS)Nr.r/r r )r?r)r#rr+rrrtest_good_section_namefs z&SectionNameTest.test_good_section_nameN) rr r!r8r?rBrCrDrErrrrr9Ks  r9c@s>eZdZdZGdddZddZddZdd Zd d Zd S) ModuleNameTestz"Test ModuleName subclass of Query.c@s(eZdZejjZdZddZddZdS)zModuleNameTest.Dummy_ModuleNamer cCst|d|_ddi|_dSr;r<rrrrrrs z(ModuleNameTest.Dummy_ModuleName.__init__cCs||jd<dSrrrrrrrusz)ModuleNameTest.Dummy_ModuleName.showerrorN) rr r!r ModuleNamer#text0rrrrrrDummy_ModuleNameosrIcCs0|d}||d|d|jddSr@rIr)r#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 rJr+rrrtest_bogus_module_name}s z%ModuleNameTest.test_bogus_module_namecCs0|d}||d|d|jddS)N itertoolsz source-basedr rJr+rrrtest_c_source_names z!ModuleNameTest.test_c_source_namecCsd|d}||d||jdd|d}||d||jdddS)Nidlelib __init__.pyr r z idlelib.idlezidle.py)rIr3r#endswithr)rr+rrrtest_good_module_names   z$ModuleNameTest.test_good_module_nameN) rr r!r8rIrKrLrNrRrrrrrFls  rFc@s6eZdZdZGdddZddZddZdd Zd S) GotoTestzTest Goto subclass of Query.c@s$eZdZejjZddZddZdS)zGotoTest.Dummy_ModuleNamecCst|d|_ddi|_dSr;r<rrrrrs z"GotoTest.Dummy_ModuleName.__init__cCs||jd<dSrrrrrrrsz#GotoTest.Dummy_ModuleName.showerrorN)rr r!rGotor#rrrrrrrIsrIcCs0|d}||d|d|jddS)Naznot a base 10 integerr rJr+rrrtest_bogus_gotos zGotoTest.test_bogus_gotocCs0|d}||d|d|jddS)N0znot a positive integerr rJr+rrr test_bad_gotos zGotoTest.test_bad_gotocCs0|d}||d||jdddS)N1r r )rIr)r#rr+rrrtest_good_gotos zGotoTest.test_good_gotoN)rr r!r8rIrVrXr[rrrrrSs rSc@s&eZdZdZGdddZddZdS)HelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c@seZdZejjZeZdS)z)HelpsourceBrowsefileTest.Dummy_HelpSourceN)rr r!r HelpSource browse_filerpathvarrrrrDummy_HelpSourcesr`c Cs|}ddddfdddtfddddfdddtffD]^\}}}|<|j|||_|||j|Wdq<1s0YqzBHelpsourceBrowsefileTest.test_file_replaces_path..cSstSN__file__rbrrrrerfZhtestcSsdSrarrbrrrrerfcSstSrgrhrbrrrrerf) r`risubTestr_setZ askfilenamer^r)get)rr,pathfuncrrrrtest_file_replaces_paths      z0HelpsourceBrowsefileTest.test_file_replaces_pathN)rr r!r8r`rorrrrr\sr\c@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|_dSr;)rrm path_error)rZ dummy_pathrrrrs z.HelpsourcePathokTest.Dummy_HelpSource.__init__NcCs||jd<dSr)rq)rrZwidgetrrrrsz/HelpsourcePathokTest.Dummy_HelpSource.showerror)N)rr r!rr]path_okrrrrrrr`sr`cCs |jt_dSrg) orig_platformrplatformclsrrr tearDownClasssz"HelpsourcePathokTest.tearDownClasscCs0|d}||d|d|jddS)Nr'z no help filer )r`r)rrr*rqr+rrrtest_path_ok_blanks z'HelpsourcePathokTest.test_path_ok_blankcCs4|td}||d|d|jddS)Nz bad-bad-badz not existr )r`rir)rrr*rqr+rrrtest_path_ok_badsz%HelpsourcePathokTest.test_path_ok_badc Cst|d}|j}dD]Z}|>|j||||||jddWdq1sd0YqdS)Nr )z www.py.orgz http://py.orgr )r`r)rjrmrkrrrq)rr,r0urlrrrtest_path_ok_webs   z%HelpsourcePathokTest.test_path_ok_webc Cs||d}dD]h\}}|H|t_|jt|||t||j ddWdq1sl0YqdS)Nr ))darwinfile://)otherr r ) r`rjrrtrmrkrir)rrrq)rr,rtprefixrrrtest_path_ok_files    z&HelpsourcePathokTest.test_path_ok_fileN)rr r!r8r`rrtrs classmethodrwrxryr{rrrrrrps  rpc@s&eZdZdZGdddZddZdS)HelpsourceEntryokTestz5Test entry_ok method of HelpSource subclass of Query.c@s,eZdZejjZiZiZddZddZ dS)z&HelpsourceEntryokTest.Dummy_HelpSourcecCs|jSrg)namerrrritem_oksz.HelpsourceEntryokTest.Dummy_HelpSource.item_okcCs|jSrg)rmrrrrrrsz.HelpsourceEntryokTest.Dummy_HelpSource.path_okN) rr r!rr]r#rrqrrrrrrrr`s r`c Csb|}dD]P\}}}|.|||_|_|||Wdq 1sR0Yq dS)N))NNN)Ndoc.txtN)docNN)rr)rr)r`rjrrmr)r#)rr,rrmrrrrtest_entry_ok_helpsources  z.HelpsourceEntryokTest.test_entry_ok_helpsourceN)rr r!r8r`rrrrrrs rc@s6eZdZdZGdddZddZddZdd Zd S) CustomRunCLIargsokTestz6Test cli_ok method of the CustomRun subclass of Query.c@s$eZdZejjZddZddZdS)z&CustomRunCLIargsokTest.Dummy_CustomRuncCst|d|_ddi|_dSr;r<rrrrrs z/CustomRunCLIargsokTest.Dummy_CustomRun.__init__cCs||jd<dSrrrrrrrsz0CustomRunCLIargsokTest.Dummy_CustomRun.showerrorN)rr r!r CustomRun cli_args_okrrrrrrDummy_CustomRunsrcCs|d}||gdS)Nr')rr)rr+rrrtest_blank_argss z&CustomRunCLIargsokTest.test_blank_argscCs0|d}||d|d|jddS)Nz'no-closing-quotez No closingr )rr)rr*rr+rrrtest_invalid_argss z(CustomRunCLIargsokTest.test_invalid_argscCsHgd}|d|d}|||dg||jdddS)N)z-nZ10z --verbosez-pz/pathz--namer'z "my name"zmy namer r )rjoinr)rr)rargsr,rrrtest_good_args sz%CustomRunCLIargsokTest.test_good_argsN)rr r!r8rrrrrrrrr s rc@s&eZdZdZGdddZddZdS)CustomRunEntryokTestz8Test entry_ok method of the CustomRun subclass of Query.c@s&eZdZejjZiZeZddZ dS)z$CustomRunEntryokTest.Dummy_CustomRuncCs|jSrg)cli_argsrrrrr.sz0CustomRunEntryokTest.Dummy_CustomRun.cli_args_okN) rr r!rrr#rr restartvarrrrrrr*src Cs|}dD]r}|j|ddgdg|fffD]L\}}|j||d&||_|||Wdq01sr0Yq0q dS)N>FT)NNzmy arg)restartr)rrrkrjrr)r#)rr,rrrrrrtest_entry_ok_customrun1s  z,CustomRunEntryokTest.test_entry_ok_customrunN)rr r!r8rrrrrrr'src@sDeZdZeddZeddZddZddZd d Zd d Z d S) QueryGuiTestcCsBtdt|_}|jtj|dddd|_t|j_ dS)NguiZTESTtestT_utest) rrrootwithdrawrr"r,rr2r)rvrrrr setUpClass@s   zQueryGuiTest.setUpClasscCs|j`|`|j|`dSrg)r,rrrurrrrwHs zQueryGuiTest.tearDownClasscCs(|jjddd|j_|jjdS)Nrend)r,rdeleterrZ reset_mockrrrrsetUpOszQueryGuiTest.setUpcCs>|j}|jdd|j||jd||jj dSNrabc) r,rinsert button_okinvoker)rr3rr4r+rrr test_click_okTs  zQueryGuiTest.test_click_okcCs0|j}|j||jd||jjdSrg)r,rrr)rZ assertFalserr4r+rrrtest_click_blank[s zQueryGuiTest.test_click_blankcCs>|j}|jdd|j||jd||jj dSr) r,rrZ button_cancelrr)rr3rr4r+rrrtest_click_cancelas  zQueryGuiTest.test_click_cancelN) rr r!rrrwrrrrrrrrr>s  rc@s eZdZeddZddZdS)SectionnameGuiTestcCs tddSNrrrurrrrkszSectionnameGuiTest.setUpClasscCslt}|tj|dddhdd}|j}||jdh|jdd|j ||j d| dS)NTtrTrrZokay) rrrr=r)r>rrrrrr)rrr,r0rrrtest_click_section_nameos z*SectionnameGuiTest.test_click_section_nameN)rr r!rrrrrrrris rc@s eZdZeddZddZdS)ModulenameGuiTestcCs tddSrrrurrrr}szModulenameGuiTest.setUpClasscCsjt}|tj|ddddd}||jd||jd|j | |j d| dS)NrrrOTrrP)rrrrGr)rHrrlrrr3rrQrrrr,rrrtest_click_module_names z(ModulenameGuiTest.test_click_module_nameNrr r!rrrrrrrr{s rc@s eZdZeddZddZdS) GotoGuiTestcCs tddSrrrurrrrszGotoGuiTest.setUpClasscCsRt}|tj|dddd}|jdd|j||j d| dS)NrrTrrZ22) rrrrTrrrrr)rrrrrrrs z"GotoGuiTest.test_click_module_nameNrrrrrrs rc@s eZdZeddZddZdS)HelpsourceGuiTestcCs tddSrrrurrrrszHelpsourceGuiTest.setUpClasscCst}|tj|ddtdd}|j}||jd||jt|j t j dkr`dnd}||j d|tf|dS)NrZ__test__T)Zmenuitemfilepathrr|r}r )rrrr]rir)rrlrmrrsysrtrr)rrr,r0rrrrtest_click_help_sources  z(HelpsourceGuiTest.test_click_help_sourceN)rr r!rrrrrrrrs rc@s eZdZeddZddZdS)CustomRunGuiTestcCs tddSrrrurrrrszCustomRunGuiTest.setUpClasscCspt}|tj|dddgdd}||jd|jtd|j ||j gddf| dS) NZTitlerUb=1T)rrza b=1z c)rUrrd) rrrrr)rrlrrrrrrrrrrtest_click_argss z CustomRunGuiTest.test_click_argsN)rr r!rrrrrrrrs r__main__F) verbosityexit)r8rOrZunittestZ test.supportrtkinterrrrrZidlelib.idle_test.mock_tkrZTestCaser r9rFrSr\rprrrrrrrrrrmainrrrrs0    3!$-+