
    z%i^<                        d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	Z	ddlm
Z
 ddlmZ  G d d	ej                        Z G d
 dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d dej                        Z G d  d!ej                        Z G d" d#ej                        Z G d$ d%ej                        Zed&k(  r ej<                  d'd()       yy)*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                   B    e Zd ZdZ G d d      Zd Zd Zd Zd Zd Z	y	)
	QueryTestzTest Query base class.c                       e Zd Zej                  j
                  Zej                  j                  Zej                  j                  Zd Zd Z	d Z
y)QueryTest.Dummy_Queryc                 T    t        |      | _        ddi| _        d | _        d| _        y )Nvaluetext F)r	   entryentry_errorresult	destroyedselfdummy_entrys     P/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_query.py__init__zQueryTest.Dummy_Query.__init__!   s(    ;/DJ &|DDK"DN    c                 "    || j                   d<   y Nr   r   r   messages     r   	showerrorzQueryTest.Dummy_Query.showerror&       '.DV$r   c                     d| _         y NT)r   r   s    r   destroyzQueryTest.Dummy_Query.destroy(   s	    !DNr   N)__name__
__module____qualname__r   Queryentry_okokcancelr   r"   r'    r   r   Dummy_Queryr      s<    ;;''[[^^##	#
	/	"r   r0   c                     | j                  d      }| j                  |j                         d        | j                  |j                  |j                  fd       | j                  d|j                  d          y )N NFz
blank liner   )r0   assertEqualr,   r   r   assertInr   r   dialogs     r   test_entry_ok_blankzQueryTest.test_entry_ok_blank+   sa    !!#&*D1&--)9)9:MJlF$6$6v$>?r   c                     | j                  d      }| j                  } ||j                         d        ||j                  |j                  fd        ||j
                  d   d       y )N  good goodr3   r   r   )r0   r4   r,   r   r   r   )r   r7   Equals      r   test_entry_ok_goodzQueryTest.test_entry_ok_good1   s\    !!),  foo(v}}f../?f  ("-r   c                 r   | j                  d      }t        j                         |j                  _        | j                  |j                         d        | j                  |j                  j                  j                         |j                  `| j                  |j                  |j                  fd       y )Nr   r3   )r0   r   Mockr   	focus_setr4   r-   
assertTruecalledr   r   r6   s     r   test_ok_blankzQueryTest.test_ok_blank8   s    !!"%!%d+..556LL"&--)9)9:MJr   c                     | j                  d      }| j                  |j                         d        | j                  |j                  |j                  fd       y )Nr;   )r;   T)r0   r4   r-   r   r   r6   s     r   test_ok_goodzQueryTest.test_ok_good@   sG    !!&)d+&--)9)9:NKr   c                     | j                  d      }| j                  |j                         d        | j                  |j                  |j                  fd       y )Nzdoes not matterr%   )r0   r4   r.   r   r   r6   s     r   test_cancelzQueryTest.test_cancelE   sH    !!"34$/&--)9)9:LIr   N)
r(   r)   r*   __doc__r0   r8   r=   rC   rE   rG   r/   r   r   r   r      s,    " " @.KL
Jr   r   c                   <    e Zd ZdZ G d d      Zd Zd Zd Zd Zy)	SectionNameTestz#Test SectionName subclass of Query.c                   J    e Zd Zej                  j
                  ZdgZd Zd Zy)!SectionNameTest.Dummy_SectionNameusedc                 8    t        |      | _        ddi| _        y Nr   r   r   r	   r   r   r   s     r   r   z*SectionNameTest.Dummy_SectionName.__init__Q       ;/DJ &|Dr   c                 "    || j                   d<   y r   r   r    s     r   r"   z+SectionNameTest.Dummy_SectionName.showerrorT   r#   r   N)	r(   r)   r*   r   SectionNamer,   
used_namesr   r"   r/   r   r   Dummy_SectionNamerL   N   s$    $$--X
	,	/r   rU   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y Nr2   zno namer   rU   r4   r,   r5   r   r6   s     r   test_blank_section_namez'SectionNameTest.test_blank_section_nameW   sB    '',*D1i!3!3F!;<r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )NrM   user   rX   r6   s     r   test_used_section_namez&SectionNameTest.test_used_section_name\   sB    ''/*D1eV//78r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )N goodgoodgoodgoodgoodgoodgoodgoodzlonger than 30r   rX   r6   s     r   test_long_section_namez&SectionNameTest.test_long_section_namea   sC    ''1*D1&(:(:6(BCr   c                     | j                  d      }| j                  |j                         d       | j                  |j                  d   d       y )Nr:   r;   r   r   )rU   r4   r,   r   r6   s     r   test_good_section_namez&SectionNameTest.test_good_section_namef   sD    ''	2*F3++F3R8r   N)	r(   r)   r*   rH   rU   rY   r\   r_   ra   r/   r   r   rJ   rJ   K   s$    )/ /=
