
    z%i=                        d Z ddlmZ ddlZddlZddlmZmZ ddlZddlm	Z	 ddlZddl
mZ de_         G d d	ej                        Z G d
 de      Z G d d      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j0                  d       yy)zTest run, coverage 54%.    )runN)captured_outputcaptured_stderr)mock)FuncTc                   ~    e Zd Zd ZdedfdedfdedffZd Ze	j                  j                  ed	d
       d        Zy)ExceptionTestc           	      J    G d dt               } |d      } |d      }	 ||# |$ r 	 |# |$ ry t               5 }t        j                  j	                  t
        d      5 }d |_        t        j                          d d d        n# 1 sw Y   nxY wd d d        n# 1 sw Y   nxY wY nw xY wY nw xY wj                         j                         j                         }| j                  dt        |             | j                  d|d	          | j                  d
|d          y )Nc                       e Zd Zd Zy)JExceptionTest.test_print_exception_unhashable.<locals>.UnhashableExceptionc                      y)NT )selfothers     N/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/idlelib/idle_test/test_run.py__eq__zQExceptionTest.test_print_exception_unhashable.<locals>.UnhashableException.__eq__   s        N)__name__
__module____qualname__r   r   r   r   UnhashableExceptionr      s    r   r   ex1ex2cleanup_tracebackc                     | S Nr   tes     r   <lambda>z?ExceptionTest.test_print_exception_unhashable.<locals>.<lambda>    s    a r      zUnhashableException: ex2   zUnhashableException: ex1
   )	Exceptionr   r   patchobjectr   side_effectprint_exceptiongetvaluestrip
splitlinesassertEquallenassertIn)r   r   r   r   outputcttbs          r   test_print_exception_unhashablez-ExceptionTest.test_print_exception_unhashable   s   	) 	 "%(!%(		.3" 	..	& .$& .&**30CD .)7++-. . .. . ..	. __$$&113SW%0"Q%80"R&9sY   $ B0,B*%B B	=	BBB	B*B$ B*'B0)B**B0/B01/0zdivision by zero
abczSname 'abc' is not defined. Did you mean: 'abs'? Or did you forget to import 'abc'?
zint.reelzAtype object 'int' has no attribute 'reel'. Did you mean: 'real'?
c           	      j   | j                   D ]8  \  }}}| j                  |      5  	 t        t        |dd             d d d        : y # |$ rX t	        j
                         \  }}}t        j                  |||      d   }|j                   d| }| j                  ||       Y gw xY w# 1 sw Y   xY w)N)code evalr   z: )
datasubTestr8   compilesysexc_infor   get_message_linesr   r,   )	r   r6   excmsgtypvalr1   actualexpects	            r   test_get_messagezExceptionTest.test_get_message1   s    "ii 	5ND#s4( 55r6235 5	5  5#&<<>LCb 223R@CF #~Ru5F$$VV4	55 5s)   B)A		AB&#B)%B&&B))B2	r   c                      d S )Nc                      y r   r   r   s     r   r    z(ExceptionTest.<lambda>.<locals>.<lambda>=       r   r   r   r   r   r    zExceptionTest.<lambda>=   s    -> r   new_callablec           
      l   | j                   }|d   |d   f|d   |d   f|d   |d   ff}d}|D ]A  \  \  }}}\  }}	}
