
    6bh<                        d Z ddlmZ ddlZddlm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                  e      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                  e      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)ExtraAssertions)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     F/opt/python-3.12.12/usr/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   r1   c                     | j                  d      }| j                  |j                         d        | j                  |j                  |j                  fd       | j                  d|j                  d          y )N NFz
blank liner   )r1   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 goodr4   r   r   )r1   r5   r-   r   r   r   )r   r8   Equals      r   test_entry_ok_goodzQueryTest.test_entry_ok_good2   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   r4   )r1   r	   Mockr   	focus_setr5   r.   
assertTruecalledr   r   r7   s     r   test_ok_blankzQueryTest.test_ok_blank9   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)r1   r5   r.   r   r   r7   s     r   test_ok_goodzQueryTest.test_ok_goodA   sG    !!&)d+&--)9)9:NKr   c                     | j                  d      }| j                  |j                         d        | j                  |j                  |j                  fd       y )Nzdoes not matterr&   )r1   r5   r/   r   r   r7   s     r   test_cancelzQueryTest.test_cancelF   sH    !!"34$/&--)9)9:LIr   N)
r)   r*   r+   __doc__r1   r9   r>   rD   rF   rH   r0   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__R       ;/DJ &|Dr   c                 "    || j                   d<   y r   r    r!   s     r   r#   z+SectionNameTest.Dummy_SectionName.showerrorU   r$   r   N)	r)   r*   r+   r   SectionNamer-   
used_namesr   r#   r0   r   r   Dummy_SectionNamerM   O   s$    $$--X
	,	/r   rV   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y Nr3   zno namer   rV   r5   r-   r6   r   r7   s     r   test_blank_section_namez'SectionNameTest.test_blank_section_nameX   sB    '',*D1i!3!3F!;<r   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )NrN   user   rY   r7   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   rY   r7   s     r   test_long_section_namez&SectionNameTest.test_long_section_nameb   sC    ''1*D1&(:(:6(BCr   c                     | j                  d      }| j                  |j                         d       | j                  |j                  d   d       y )Nr;   r<   r   r   )rV   r5   r-   r   r7   s     r   test_good_section_namez&SectionNameTest.test_good_section_nameg   sD    ''	2*F3++F3R8r   N)	r)   r*   r+   rI   rV   rZ   r]   r`   rb   r0   r   r   rK   rK   L   s$    )/ /=
9
D
9r   rK   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 rP   rQ   r   s     r   r   z(ModuleNameTest.Dummy_ModuleName.__init__s   rR   r   c                 "    || j                   d<   y r   r    r!   s     r   r#   z)ModuleNameTest.Dummy_ModuleName.showerrorv   r$   r   N)	r)   r*   r+   r   
ModuleNamer-   text0r   r#   r0   r   r   Dummy_ModuleNamerf   p   s"    ##,,	,	/r   rk   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y rX   rk   r5   r-   r6   r   r7   s     r   test_blank_module_namez%ModuleNameTest.test_blank_module_namey   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   rm   r7   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   rm   r7   s     r   test_c_source_namez!ModuleNameTest.test_c_source_name   sB    &&{3*D1nf&8&8&@Ar   c                 D   | j                  d      }| j                  |j                         d       | j                  |j                  d   d       | j                  d      }| j                  |j                         d       | j                  |j                  d   d       y )Nidlelib__init__.pyr   r   zidlelib.idlezidle.py)rk   assertEndsWithr-   r5   r   r7   s     r   test_good_module_namez$ModuleNameTest.test_good_module_name   s    &&y1FOO-}=++F3R8&&~6FOO-y9++F3R8r   N)	r)   r*   r+   rI   rk   rn   rq   rt   ry   r0   r   r   rd   rd   m   s$    (/ /=
?
B
9r   rd   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 rP   rQ   r   s     r   r   z"GotoTest.Dummy_ModuleName.__init__   rR   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#   r0   r   r   rk   r}      s    ::&&	,	/r   rk   c                     | j                  d      }| j                  |j                         d        | j                  d|j                  d          y )Naznot a base 10 integerr   rm   r7   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   rm   r7   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   )rk   r5   r-   r   r7   s     r   test_good_gotozGotoTest.test_good_goto   sD    &&s+*A.++F3R8r   N)r)   r*   r+   rI   rk   r   r   r   r0   r   r   r{   r{      s     "/ /K
L
9r   r{   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
   pathvarr0   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   r0   r   bcs      r   <lambda>zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s    "r   c                     t         S N__file__r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s    8r   htestc                      yr   r0   r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s    rr   c                     t         S r   r   r   s      r   r   zBHelpsourceBrowsefileTest.test_file_replaces_path.<locals>.<lambda>   s    r   )	r   r   subTestr   setaskfilenamer   r5   get)r   r8   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+   rI   r   r   r0   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 rP   )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#   r0   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 )Nr3   zno help filer   )r   r5   r   r6   r   r7   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   r5   r   r6   r   r7   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   r5   r   r   r   r   r   )r   r8   r=   urls       r   test_path_ok_webz%HelpsourcePathokTest.test_path_ok_web   s    &&r*  0C$  !137  !2!26!:B?   1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   r5   r   r   )r   r8   r   prefixs       r   test_path_ok_filez&HelpsourcePathokTest.test_path_ok_file   s    &&r* DHf!))  !16H3DE  !2!26!:B?	   !Es   A1B&&B/	N)r)   r*   r+   rI   r   r   r   r   classmethodr   r   r   r   r   r0   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   r0   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   r5   r-   )r   r8   r   r   r   s        r   test_entry_ok_helpsourcez.HelpsourceEntryokTest.test_entry_ok_helpsource   sf    &&(#KD$ +/(V[  !2F;  	#K  s   0A%%A.	N)r)   r*   r+   rI   r   r   r0   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 rP   rQ   r   s     r   r   z/CustomRunCLIargsokTest.Dummy_CustomRun.__init__  rR   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#   r0   r   r   Dummy_CustomRunr     s    oo11	,	/r   r   c                 f    | j                  d      }| j                  |j                         g        y )Nr3   )r   r5   r   r7   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   r5   r   r6   r   r7   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--namer3   z
 "my name"zmy namer   r   )r   joinr5   r   r   )r   argsr8   s      r   test_good_argsz%CustomRunCLIargsokTest.test_good_args!  s_    A%%chhtn|&CD++-tyk/AB++F3R8r   N)r)   r*   r+   rI   r   r   r   r   r0   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   r0   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   r5   r-   )r   r8   r   r   r   s        r   test_entry_ok_customrunz,CustomRunEntryokTest.test_entry_ok_customrun2  s    %%'$G!!'*%1'/jH:w2G%H%J &\\'H\E&.FO$$V__%6? FE%J % FEs   (B		BN)r)   r*   r+   rI   r   r   r0   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,   r8   r	   r@   r(   )r   r   s     r   
