o
    ĎiT                      @   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
mZ ddlmZ G dd dej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)AutoSuggestFromHistory)tools)_elide(_adjust_completion_text_based_on_context)NavigableAutoSuggestFromHistoryc                   @      e Zd Zdd ZdS )TestAutoSuggestc                 C   sF   t  }d |_| |jd  d|_| |jt d|_| |jt d S )Nr   r   )get_ipythonautosuggestions_providerassertEqualauto_suggestassertIsInstancer   r   selfip r   g/home/jeff/fluffinator/venv/lib/python3.10/site-packages/IPython/terminal/tests/test_interactivshell.pytest_changing_provider   s   z&TestAutoSuggest.test_changing_providerN)__name__
__module____qualname__r   r   r   r   r   r          r   c                   @   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   r   ossepjoin)r   test_stringexpect_stringr   r   r   
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_match7   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_matchA   s   z#TestElide.test_elide_typed_no_matchN)r   r   r   r$   r+   r/   r0   r   r   r   r   r      s
    

r   c                   @   r   )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_contextR   s   zGTestContextAwareCompletion.test_adjust_completion_text_based_on_contextN)r   r   r   r5   r   r   r   r   r1   Q   r   r1   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	exceptionr	   r   )r   r8   r   r   r   __init__o   s   zmock_input_helper.__init__c                 C   s   | j j| _| j| j _| S r7   )r   prompt_for_codeorig_prompt_for_code
fake_inputr*   r   r   r   	__enter__t   s   

zmock_input_helper.__enter__c                 C   s   | j | j_d S r7   )r<   r   r;   )r   etypevaluetbr   r   r   __exit__y   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   )nextr8   StopIterationr   keep_runningsysexc_infor9   r*   r   r   r   r=   |   s   
zmock_input_helper.fake_inputN)r   r   r   __doc__r:   r>   rB   r=   r   r   r   r   r6   j   s    r6   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)r6   r   interactr9   	tracebackprint_tbrF   stdout)r   r8   mihr?   r@   rA   rK   testfuncr   r   test_method   s   

zmock_input.<locals>.test_methodr   )rP   rQ   r   rO   r   
mock_input   s   rR   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   rY   nr   rX   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))r	   input_transformers_postappendsyntax_error_transformerttAssertPrintsremover   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   rk   rl   r   r   r   r   Test   s    rm   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.displayrn   ro   )r   rn   ro   r   r   r   _ipython_display_   s   zRInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2._ipython_display_N)r   r   r   rq   r   r   r   r   Test2   r   rr   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)r	   display_formatteractive_typesipython_display_formatterenabledobjectformatr   reprrd   
formattersmime_renderersrn   )	r   r   	formatterrm   objrt   _rr   rx   r   rv   r   test_repl_not_plain_text   s,   



z1InteractiveShellTestCase.test_repl_not_plain_textN)r   r   r   r_   rR   ri   r   r   r   r   r   rS      s
    
rS   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"r[   )findSyntaxErrortextoffset)lineslineposer   r   r   re      s   

re   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   )r	   magics_managerregistrystore_or_executer   user_ns)r   r   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   )rH   rF   unittestr   prompt_toolkit.auto_suggestr   IPython.testingr   rf   IPython.terminal.ptutilsr   r   'IPython.terminal.shortcuts.auto_suggestr   TestCaser   r   r1   r}   r6   rR   rS   re   r   r   r   r   r   <module>   s    3I