o
    û›h¥1  ã                   @   s€  d Z ddlZddlZddlZddlZddlZddl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mZ ddlmZmZ ddlmZ d	Zd
Zdd„ ZG dd„ dejƒZdZG dd„ dejƒZG dd„ dejƒZdZ G dd„ dejƒZ!edƒdd„ ƒZ"dZ#dZ$G dd„ dejƒZ%ddlZe &¡ dkrŸ	 G dd „ d ejƒZ'G d!d"„ d"ejƒZ(G d#d$„ d$ejƒZ)G d%d&„ d&ejƒZ*d'd(„ Z+dS ))zTests for IPython.core.ultratb
é    N)Údedent)ÚTemporaryDirectory)ÚColorTBÚ	VerboseTB)Útools)Úonlyif_unicode_pathsÚskip_without)Úprepended_to_syspathz1
2
3
def f():
  1/0
zdef f():
  1/0
c                    s   ‡ fdd„}|S )z:
    decorator to set the recursion limit temporarily
    c                    s   ‡‡ fdd„}|S )Nc               	      s:   t  ¡ }t  ˆ ¡ zˆ| i |¤ŽW t  |¡ S t  |¡ w ©N)ÚsysÚgetrecursionlimitÚsetrecursionlimit)ÚargsÚkwargsZrl)ÚframesÚtest_function© úUc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_ultratb.pyÚwrapper&   s
   
z.recursionlimit.<locals>.inner.<locals>.wrapperr   )r   r   ©r   )r   r   Úinner%   s   zrecursionlimit.<locals>.innerr   )r   r   r   r   r   Úrecursionlimit    s   r   c                   @   ó   e Zd Zdd„ ZdS )ÚChangedPyFileTestc              
   C   s¶  t ƒ �Î}tj |d¡}t|ddd��}| t¡ W d  ƒ n1 s"w   Y  t|ƒ� t 	d¡ W d  ƒ n1 s;w   Y  t
 d¡� t 	d¡ W d  ƒ n1 sUw   Y  t|ddd��}| t¡ W d  ƒ n1 sqw   Y  t
jd	d
d��< t
 d¡� t 	d¡ W d  ƒ n1 s“w   Y  t
 d¡� t 	d¡ W d  ƒ n1 s­w   Y  W d  ƒ n1 s¼w   Y  W d  ƒ dS W d  ƒ dS 1 sÔw   Y  dS )z„Traceback produced if the line where the error occurred is missing?

        https://github.com/ipython/ipython/issues/1456
        úfoo.pyÚwúutf-8©ÚencodingNú
import fooÚZeroDivisionErrorúfoo.f()zInternal Python errorÚstderr)Zchannel)r   ÚosÚpathÚjoinÚopenÚwriteÚfile_1r	   ÚipÚrun_cellÚttÚAssertPrintsÚfile_2ÚAssertNotPrints©ÚselfÚtdÚfnameÚfr   r   r   Útest_changing_py_file4   s4   ÿ
ÿÿÿÿÿ€ýï"ïz'ChangedPyFileTest.test_changing_py_fileN)Ú__name__Ú
__module__Ú__qualname__r4   r   r   r   r   r   3   ó    r   uL   # coding: iso-8859-5

def fail():
    """Ð´Ð±Ð˜Ð–"""
    1/0     # Ð´Ð±Ð˜Ð–
c                   @   s(   e Zd Zedd„ ƒZdd„ Zdd„ ZdS )ÚNonAsciiTestc              	   C   sì   t dd��g}tj |d¡}t|ddd��}| t¡ W d   ƒ n1 s$w   Y  t|ƒ� t 	d¡ W d   ƒ n1 s=w   Y  t
 d¡� t 	d	¡ W d   ƒ n1 sWw   Y  W d   ƒ d S W d   ƒ d S 1 sow   Y  d S )
