U
    -eT                      @   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                   @   s   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_ipythonZautosuggestions_providerassertEqualZauto_suggestZassertIsInstancer   r   selfip r   l/var/www/html/Darija-Ai-Train/env/lib/python3.8/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      s   r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	TestElidec                 C   sn   t dd t dd | t ddd tjdddddg}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.hhhhhhZ
aaaaaaaaaaZ
bbbbbbbbbbZ
ccccccccccau   …b)r   r	   ossepjoin)r   test_stringZ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
   Z	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   s   |  tddddd dS )Y
        if the match is too short we don't elide.
        avoid the "the...the"
        r   Zther   r   Nr   r    r   r   r   test_elide_typed_short_match7   s    z&TestElide.test_elide_typed_short_matchc                 C   s   |  tddddd dS )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#   r$   r   r   r   r   r      s   

r   c                   @   s   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=)   Zarg1zfunc1(a)zfunc1(az%magicZ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   r'   r   r   r   r   r%   Q   s   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	exceptionr   r   )r   r*   r   r   r   __init__o   s    zmock_input_helper.__init__c                 C   s   | j j| _| j| j _| S r)   )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 r)   )r.   r   r-   )r   etypevaluetbr   r   r   __exit__y   s    zmock_input_helper.__exit__c                 C   sN   zt | jW S  tk
r*   d| j_Y dS    t | _d| j_Y dS X d S )NFr   )nextr*   StopIterationr   Zkeep_runningsysexc_infor+   r    r   r   r   r/   |   s    
zmock_input_helper.fake_inputN)r   r   r   __doc__r,   r0   r4   r/   r   r   r   r   r(   j   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              	      s^    | }t |}|j  W 5 Q R X |jd k	rZ|j\}}}dd l}|j|tjd ~|d S )Nr   )file)r(   r   Zinteractr+   	tracebackprint_tbr7   stdout)r   r*   Zmihr1   r2   r3   r;   testfuncr   r   test_method   s    

zmock_input.<locals>.test_methodr   )r?   r@   r   r>   r   
mock_input   s    rA   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   )Zget_history_itemget_current_history_length).0xrlr   r   
<listcomp>   s   z<InteractiveShellTestCase.rl_hist_entries.<locals>.<listcomp>   )range)r   rG   nr   rF   r   rl_hist_entries   s    
z(InteractiveShellTestCase.rl_hist_entriesc              	   c   s   t  }|jt zdtjddd dV  W 5 Q R X tjddd dV  W 5 Q R X tjddd dV  W 5 Q R X W 5 |jt X d S )	N4F)suppressz
print(2*2)zSyntaxError: input containszprint(2345) # syntaxerrorZ16z
print(4*4))r   Zinput_transformers_postappendsyntax_error_transformerremovettZAssertPrintsr
   r   r   r   !test_inputtransformer_syntaxerror   s    z:InteractiveShellTestCase.test_inputtransformer_syntaxerrorc           	   	      s   t  }|j}|jdgkst|jjs(t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 5 d|jjd	 _|jd	= X  d
kst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   rV   rW   r   r   r   r   Test   s   rX   c                   @   s   e Zd Zdd ZdS )z@InteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2c                 S   s    ddl m}m} ||d d S )Nr   )displayHTMLz<custom>)IPython.displayrY   rZ   )r   rY   rZ   r   r   r   _ipython_display_   s    zRInteractiveShellTestCase.test_repl_not_plain_text.<locals>.Test2._ipython_display_N)r   r   r   r\   r   r   r   r   Test2   s   r]   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_formatterZactive_typesAssertionErrorZipython_display_formatterenabledobjectformatr	   reprrP   
formattersZmime_renderersrY   )	r   r   	formatterrX   objr_   _r]   rc   r   ra   r   test_repl_not_plain_text   s(    

z1InteractiveShellTestCase.test_repl_not_plain_textN)r   r   r   rM   rA   rT   rn   r   r   r   r   rB      s   
rB   c                 C   s<   | D ]2}| d}|dkrtd}||_|d |_|q| S )zDTransformer that throws SyntaxError if 'syntaxerror' is in the code.Zsyntaxerrorr   zinput contains "syntaxerror"rI   )findSyntaxErrortextoffset)lineslineposer   r   r   rQ      s    

rQ   c                   @   s   e Zd Zdd ZdS )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 bZTerminalMagicsN)nameZpasted_func6   7   )r   Zmagics_managerregistryZstore_or_executer	   Z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   rw      s   rw   )r9   r7   Zunittestr   Zprompt_toolkit.auto_suggestr   ZIPython.testingr   rS   ZIPython.terminal.ptutilsr   r   Z'IPython.terminal.shortcuts.auto_suggestr   ZTestCaser   r   r%   rg   r(   rA   rB   rQ   rw   r   r   r   r   <module>   s   3I