o
    ˷eE                     @   s   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
 ddlmZmZ G dd dejZG d	d
 d
ejZG dd deZdd ZG dd dejZdd ZG dd dejZdS )z:Tests for the TerminalInteractiveShell and related pieces.    N)InputTransformer)tools)capture_output)_elide(_adjust_completion_text_based_on_contextc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	TestElidec                 C   sh   t dd t dd | t ddd tjg d}tjd d d	 tj d
 }| 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   assertEqualossepjoin)selftest_stringexpect_stirng r   b/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/terminal/tests/test_interactivshell.py
test_elide   s   

zTestElide.test_elidec                 C   s   |  td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   r   r   r   test_elide_typed_normal    s   z!TestElide.test_elide_typed_normalc                 C      |  td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   r   r   r   test_elide_typed_short_match*   s   z&TestElide.test_elide_typed_short_matchc                 C   r   )r    r   zthe quick red foxr   r   Nr   r   r   r   r   test_elide_typed_no_match4   s   z#TestElide.test_elide_typed_no_matchN)__name__
__module____qualname__r   r   r"   r#   r   r   r   r   r      s
    

r   c                   @      e Zd Zdd ZdS )TestContextAwareCompletionc                 C   sh   |  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   r   r   r   ,test_adjust_completion_text_based_on_contextE   s   zGTestContextAwareCompletion.test_adjust_completion_text_based_on_contextN)r$   r%   r&   r,   r   r   r   r   r(   D       r(   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )mock_input_helperzZMachinery for tests of the main interact loop.

    Used by the mock_input decorator.
    c                 C   s   || _ d | _t | _d S N)testgen	exceptionget_ipythonip)r   r0   r   r   r   __init__b   s   zmock_input_helper.__init__c                 C   s   | j j| _| j| j _| S r/   )r3   prompt_for_codeorig_prompt_for_code
fake_inputr   r   r   r   	__enter__g   s   

zmock_input_helper.__enter__c                 C   s   | j | j_d S r/   )r6   r3   r5   )r   etypevaluetbr   r   r   __exit__l   s   zmock_input_helper.__exit__c                 C   sF   zt | jW S  ty   d| j_Y dS    t | _d| j_Y dS )NFr   )nextr0   StopIterationr3   keep_runningsysexc_infor1   r   r   r   r   r7   o   s   
zmock_input_helper.fake_inputN)r$   r%   r&   __doc__r4   r8   r<   r7   r   r   r   r   r.   ]   s    r.   c                    s    fd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                    sr    | }t |}|j  W d    n1 sw   Y  |jd ur7|j\}}}dd l}|j|tjd ~|d S )Nr   )file)r.   r3   interactr1   	tracebackprint_tbr@   stdout)r   r0   mihr9   r:   r;   rE   testfuncr   r   test_method   s   

zmock_input.<locals>.test_methodr   )rJ   rK   r   rI   r   
mock_inputz   s   rL   c                   @   s(   e Zd Zdd Zedd Zdd ZdS )InteractiveShellTestCasec                    s    fddt |d ddD S )z-Get last n readline history entries as a listc                    s   g | ]}    | qS r   )get_history_itemget_current_history_length).0xrlr   r   
<listcomp>   s    z<InteractiveShellTestCase.rl_hist_entries.<locals>.<listcomp>   )range)r   rS   nr   rR   r   rl_hist_entries   s   
z(InteractiveShellTestCase.rl_hist_entriesc              	   c   s    t  }|jt z`tjddd dV  W d    n1 s w   Y  tjddd dV  W d    n1 s:w   Y  tjddd dV  W d    n1 sTw   Y  W |jt d S W |jt d S |jt w )	N4F)suppressz
print(2*2)zSyntaxError: input containszprint(2345) # syntaxerror16z
print(4*4))r2   input_transformers_postappendsyntax_error_transformerttAssertPrintsremove)r   r3   r   r   r   !test_inputtransformer_syntaxerror   s    z:InteractiveShellTestCase.test_inputtransformer_syntaxerrorc           	   	      s   t  }|j}|jdgksJ |jjsJ G dd dt}| }||\}}| |dt|i G dd d|}d  fdd}|jj	d	 d
|jj
d	 _||jd	< z| }t| W d|jj
d	 _|jd	= nd|jj
d	 _|jd	= w  d
kszJ d S )Nz
text/plainc                   @   s   e Zd Zdd Zdd ZdS )z?InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Testc                 S   s   dt |  S )Nz	<Test %i>)idr   r   r   r   __repr__   s   zHInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test.__repr__c                 S   s   dS )Nz<html>r   r   r   r   r   _repr_html_   s   zKInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test._repr_html_N)r$   r%   r&   re   rf   r   r   r   r   Test   s    rg   c                   @   r'   )z@InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2c                 S   s    ddl m}m} ||d d S )Nr   )displayHTMLz<custom>)IPython.displayrh   ri   )r   rh   ri   r   r   r   _ipython_display_   s   zRInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2._ipython_display_N)r$   r%   r&   rk   r   r   r   r   Test2   r-   rl   Fc                    s   t d d d S )NzHandler calledT)print)datametadatacalledr   r   handler   s   zBInteractiveShellTestCase.test_repl_not_plain_text.<locals>.handlerz	text/htmlT)r2   display_formatteractive_typesipython_display_formatterenabledobjectformatr   reprr^   
formattersmime_renderersrh   )	r   r3   	formatterrg   objrn   _rl   rr   r   rp   r   test_repl_not_plain_text   s,   



z1InteractiveShellTestCase.test_repl_not_plain_textN)r$   r%   r&   rY   rL   rc   r   r   r   r   r   rM      s
    
rM   c                 C   s<   | D ]}| d}|dkrtd}||_|d |_|q| S )zDTransformer that throws SyntaxError if 'syntaxerror' is in the code.syntaxerrorr   zinput contains "syntaxerror"rU   )findSyntaxErrortextoffset)lineslineposer   r   r   r_      s   

r_   c                   @   r'   )TerminalMagicsTestCasec                 C   s>   t  }d}|jjd }|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   )r2   magics_managerregistrystore_or_executer   user_ns)r   r3   stmr   r   r   test_paste_magics_blankline   s
   z2TerminalMagicsTestCase.test_paste_magics_blanklineN)r$   r%   r&   r   r   r   r   r   r      r-   r   )rB   r@   unittestr   IPython.core.inputtransformerr   IPython.testingr   r`   IPython.utils.capturer   IPython.terminal.ptutilsr   r   TestCaser   r(   rw   r.   rL   rM   r_   r   r   r   r   r   <module>   s   3I