| j                  ||f      5  	 t        t        |dd             d d d        C | j                  |t        |             y # |$ r 	 t        t        |dd             nx# |	$ rp t	               5 }t        j                          d d d        n# 1 sw Y   nxY wj                         }| j                  ||       | j                  |
|       |dz  }Y nw xY wY w xY w# 1 sw Y   xY w)Nr         )codesr7   r8   )r9   r:   r8   r;   r   r   r(   r)   r.   r,   r-   )r   r   ddata2subtestscode1exc1msg1code2exc2msg2r/   rC   s                r   test_get_multiple_messagez'ExceptionTest.test_get_multiple_message<   sL    IIA$!!ad|adAaD\:8= 	&4UD$!4%tU5M2 &&F34& &	& 	3u:.  	&&WUB78 &,. 2&//12 2 2!'!2dF3dF3 A&	&& &sg   D)BD&B+*D&+D 	:C	D 	C!A D 	D&D 	 D&#D)%D&&D))D3	N)r   r   r   r2   ZeroDivisionError	NameErrorAttributeErrorr9   rE   r   r%   r&   r   rX   r   r   r   r	   r	      su    :. %';<I  F G +,	D	5 
ZZs/$?  A/A/r   r	   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)Sc                 2    dt        |       j                  z  S )Nz%s:strtyper   r   s    r   __str__z	S.__str__U   s    $t*----r   c                 2    dt        |       j                  z  S )Nz
%s:unicoder_   ra   s    r   __unicode__zS.__unicode__W   s    d4j1111r   c                      yNr"   r   ra   s    r   __len__z	S.__len__Y   s    r   c                     t        d      S )Nr4   )iterra   s    r   __iter__z
S.__iter__[   s    E{r   c                 2    dt        |       j                  z  S )Nz%s:itemr_   r   argss     r   __getitem__zS.__getitem__]   s    4:....r   c                 2    dt        |       j                  z  S )Nz%s:slicer_   rl   s     r   __getslice__zS.__getslice___   s    DJ////r   N)	r   r   r   rb   rd   rg   rj   rn   rp   r   r   r   r]   r]   T   s     .2/0r   r]   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)	MockShellc                 $    | j                          y r   )resetra   s    r   __init__zMockShell.__init__d   s    

r   c                 :    | j                   j                  |       y r   )writtenappendrl   s     r   writezMockShell.writef   s    D!r   c                 6    | j                   j                         S r   )linespopra   s    r   readlinezMockShell.readlineh   s    zz~~r   c                      y r   r   ra   s    r   closezMockShell.closej   s    r   c                     g | _         y r   )rw   ra   s    r   rt   zMockShell.resetl   s	    r   c                 0    t        |      d d d   | _        y )N)listr{   )r   r{   s     r   pushzMockShell.pushn   s    %[2&
r   N)	r   r   r   ru   ry   r}   r   rt   r   r   r   r   rr   rr   c   s     " 'r   rr   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)StdInputFilesTestc                    t               }t        j                  |d      }| j                  |t        j
                         | j                  |j                  d       | j                  |j                  d       | j                  |j                         | j                  |j                  d       | j                  |j                         | j                  |j                                | j                  |j!                                | j                  |j#                                | j                  |j%                                y )Nstdinutf-8strictz<stdin>)rr   r   StdInputFileassertIsInstanceio
TextIOBaser,   encodingerrorsassertIsNonenewlinesnameassertFalseclosed
assertTrueisattyreadablewritableseekabler   shellfs      r   	test_misczStdInputFilesTest.test_misct   s    UG,a/W-8,!**%+"
#

%&&r   c                    t               }t        j                  |d      }| j                  t        |j
                         | j                  t        |j                         | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  dg       y )Nr   r   x)
rr   r   r   assertRaisesOSErrorfilenotellseekry   
writelinesr   s      r   test_unsupportedz"StdInputFilesTest.test_unsupported   s    UG,'188,'166*'1661-'177C0'1<<#7r   c                    t               }t        j                  |d      }|j                  g d       | j	                  |j                         d       |j                  g d       | j	                  |j                  d      d       |j                  g d       | j	                  |j                  d       d       |j                  g d       | j	                  |j                  d      d       | j	                  |j                  d      d	       | j	                  |j                  d
      d       |j                  ddg       | j	                  |j                  d      d       | j                  t        |j
                  d       | j                  t        |j
                  d       | j                  t        |j
                  dd       y )Nr   one
two
r7   one
two
r   )r   r   three
r7   rM   onr"   ze
tr#   z	wo
three
r   r   r   r7         ?1rL   )rr   r   r   r   r,   readr   	TypeErrorr   s      r   	test_readzStdInputFilesTest.test_read   sJ   UG,

)*<0

)*\2

)*|4

