o
    i8                     @   s  d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZ d
d Zdd Ze jdddgdd Ze jdddgdd Z e jdg ddd Z!e jdg ddd Z"e jdg dd d! Z#e jdg d"d#d$ Z$e jd%d&d'gd(d) Z%d*d+ Z&d,d- Z'd.d/ Z(d0d1 Z)d2d3 Z*d4d5 Z+e j,d6d7 Z-d8d9 Z.d:d; Z/d<d= Z0d>d? Z1d@dA Z2dBdC Z3dDdE Z4dFdG Z5dHdI Z6dS )J    N)
acceptaccept_or_jump_to_endaccept_tokenaccept_characteraccept_wordaccept_and_keep_cursordiscardNavigableAutoSuggestFromHistoryswap_autosuggestion_upswap_autosuggestion_down)	skip_over)create_ipython_shortcuts)InMemoryHistory)Buffer)Document)AutoSuggestFromHistory)patchMockc                  C   sR   dd l m  m  m}  tjtdd | j W d    d S 1 s"w   Y  d S )Nr   z8\.12.+accept_or_jump_to_endmatch)'IPython.terminal.shortcuts.auto_suggestterminal	shortcutsauto_suggestpytestwarnsDeprecationWarningaccept_in_vi_insert_mode)iptsa r   `/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/IPython/terminal/tests/test_shortcuts.pytest_deprected   s   "r!   c                 C   sF   t  }t  |_t  |j_| |j_||j_||jj_t| |d|j_|S )N)textcursor_position)r   current_buffer
suggestionr"   r#   r   document)r"   cursorr%   eventr   r   r    
make_event    s   

r)   ztext, suggestion, expected) def out(tag: str, n=50):r+   )def out(tag: str, n=50):r-   c                 C   sL   t | t| |}|j}t |_t| |jjsJ |jjd |fks$J d S Nr   )r)   lenr$   r   insert_textr   called	call_args)r"   r%   expectedr(   bufferr   r   r    test_accept+   s   r5   ztext, suggestion)r*   r+   )r,   r-   c                 C   sD   t | t| |}|j}t |_t| |jjrJ |jd u s J d S N)r)   r/   r$   r   r0   r   r1   r%   )r"   r%   r(   r4   r   r   r    test_discard;   s   r7   z text, cursor, suggestion, called))123456   	123456789T)r8      r:   F)z123456   
789r9   r:   Tc                 C   sB   t | ||}t |j_t| |r|jj  dS |jj  dS )z?
    test that autosuggest is only applied at end of line.
    N)r)   r   r$   r0   r   assert_calledassert_not_called)r"   r'   r%   r1   r(   r   r   r    test_autosuggest_at_EOLK   s   
r>   )r*   r+   r,   def out(tag: str, n=50):zef )de f out(tag: str, n=50):f defz out(tag: str, n=50): )r,   r-   zout()zdef ozut(tag: str, n=50):zut()zdef ouzt(tag: str, n=50):zt()zdef outz(tag: str, n=50):()zdef out(ztag: str, n=50):ztag: )z	def out(tzag: str, n=50):zag: )z
def out(tazg: str, n=50):zg: )zdef out(tagz: str, n=50):z: )zdef out(tag:z str, n=50):rH   )zdef out(tag: zstr, n=50):zstr, )zdef out(tag: sz
tr, n=50):ztr, )zdef out(tag: stz	r, n=50):zr, )zdef out(tag: strz, n=50):z, n)zdef out(tag: str,z n=50):z n)zdef out(tag: str, zn=50):zn=)zdef out(tag: str, nz=50):=)zdef out(tag: str, n=z50):z50))zdef out(tag: str, n=5z0):z0))zdef out(tag: str, n=50):rK   )zdef out(tag: str, n=50):rL   c                 C   L   t | t| |}t |j_t| |jjjsJ |jjjd |fks$J d S r.   )r)   r/   r   r$   r0   r   r1   r2   r"   r%   r3   r(   r   r   r    test_autosuggest_tokenb   s
   
rO   ))r*   r+   rA   )rA   rB   e)rC   rD   frF   c                 C   rM   r.   )r)   r/   r   r$   r0   r   r1   r2   rN   r   r   r    test_accept_character   s
   

rR   )r?   r@   )derD   rE   rF   )r,   r-   z	out(tag: c                 C   rM   r.   )r)   r/   r   r$   r0   r   r1   r2   rN   r   r   r    test_accept_word   s
   
rT   z"text, suggestion, expected, cursor)r*   r+   r+   r   )r,   r-   r-      c                 C   sV   t | ||}|j}t |_t| |jjsJ |jjd |fks"J |j|ks)J d S r.   )r)   r$   r   r0   r   r1   r2   r#   )r"   r%   r3   r'   r(   r4   r   r   r    test_accept_and_keep_cursor   s   rV   c                  C   sl   d} t | t| d}t |j_td}t| |jjjrJ |js$J W d    d S 1 s/w   Y  d S )Nr+   r*   z?prompt_toolkit.key_binding.bindings.named_commands.forward_word)r)   r/   r   r$   r0   r   r   r1   )fullr(   forward_wordr   r   r    test_autosuggest_token_empty   s   
"rY   c                  C   sD   t  } t }| |_t }t |_t|du sJ t|du s J dS )zHEnsure that swapping autosuggestions does not break with other providersN)r   get_ipythonr   r   r   r$   r
   r   )provideripr(   r   r   r    test_other_providers   s   r]   c                     s.  t  tg dd} t| d t }|_|  2 z3 d H W }q6 d _d _t}t	}t
 } |_ fdd}| jdksAJ || | jd	ksMJ || | jd
