
    9 fT                      <   d 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  G d dej                  Z G d	 d
ej                  Z G d dej                  Z G d de          Zd Z G d dej                  Zd Z G d dej                  ZdS )z:Tests for the TerminalInteractiveShell and related pieces.    N)AutoSuggestFromHistory)tools)_elide(_adjust_completion_text_based_on_context)NavigableAutoSuggestFromHistoryc                       e Zd Zd ZdS )TestAutoSuggestc                    t                      }d |_        |                     |j        d            d|_        |                     |j        t
                     d|_        |                     |j        t                     d S )Nr   r   )get_ipythonautosuggestions_providerassertEqualauto_suggestassertIsInstancer   r   selfips     a/var/www/equiseq/venv/lib/python3.11/site-packages/IPython/terminal/tests/test_interactivshell.pytest_changing_providerz&TestAutoSuggest.test_changing_provider   ss    ]]&*#$///&>#bo/EFFF&G#bo/NOOOOO    N)__name__
__module____qualname__r    r   r   r	   r	      s(        P P P P Pr   r	   c                   &    e Zd Zd Zd Zd Zd ZdS )	TestElidec                 b   t          dd           t          dd           |                     t          dd          d           t          j                            g d          }t          j        dz   dz   d	z   t          j        z   d
z   }|                     t          |d          |           d S )Nzconcatenate((a1, a2, ...), axis z concatenate((a1, a2, ..), . axisz0aaaa.bbbb.ccccc.dddddd.eeeee.fffff.gggggg.hhhhhhu   aaaa.b…g.hhhhhh)r   
aaaaaaaaaa
bbbbbbbbbb
ccccccccccr   au   …br    )r   r   ossepjoin)r   test_stringexpect_strings      r   
test_elidezTestElide.test_elide   s    0"55512666ErJJ	
 	
 	

 fkk"H"H"HIIFSL44s:RVChN 	 	R00-@@@@@r   c                 R    |                      t          ddd          d           d S )N,the quick brown fox jumped over the lazy dogzthe quick brown fox
   	min_elideu"   the…fox jumped over the lazy dogr   r   r   s    r   test_elide_typed_normalz!TestElide.test_elide_typed_normal-   sD    >%  
 1	
 	
 	
 	
 	
r   c                 R    |                      t          ddd          d           dS )Y
        if the match is too short we don't elide.
        avoid the "the...the"
        r*   ther+   r,   Nr.   r/   s    r   test_elide_typed_short_matchz&TestElide.test_elide_typed_short_match7   s=    
 	A5TVWWW:	
 	
 	
 	
 	
r   c                 R    |                      t          ddd          d           dS )r2   r*   zthe quick red foxr+   r,   Nr.   r/   s    r   test_elide_typed_no_matchz#TestElide.test_elide_typed_no_matchA   sF     	>#  
 ;	
 	
 	
 	
 	
r   N)r   r   r   r(   r0   r4   r6   r   r   r   r   r      sS        A A A
 
 

 
 

 
 
 
 
r   r   c                       e Zd Zd ZdS )TestContextAwareCompletionc                 x   |                      t          ddd          d           |                      t          ddd          d           |                      t          ddd          d           |                      t          ddd          d           |                      t          ddd          d           d S )	Nzarg1=z	func1(a=)   arg1zfunc1(a)zfunc1(az%magicfunc2)r   r   r/   s    r   ,test_adjust_completion_text_based_on_contextzGTestContextAwareCompletion.test_adjust_completion_text_based_on_contextR   s    4Wk1MMv	
 	
 	

 	4Wj!LLg	
 	
 	
 	4WiKKW	
 	
 	
 	4X{ANNPX	
 	
 	
 	4Wk1MMw	
 	
 	
 	
 	
r   N)r   r   r   r=   r   r   r   r8   r8   Q   s#        
 
 
 
 
r   r8   c                   *    e Zd ZdZd Zd Zd Zd ZdS )mock_input_helperzZMachinery for tests of the main interact loop.

    Used by the mock_input decorator.
    c                 H    || _         d | _        t                      | _        d S N)testgen	exceptionr   r   )r   rB   s     r   __init__zmock_input_helper.__init__o   s    --r   c                 J    | j         j        | _        | j        | j         _        | S rA   )r   prompt_for_codeorig_prompt_for_code
fake_inputr/   s    r   	__enter__zmock_input_helper.__enter__t   s     $(G$;!"&/r   c                 (    | j         | j        _        d S rA   )rG   r   rF   )r   etypevaluetbs       r   __exit__zmock_input_helper.__exit__y   s    "&";r   c                     	 t          | j                  S # t          $ r d| j        _        Y dS  t          j                    | _        d| j        _        Y dS xY w)NFr   )nextrB   StopIterationr   keep_runningsysexc_inforC   r/   s    r   rH   zmock_input_helper.fake_input|   sa    	%%% 	 	 	#(DG 33	 \^^DN#(DG 33s    A%AN)r   r   r   __doc__rD   rI   rN   rH   r   r   r   r?   r?   j   sZ              
  
< < <	 	 	 	 	r   r?   c                       fd}|S )zDecorator for tests of the main interact loop.

    Write the test as a generator, yield-ing the input strings, which IPython
    will see as if they were typed in at the prompt.
    c                     |           }t          |          5 }|j                                         d d d            n# 1 swxY w Y   |j        3|j        \  }}}dd l}|                    |t          j                   ~|d S )Nr   )file)r?   r   interactrC   	tracebackprint_tbrS   stdout)r   rB   mihrK   rL   rM   rZ   testfuncs          r   test_methodzmock_input.<locals>.test_method   s    (4..w'' 	3FOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 =$"}E5"r