45D)F+]3

GW%&B')QVVS1)QVVS1)QVVQ2r   c                    t               }t        j                  |d      }|j                  g d       | j	                  |j                         d       | j	                  |j                  d      d       | j	                  |j                  d       d       |j                  dg       | j	                  |j                         d       | j	                  |j                         d       |j                  g d       | j	                  |j                         d	       | j	                  |j                         d
       |j                  g d       | j	                  |j                  d      d       | j	                  |j                  d      d       | j	                  |j                  d      d       | j	                  |j                  d      d       |j                  ddg       | j	                  |j                  d      d       | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  dd       y )Nr   )r   r   r   zfour
r   r   r   r   r   )onetwothreer   r   )r   r   r   rM   r   rL   r   
r#   r   r7   r   r   )	rr   r   r   r   r,   r}   r   r   	readlinesr   s      r   test_readlinezStdInputFilesTest.test_readline   s   UG,

:;w/B1D)95

L>"w/w/

*+u-u-

01A-A,A-B1

GW%&A+)Q[[#6)Q[[#6)Q[[!Q7r   c                    t               }t        j                  |d      }|j                  g d       | j	                  |j                         ddg       |j                  g d       | j	                  |j                  d      ddg       |j                  g d       | j	                  |j                  d       ddg       |j                  g d       | j	                  |j                  d      ddg       |j                  g d       | j	                  |j                  d      dg       |j                  g d       | j	                  |j                  d      ddg       |j                  g d       | j                  t        |j
                  d	       | j                  t        |j
                  d
       | j                  t        |j
                  dd       y )Nr   r   r   r   r   r   r"      r   r   rL   )rr   r   r   r   r,   r   r   r   r   s      r   test_readlinesz StdInputFilesTest.test_readlines   sd   UG,

)*'(:;

)*R7G*<=

)*T*Wg,>?

)*Q'7);<

)*Q'3

)*Q'7);<

)*)Q[[#6)Q[[#6)Q[[!Q7r   c                    t               }t        j                  |d      }|j                  g d       | j	                  |j
                         | j                  |j                         d       |j                          | j	                  |j
                         | j                  |j                         d       | j                  t        |j                  d       y )Nr   r   r   r   rL   )rr   r   r   r   r   r   r,   r}   r   r   r   r   s      r   
test_closezStdInputFilesTest.test_close   s    UG,

)*"w/		"w/)QWWa0r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s     '83(828*	1r   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)StdOutputFilesTestc                    t               }t        j                  |d      }| j                  |t        j
                         | j                  |j                  d       | j                  |j                  d       | j                  |j                         | j                  |j                  d       | j                  |j                         | j                  |j                                | j                  |j!                                | j                  |j#                                | j                  |j%                                y )Nstdoutr   r   z<stdout>)rr   r   StdOutputFiler   r   r   r,   r   r   r   r   r   r   r   r   r   r   r   r   r   s      r   r   zStdOutputFilesTest.test_misc   s    eX.a/W-8,!**%,"
#&

%&r   c                    t               }t        j                  |d      }| j                  t        |j
                         | j                  t        |j                         | j                  t        |j                  d       | j                  t        |j                  d       | j                  t        |j                  d       y )Nr   r   )
rr   r   r   r   r   r   r   r   r   r}   r   s      r   r   z#StdOutputFilesTest.test_unsupported   s    eX.'188,'166*'1661-'1661-'1::q1r   c                    t               }t        j                  |d      }|j                  d       | j	                  |j
                  dg       |j                          |j                  d       | j	                  |j
                  dg       |j                          |j                  t        d             | j	                  |j
                  dg       | j	                  t        |j
                  d   d         t               |j                          | j                  t        |j                         | j	                  |j
                  g        | j                  t        |j                  d       | j                  t        |j                  d       | j	                  |j
                  g        | j                  t        |j                  dd	       | j	                  |j
                  g        y )