Nõ   Ã©)Úsuffixu   fooÃ©.pyr   r   r   r   r    r!   )r   r#   r$   r%   r&   r'   r(   r	   r)   r*   r+   r,   r/   r   r   r   Útest_nonascii_pathX   s   ÿ
ÿÿø"øzNonAsciiTest.test_nonascii_pathc              
   C   s  t ƒ �}tj |d¡}tj|ddd��}| t¡ W d   ƒ n1 s#w   Y  t|ƒ� t	 
d¡ W d   ƒ n1 s<w   Y  t d¡�$ tjddd	�� t	 
d
¡ W d   ƒ n1 s^w   Y  W d   ƒ n1 smw   Y  W d   ƒ d S W d   ƒ d S 1 s…w   Y  d S )Nz
dfghjkl.pyr   z
iso-8859-5r   zfrom dfghjkl import failr    u   Ð´Ð±Ð˜Ð–F©Úsuppresszfail())r   r#   r$   r%   Úior&   r'   Úiso_8859_5_filer	   r)   r*   r+   r,   r/   r   r   r   Útest_iso8859_5f   s"   ÿ
ÿÿ€ÿ÷	"÷zNonAsciiTest.test_iso8859_5c                 C   s  d}d}t  d¡ t |¡� t  |¡ W d   ƒ n1 sw   Y  t  d¡ t |¡� t  |¡ W d   ƒ n1 s=w   Y  t  d¡ t |¡� t  |¡ W d   ƒ n1 s\w   Y  t  d¡ t d¡� t  |¡ W d   ƒ n1 s{w   Y  t  d¡ d S )Nu   raise Exception('Ã©')u   Exception('Ã©')z%xmode plainz%xmode verbosez%xmode contextz%xmode minimalu   Exception: Ã©)r)   r*   r+   r,   )r0   ÚcellÚexpectedr   r   r   Útest_nonascii_msgt   s&   
ÿ
ÿ
ÿ
ÿzNonAsciiTest.test_nonascii_msgN)r5   r6   r7   r   r<   rA   rD   r   r   r   r   r9   W   s
    
r9   c                   @   s   e Zd ZdZdd„ ZdS )ÚNestedGenExprTestCasez™
    Regression test for the following issues:
    https://github.com/ipython/ipython/issues/8293
    https://github.com/ipython/ipython/issues/8205
    c                 C   sF   t dƒ}tjddd�� t |¡ W d   ƒ d S 1 sw   Y  d S )NzÖ            class SpecificException(Exception):
                pass

            def foo(x):
                raise SpecificException("Success!")

            sum(sum(foo(x) for _ in [0]) for x in [0])
            zSpecificException: Success!Fr=   )r   r+   r,   r)   r*   )r0   Úcoder   r   r   Útest_nested_genexpr�   s   ÿ"ÿz)NestedGenExprTestCase.test_nested_genexprN)r5   r6   r7   Ú__doc__rG   r   r   r   r   rE   Š   s    rE   zif True:
zoom()
c                   @   r   )ÚIndentationErrorTestc              
   C   sH  t  d¡�$ t jddd�� t t¡ W d   ƒ n1 sw   Y  W d   ƒ n1 s,w   Y  tƒ �f}tj |d¡}t	|ddd��}| 
t¡ W d   ƒ n1 sSw   Y  t  d¡�% t jddd�� t d	|¡ W d   ƒ n1 svw   Y  W d   ƒ n1 s…w   Y  W d   ƒ d S W d   ƒ d S 1 s�w   Y  d S )
NÚIndentationErrorzzoom()Fr=   r   r   r   r   Úrun)r+   r,   r)   r*   Úindentationerror_filer   r#   r$   r%   r&   r'   Úrun_line_magicr/   r   r   r   Ú test_indentationerror_shows_line¥   s(   ÿ€ÿÿÿ€ÿû"ûz5IndentationErrorTest.test_indentationerror_shows_lineN)r5   r6   r7   rN   r   r   r   r   rI   ¤   r8   rI   Zpandasc                  C   s>   d} t  d¡� t | ¡ W d   ƒ d S 1 sw   Y  d S )Nz‡
    import pandas
    df = pandas.DataFrame([])

    # Important: only fails inside of an "exec" call:
    exec("df.foobarbaz()")
    zCould not get source)r+   r,   r)   r*   )rF   r   r   r   Útest_dynamic_codeµ   s   "ÿrO   z1