setUpClasszQueryGuiTest.setUpClassA  sO    $4[[vvdC
!YY[

r   c                 X    | j                   `| ` | j                  j                          | `y r   )r8   r(   r   r   s    r   r   zQueryGuiTest.tearDownClassI  s&    JJJHr   c                     | j                   j                  j                  dd       d | j                   _        | j                   j                  j                          y )Nr   end)r8   r   deleter   r(   
reset_mockr'   s    r   setUpzQueryGuiTest.setUpP  s>      E*!&&(r   c                 
   | j                   }|j                  j                  dd       |j                  j	                          | j                  |j                  d       | j                  |j                  j                         y Nr   abc)
r8   r   insert	button_okinvoker5   r   rB   r(   rC   r7   s     r   test_click_okzQueryGuiTest.test_click_okU  s[    Au%!.--.r   c                     | j                   }|j                  j                          | j                  |j                  d        | j                  |j                  j                         y r   )r8   r  r  r5   r   assertFalser(   rC   r7   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  )
r8   r   r  button_cancelr  r5   r   rB   r(   rC   r7   s     r   test_click_cancelzQueryGuiTest.test_click_cancelb  s[    Au%##%---.r   N)
r)   r*   r+   r   r   r   r   r  r	  r  r0   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.setUpClassl  	    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   rT   r5   rU   r   r  r  r  r   r(   )r   r   r8   r=   s       r   test_click_section_namez*SectionnameGuiTest.test_click_section_namep  s    t##D#sUGDI  **UG4Av&!/r   N)r)   r*   r+   r   r   r  r0   r   r   r  r  j       	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                  d       |j                          y )Nr  r  rv   Tr   rw   )r   r   r   ri   r5   rj   r   r   r  r  rx   r   r(   r   r   r8   s      r   test_click_module_namez(ModulenameGuiTest.test_click_module_name  s    t""4c9TJy1))+Y7!FMM=9r   Nr)   r*   r+   r   r   r  r0   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  r5   r   r(   r  s      r   r  z"GotoGuiTest.test_click_module_name  si    t**T3D9At$!+r   Nr  r0   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   r5   r   r   r   r  r  sysr   r   r(   )r   r   r8   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-  r0   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   r5   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  r0   r   r   r/  r/    r  r   r/  __main__   F)	verbosityexit)!rI   rv   r   unittesttest.supportr   test.support.testcaser   tkinterr   r   r,  r	   idlelib.idle_test.mock_tkr
   TestCaser   rK   rd   r{   r   r   r   r   r   r   r  r  r   r&  r/  r)   mainr0   r   r   <module>r@     s`  
   ! 1  
  )
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   