
    fT                      H   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y)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y)TestAutoSuggestc                     t               }d |_        | j                  |j                  d        d|_        | j	                  |j                  t
               d|_        | j	                  |j                  t               y )Nr   r   )get_ipythonautosuggestions_providerassertEqualauto_suggestassertIsInstancer   r   selfips     f/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/terminal/tests/test_interactivshell.pytest_changing_providerz&TestAutoSuggest.test_changing_provider   s_    ]&*#$/&>#boo/EF&G#boo/NO    N)__name__
__module____qualname__r    r   r   r	   r	      s    Pr   r	   c                   $    e Zd Zd Zd Zd Zd Zy)	TestElidec                 @   t        dd       t        dd       | j                  t        dd      d       t        j                  j	                  g d      }t        j                  dz   dz   d	z   t        j                  z   d
z   }| j                  t        |d      |       y )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126ErJ	

 ffkk"HIFFSL44s:RVVChN 	 	R0-@r   c                 @    | j                  t        ddd      d       y )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-   s&    >%
 1	
r   c                 @    | j                  t        ddd      d       y)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:	
r   c                 @    | j                  t        ddd      d       y)r2   r*   zthe quick red foxr+   r,   Nr.   r/   s    r   test_elide_typed_no_matchz#TestElide.test_elide_typed_no_matchA   s(     	>#
 ;	
r   N)r   r   r   r(   r0   r4   r6   r   r   r   r   r      s    A


r   r   c                       e Zd Zd Zy)TestContextAwareCompletionc                 &   | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        ddd      d       | j                  t        ddd      d       y )	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Mv	

 	4Wj!Lg	
 	4WiKW	
 	4X{ANPX	
 	4Wk1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y)mock_input_helperzZMachinery for tests of the main interact loop.

    Used by the mock_input decorator.
    c                 >    || _         d | _        t               | _        y N)testgen	exceptionr   r   )r   rB   s     r   __init__zmock_input_helper.__init__o   s    -r   c                 r    | 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)    $(GG$;$;!"&//r   c                 :    | j                   | j                  _        y 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 y t        j                         | _        d| j                  _        Y yxY w)NFr   )nextrB   StopIterationr   keep_runningsysexc_inforC   r/   s    r   rH   zmock_input_helper.fake_input|   sP    	%% 	#(DGG 	 \\^DN#(DGG s    A +A N)r   r   r   __doc__rD   rI   rN   rH   r   r   r   r?   r?   j   s     

<	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                  j                          d d d        j                  8|j                  \  }}}dd l}|j                  |t        j                         ~|y # 1 sw Y   NxY w)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FFOO	 ==$"}}E5"r

3K %	 	s   A==Br   )r^   r_   s   ` r   
mock_inputr`      s     r   c                   (    e Zd Zd Zed        Zd Zy)InteractiveShellTestCasec                     t        |dz
  dd      D cg c]$  }|j                  |j                         |z
        & c}S c c}w )z-Get last n readline history entries as a list   )rangeget_history_itemget_current_history_length)r   rlnxs       r   rl_hist_entriesz(InteractiveShellTestCase.rl_hist_entries   sJ     q1ub"-/ ##B$A$A$Ca$GH / 	/ /s   )?c              #     K   t               }|j                  j                  t               	 t	        j
                  dd      5  d d d d        t	        j
                  dd      5  d d d d        t	        j
                  dd      5  d d d d        |j                  j                  t               y # 1 sw Y   qxY w# 1 sw Y   YxY w# 1 sw Y   AxY w# |j                  j                  t               w xY w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	Hu5 $##$ !>O 3223 6 $##$ &&--.FG$ $3 3$ $ &&--.FGsd   *DC B9	C (C-C CC  D9C>C C
C CC !C>>Dc                   	 t               }|j                  }|j                  dgk(  sJ |j                  j                  sJ  G d dt
              } |       }|j                  |      \  }}| j                  |dt        |      i        G d d|      }d		fd}|j                  j                  j                  d       d	|j                  j                  d   _        ||j                  d<   	  |       }t        |       d|j                  j                  d   _        |j                  d= 	d	k(  sJ y # d|j                  j                  d   _        |j                  d= w xY w)
Nz
text/plainc                       e Zd Zd Zd Zy)?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X--r   c                      y)Nz<html>r   r/   s    r   _repr_html_zKInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test._repr_html_   s    r   N)r   r   r   r}   r   r   r   r   Testrz      s    . r   r   c                       e Zd Zd Zy)@InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2c                 0    ddl m}m}  | |d             y )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Z()r   N)r   r   r   r   r   r   r   Test2r      s    *r   r   Fc                      t        d       dy )NzHandler calledT)print)datametadatacalleds     r   handlerzBInteractiveShellTestCase.test_repl_not_plain_text.<locals>.handler   s    "#Fr   z	text/htmlT)r   display_formatteractive_typesipython_display_formatterenabledobjectformatr   reprrr   
formattersmime_renderersr   )
r   r   	formatterr   objr   _r   r   r   s
            @r   test_repl_not_plain_textz1InteractiveShellTestCase.test_repl_not_plain_text   sT   ]((	%%,777 22::::	 6 	  f""3'ad3i89	*D 	* 	
 	))00=?C''4<)0+&	/&CCLCHB  ++K8@!!+.~~ DIB  ++K8@!!+.s   .D3 3-E N)r   r   r   rl   r`   rw   r   r   r   r   rb   rb      s"    /
 H H$-r   rb   c                 |    | D ]6  }|j                  d      }|dk\  st        d      }||_        |dz   |_        | | S )zDTransformer that throws SyntaxError if 'syntaxerror' is in the code.syntaxerrorr   zinput contains "syntaxerror"rd   )findSyntaxErrortextoffset)lineslineposes       r   rs   rs      sO     ii&!8:;AAFQwAHG Lr   c                       e Zd Zd Zy)TerminalMagicsTestCasec                     t               }d}|j                  j                  d   }|j                  |d       | j	                   |j
                  d   d      d       y)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   s]    ]
 ''(89
AD)2M226;r   N)r   r   r   r   r   r   r   r   r      s    <r   r   )rU   rS   unittestr#   prompt_toolkit.auto_suggestr   IPython.testingr   rt   IPython.terminal.ptutilsr   r   'IPython.terminal.shortcuts.auto_suggestr   TestCaser	   r   r8   r   r?   r`   rb   rs   r   r   r   r   <module>r      s    @   	 > ( U SPh'' P0
!! 0
f
!2!2 
2 :.Fx00 FR	<X.. <r   