9
D
9r   rJ   c                   <    e Zd ZdZ G d d      Zd Zd Zd Zd Zy)	ModuleNameTestz"Test ModuleName subclass of Query.c                   H    e Zd Zej                  j
                  ZdZd Zd Zy)ModuleNameTest.Dummy_ModuleNamer   c                 8    t        |      | _        ddi| _        y rO   rP   r   s     r   r   z(ModuleNameTest.Dummy_ModuleName.__init__r   rQ   r   c                 "    || j                   d<   y r   r   r    s     r   r"   z)ModuleNameTest.Dummy_ModuleName.showerroru   r#   r   N)	r(   r)   r*   r   
ModuleNamer,   text0r   r"   r/   r   r   Dummy_ModuleNamere   o   s"    ##,,	,	/r   rj   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y rW   rj   r4   r,   r5   r   r6   s     r   test_blank_module_namez%ModuleNameTest.test_blank_module_namex   sB    &&s+*D1i!3!3F!;<r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )N __name_xyz123_should_not_exist__z	not foundr   rl   r6   s     r   test_bogus_module_namez%ModuleNameTest.test_bogus_module_name}   sC    &&'IJ*D1k6#5#5f#=>r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )N	itertoolszsource-basedr   rl   r6   s     r   test_c_source_namez!ModuleNameTest.test_c_source_name   sB    &&{3*D1nf&8&8&@Ar   c                 |   | j                  d      }| j                  |j                         j                  d             | j	                  |j
                  d   d       | j                  d      }| j                  |j                         j                  d             | j	                  |j
                  d   d       y )Nidlelib__init__.pyr   r   zidlelib.idlezidle.py)rj   rA   r,   endswithr4   r   r6   s     r   test_good_module_namez$ModuleNameTest.test_good_module_name   s    &&y1)22=AB++F3R8&&~6)229=>++F3R8r   N)	r(   r)   r*   rH   rj   rm   rp   rs   rx   r/   r   r   rc   rc   l   s$    (/ /=
?
B
9r   rc   c                   6    e Zd ZdZ G d d      Zd Zd Zd Zy)GotoTestzTest Goto subclass of Query.c                   D    e Zd Zej                  j
                  Zd Zd Zy)GotoTest.Dummy_ModuleNamec                 8    t        |      | _        ddi| _        y rO   rP   r   s     r   r   z"GotoTest.Dummy_ModuleName.__init__   rQ   r   c                 "    || j                   d<   y r   r   r    s     r   r"   z#GotoTest.Dummy_ModuleName.showerror   r#   r   N)r(   r)   r*   r   Gotor,   r   r"   r/   r   r   rj   r|      s    ::&&	,	/r   rj   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )Naznot a base 10 integerr   rl   r6   s     r   test_bogus_gotozGotoTest.test_bogus_goto   sC    &&s+*D1-v/A/A&/IJr   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )N0znot a positive integerr   rl   r6   s     r   test_bad_gotozGotoTest.test_bad_goto   sC    &&s+*D1.0B0B60JKr   c                     | j                  d      }| j                  |j                         d       | j                  |j                  d   d       y )N1   r   r   )rj   r4   r,   r   r6   s     r   test_good_gotozGotoTest.test_good_goto   sD    &&s+*A.++F3R8r   N)r(   r)   r*   rH   rj   r   r   r   r/   r   r   rz   rz      s     "/ /K
L
9r   rz   c                   *    e Zd ZdZ G d d      Zd Zy)HelpsourceBrowsefileTestz8Test browse_file method of ModuleName subclass of Query.c                   F    e Zd Zej                  j
                  Z e       Zy))HelpsourceBrowsefileTest.Dummy_HelpSourceN)r(   r)   r*   r   