Nr   testr   r   	   tèś𝖙)r   r   r      test{   spamrr   r   r   ry   r,   rw   rt   r]   r`   strr   r   r   s      r   
test_writezStdOutputFilesTest.test_write   s_   eX.	);(<=	'()L(MN	)*+)L(MNemmA.q12C8)QWW-+)QWWg6)QWWc2+)QWWff=+r   c                 `   t               }t        j                  |ddd      }|j                  d       | j	                  |j
                  dg       |j                          |j                  t        d             | j	                  |j
                  dg       | j	                  t        |j
                  d   d         t               |j                          | j                  t        |j                         | j	                  |j
                  g        | j                  t        |j                  d       | j                  t        |j                  d       | j	                  |j
                  g        | j                  t        |j                  d	d
       | j	                  |j
                  g        y )Nstderrziso-8859-15backslashreplaceu   tèś𝖙¤)u   tè\u015b\U0001d599\xa4r   r   r   r   r   r   r   r   s      r   test_write_stderr_nonencodablez1StdOutputFilesTest.test_write_stderr_nonencodable	  s8   eX}>PQ	+,)S(TU	-./)S(TUemmA.q12C8)QWW-+)QWWg6)QWWc2+)QWWff=+r   c                    t               }t        j                  |d      }|j                  g        | j	                  |j
                  g        |j                          |j                  ddg       | j	                  |j
                  ddg       |j                          |j                  ddg       | j	                  |j
                  dd	g       |j                          |j                  t        d
      g       | j	                  |j
                  dg       | j	                  t        |j
                  d   d         t               |j                          | j                  t        |j                         | j	                  |j
                  g        | j                  t        |j                  d       | j	                  |j
                  g        | j                  t        |j                  dg       | j                  t        |j                  dg       | j	                  |j
                  g        | j                  t        |j                  g g        | j	                  |j
                  g        y )Nr   r   r   )r   r   )r   r      onè
   twò)r   r   )r   r      tèst)r   r   r   r   r   )rr   r   r   r   r,   rw   rt   r]   r`   r   r   r   r   s      r   test_writelinesz"StdOutputFilesTest.test_writelines  s   eX.	R+	gu%&-/@A	C	j(+,02FG	I	a	l^$)>(?@emmA.q12C8)Q\\2+)Q\\37+)Q\\G9=)Q\\C59+)Q\\2r:+r   c                    t               }t        j                  |d      }| j                  |j                         |j                  d       |j                          | j                  |j                         | j                  t        |j
                  d       | j                  |j                  dg       |j                          | j                  t        |j                  d       y )Nr   r   r   r   rL   )rr   r   r   r   r   ry   r   r   r   
ValueErrorr,   rw   r   r   s      r   r   zStdOutputFilesTest.test_close;  s    eX."			!*aggs3);(<=		)QWWa0r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      s     '2,.,(,<
1r   r   c                   $    e Zd Zd Zd Zd Zd Zy)RecursionLimitTestc                    t        j                          | j                  t         j                         t        j
                  }| j                  t        |d       | j                  t        |dd       | j                  t        |d       y )Nd   )limiti  r   )	r   install_recursionlimit_wrappers
addCleanup!uninstall_recursionlimit_wrappersr<   setrecursionlimitr   r   r   )r   r   s     r    test_bad_setrecursionlimit_callsz3RecursionLimitTest.test_bad_setrecursionlimit_callsK  sf    ++-==>!!)Qc2)QT2*a+r   c                 T   t        j                          | j                  t         j                         t	        j
                         }| j                  t        j                  |       t	        j                  |dz          t	        j
                         }| j                  ||dz          y rf   )r   r   r   r   r<   getrecursionlimitr   r,   r   orig_reclimitnew_reclimits      r   test_roundtripz!RecursionLimitTest.test_roundtripS  s|    ++-==> --/--}=ma/0 ,,.}q'89r   c                     t        j                         }t        j                          | j	                  t        j
                         t        j                         }| j                  ||       y r   )r<   r   r   r   r   r   r,   r   s      r   &test_default_recursion_limit_preservedz9RecursionLimitTest.test_default_recursion_limit_preserved`  sL    --/++-==>,,.}5r   c                     d }t        j                  |d       | j                  |j                  d       d |_        t        j                  |d       | j                  |j                  d       y )Nc                       y)	docstringNr   r   r   r   funcz,RecursionLimitTest.test_fixdoc.<locals>.funci  rH   r   morezdocstring

