
    ;eG=                        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j        d           dS dS )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
                            ed	d
           d             ZdS )ExceptionTestc           	          G d dt                     } |d          } |d          }	 ||# |$ r 	 |# |$ r t                      5 }t          j                            t
          d          5 }d |_        t          j                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   Y nw xY wY nw xY w|                                	                                
                                }|                     dt          |                     |                     d|d	                    |                     d
|d                    d S )Nc                       e Zd Zd ZdS )JExceptionTest.test_print_exception_unhashable.<locals>.UnhashableExceptionc                     dS )NT )selfothers     1/usr/lib/python3.11/idlelib/idle_test/test_run.py__eq__zQExceptionTest.test_print_exception_unhashable.<locals>.UnhashableException.__eq__   s    t    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D .)7+---. . . . . . . . . . . . . . .. . . . . . . . . . . . . . ..	. __$$&&1133SWW%%%0"Q%8880"R&99999sr   . C6B<	&B./B	B.BB.BB."B<.B22B<5B26B<9C;B<<CC1/0zdivision by zero
abcz0name 'abc' is not defined. Did you mean: 'abs'?
zint.reelzAtype object 'int' has no attribute 'reel'. Did you mean: 'real'?
c           	      ~   | j         D ]\  }}}|                     |          5  	 t          t          |dd                     n`# |$ rX t	          j                    \  }}}t          j        |||          d         }|j         d| }| 	                    ||           Y nw xY wd d d            n# 1 swxY w Y   d S )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_message0   s%   "i 	5 	5ND#s4(( 5 55r6223333 5 5 5#&<>>LCb 23R@@CF #5555F$$VV44444	55 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5s5   B1AB1AB"B1!B""B11B5	8B5	r   c                      d S )Nc                     d S r   r   r   s     r   r    z(ExceptionTest.<lambda>.<locals>.<lambda><   s    $ r   r   r   r   r   r    zExceptionTest.<lambda><   s
    ->-> r   new_callablec           
         | j         }|d         |d         f|d         |d         f|d         |d         ff}d}|D ]\  \  }}}\  }}	}
|                     ||f          5  	 t          t          |dd                     n# |$ r 	 t          t          |dd                     n# |	$ r t	                      5 }t          j                     d d d            n# 1 swxY w Y   |                                }|                     ||           |                     |
|           |dz  }Y nw xY wY nw xY wd d d            n# 1 swxY w Y   | 	                    |t          |                     d S )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;   s!    IA$!!ad|adAaD\:8= 	& 	&4UD$!4%tU5M22 & &&F334444 	& 	& 	&&WUB778888 & & &,.. 2&/1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2!'!2!2dF333dF333 A&	&& & & & & & & & & & & & & & & 	3u::.....s   !E#BED3B'&D3'D-	:CD-	CD-	!C"AD-	*D3,D-	-D30E2D33EE		E	N)r   r   r   r2   ZeroDivisionError	NameErrorAttributeErrorr9   rE   r   r%   r&   r   rW   r   r   r   r	   r	      s        : : :. %';<I  8 9+,D	5 	5 	5 
Zs/$?$?  A A/ /A A/ / /r   r	   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )Sc                 0    dt          |           j        z  S )Nz%s:strtyper   r   s    r   __str__z	S.__str__T   s    $t**---r   c                 0    dt          |           j        z  S )Nz
%s:unicoder^   r`   s    r   __unicode__zS.__unicode__V   s    d4jj111r   c                     dS Nr"   r   r`   s    r   __len__z	S.__len__X   s    qr   c                      t          d          S )Nr4   )iterr`   s    r   __iter__z
S.__iter__Z   s    E{{r   c                 0    dt          |           j        z  S )Nz%s:itemr^   r   argss     r   __getitem__zS.__getitem__\   s    4::...r   c                 0    dt          |           j        z  S )Nz%s:slicer^   rk   s     r   __getslice__zS.__getslice__^   s    DJJ///r   N)	r   r   r   ra   rc   rf   ri   rm   ro   r   r   r   r\   r\   S   sn        . . .2 2 2    / / /0 0 0 0 0r   r\   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )	MockShellc                 .    |                                   d S r   )resetr`   s    r   __init__zMockShell.__init__c   s    