HelpSourcebrowse_filer	   pathvarr/   r   r   Dummy_HelpSourcer      s    &&22%r   r   c                 t   | j                         }dd dfdd t        fdd dfdd t        ffD ]{  \  }}}| j                         5  |j                  j	                  |       ||_        |j                          | j                  |j                  j                         |       d d d        } y # 1 sw Y   xY w)Nr   c                      yNr   r/   r   bcs      r   <lambda>zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>       r   c                     t         S N__file__r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s    8 r   htestc                      yr   r/   r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   r   r   c                     t         S r   r   r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s     r   )	r   r   subTestr   setaskfilenamer   r4   get)r   r7   pathfuncr   s        r   test_file_replaces_pathz0HelpsourceBrowsefileTest.test_file_replaces_path   s    &&( _b)+X6/730(;	#= 		?D$
  ?""4(%)"""$  !3!3!5v>	? ?		?
? ?s   AB..B7	N)r(   r)   r*   rH   r   r   r/   r   r   r   r      s    > ?r   r   c                   d    e Zd ZdZ G d d      Zej                  Zed        Z	d Z
d Zd Zd Zy	)
HelpsourcePathokTestz4Test path_ok method of HelpSource subclass of Query.c                   F    e Zd Zej                  j
                  Zd ZddZy)%HelpsourcePathokTest.Dummy_HelpSourcec                 8    t        |      | _        ddi| _        y rO   )r	   r   
path_error)r   
dummy_paths     r   r   z.HelpsourcePathokTest.Dummy_HelpSource.__init__   s    *-DI%rlDOr   Nc                 "    || j                   d<   y r   )r   )r   r!   widgets      r   r"   z/HelpsourcePathokTest.Dummy_HelpSource.showerror   s    &-DOOF#r   r   )r(   r)   r*   r   r   path_okr   r"   r/   r   r   r   r      s    ""**	+	.r   r   c                 .    | j                   t        _        y r   )orig_platformr   platformclss    r   tearDownClassz"HelpsourcePathokTest.tearDownClass   s    **r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )Nr2   zno help filer   )r   r4   r   r5   r   r6   s     r   test_path_ok_blankz'HelpsourcePathokTest.test_path_ok_blank   sB    &&s+)40nf&7&7&?@r   c                     | j                  t        dz         }| j                  |j                         d        | j	                  d|j
                  d          y )Nzbad-bad-badz	not existr   )r   r   r4   r   r5   r   r6   s     r   test_path_ok_badz%HelpsourcePathokTest.test_path_ok_bad   sG    &&x-'?@)40k6#4#4V#<=r   c                 J   | j                  d      }| j                  }dD ]u  }| j                         5  |j                  j	                  |       | j                  |j                         |       | j                  |j                  d   d       d d d        w y # 1 sw Y   xY w)Nr   )z
www.py.orgzhttp://py.orgr   )r   r4   r   r   r   r   r   )r   r7   r<   urls       r   test_path_ok_webz%HelpsourcePathokTest.test_path_ok_web   s    &&r*  0 	@C @$  !137  !2!26!:B?@ @	@@ @s   ABB"	c                 d   | j                  d      }dD ]  \  }}| j                         5  |t        _        |j                  j                  t               | j                  |j                         |t        z          | j                  |j                  d   d       d d d         y # 1 sw Y   xY w)Nr   ))darwinfile://)otherr   r   )
r   r   r   r   r   r   r   r4   r   r   )r   r7   r   prefixs       r   test_path_ok_filez&HelpsourcePathokTest.test_path_ok_file   s    &&r* D 	@Hf @!))  !16H3DE  !2!26!:B?	@ @	@@ @s   A1B&&B/	N)r(   r)   r*   rH   r   r   r   r   classmethodr   r   r   r   r   r/   r   r   r   r      sC    :. . NNM+ +A
>
@@r   r   c                   *    e Zd ZdZ G d d      Zd Zy)HelpsourceEntryokTestz5Test entry_ok method of HelpSource subclass of Query.c                   L    e Zd Zej                  j
                  Zi Zi Zd Zd Z	y)&HelpsourceEntryokTest.Dummy_HelpSourcec                     | j                   S r   )namer&   s    r   item_okz.HelpsourceEntryokTest.Dummy_HelpSource.item_ok       99r   c                     | j                   S r   )r   r&   s    r   r   z.HelpsourceEntryokTest.Dummy_HelpSource.path_ok   r   r   N)
r(   r)   r*   r   r   r,   r   r   r   r   r/   r   r   r   r      s'    ##,,
		r   r   c                     | j                         }dD ]N  \  }}}| j                         5  ||c|_        |_        | j	                  |j                         |       d d d        P y # 1 sw Y   [xY w)N))NNN)Ndoc.txtN)docNN)r   r   )r   r   )r   r   r   r   r4   r,   )r   r7   r   r   r   s        r   test_entry_ok_helpsourcez.HelpsourceEntryokTest.test_entry_ok_helpsource   su    &&(#K 	<D$  <+/(V[  !2F;< <		<< <s   0A%%A.	N)r(   r)   r*   rH   r   r   r/   r   r   r   r      s    ; <r   r   c                   6    e Zd ZdZ G d d      Zd Zd Zd Zy)CustomRunCLIargsokTestz6Test cli_ok method of the CustomRun subclass of Query.c                   D    e Zd Zej                  j
                  Zd Zd Zy)&CustomRunCLIargsokTest.Dummy_CustomRunc                 8    t        |      | _        ddi| _        y rO   rP   r   s     r   r   z/CustomRunCLIargsokTest.Dummy_CustomRun.__init__  rQ   r   c                 "    || j                   d<   y r   r   r    s     r   r"   z0CustomRunCLIargsokTest.Dummy_CustomRun.showerror  r#   r   N)r(   r)   r*   r   	CustomRuncli_args_okr   r"   r/   r   r   Dummy_CustomRunr     s    oo11	,	/r   r   c                 f    | j                  d      }| j                  |j                         g        y )Nr2   )r   r4   r   r6   s     r   test_blank_argsz&CustomRunCLIargsokTest.test_blank_args  s+    %%c*++-r2r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )Nz'no-closing-quotez
No closingr   )r   r4   r   r5   r   r6   s     r   test_invalid_argsz(CustomRunCLIargsokTest.test_invalid_args  sE    %%&9:++-t4lF$6$6v$>?r   c                     g d}| j                  dj                  |      dz         }| j                  |j                         |dgz          | j                  |j                  d   d       y )N)z-n10z	--verbosez-pz/pathz--namer2   z
 "my name"zmy namer   r   )r   joinr4   r   r   )r   argsr7   s      r   test_good_argsz%CustomRunCLIargsokTest.test_good_args   s_    A%%chhtn|&CD++-tyk/AB++F3R8r   N)r(   r)   r*   rH   r   r   r   r   r/   r   r   r   r     s    </ /3@
9r   r   c                   *    e Zd ZdZ G d d      Zd Zy)CustomRunEntryokTestz8Test entry_ok method of the CustomRun subclass of Query.c                   P    e Zd Zej                  j
                  Zi Z e       Zd Z	y)$CustomRunEntryokTest.Dummy_CustomRunc                     | j                   S r   )cli_argsr&   s    r   r   z0CustomRunEntryokTest.Dummy_CustomRun.cli_args_ok.  s    == r   N)
r(   r)   r*   r   r   r,   r   r	   
restartvarr   r/   r   r   r   r   *  s"    ??++U
	!r   r   c                 *   | j                         }dD ]r  }|j                  j                  |       ddgdg|fffD ]H  \  }}| j                  ||      5  ||_        | j                  |j                         |       d d d        J t y # 1 sw Y   WxY w)N>   FT)NNzmy arg)restartr   )r   r   r   r   r   r4   r,   )r   r7   r   r   r   s        r   test_entry_ok_customrunz,CustomRunEntryokTest.test_entry_ok_customrun1  s    %%'$ 	@G!!'*%1'/jH:w2G%H%J @ &\\'H\E @&.FO$$V__%6?@ @@	@@ @s   (B		BN)r(   r)   r*   rH   r   r   r/   r   r   r   r   '  s    >! !@r   r   c                   D    e Zd Zed        Zed        Zd Zd Zd Zd Z	y)QueryGuiTestc                     t        d       t               x| _        }| j                  j                          t	        j
                  |ddd      | _        t        j                         | j                  _	        y )NguiTESTtestT_utest)
r   r   rootwithdrawr   r+   r7   r   r?   r'   )r   r   s     r   
setUpClasszQueryGuiTest.setUpClass@  sO    $4[[vvdC
!YY[

r   c                 X    | j                   `| ` | j                  j                          | `y r   )r7   r'   r   r   s    r   r   zQueryGuiTest.tearDownClassH  s&    JJJHr   c                     | j                   j                  j                  dd       d | j                   _        | j                   j                  j                          y )Nr   end)r7   r   deleter   r'   
reset_mockr&   s    r   setUpzQueryGuiTest.setUpO  s>      E*!&&(r   c                 
   | j                   }|j                  j                  dd       |j                  j	                          | j                  |j                  d       | j                  |j                  j                         y Nr   abc)
r7   r   insert	button_okinvoker4   r   rA   r'   rB   r6   s     r   test_click_okzQueryGuiTest.test_click_okT  s[    Au%!.--.r   c                     | j                   }|j                  j                          | j                  |j                  d        | j                  |j                  j                         y r   )r7   r  r  r4   r   assertFalser'   rB   r6   s     r   test_click_blankzQueryGuiTest.test_click_blank[  sI    !-../r   c                 
   | j                   }|j                  j                  dd       |j                  j	                          | j                  |j                  d        | j                  |j                  j                         y r  )
r7   r   r  button_cancelr  r4   r   rA   r'   rB   r6   s     r   test_click_cancelzQueryGuiTest.test_click_cancela  s[    Au%##%---.r   N)
r(   r)   r*   r   r   r   r   r  r	  r  r/   r   r   r   r   >  s<    ) )  )
/0/r   r   c                   "    e Zd Zed        Zd Zy)SectionnameGuiTestc                     t        d       y Nr   r   r   s    r   r   zSectionnameGuiTest.setUpClassk  	    r   c                    t               }|j                          t        j                  |dddhd      }| j                  }| j	                  |j
                  dh       |j                  j                  dd       |j                  j                          | j	                  |j                  d       |j                          y )NTtr  Tr   r   okay)r   r   r   rS   r4   rT   r   r  r  r  r   r'   )r   r   r7   r<   s       r   test_click_section_namez*SectionnameGuiTest.test_click_section_nameo  s    t##D#sUGDI  **UG4Av&!/r   N)r(   r)   r*   r   r   r  r/   r   r   r  r  i       	r   r  c                   "    e Zd Zed        Zd Zy)ModulenameGuiTestc                     t        d       y r  r   r   s    r   r   zModulenameGuiTest.setUpClass}  r  r   c                    t               }|j                          t        j                  |dddd      }| j	                  |j
                  d       | j	                  |j                  j                         d       |j                  j                          | j                  |j                  j                  d             |j                          y )Nr  r  ru   Tr   rv   )r   r   r   rh   r4   ri   r   r   r  r  rA   r   rw   r'   r   r   r7   s      r   test_click_module_namez(ModulenameGuiTest.test_click_module_name  s    t""4c9TJy1))+Y7!..}=>r   Nr(   r)   r*   r   r   r  r/   r   r   r  r  {  s     r   r  c                   "    e Zd Zed        Zd Zy)GotoGuiTestc                     t        d       y r  r   r   s    r   r   zGotoGuiTest.setUpClass  r  r   c                 .   t               }|j                          t        j                  |ddd      }|j                  j                  dd       |j                  j                          | j                  |j                  d       |j                          y )Nr  r  Tr   r   22   )r   r   r   r   r   r  r  r  r4   r   r'   r  s      r   r  z"GotoGuiTest.test_click_module_name  si    t**T3D9At$!+r   Nr  r/   r   r   r   r     s     r   r   c                   "    e Zd Zed        Zd Zy)HelpsourceGuiTestc                     t        d       y r  r   r   s    r   r   zHelpsourceGuiTest.setUpClass  r  r   c                    t               }|j                          t        j                  |ddt        d      }| j
                  } ||j                  j                         d        ||j                  j                         t               |j                  j                          t        j                  dk(  rdnd} ||j                  d|t        z   f       |j                          y )Nr  __test__T)menuitemfilepathr   r   r   r   )r   r   r   r   r   r4   r   r   r   r  r  sysr   r   r'   )r   r   r7   r<   r   s        r   test_click_help_sourcez(HelpsourceGuiTest.test_click_help_source  s    t""4z,4TC  fll *-fkkoo*!!llh6Bfmmj&8*;<=r   N)r(   r)   r*   r   r   r-  r/   r   r   r&  r&    s     r   r&  c                   "    e Zd Zed        Zd Zy)CustomRunGuiTestc                     t        d       y r  r   r   s    r   r   zCustomRunGuiTest.setUpClass  r  r   c                    t               }|j                          t        j                  |dddgd      }| j	                  |j
                  j                         d       |j
                  j                  t        d       |j                  j                          | j	                  |j                  g ddf       |j                          y )	NTitler   b=1T)r   r   za b=1z c)r   r3  r   )r   r   r   r   r4   r   r   r  r   r  r  r   r'   r  s      r   test_click_argsz CustomRunGuiTest.test_click_args  s    t//$,/<F))+W5C&!):D(ABr   N)r(   r)   r*   r   r   r4  r/   r   r   r/  r/    r  r   r/  __main__   F)	verbosityexit)rH   ru   r   unittesttest.supportr   tkinterr   r   r,  r   idlelib.idle_test.mock_tkr	   TestCaser   rJ   rc   rz   r   r   r   r   r   r   r  r  r   r&  r/  r(   mainr/   r   r   <module>r?     sY  
   !  
  )
0J!! 0Jf9h'' 9B!9X&& !9H9x   9:?x00 ?2*@8,, *@Z<H-- <29X.. 96@8,, @.(/8$$ (/V** $)) "(##  )) (x(( $ zHMMAE* r   