ksYJ || | jdkseJ || | jd
ksqJ || | jd	ks}J || | jdksJ || | jd
ksJ d S )N)very_averyvery_bvery_chistory_stringshistory   r_   c                           j} |  _| S r6   get_suggestionr&   r%   r%   r4   r[   r   r    ri         z/test_navigable_provider.<locals>.get_suggestion_c_b_ar	   r   r   rZ   r   loadr#   r"   r
   r   r   r$   re   r\   _updownr(   ri   r   rk   r    test_navigable_provider   s>   
rv   c                     s   t  tddgd} t| d t }|_|  2 z3 d H W }q6 d _d _t}t	}t
 } |_ fdd}| jd	ksAJ || | jd
ksMJ || | jdksYJ || | jd
kseJ || | jd	ksqJ d S )Nzvery_a
very_bra   rb   rd   rf   r_   c                     rg   r6   rh   rj   rk   r   r    ri     rl   zAtest_navigable_provider_multiline_entries.<locals>.get_suggestionrm   rn   ro   rp   rr   r   rk   r    )test_navigable_provider_multiline_entries  s2   
rw   c                  C   s   t  } t | _| S r6   )r   r   default_buffer)sessionr   r   r    create_session_mock.  s   rz   c                  C   s   t  } d| _t }| | | jdksJ |jj  | jdks"J t }| | d| _| jdks4J |jj  | jdksAJ d| _|   |jj  |jj  | jdks[J d S )N   r      r;   )r	   
skip_linesrz   connectrx   on_text_insertfire
disconnect)r[   	session_1	session_2r   r   r    "test_navigable_provider_connection4  s$   

r   c                  c   s8    t  } t | _t| | j_z	| V  W d | _d S d | _w r6   )rZ   r   pt_appr   key_bindings)r\   r   r   r    ipython_with_promptN  s   r   c                    s   t  } fdd|jjjD S )Nc                    s   g | ]	}|j  kr|qS r   )handler).0bindingcommandr   r    
<listcomp>[  s
    
z,find_bindings_by_command.<locals>.<listcomp>)rZ   r   r   bindings)r   r\   r   r   r    find_bindings_by_commandY  s   
r   c                 C   s  t t}t|dksJ dg ddg| _t t}t|dks!J t|d jg dks.J t|d jt|d jks>J |d j|d jksJJ dddg| _t t}t|dks]J t|d jg dksjJ t|d jt|d jkszJ |d j|d jksJ d S )Nr{   !IPython:auto_suggest.accept_token)abcr   new_keysr   always)r   
new_filter)r   r   r/   r   listkeysfilter)r   originalmatchedr   r   r    test_modify_unique_shortcutb  s      r   c                 C   s`   t t}t|dksJ dg dg| _t t}t|dksJ g | _t t}t|dks.J d S )Nr{   r   r   r   )r   r   r/   r   r   r   r   r   r    test_disable_shortcuty  s   r   c                 C   s   t t}dd |D }|h dksJ tjtdd ddgdg| _W d    n1 s-w   Y  ddgd	d
g| _t t}dd |D }|h dksNJ d S )Nc                 S      h | ]}|j d  qS r   r   r   mr   r   r    	<setcomp>      z4test_modify_shortcut_with_filters.<locals>.<setcomp>>   }"')]zMultiple shortcuts matchingr   IPython:auto_match.skip_overxr   z6focused_insert & auto_match & followed_by_single_quote)r   r   match_filterc                 S   r   r   r   r   r   r   r    r     r   >   r   r   r   r   r   )r   r   r   raises
ValueErrorr   )r   r   matched_keysr   r   r    !test_modify_shortcut_with_filters  s   
r   c                   C   s   d S r6   r   r   r   r   r    example_command  s   r   c                 C   sr   t t}t|dksJ tjtdd ddgdg| _W d    n1 s&w   Y  t t}t|dks7J d S )Nr   zexample_command is not a knownr   r   r   r   )r   r   r/   r   r   r   r   r   r   r   r    !test_add_shortcut_for_new_command  s   
r   c                 C   sH   t jtdd ddgdgdg| _W d    d S 1 sw   Y  d S )NzNo shortcuts matchingr   r   r   y)r   
match_keysr   )r   r   r   r   )r   r   r   r    test_modify_shortcut_failure  s   "r   c                 C   s   t t}t|dksJ tjtdd dg ddg| _W d    n1 s&w   Y  ddgddg| _t t}t|dks@J g | _t t}t|dksOJ d S )	Nrf   z"Cannot add a shortcut without keysr   r   Tr   r   creater   r9   )r   r   r/   r   r   r   r   r   r   r   r    &test_add_shortcut_for_existing_command  s   
r   c                  C   s<   t  } | jd u s
J ddgddg}|| _| j|ksJ d S )Nr   r   Tr   )rZ   r   r   )ipythonr   r   r   r    )test_setting_shortcuts_before_pt_app_init  s   r   )7r   r   r   r   r   r   r   r   r   r	   r
   r   %IPython.terminal.shortcuts.auto_matchr   IPython.terminal.shortcutsr   prompt_toolkit.historyr   prompt_toolkit.bufferr   prompt_toolkit.documentr   prompt_toolkit.auto_suggestr   unittest.mockr   r   r!   r)   markparametrizer5   r7   r>   rO   rR   rT   rV   rY   r]   rv   rw   rz   r   fixturer   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>   s    0
	
	


	


4&

	