Format: application/x-python-code
⬇ Download File (15.3 KB)
   1  o
   2  
   3  ��h�1�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	m
   4  Z
   5  ddlmZddl
   6  mZmZddlmZddlmZmZddlmZd	Zd
   7  Zdd�ZGd
   8  d�dej�ZdZGdd�dej�ZGdd�dej�ZdZ Gdd�dej�Z!ed�dd��Z"dZ#dZ$Gdd�dej�Z%ddlZe�&�dkr�	Gdd �d ej�Z'Gd!d"�d"ej�Z(Gd#d$�d$ej�Z)Gd%d&�d&ej�Z*d'd(�Z+dS))zTests for IPython.core.ultratb
   9  �N)�dedent)�TemporaryDirectory)�ColorTB�	VerboseTB)�tools)�onlyif_unicode_paths�skip_without)�prepended_to_syspathz1
  10  2
  11  3
  12  def f():
  13    1/0
  14  zdef f():
  15    1/0
  16  cs�fdd�}|S)z:
  17      decorator to set the recursion limit temporarily
  18      cs��fdd�}|S)Nc	s:t��}t���z
  19  �|i|��Wt�|�St�|�w�N)�sys�getrecursionlimit�setrecursionlimit)�args�kwargsZrl)�frames�
  20  test_function��Uc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_ultratb.py�wrapper&s
  21  
  22  z.recursionlimit.<locals>.inner.<locals>.wrapperr)rr�r)rr�inner%szrecursionlimit.<locals>.innerr)rrrrr�recursionlimit src@�eZdZdd�ZdS)�ChangedPyFileTestc
  23  Cs�t���}tj�|d�}t|ddd��
  24  }|�t�Wd�n1s"wYt|��
  25  t�	d�Wd�n1s;wYt
  26  �d��
  27  t�	d�Wd�n1sUwYt|ddd��
  28  }|�t�Wd�n1sqwYt
  29  j
  30  d	d
  31  d��<t
  32  �d��
  33  t�	d�Wd�n1s�wYt
  34  �d��
  35  t�	d�Wd�n1s�wYWd�n1s�wYWd�dSWd�dS1s�wYdS)z�Traceback produced if the line where the error occurred is missing?
  36  
  37          https://github.com/ipython/ipython/issues/1456
  38          �foo.py�w�utf-8��encodingN�
  39  import foo�ZeroDivisionError�foo.f()zInternal Python error�stderr)Zchannel)r�os�path�join�open�write�file_1r	�ip�run_cell�tt�AssertPrints�file_2�AssertNotPrints��self�td�fname�frrr�test_changing_py_file4s4�
  40  ��������"�z'ChangedPyFileTest.test_changing_py_fileN)�__name__�
  41  __module__�__qualname__r4rrrrr3�ruL# coding: iso-8859-5
  42  
  43  def fail():
  44      """дбИЖ"""
  45      1/0     # дбИЖ
  46  c@s(eZdZedd��Zdd�Zdd�ZdS)�NonAsciiTestc	Cs�tdd��g}tj�|d�}t|ddd��
  47  }|�t�Wd�n1s$wYt|��
  48  t�	d�Wd�n1s=wYt
  49  �d��
  50  t�	d	�Wd�n1sWwYWd�dSWd�dS1sowYdS)
  51  N�é)�suffixufooé.pyrrrrr r!)rr#r$r%r&r'r(r	r)r*r+r,r/rrr�test_nonascii_pathXs�
  52  ���"�zNonAsciiTest.test_nonascii_pathc
  53  Cst��}tj�|d�}tj|ddd��
  54  }|�t�Wd�n1s#wYt|��
  55  t	�
  56  d�Wd�n1s<wYt�d��$tjddd	��
  57  t	�
  58  d
  59  �Wd�n1s^wYWd�n1smwYWd�dSWd�dS1s�wYdS)Nz
  60  dfghjkl.pyrz
  61  iso-8859-5rzfrom dfghjkl import failr uдбИЖF��suppresszfail())
  62  rr#r$r%�ior&r'�iso_8859_5_filer	r)r*r+r,r/rrr�test_iso8859_5fs"�
  63  �����	"�zNonAsciiTest.test_iso8859_5cCsd}d}t�d�t�|��
  64  t�|�Wd�n1swYt�d�t�|��
  65  t�|�Wd�n1s=wYt�d�t�|��
  66  t�|�Wd�n1s\wYt�d�t�d��
  67  t�|�Wd�n1s{wYt�d�dS)Nuraise Exception('é')uException('é')z%xmode plainz%xmode verbosez%xmode contextz%xmode minimalu
  68  Exception: é)r)r*r+r,)r0�cell�expectedrrr�test_nonascii_msgts&
  69  �
  70  �
  71  �
  72  �zNonAsciiTest.test_nonascii_msgN)r5r6r7rr<rArDrrrrr9Ws
  73  
  74  
  75  r9c@seZdZdZdd�ZdS)�NestedGenExprTestCasez�
  76      Regression test for the following issues:
  77      https://github.com/ipython/ipython/issues/8293
  78      https://github.com/ipython/ipython/issues/8205
  79      cCsFtd�}tjddd��t�|�Wd�dS1swYdS)Nz�            class SpecificException(Exception):
  80                  pass
  81  
  82              def foo(x):
  83                  raise SpecificException("Success!")
  84  
  85              sum(sum(foo(x) for _ in [0]) for x in [0])
  86              zSpecificException: Success!Fr=)rr+r,r)r*)r0�coderrr�test_nested_genexpr�s�"�z)NestedGenExprTestCase.test_nested_genexprN)r5r6r7�__doc__rGrrrrrE�srEzif True:
  87  zoom()
  88  c@r)�IndentationErrorTestc
  89  CsHt�d��$tjddd��
  90  t�t�Wd�n1swYWd�n1s,wYt��f}tj�|d�}t	|ddd��
  91  }|�
  92  t�Wd�n1sSwYt�d��%tjddd��t�d	|�Wd�n1svwYWd�n1s�wYWd�dSWd�dS1s�wYdS)
  93  N�IndentationErrorzzoom()Fr=rrrr�run)r+r,r)r*�indentationerror_filerr#r$r%r&r'�run_line_magicr/rrr� test_indentationerror_shows_line�s(��������"�z5IndentationErrorTest.test_indentationerror_shows_lineN)r5r6r7rNrrrrrI�r8rIZpandascCs>d}t�d��t�|�Wd�dS1swYdS)Nz�
  94      import pandas
  95      df = pandas.DataFrame([])
  96  
  97      # Important: only fails inside of an "exec" call:
  98      exec("df.foobarbaz()")
  99      zCould not get source)r+r,r)r*)rFrrr�test_dynamic_code�s"�rOz1
 100  2
 101  7/
 102  z7/
 103  c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
 104  �SyntaxErrorTestcCsrd}t�d��
 105  t�|�Wd�n1swYt�d��t�|�Wd�dS1s2wYdS)Nz
 106  def foo():
 107      ..
 108  �SyntaxError�foo())r+r,r)r*r.)r0Zsyntax_error_at_compile_timerrr�.test_syntaxerror_no_stacktrace_at_compile_time�s�"�z>SyntaxErrorTest.test_syntaxerror_no_stacktrace_at_compile_timecCs�d}t�d��
 109  t�|�Wd�n1swYt�ddg��
 110  t�|�Wd�n1s3wYtjd=tjd=dS)Nz8
 111  def foo():
 112      eval("..")
 113  
 114  def bar():
 115      foo()
 116  
 117  bar()
 118  rQrRzbar()�bar�foo)r+r,r)r*Zuser_ns)r0Zsyntax_error_at_runtimerrr�6test_syntaxerror_stacktrace_when_running_compiled_code�s	��zFSyntaxErrorTest.test_syntaxerror_stacktrace_when_running_compiled_codec	Cs.t���}tj�|d�}t|ddd��
 119  }|�t�Wd�n1s"wYt�ddg��t	�
 120  d|�Wd�n1s?wYt|ddd��
 121  }|�t�Wd�n1s[wYt�ddg��t	�
 122  d|�Wd�n1sxwYWd�dSWd�dS1s�wYdS)Nrrrrz7/rQrK)rr#r$r%r&r'�	se_file_1r+r,r)rM�	se_file_2r/rrrr4�s"�����
 123  "�z%SyntaxErrorTest.test_changing_py_filecCsTztd��ty)t�d��t��Wd�YdS1s!wYYdSw)NZQWERTY)�
 124  ValueErrorr+r,r)�showsyntaxerror�r0rrr�test_non_syntaxerror�s
 125  &��z$SyntaxErrorTest.test_non_syntaxerrorN)r5r6r7rSrVr4r\rrrrrP�s
 126  rP�PyPyc@r)�MemoryErrorTestcCsd}t�|�dS)Na�(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))r)r*)r0Zmemoryerror_coderrr�test_memoryerrorsz MemoryErrorTest.test_memoryerrorN)r5r6r7r_rrrrr^
 127  r8r^c@sTeZdZdZdZdZdZdd�Zdd�Zd	d
 128  �Z	dd�Z
 129  d
 130  d�Zdd�Zdd�Z
 131  dS)�Python3ChainedExceptionsTestz�
 132  try:
 133      x = 1 + 2
 134      print(not_defined_here)
 135  except Exception as e:
 136      x += 55
 137      x - 1
 138      y = {}
 139      raise KeyError('uh') from e
 140      z�
 141  try:
 142      x = 1 + 2
 143      print(not_defined_here)
 144  except Exception as e:
 145      x += 55
 146      x - 1
 147      y = {}
 148      raise KeyError('uh')
 149      zL
 150  try:
 151      1/0
 152  except Exception:
 153      raise ValueError("Yikes") from None
 154      zA
 155  try:
 156      1/0
 157  except Exception as e:
 158      raise SystemExit(1)
 159      cC�@t�gd���t�|j�Wd�dS1swYdS)N��KeyError�	NameErrorzdirect cause�r+r,r)r*�DIRECT_CAUSE_ERROR_CODEr[rrr�test_direct_cause_error5�"�z4Python3ChainedExceptionsTest.test_direct_cause_errorcCra)N�rcrdzDuring handling�r+r,r)r*�EXCEPTION_DURING_HANDLING_CODEr[rrr�$test_exception_during_handling_error9rhzAPython3ChainedExceptionsTest.test_exception_during_handling_errorc	Cs�t�ddg��/tjdgdd��t�|j�Wd�n1s!wYWd�dSWd�dS1s9wYdS)N�
 160  SystemExitzto see the full tracebackzanother exceptionFr=)r+r,r.r)r*�SYS_EXIT_WITH_CONTEXT_CODEr[rrr�!test_sysexit_while_handling_error=s��"�z>Python3ChainedExceptionsTest.test_sysexit_while_handling_errorc	Cszt�d��.tjddd��t�|j�Wd�n1swYWd�dSWd�dS1s6wYdS)Nr rYFr=�r+r.r,r)r*�SUPPRESS_CHAINING_CODEr[rrr� test_suppress_exception_chainingBs
 161  �P�z=Python3ChainedExceptionsTest.test_suppress_exception_chainingcC�Tt�gd���t�d�t�|j�t�d�Wd�dS1s#wYdS)Nrb�%xmode Plain�%xmode Verboserer[rrr�test_plain_direct_cause_errorG�
 162  
 163  "�z:Python3ChainedExceptionsTest.test_plain_direct_cause_errorcCrs)Nrirtrurjr[rrr�*test_plain_exception_during_handling_errorMrwzGPython3ChainedExceptionsTest.test_plain_exception_during_handling_errorc	Cs�t�d��8tjddd��t�d�t�|j�t�d�Wd�n1s(wYWd�dSWd�dS1s@wYdS)Nr rYFr=rtrurpr[rrr�&test_plain_suppress_exception_chainingSs�
 164  P�zCPython3ChainedExceptionsTest.test_plain_suppress_exception_chainingN)r5r6r7rfrkrqrnrgrlrorrrvrxryrrrrr`sr`c@s@eZdZdZdd�Zdd�Zed�dd��Zed	�d
 165  d��ZdS)
 166  �
 167  RecursionTestz�
 168  def non_recurs():
 169      1/0
 170  
 171  def r1():
 172      r1()
 173  
 174  def r3a():
 175      r3b()
 176  
 177  def r3b():
 178      r3c()
 179  
 180  def r3c():
 181      r3a()
 182  
 183  def r3o1():
 184      r3a()
 185  
 186  def r3o2():
 187      r3o1()
 188  cCst�|j�dSr
 189  )r)r*�DEFINITIONSr[rrr�setUprszRecursionTest.setUpcCs:t�d��t�d�Wd�dS1swYdS)Nzskipping similar framesznon_recurs())r+r.r)r*r[rrr�test_no_recursionus"�zRecursionTest.test_no_recursion��cCs@t�t�d���t�d�Wd�dS1swYdS)NzB\[\.\.\. skipping similar frames: r1 at line 5 \(\d{2,3} times\)\]zr1()�r+r,�re�compiler)r*r[rrr�test_recursion_one_frameys
 190  �"�z&RecursionTest.test_recursion_one_frame�cCs�t�d��dtjt�d�dd��Atjt�d�dd��'tjt�d�dd��
 191  t�d�Wd�n1s6wYWd�n1sEwYWd�n1sTwYWd�dSWd�dS1slwYdS)Nz[... skipping similar frames: zr3a at line 8 \(\d{2} times\)Fr=zr3b at line 11 \(\d{2} times\)zr3c at line 14 \(\d{2} times\)zr3o2()rr[rrr�test_recursion_three_frames�s������Pz)RecursionTest.test_recursion_three_framesN)	r5r6r7r{r|r}rr�r�rrrrrz[s
 192  rzc@s eZdZdZdd�Zdd�ZdS)�PEP678NotesReportingTestz�
 193  try:
 194      raise AssertionError("Message")
 195  except Exception as e:
 196      try:
 197          e.add_note("This is a PEP-678 note.")
 198      except AttributeError:  # Python <= 3.10
 199          e.__notes__ = ("This is a PEP-678 note.",)
 200      raise
 201      cCra)N��AssertionError�MessagezThis is a PEP-678 note.�r+r,r)r*�ERROR_WITH_NOTEr[rrr�test_verbose_reports_notes�rhz3PEP678NotesReportingTest.test_verbose_reports_notescCrs)Nr�rtrur�r[rrr�test_plain_reports_notes�rwz1PEP678NotesReportingTest.test_plain_reports_notesN)r5r6r7r�r�r�rrrrr��sr�cs�fdd�}d�fdd�	�t�fdd��t��}|�d�|�d	�z
 202  |�|dd
 203  ��Wn
 204  tj|d�Yt|d�}|�d
 205  �z
 206  |�|dd
 207  ��Wn
 208  |t���Y|�d�t	|d�}|�d�z
 209  |�|dd
 210  ��Wn
 211  |t���Y|�d�dS)Ncs&|\}}||}||}�||�dSr
 212  r)�cZd_e�d�e�x�y)rUrr�spam�sztest_handlers.<locals>.spam�cs�|||�dSr
 213  r)�a�brT)�eggsrrrU�sztest_handlers.<locals>.foocSs||}||}||Sr
 214  r)r3�g�z�h�irrrr��sztest_handlers.<locals>.eggs�z*** Before ***)��)�file)Zostreamz*** ColorTB ***z*** VerboseTB ***)r�)
 215  �globalsr?�StringIOr'�	traceback�	print_excrr�exc_infor)r�Zbuff�handlerr)r�rUr�
 216  test_handlers�s0
 217  
 218  
 219  
 220  
 221  
 222  
 223  r�),rHr?Zos.pathr#�platformr�rr�Zunittest�textwrapr�tempfilerZIPython.core.ultratbrrZIPython.testingrr+ZIPython.testing.decoratorsrrZIPython.utils.syspathcontextr	r(r-rZTestCaserr@r9rErLrIrOrWrXrP�python_implementationr^r`rzr�r�rrrr�<module>sH3
 224  
 225  9K.