r   c                 :    | j                             |           d S r   )writtenappendrk   s     r   writezMockShell.writee   s    D!!!!!r   c                 4    | j                                         S r   )linespopr`   s    r   readlinezMockShell.readlineg   s    z~~r   c                     d S r   r   r`   s    r   closezMockShell.closei   s    r   c                     g | _         d S r   )rv   r`   s    r   rs   zMockShell.resetk   s    r   c                 @    t          |          d d d         | _        d S )N)listrz   )r   rz   s     r   pushzMockShell.pushm   s    %[[2&


r   N)	r   r   r   rt   rx   r|   r~   rs   r   r   r   r   rq   rq   b   sn          " " "         ' ' ' ' 'r   rq   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )StdInputFilesTestc                    t                      }t          j        |d          }|                     |t          j                   |                     |j        d           |                     |j        d           | 	                    |j
                   |                     |j        d           |                     |j                   |                     |                                           |                     |                                           |                     |                                           |                     |                                           d S )Nstdinutf-8strictz<stdin>)rq   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_miscs   s   UG,,a///W---8,,,!*%%%+++"""

###

%%%&&&&&&&&r   c                    t                      }t          j        |d          }|                     t          |j                   |                     t          |j                   |                     t          |j        d           |                     t          |j        d           |                     t          |j	        dg           d S )Nr   r   x)
rq   r   r   assertRaisesOSErrorfilenotellseekrx   
writelinesr   s      r   test_unsupportedz"StdInputFilesTest.test_unsupported   s    UG,,'18,,,'16***'161---'17C000'1<#77777r   c                 6   t                      }t          j        |d          }|                    g d           |                     |                                d           |                    g d           |                     |                    d          d           |                    g d           |                     |                    d           d           |                    g d           |                     |                    d          d           |                     |                    d          d	           |                     |                    d
          d           |                    ddg           |                     |                    d          d           |                     t          |j        d           |                     t          |j        d           |                     t          |j        dd           d S )Nr   one
two
r7   one
two
r   )r   r   three
r7   rL   onr"   ze
tr#   z	wo
three
r   r   r   r7         ?1rK   )rq   r   r   r   r,   readr   	TypeErrorr   s      r   	test_readzStdInputFilesTest.test_read   s   UG,,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

)))***"""w///				"""w///)QWa00000r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   q   sn        ' ' '8 8 83 3 3(8 8 828 8 8*	1 	1 	1 	1 	1r   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )StdOutputFilesTestc                    t                      }t          j        |d          }|                     |t          j                   |                     |j        d           |                     |j        d           | 	                    |j
                   |                     |j        d           |                     |j                   |                     |                                           |                     |                                           |                     |                                           |                     |                                           d S )Nstdoutr   r   z<stdout>)rq   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          }|                     t          |j                   |                     t          |j                   |                     t          |j        d           |                     t          |j        d           |                     t          |j	        d           d S )Nr   r   )
rq   r   r   r   r   r   r   r   r   r|   r   s      r   r   z#StdOutputFilesTest.test_unsupported   s    eX..'18,,,'16***'161---'161---'1:q11111r   c                     t                      }t          j        |d          }|                    d           |                     |j        dg           |                                 |                    d           |                     |j        dg           |                                 |                    t          d                     |                     |j        dg           |                     t          |j        d         d                   t                     |                                 | 
                    t          |j                   |                     |j        g            | 
                    t          |j        d           | 
                    t          |j        d           |                     |j        g            | 
                    t          |j        dd	           |                     |j        g            d S )
Nr   testr   r   	   tèś𝖙)r   r   r      test{   spamrq   r   r   rx   r,   rv   rs   r\   r_   strr   r   r   s      r   
test_writezStdOutputFilesTest.test_write   s   eX..	);(<===	'((()L(MNNN	)**+++)L(MNNNemA.q122C888)QW---+++)QWg666)QWc222+++)QWff===+++++r   c                    t                      }t          j        |ddd          }|                    d           |                     |j        dg           |                                 |                    t          d                     |                     |j        dg           |                     t          |j        d         d                   t                     |                                 | 
                    t          |j                   |                     |j        g            | 
                    t          |j        d           | 
                    t          |j        d           |                     |j        g            | 
                    t          |j        d	d
           |                     |j        g            d S )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  s   eX}>PQQ	+,,,)S(TUUU	-..///)S(TUUUemA.q122C888)QW---+++)QWg666)QWc222+++)QWff===+++++r   c                 2   t                      }t          j        |d          }|                    g            |                     |j        g            |                                 |                    ddg           |                     |j        ddg           |                                 |                    ddg           |                     |j        dd	g           |                                 |                    t          d
          g           |                     |j        dg           |                     t          |j        d         d                   t                     |                                 | 
                    t          |j                   |                     |j        g            | 
                    t          |j        d           |                     |j        g            | 
                    t          |j        dg           | 
                    t          |j        dg           |                     |j        g            | 
                    t          |j        g g            |                     |j        g            d S )Nr   r   r   )r   r   )r   r      onè
   twò)r   r   )r   r      tèst)r   r   r   r   r   )rq   r   r   r   r,   rv   rs   r\   r_   r   r   r   r   s      r   test_writelinesz"StdOutputFilesTest.test_writelines  sE   eX..	R+++	gu%&&&-/@A	C 	C 	C	j(+,,,02FG	I 	I 	I	a	ll^$$$)>(?@@@emA.q122C888)Q\222+++)Q\3777+++)Q\G9===)Q\C5999+++)Q\2r:::+++++r   c                    t                      }t          j        |d          }|                     |j                   |                    d           |                                 |                     |j                   |                     t          |j        d           | 
                    |j        dg           |                                 |                     t          |j        d           d S )Nr   r   r   r   rK   )rq   r   r   r   r   rx   r~   r   r   
ValueErrorr,   rv   r   r   s      r   r   zStdOutputFilesTest.test_close:  s    eX.."""					!!!*ags333);(<===				)QWa00000r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      sn        ' ' '2 2 2, , ,., , ,(, , ,<
1 
1 
1 
1 
1r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )RecursionLimitTestc                 .   t          j                     |                     t           j                   t          j        }|                     t          |d           |                     t          |dd           |                     t          |d           d S )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_callsJ  s    +---=>>>!)Qc222)QT222*a+++++r   c                 V   t          j                     |                     t           j                   t	          j                    }|                     t          j        |           t	          j        |dz              t	          j                    }|                     ||dz              d S re   )r   r   r   r   r<   getrecursionlimitr   r,   r   orig_reclimitnew_reclimits      r   test_roundtripz!RecursionLimitTest.test_roundtripR  s    +---=>>> -//-}===ma/000 ,..}q'899999r   c                     t          j                    }t          j                     |                     t          j                   t          j                    }|                     ||           d S r   )r<   r   r   r   r   r   r,   r   s      r   &test_default_recursion_limit_preservedz9RecursionLimitTest.test_default_recursion_limit_preserved_  s^    -//+---=>>>,..}55555r   c                     d }t          j        |d           |                     |j        d           d |_        t          j        |d           |                     |j        d           d S )Nc                      dS )	docstringNr   r   r   r   funcz,RecursionLimitTest.test_fixdoc.<locals>.funch  s      r   morezdocstring

more)r   fixdocr,   __doc__)r   r   s     r   test_fixdoczRecursionLimitTest.test_fixdocf  sm    
4   ':;;;
4   v.....r   N)r   r   r   r   r   r   r   r   r   r   r   r   G  sP        , , ,: : :6 6 6/ / / / /r   r   c                       e Zd Zd ZdS )HandleErrorTestc                 @   | j         }t          d          5 }t          j        dt                    5 }	 t
          # t
          $ r$ t          j                            d dd           Y nw xY w |t          j	        d           dt          _	         ||
                                d           	 t          # t          $ r$ t          j                            d dd           Y nw xY w |t          j        d           dt          _        |
                                }|                     d|           |                     d|           |                     d	|            ||j        d
           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N
__stderr__z!idlelib.run.thread.interrupt_mainrH   r4   123TFr7   
IndexErrorrL   )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_errorr  s+   \** 	cZ;%)+ + +	.2A A A A,,T5%@@@@@ABs|T""" CLBs||~~r"""A   A A A,,T5%@@@@@ABs|T""" CL,,..CMM%%%%MM%%%%MM,,,,Bt{A+	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	so   FE;<+A*'E;)A**AE;.B55+C# E;"C##BE;/F;E?	?FE?	FFFN)r   r   r   r  r   r   r   r   r   p  s#            r   r   c                   @    e Zd Zed             Zed             Zd ZdS )ExecRuncodeTestc                 2   |                      t          t          dt          j                   t	                      | _        | j        t          _        t          j                    }t	          d          |j        _	        t          j
        |          | _        d S )Nr(   F)result)addClassCleanupsetattrr   r(   r   prtr   Mockconsolegetvar	Executiveex)clsmockrpcs     r   
setUpClasszExecRuncodeTest.setUpClass  sj    GC(9#:MNNN&&!g)++!%U!3!3!3w''r   c                 >    t           j        t           j        k    sJ d S r   )r<   
excepthook__excepthook__)r  s    r   tearDownClasszExecRuncodeTest.tearDownClass  s    ~!3333333r   c                 f   | j         }|                    d           |                     |j        d         t                     |                     t          t          dt          j                   d t          _	        |                    d           |                     | j
        j        d         t                     d t          _	        |                    d           |j        \  }}}|                     |t                     |                     t          |j        t                               d S )Nr3   r   r  c                 *    t          j        |           S r   )r   r(   )r   r   r1   s      r   r    z1ExecRuncodeTest.test_exceptions.<locals>.<lambda>  s    #*=a*@*@ r   c                      d S r   r   r   r   r   r    z1ExecRuncodeTest.test_exceptions.<locals>.<lambda>  s     r   )r  runcodeassertIsuser_exc_inforX   r   r  r<   r  r  r	  rl   r   r   
isinstance__context__)r   r  r   r   r1   s        r   test_exceptionszExecRuncodeTest.test_exceptions  s    W


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


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


5#1ba###
1=2CDDEEEEEr   N)r   r   r   classmethodr  r  r  r   r   r   r  r    s\        ( ( [( 4 4 [4F F F F Fr   r  __main__rL   )	verbosity)r   idlelibr   r   r<   test.supportr   r   unittestr   idlelib.idle_test.mock_idler   testingTestCaser	   r   r\   rq   r   r   r   r   r  r   mainr   r   r   <module>r)     s9           				 



 9 9 9 9 9 9 9 9         , , , , , ,@/ @/ @/ @/ @/H% @/ @/ @/H0 0 0 0 0 0 0 0' ' ' ' ' ' ' 'd1 d1 d1 d1 d1) d1 d1 d1Nl1 l1 l1 l1 l1* l1 l1 l1^&/ &/ &/ &/ &/* &/ &/ &/R    h'   8F F F F Fh' F F F@ zHMA r   