2
7/
z7/
c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚSyntaxErrorTestc                 C   sr   d}t  d¡� t |¡ W d   ƒ n1 sw   Y  t  d¡� t |¡ W d   ƒ d S 1 s2w   Y  d S )Nz
def foo():
    ..
ÚSyntaxErrorúfoo())r+   r,   r)   r*   r.   )r0   Zsyntax_error_at_compile_timer   r   r   Ú.test_syntaxerror_no_stacktrace_at_compile_timeÍ   s   ÿ"ÿz>SyntaxErrorTest.test_syntaxerror_no_stacktrace_at_compile_timec                 C   s„   d}t  d¡� t |¡ W d   ƒ n1 sw   Y  t  ddg¡� t |¡ W d   ƒ n1 s3w   Y  tjd= tjd= d S )Nz8
def foo():
    eval("..")

def bar():
    foo()

bar()
rQ   rR   zbar()ÚbarÚfoo)r+   r,   r)   r*   Zuser_ns)r0   Zsyntax_error_at_runtimer   r   r   Ú6test_syntaxerror_stacktrace_when_running_compiled_codeØ   s   	ÿÿzFSyntaxErrorTest.test_syntaxerror_stacktrace_when_running_compiled_codec              	   C   s.  t ƒ �Š}tj |d¡}t|ddd��}| t¡ W d   ƒ n1 s"w   Y  t ddg¡� t	 
d|¡ W d   ƒ n1 s?w   Y  t|ddd��}| t¡ W d   ƒ n1 s[w   Y  t ddg¡� t	 
d|¡ W d   ƒ n1 sxw   Y  W d   ƒ d S W d   ƒ d S 1 s�w   Y  d S )Nr   r   r   r   z7/rQ   rK   )r   r#   r$   r%   r&   r'   Ú	se_file_1r+   r,   r)   rM   Ú	se_file_2r/   r   r   r   r4   ê   s"   ÿÿÿÿó"óz%SyntaxErrorTest.test_changing_py_filec                 C   sT   zt dƒ‚ t y)   t d¡� t ¡  W d   ƒ Y d S 1 s!w   Y  Y d S w )NZQWERTY)Ú
ValueErrorr+   r,   r)   Úshowsyntaxerror©r0   r   r   r   Útest_non_syntaxerrorû   s   
&ÿÿz$SyntaxErrorTest.test_non_syntaxerrorN)r5   r6   r7   rS   rV   r4   r\   r   r   r   r   rP   Ë   s
    rP   ÚPyPyc                   @   r   )ÚMemoryErrorTestc                 C   s   d}t  |¡ d S )Na�  (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))r)   r*   )r0   Zmemoryerror_coder   r   r   Útest_memoryerror  s   z MemoryErrorTest.test_memoryerrorN)r5   r6   r7   r_   r   r   r   r   r^   
  r8   r^   c                   @   sT   e Zd ZdZdZdZdZdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚPython3ChainedExceptionsTestzŒ
try:
    x = 1 + 2
    print(not_defined_here)
except Exception as e:
    x += 55
    x - 1
    y = {}
    raise KeyError('uh') from e
    z…
try:
    x = 1 + 2
    print(not_defined_here)
except Exception as e:
    x += 55
    x - 1
    y = {}
    raise KeyError('uh')
    zL
try:
    1/0
except Exception:
    raise ValueError("Yikes") from None
    zA
try:
    1/0