333K %$s   AA	Ar   )r^   r_   s   ` r   
mock_inputr`      s$         r   c                   0    e Zd Zd Zed             Zd ZdS )InteractiveShellTestCasec                 D    fdt          |dz
  dd          D             S )z-Get last n readline history entries as a listc                 d    g | ],}                                                     |z
            -S r   )get_history_itemget_current_history_length).0xrls     r   
<listcomp>z<InteractiveShellTestCase.rl_hist_entries.<locals>.<listcomp>   sH     / / / ##B$A$A$C$Ca$GHH / / /r      )range)r   ri   ns    ` r   rl_hist_entriesz(InteractiveShellTestCase.rl_hist_entries   s>    / / / /q1ub"--/ / / 	/r   c              #     K   t                      }|j                            t                     	 t	          j        dd          5  dV  d d d            n# 1 swxY w Y   t	          j        dd          5  dV  d d d            n# 1 swxY w Y   t	          j        dd          5  dV  d d d            n# 1 swxY w Y   |j                            t                     d S # |j                            t                     w xY w)	N4F)suppressz
print(2*2)zSyntaxError: input containszprint(2345) # syntaxerror16z
print(4*4))r   input_transformers_postappendsyntax_error_transformerttAssertPrintsremover   s     r   !test_inputtransformer_syntaxerrorz:InteractiveShellTestCase.test_inputtransformer_syntaxerror   s     ]]
"))*BCCC	Hu555 $ $####$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ !>OOO 3 322223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 666 $ $####$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ &--.FGGGGGB&--.FGGGGsw   C( AC( AC( A C( 9B
>C( 
BC( BC( +B<0C( <C  C( C C( (!D	c                   	 t                      }|j        }|j        dgk    sJ |j        j        sJ  G d dt
                    } |            }|                    |          \  }}|                     |dt          |          i            G d d|          }d		fd}|j        j        	                    d           d	|j        j
        d         _        ||j        d<   	  |            }t          |           d|j        j
        d         _        |j        d= n$# d|j        j
        d         _        |j        d= w xY w	d	k    sJ d S )
Nz
text/plainc                       e Zd Zd Zd ZdS )?InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Testc                 &    dt          |           z  S )Nz	<Test %i>)idr/   s    r   __repr__zHInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test.__repr__   s    "RXX--r   c                     dS )Nz<html>r   r/   s    r   _repr_html_zKInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test._repr_html_   s    xr   N)r   r   r   r   r   r   r   r   Testr}      s2        . . .         r   r   c                       e Zd Zd ZdS )@InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2c                 >    ddl m}m}  | |d                     d S )Nr   )displayHTMLz<custom>)IPython.displayr   r   )r   r   r   s      r   _ipython_display_zRInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2._ipython_display_   s:    99999999Z(()))))r   N)r   r   r   r   r   r   r   Test2r      s#        * * * * *r   r   Fc                 *    t          d           dd S )NzHandler calledT)print)datametadatacalleds     r   handlerzBInteractiveShellTestCase.test_repl_not_plain_text.<locals>.handler   s    "###FFFr   z	text/htmlT)r   display_formatteractive_typesipython_display_formatterenabledobjectformatr   reprru   
formattersmime_renderersr   )
r   r   	formatterr   objr   _r   r   r   s
            @r   test_repl_not_plain_textz1InteractiveShellTestCase.test_repl_not_plain_text   s   ]](	%,7777 2::::	  	  	  	  	 6 	  	  	  dff""3''ad3ii8999	* 	* 	* 	* 	*D 	* 	* 	* 	 	 	 	 	
 	)00===?C'4<)0+&	/$&&CCLLLCHB +K8@!+.. DIB +K8@!+.....~~~~~~s   #D !D=N)r   r   r   ro   r`   rz   r   r   r   r   rb   rb      sP        / / /
 H H ZH$- - - - -r   rb   c                     | D ]?}|                     d          }|dk    r"t          d          }||_        |dz   |_        |@| S )zDTransformer that throws SyntaxError if 'syntaxerror' is in the code.syntaxerrorr   zinput contains "syntaxerror"rk   )findSyntaxErrortextoffset)lineslineposes       r   rv   rv      s\      ii&&!88:;;AAFQwAHG	 
 Lr   c                       e Zd Zd ZdS )TerminalMagicsTestCasec                     t                      }d}|j        j        d         }|                    |d           |                      |j        d         d          d           dS )z=Test that code with a blank line doesn't get split (gh-3246).z-def pasted_func(a):
    b = a+1

    return bTerminalMagicsN)namepasted_func6   7   )r   magics_managerregistrystore_or_executer   user_ns)r   r   stms       r   test_paste_magics_blanklinez2TerminalMagicsTestCase.test_paste_magics_blankline   sl    ]]
 '(89
AD)))2M2266;;;;;r   N)r   r   r   r   r   r   r   r   r      s#        < < < < <r   r   )rU   rS   unittestr#   prompt_toolkit.auto_suggestr   IPython.testingr   rw   IPython.terminal.ptutilsr   r   'IPython.terminal.shortcuts.auto_suggestr   TestCaser	   r   r8   r   r?   r`   rb   rv   r   r   r   r   <module>r      s   @ @ 


  				 > > > > > > ( ' ' ' ' ' U U U U U U U U S S S S S SP P P P Ph' P P P0
 0
 0
 0
 0
! 0
 0
 0
f
 
 
 
 
!2 
 
 
2       :  .F F F F Fx0 F F FR	 	 	< < < < <X. < < < < <r   