more)r   fixdocr,   __doc__)r   r   s     r   test_fixdoczRecursionLimitTest.test_fixdocg  sQ    

4 ':;

4 v.r   N)r   r   r   r   r   r   r   r   r   r   r   r   H  s    ,:6/r   r   c                       e Zd Zd Zy)HandleErrorTestc                    | j                   }t        d      5 }t        j                  dt              5 }	 t
        # t
        $ r$ t        j                  j                  d dd       Y nw xY w |t        j                  d       dt        _	         ||j                         d       	 t        # t        $ r$ t        j                  j                  d dd       Y nw xY w |t        j                  d       dt        _        |j                         }| j                  d|       | j                  d|       | j                  d	|        ||j                  d
       d d d        n# 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)N
__stderr__z!idlelib.run.thread.interrupt_mainrI   r4   123TFr7   
IndexErrorrM   )r,   r   r   r%   r   EOFErrorr   MyRPCServerhandle_errorexit_nowr)   r   quittingr.   called)r   eqerrr   r@   s        r   test_fatal_errorz HandleErrorTest.test_fatal_errors  s8   \* 	cZZ;%)+	.2A A,,T5%@As||T" CLs||~r"A   A,,T5%@As||T" CL,,.CMM%%MM%%MM,,t{{A+	 	 	 	 	 	s\   E5E <*A)&E (A))<E &B,,*CE CA>E 	E5 E)	%E55E>N)r   r   r   r  r   r   r   r   r   q  s    r   r   c                   2    e Zd Zed        Zed        Zd Zy)ExecRuncodeTestc                 2   | j                  t        t        dt        j                         t	               | _        | j
                  t        _        t        j                         }t	        d      |j                  _	        t        j                  |      | _        y )Nr(   F)result)addClassCleanupsetattrr   r(   r   prtr   Mockconsolegetvar	Executiveex)clsmockrpcs     r   
setUpClasszExecRuncodeTest.setUpClass  s^    GC(9#:M:MN&!gg))+!%U!3w'r   c                      y r   r   )r  s    r   tearDownClasszExecRuncodeTest.tearDownClass  rH   r   c                 D   | j                   }|j                  d       | j                  |j                  d   t               | j                  t        t        dt        j                         d t        _	        |j                  d       | j                  | j                  j                  d   t               d t        _	        |j                  d       |j                  \  }}}| j                  |t               | j                  t        |j                  t                     y )Nr3   r   
excepthookc                 ,    t        j                  |       S r   )r   r(   )r   r   r1   s      r   r    z1ExecRuncodeTest.test_exceptions.<locals>.<lambda>  s    #*=*=a*@ r   c                       y r   r   r   r   r   r    z1ExecRuncodeTest.test_exceptions.<locals>.<lambda>  rH   r   )r  runcodeassertIsuser_exc_inforY   r   r	  r<   __excepthook__r  r
  rm   r   r   
isinstance__context__)r   r  r   r   r1   s        r   test_exceptionszExecRuncodeTest.test_exceptions  s    WW


5b&&q)+<=lC4F4FG@


5dhhmmA&(9:%


5##1ba#
1==2CDEr   N)r   r   r   classmethodr  r  r  r   r   r   r  r    s.    ( ( 4 4Fr   r  __main__rM   )	verbosity)r   idlelibr   r   r<   test.supportr   r   unittestr   idlelib.idle_test.mock_idler   testingTestCaser	   r   r]   rr   r   r   r   r   r  r   mainr   r   r   <module>r*     s      	 
 9    ,A/H%% A/J0 0' 'd1)) d1Nl1** l1^&/** &/Rh'' 8Fh'' F@ zHMMA r   