except Exception as e:
    raise SystemExit(1)
    c                 C   ó@   t  g d¢¡� t | j¡ W d   ƒ d S 1 sw   Y  d S )N©ÚKeyErrorÚ	NameErrorzdirect cause©r+   r,   r)   r*   ÚDIRECT_CAUSE_ERROR_CODEr[   r   r   r   Útest_direct_cause_error5  ó   "ÿz4Python3ChainedExceptionsTest.test_direct_cause_errorc                 C   ra   )N©rc   rd   zDuring handling©r+   r,   r)   r*   ÚEXCEPTION_DURING_HANDLING_CODEr[   r   r   r   Ú$test_exception_during_handling_error9  rh   zAPython3ChainedExceptionsTest.test_exception_during_handling_errorc              	   C   s€   t  ddg¡�/ t jdgdd�� t | j¡ W d   ƒ n1 s!w   Y  W d   ƒ d S W d   ƒ d S 1 s9w   Y  d S )NÚ
SystemExitzto see the full tracebackzanother exceptionFr=   )r+   r,   r.   r)   r*   ÚSYS_EXIT_WITH_CONTEXT_CODEr[   r   r   r   Ú!test_sysexit_while_handling_error=  s   ÿÿ"ÿz>Python3ChainedExceptionsTest.test_sysexit_while_handling_errorc              	   C   sz   t  d¡�. t jddd�� t | j¡ W d   ƒ n1 sw   Y  W d   ƒ d S W d   ƒ d S 1 s6w   Y  d S )Nr    rY   Fr=   ©r+   r.   r,   r)   r*   ÚSUPPRESS_CHAINING_CODEr[   r   r   r   Ú test_suppress_exception_chainingB  s
   ÿPþz=Python3ChainedExceptionsTest.test_suppress_exception_chainingc                 C   óT   t  g d¢¡� t d¡ t | j¡ t d¡ W d   ƒ d S 1 s#w   Y  d S )Nrb   ú%xmode Plainú%xmode Verbosere   r[   r   r   r   Útest_plain_direct_cause_errorG  ó
   
"ýz:Python3ChainedExceptionsTest.test_plain_direct_cause_errorc                 C   rs   )Nri   rt   ru   rj   r[   r   r   r   Ú*test_plain_exception_during_handling_errorM  rw   zGPython3ChainedExceptionsTest.test_plain_exception_during_handling_errorc              	   C   sŽ   t  d¡�8 t jddd�� t d¡ t | j¡ t d¡ W d   ƒ n1 s(w   Y  W d   ƒ d S W d   ƒ d S 1 s@w   Y  d S )Nr    rY   Fr=   rt   ru   rp   r[   r   r   r   Ú&test_plain_suppress_exception_chainingS  s   ÿ
PüzCPython3ChainedExceptionsTest.test_plain_suppress_exception_chainingN)r5   r6   r7   rf   rk   rq   rn   rg   rl   ro   rr   rv   rx   ry   r   r   r   r   r`     s    r`   c                   @   s@   e Zd ZdZdd„ Zdd„ Zedƒdd„ ƒZed	ƒd
d„ ƒZdS )ÚRecursionTestz 
def non_recurs():
    1/0

def r1():
    r1()

def r3a():
    r3b()

def r3b():
    r3c()

def r3c():
    r3a()

def r3o1():
    r3a()

def r3o2():
    r3o1()
