Format: application/x-python-code
⬇ Download File (19.9 KB)
   1  o
   2  
   3  ��h�Z�@s�dZddlZddlZddlZejedd��ddlmZWd�n1s&wYddl	m
   4  Z
   5  ddlmZm
   6  Z
   7  ddlmZd	d
   8  �Zdd�Zd
   9  d�Zdd�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�de�Zedkr�ddlmZe�dZZdZz9	eZ e�!�r�de�"�Z#er�e#e$e e#�Z%ne$e �Z%e�&e%�d Z e�!�s�ej'Z(e�)�Z*e+d!e*�e+d"e(�q�e,y�e+d#�Ynwd$d%�Z-d&d'�Z.Gd(d)�d)e/�Z0Gd*d+�d+e0ej�Z1Gd,d-�d-e0ej�Z2gd.�Z3d/d0�Z4dS)1z#Tests for the inputsplitter module.�N�
  10  inputsplitter)�match)r)�InputTransformer)�syntax�	syntax_ml)�toolscCsXddlm}|�}|��r&d|��}d|}|||�}|�|�|��s
  11  |��}|S)z�Minimal example of the logic of an interactive interpreter loop.
  12  
  13      This serves as an example, and it is used by the test system with a fake
  14      raw_input that simulates interactive input.r)�
  15  InputSplitter� z>>> )�IPython.core.inputsplitterr�push_accepts_more�get_indent_spaces�push�source_reset)Z
  16  input_funcr�isp�indent�prompt�line�src�r�[c:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_inputsplitter.py�mini_interactive_loops
  17  �rcst|���fdd�}|S)zDReturn a function that acts like raw_input but feeds the input list.cs zt��WStyYdSw)N�)�next�
  18  StopIteration)r�Zilinesrr�raw_in9s
  19  
  20  �zpseudo_input.<locals>.raw_in)�iter)�linesrrrr�pseudo_input6srcCsFgd�}t�t��t�tj|�Wd�dS1swYdS)N)
  21  �rr)r	�)�
  22  r)z 
  23  r )�xr)z xr )z  x�)z    x�)z	xr )z	 xr#)�pytest�warns�PendingDeprecationWarning�tt�check_pairsrZnum_ini_spaces��testsrrr�test_spacesCs"�r,cCsgd�}t�tj|�dS)N))�textr-)ztext # commentztext )ztext # comment
  24  �text 
  25  )ztext # comment 
  26  r.)zline # c 
  27  line
  28  zline 
  29  line
  30  )z"line # c 
  31  line#c2  
  32  line
  33  line #c
  34  
  35  zline 
  36  line
  37  line
  38  line 
  39  
  40  )r(r)rZremove_commentsr*rrr�test_remove_commentsTsr/cCs,t��}t|t�sJ�d�|�dksJ�dS)N�teststest)r�get_input_encoding�
  41  isinstance�str�encode)�encodingrrr�test_get_input_encoding`sr6c@�$eZdZdd�Zdd�Zdd�ZdS)�NoInputEncodingTestCasecCs&tj|_Gdd�d�}|�}|t_dS)Nc@seZdZdS)z(NoInputEncodingTestCase.setUp.<locals>.XN)�__name__�
  42  __module__�__qualname__rrrr�Xksr<)�sys�stdin�	old_stdin)�selfr<Z
  43  fake_stdinrrr�setUpis
  44  zNoInputEncodingTestCase.setUpcCst��}|�|d�dS)N�ascii)rr1�assertEqual)r@�encrrrr0oszNoInputEncodingTestCase.testcCs|jt_dS�N)r?r=r>�r@rrr�tearDownusz NoInputEncodingTestCase.tearDownN)r9r:r;rAr0rGrrrrr8hsr8c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
  45  �Zdd�Zd
  46  d�Z	dd�Z
  47  dd�Zdd�Zdd�Z
  48  dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zejjd/ejd0ved1d2�d3d4��Z d5d6�Z!d7S)8�InputSplitterTestCasecC�t��|_dSrE)rrrFrrrrAz�zInputSplitterTestCase.setUpcCsd|j}|�d�|��|�|jg�|�|��d�|�|jd�|�|jd�|�|jd�dS)N�x=1rrF)	rr
  49  �resetrC�_bufferr�source�codeZ_is_complete�r@rrrr�
  50  test_reset}s
  51  z InputSplitterTestCase.test_resetcCsv|j�d�|j�d�|�|jjd�|�t|jj�dkd�|�|j��d�|�|jjg�|�|jjd�dS)N�1�2z1
  52  2
  53  rTr)r�_storerCrN�lenrMrrFrrr�test_source�sz!InputSplitterTestCase.test_sourcecCsX|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)NrKrz
  54  if 1:
  55      x=1r$�y=2
  56  �rr
  57  rCrrPrrr�test_indent��
  58  
  59  
  60  z!InputSplitterTestCase.test_indentcCsX|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)N�if 1:r$z    x=1z  rXrPrrr�test_indent2�s
  61  
  62  
  63  z"InputSplitterTestCase.test_indent2cCs.|j}|�d�|�d�|�|��d�dS)Nr[z    x = (1+
  64      2)r$rXrPrrr�test_indent3�s
  65  
  66  z"InputSplitterTestCase.test_indent3cCsr|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nzif 1: 
  67      x=1r$rWrzif 1:	
  68      x=1rXrPrrr�test_indent4��
  69  
  70  
  71  
  72  z"InputSplitterTestCase.test_indent4cC�X|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nzif 1:
  73      passes = 5r$zif 1:
  74       passrzif 1:
  75       pass   rXrPrrr�test_dedent_pass��
  76  
  77  
  78  z&InputSplitterTestCase.test_dedent_passcCr`)Nzwhile 1:
  79      breaks = 5r$zwhile 1:
  80       breakrzwhile 1:
  81       break   rXrPrrr�test_dedent_break�rbz'InputSplitterTestCase.test_dedent_breakcCr`)Nzwhile 1:
  82      continues = 5r$zwhile 1:
  83       continuerzwhile 1:
  84       continue   rXrPrrr�test_dedent_continue�rbz*InputSplitterTestCase.test_dedent_continuecCsr|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nzif 1:
  85      raised = 4r$zif 1:
  86       raise TypeError()rzif 1:
  87       raisezif 1:
  88       raise      rXrPrrr�test_dedent_raise�r_z'InputSplitterTestCase.test_dedent_raisecCs�|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nzif 1:
  89      returning = 4r$zif 1:
  90       return 5 + 493rzif 1:
  91       returnzif 1:
  92       return      zif 1:
  93       return(0)rXrPrrr�test_dedent_return�s
  94  
  95  
  96  
  97  
  98  z(InputSplitterTestCase.test_dedent_returncCs|j}|�|�d�d�dS)NrKT)rrCr
  99  rPrrr�	test_push�szInputSplitterTestCase.test_pushcCs@|j}|�|�d�d�dD]}t|�|�|�|�d�qdS)Nr[F)�  x=1z# a commentz  y=2T)rrCr
 100  �print)r@rrrrr�
 101  test_push2�s�z InputSplitterTestCase.test_push2cCs0|j}|�d�|�d�|�|�d�d�dS)Nzif True:z  a = 1zb = [1,F)rr
 102  rCrPrrr�
 103  test_push3�s
 104  
 105  z InputSplitterTestCase.test_push3cC�$|j}|�d�|�|��d�dS)NrKF�rr
 106  rCrrPrrr�test_push_accepts_more�
 107  z,InputSplitterTestCase.test_push_accepts_morecCsX|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nr[TrhrFrmrPrrr�test_push_accepts_more2rZz-InputSplitterTestCase.test_push_accepts_more2cCrl)Nz
 108  x = (2+
 109  3)FrmrPrrr�test_push_accepts_more3roz-InputSplitterTestCase.test_push_accepts_more3cCsl|j}|�d�|�d�|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)Nr[z    x = (2+z    3)Tz	    y = 3rFrmrPrrr�test_push_accepts_more4s
 110  
 111  
 112  
 113  
 114  z-InputSplitterTestCase.test_push_accepts_more4cCsB|j}|�d�|�d�|�d�|�d�|�|��d�dS)Nztry:z	    a = 5zexcept:z	    raiseTrmrPrrr�test_push_accepts_more5%s
 115  
 116  
 117  
 118  z-InputSplitterTestCase.test_push_accepts_more5cCs>|j}|�d�|�|��d�|�d�|�|��d�dS)Nzimport os, \Tr=FrmrPrrr�test_continuation/s
 119  
 120  
 121  z'InputSplitterTestCase.test_continuationcCrl)Nzrun fooFrmrPrrr�test_syntax_error6s
 122  z'InputSplitterTestCase.test_syntax_errorcCs(|j�d�|j�d�|j�d�dS)NuPérezuéuu'é')rr
 123  rFrrr�test_unicode>sz"InputSplitterTestCase.test_unicodeu"Bug in python 3.9.8 – bpo 45738))��r�alphar#T)�reason�	conditionZraises�strictcCsX|j}|�d�|�|��d�|�d�|�|��d�|�d�|�|��d�dS)z Test issue #2108.z1 \
 124  
 125  Fz1 \ z(1 \ NrmrPrrr�test_line_continuationCs
 126  
 127  
 128  z,InputSplitterTestCase.test_line_continuationcCsd|j}|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�|�d	�d�dS)
 129  N�a = 1)ZcompleteNzfor a in range(5):)�
 130  incompleter$z	raise = 2)�invalidNz
 131  a = [1,
 132  2,)rrzdef a():
 133   x=1
 134   global x)rrCZcheck_completerPrrr�test_check_completeYsz)InputSplitterTestCase.test_check_completeN)"r9r:r;rArQrVrYr\r]r^rarcrdrerfrgrjrkrnrprqrrrsrtrurvr%�markZxfailr=�version_info�SystemErrorr}r�rrrrrHys@
 135  		
 136  
 137  
 138  
 139  	
 140  �
 141  rHc@�@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
 142  d�Zdd
 143  �Z	dS)�InteractiveLoopTestCasez7Tests for an interactive loop like a python shell.
 144      cCs@tt|��}i}t||�|��D]\}}|�|||�qdS)a$Validate that the given input lines produce the resulting namespace.
 145  
 146          Note: the input lines are given exactly as they would be typed in an
 147          auto-indenting environment, as mini_interactive_loop above already does
 148          auto-indenting and prepends spaces to the input.
 149          N)rr�exec�itemsrC)r@r�nsrZtest_ns�k�vrrr�check_nsds
 150  �z InteractiveLoopTestCase.check_nscCs|�dgtdd��dS)NrKr �r"�r��dictrFrrr�test_simpletsz#InteractiveLoopTestCase.test_simplecCs|�ddgtdd��dS)Nr[zx=2r#r�r�rFrrr�test_simple2w�z$InteractiveLoopTestCase.test_simple2cCs|�dgtddd��dS)Nzx=1; y=2r r#)r"�yr�rFrrr�test_xyzr�zInteractiveLoopTestCase.test_xycCs|�gd�tdddd��dS)N)r[za=1zb=2zc=3r r#rw)�a�b�cr�rFrrr�test_abc}sz InteractiveLoopTestCase.test_abccCs|�gd�tdd��dS)N)zx =(1+z1+z2)r$r�r�rFrrr�
 151  test_multi�r�z"InteractiveLoopTestCase.test_multiN)
 152  r9r:r;�__doc__r�r�r�r�r�r�rrrrr�asr�c@r�)�IPythonInputTestCaseaSBy just creating a new class whose .isp is a different instance, we
 153      re-run the same test battery on the new input splitter.
 154  
 155      In addition, this runs the tests over the syntax and syntax_ml dicts that
 156      were tested by individual functions, as part of the OO interface.
 157  
 158      It also makes some checks on the raw buffer storage.
 159      cCrIrE)r�IPythonInputSplitterrFrrrrA�rJzIPythonInputTestCase.setUpcCs�|j}t��D]7}|D]2\}}|�d�rq|�|d�|j}|��}|�|��|t	j
 160  �d|||��|�|��|���qqdS)z6Call all single-line syntax tests from the main objectr	r!rN)rr�values�
 161  startswithr
 162  �
 163  source_rawrrC�rstripr(Z
 164  pair_fail_msg�format)r@r�example�raw�out_t�out_raw�outrrr�test_syntax�s
 165  ���z IPythonInputTestCase.test_syntaxcCs�|j}t��D]N}|D]I}g}g}|D]\}}|dur |�|�|dur.|�|�|�|�q|j}|��}	d�|���}
 166  d�|���}|�	|	��|
 167  �|�	|��|�qqdS�Nr!)
 168  rrr��appendr
 169  r�r�joinr�rC)r@rr��
 170  line_pairs�out_t_partsZ	raw_partsZlrawZ
 171  out_t_partr�r�r�r�rrr�test_syntax_multiline�s(
 172  
 173  
 174  ���z*IPythonInputTestCase.test_syntax_multilinecCsl|j}t��D],}g}|D]%}d�dd�|D��}d�dd�|D��}|�|�}|�|��|���q
 175  qdS)Nr!css �|]\}}|dur|VqdSrEr)�.0�r�_rrr�	<genexpr>���zBIPythonInputTestCase.test_syntax_multiline_cell.<locals>.<genexpr>css �|]\}}|dur|VqdSrEr)r�r��trrrr��r�)rrr�r��transform_cellrCr�)r@rr�r�r�r�r�r�rrr�test_syntax_multiline_cell�s
 176  ��z/IPythonInputTestCase.test_syntax_multiline_cellcCsH|j}dD]\}}}}d|||f}|�|�}|�|��|���qdS)N))z%%cellm a
 177  In[1]:�cellmr�zIn[1]:)z%%cellm 
 178  line
 179  >>> hir�rzline
 180  >>> hi)z>>> %%cellm 
 181  line
 182  >>> hir�rzline
 183  hi)z%%cellm 
 184  >>> hir�rz>>> hi)z%%cellm 
 185  line1
 186  line2r�rzline1
 187  line2)z%%cellm 
 188  line1\\
 189  line2r�rz
 190  line1\\
 191  line2z(get_ipython().run_cell_magic(%r, %r, %r))rr�rCr�)r@rr��namer�cell�expectedr�rrr�test_cellmagic_preempt�s�
 192  �z+IPythonInputTestCase.test_cellmagic_preemptcCsv|j}Gdd�dt�}|j�d|��ddddfdd	d
 193  fdddffD]\}}|�|�}|�|��|���q%dS)
 194  Nc@r7)zKIPythonInputTestCase.test_multiline_passthrough.<locals>.CommentTransformercSs
 195  g|_dSrE)�_linesrFrrr�__init__�s
 196  zTIPythonInputTestCase.test_multiline_passthrough.<locals>.CommentTransformer.__init__cSs|j�|d�dS)N�#)r�r�)r@rrrrr
 197  �szPIPythonInputTestCase.test_multiline_passthrough.<locals>.CommentTransformer.pushcSsd�|j�}g|_|Sr�)r�r�)r@r-rrrrL�szQIPythonInputTestCase.test_multiline_passthrough.<locals>.CommentTransformer.resetN)r9r:r;r�r
 198  rLrrrr�CommentTransformer�sr�r)za=5za=5#z%ls fooz$get_ipython().run_line_magic(%r, %r))�lszfoo#z!ls foo
 199  %ls barz=get_ipython().system(%r)
 200  get_ipython().run_line_magic(%r, %r))zls foo#r�zbar#z1
 201  2
 202  3
 203  %ls foo
 204  4
 205  5z31#
 206  2#
 207  3#
 208  get_ipython().run_line_magic(%r, %r)
 209  4#
 210  5#)rrZphysical_line_transforms�insertr�rCr�)r@rr�r�r�r�rrr�test_multiline_passthrough�s
 211  
 212  
 213  �
 214  �z/IPythonInputTestCase.test_multiline_passthroughN)
 215  r9r:r;r�rAr�r�r�r�r�rrrrr��s	r��__main__)r�zIn> Tr	z... zInput source was:
 216  zRaw source was:
 217  ZByecCs�t�d�dus	J�t�d�dusJ�t�d�dusJ�t�d�dus$J�t�d�dus-J�t�d�dus6J�t�d	�dus?J�t�d
 218  �dusHJ�t�d�dusQJ�t�d�dusZJ�t�d
 219  �duscJ�dS)NrF�abc�abc
 220  zabc
 221  ar!Tz
 222   zabc
 223   �abc
 224  
 225  zabc
 226  d
 227  
 228  z	abc
 229  d
 230  e
 231  
 232  z
 233  abc 
 234   
 235   
 236  
 237  )rZ
 238  last_blankrrrr�test_last_blanksr�cCs$t�d�dus	J�t�d�dusJ�t�d�dusJ�t�d�dus$J�t�d�dus-J�t�d�dus6J�t�d�d	us?J�t�d
 239  �d	usHJ�t�d�d	usQJ�t�d�d	usZJ�t�d
 240  �d	uscJ�t�d�d	uslJ�t�d�d	usuJ�t�d�d	us~J�t�d�d	us�J�t�d�d	us�J�dS)NrFr�r�zabc
 241  
 242  azabc
 243   
 244  r�z
 245  
 246  Tz
 247  
 248   z
 249   
 250  zabc
 251  
 252   zabc
 253  
 254  
 255  zabc
 256  
 257   
 258  zabc
 259  
 260   
 261   z	abc
 262  
 263   
 264   
 265  zabc
 266  d
 267  
 268  
 269  zabc
 270  d
 271  e
 272  f
 273  
 274  
 275  )rZlast_two_blanksrrrr�test_last_two_blanks#s r�c@r7)�CellMagicsCommoncCs$d}|j�|�}d}||ksJ�dS)Nz%%cellm line
 276  body
 277  z6get_ipython().run_cell_magic('cellm', 'line', 'body')
 278  )�spr�)r@rr��refrrr�test_whole_cell9sz CellMagicsCommon.test_whole_cellcCs"|j�d�|j��dusJ�dS)Nz%%cellm?F�r�r
 279  rrFrrr�test_cellmagic_help?sz$CellMagicsCommon.test_cellmagic_helpcCs|j��dSrE)r�rLrFrrrrGCrJzCellMagicsCommon.tearDownN)r9r:r;r�r�rGrrrrr�7sr�c@s(eZdZejdd�Zdd�Zdd�ZdS)�CellModeCellMagicsF�Zline_input_checkercCsX|j}|�d�|��dusJ�|�d�|��dusJ�|�d�|��dus*J�dS)Nz%%cellm firstline
 280  Tzline2
 281  r!r��r@r�rrr�test_incrementalJs
 282  
 283  
 284  z#CellModeCellMagics.test_incrementalcCs*d�gd��}|j�|�}d|vsJ�dS)Nr!)z%%writefile foo.py�# coding: utf-8uprint(u"üñîçø∂é")r�)r�r�r�)r@rr�rrr�test_no_strip_codingTsz'CellModeCellMagics.test_no_strip_codingN)r9r:r;rr�r�r�r�rrrrr�Gs
 285  r�c@s eZdZejdd�Zdd�ZdS)�LineModeCellMagicsTr�cCs>|j}|�d�|��dusJ�|�d�|��dusJ�dS)Nz%%cellm line2
 286  Tr!Fr�r�rrrr�as
 287  
 288  
 289  z#LineModeCellMagics.test_incrementalN)r9r:r;rr�r�r�rrrrr�^sr�))r~r)zfor a in b:r$)zdef f():r$)zdef f(): #commentr$)za = ":#not a comment"r)zdef f():
 290      a = 1r$)zdef f():
 291      return 1r)z'for a in b:
 292     if a < 0:       continuerw)za = {r$)z
 293  a = {
 294       1,�)z
 295  b = """123rr)zdef f():
 296      passr)z$class Bar:
 297      def f():
 298          passr$)z%class Bar:
 299      def f():
 300          raiser$cCs:tD]\}}t�|�}d�|||�}||ksJ|��qdS)Nz#{!r} != {!r} (expected)
 301   Code: {!r})�indentation_samplesrZfind_next_indentr�)rO�exp�res�msgrrr�test_find_next_indents
 302  
 303  �r�)5r�Zunittestr%r=r&�DeprecationWarningZIPython.corerrZIPython.core.inputtransformerrZ(IPython.core.tests.test_inputtransformerrrZIPython.testingrr(rrr,r/r6ZTestCaser8rHr�r�r9r
 304  r�Zstart_promptZ
 305  autoindentrrrr�inputrr
 306  r�r�rrri�EOFErrorr�r��objectr�r�r�r�r�rrrr�<module>sd�	
 307  i#l
 308  �
 309  
 310  ��