c                 C   s   t  | j¡ d S r
   )r)   r*   ÚDEFINITIONSr[   r   r   r   ÚsetUpr  s   zRecursionTest.setUpc                 C   s:   t  d¡� t d¡ W d   ƒ d S 1 sw   Y  d S )Nzskipping similar framesznon_recurs())r+   r.   r)   r*   r[   r   r   r   Útest_no_recursionu  s   "ÿzRecursionTest.test_no_recursionéÈ   c                 C   s@   t  t d¡¡� t d¡ W d   ƒ d S 1 sw   Y  d S )NzB\[\.\.\. skipping similar frames: r1 at line 5 \(\d{2,3} times\)\]zr1()©r+   r,   ÚreÚcompiler)   r*   r[   r   r   r   Útest_recursion_one_framey  s
   ÿ"ýz&RecursionTest.test_recursion_one_frameé    c                 C   sæ   t  d¡�d t jt d¡dd��A t jt d¡dd��' t jt d¡dd�� t d¡ W d   ƒ n1 s6w   Y  W d   ƒ n1 sEw   Y  W d   ƒ n1 sTw   Y  W d   ƒ d S W d   ƒ d S 1 slw   Y  d S )Nz[... skipping similar frames: zr3a at line 8 \(\d{2} times\)Fr=   zr3b at line 11 \(\d{2} times\)zr3c at line 14 \(\d{2} times\)zr3o2()r   r[   r   r   r   Útest_recursion_three_frames€  s   ÿþýü€ €P z)RecursionTest.test_recursion_three_framesN)	r5   r6   r7   r{   r|   r}   r   r‚   r„   r   r   r   r   rz   [  s    
rz   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚPEP678NotesReportingTestzæ
try:
    raise AssertionError("Message")
except Exception as e:
    try:
        e.add_note("This is a PEP-678 note.")
    except AttributeError:  # Python <= 3.10
        e.__notes__ = ("This is a PEP-678 note.",)
    raise
    c                 C   ra   )N©ÚAssertionErrorÚMessagezThis is a PEP-678 note.©r+   r,   r)   r*   ÚERROR_WITH_NOTEr[   r   r   r   Útest_verbose_reports_notes•  rh   z3PEP678NotesReportingTest.test_verbose_reports_notesc                 C   rs   )Nr†   rt   ru   r‰   r[   r   r   r   Útest_plain_reports_notes™  rw   z1PEP678NotesReportingTest.test_plain_reports_notesN)r5   r6   r7   rŠ   r‹   rŒ   r   r   r   r   r…   ‰  s    r…   c                     s  ‡fdd„} d‡ fdd„	‰t ƒ fdd„‰ t ¡ }| d¡ | d	¡ z
| | dd
ƒ¡ W n
   tj|d� Y t|d�}| d¡ z
| | dd
ƒ¡ W n
   |t ¡ Ž  Y | d¡ t	|d�}| d¡ z
| | dd
ƒ¡ W n
   |t ¡ Ž  Y | d¡ d S )Nc                    s&   |\}}| | }| | }ˆ ||ƒ d S r
   r   )ÚcZd_eÚdÚeÚxÚy)rU   r   r   Úspam¤  s   ztest_handlers.<locals>.spamé   c                    s   ˆ | || ƒ d S r
   r   )ÚaÚbrT   )Úeggsr   r   rU   ª  s   ztest_handlers.<locals>.fooc                 S   s   | | }| | }|| S r
   r   )r3   ÚgÚzÚhÚir   r   r   r–   ­  s   ztest_handlers.<locals>.eggsÚ z*** Before ***)é   é   )Úfile)Zostreamz*** ColorTB ***z*** VerboseTB ***)r“   )
Úglobalsr?   ÚStringIOr'   Ú	tracebackÚ	print_excr   r   Úexc_infor   )r’   ZbuffÚhandlerr   )r–   rU   r   Útest_handlers£  s0   






r¥   ),rH   r?   Zos.pathr#   Úplatformr€   r   r¡   ZunittestÚtextwrapr   Útempfiler   ZIPython.core.ultratbr   r   ZIPython.testingr   r+   ZIPython.testing.decoratorsr   r   ZIPython.utils.syspathcontextr	   r(   r-   r   ZTestCaser   r@   r9   rE   rL   rI   rO   rW   rX   rP   Úpython_implementationr^   r`   rz   r…   r¥   r   r   r   r   Ú<module>   sH   3
9K.