
    9 fX:                     F   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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 Zd Ze j         !                    dddg          d             Z"e j         !                    dddg          d             Z#e j         !                    dg d          d             Z$e j         !                    dg d          d             Z%e j         !                    dg d          d             Z&e j         !                    dg d          d             Z'e j         !                    ddd g          d!             Z(d" Z)d# Z*d$ Z+d% Z,d& Z-d' Z.d( Z/e j0        d)             Z1d* Z2d+ Z3d, Z4d- Z5d. Z6d/ Z7d0 Z8d1 Z9d2 Z:dS )3    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reset_search_buffer)InMemoryHistory)Buffer)Document)AutoSuggestFromHistory)DEFAULT_BUFFER)patchMockc                      dd l mc mc m}  t	          j        t          d          5  | j         d d d            d S # 1 swxY 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)iptsas    [/var/www/equiseq/venv/lib/python3.11/site-packages/IPython/terminal/tests/test_shortcuts.pytest_deprectedr$      s    ;;;;;;;;;;;;	(0O	P	P	P ' '&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   =AAc                     t                      }t                      |_        t                      |j        _        | |j        _        ||j        _        ||j        j        _        t          | |          |j        _        |S )N)textcursor_position)r   current_buffer
suggestionr&   r'   r   document)r&   cursorr)   events       r#   
make_eventr-   !   sg    FFE66E&*ffE# $E+1E(+5E#($,$$O$O$OE!L    ztext, suggestion, expected) def out(tag: str, n=50):r0   )def out(tag: str, n=50):r2   c                     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,   buffers        r#   test_acceptr;   ,   sp     tSYY
33E!FF
5MMM$$$$'*xk999999r.   ztext, suggestion)r/   r0   )r1   r2   c                     t          | t          |           |          }|j        }t                      |_        t          |           |j        j        rJ |j        J d S N)r-   r5   r(   r   r6   r	   r7   r)   )r&   r)   r,   r:   s       r#   test_discardr>   <   sa     tSYY
33E!FFENNN!(((($$$$$r.   z text, cursor, suggestion, called))123456   	123456789T)r?      rA   F)z123456   
789r@   rA   Tc                     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(   r6   r   assert_calledassert_not_called)r&   r+   r)   r7   r,   s        r#   test_autosuggest_at_EOLrF   L   sv     tVZ00E'+vvE$%    =(6688888(::<<<<<r.   )r/   r0   r1   def out(tag: str, n=50):zef )de f out(tag: str, n=50):f defz out(tag: str, n=50): )r1   r2   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):rP   )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):rS   )zdef out(tag: str, n=50):rT   c                     t          | t          |           |          }t                      |j        _        t          |           |j        j        j        sJ |j        j        j        d         |fk    sJ d S r4   )r-   r5   r   r(   r6   r   r7   r8   r&   r)   r9   r,   s       r#   test_autosuggest_tokenrW   c   st    < tSYY
33E'+vvE$+2222+5a8XKGGGGGGr.   ))r/   r0   rI   )rI   rJ   e)rK   rL   frN   c                     t          | t          |           |          }t                      |j        _        t          |           |j        j        j        sJ |j        j        j        d         |fk    sJ d S r4   )r-   r5   r   r(   r6   r   r7   r8   rV   s       r#   test_accept_characterr[      st     tSYY
33E'+vvE$U+2222+5a8XKGGGGGGr.   )rG   rH   )derL   rM   rN   )r1   r2   z	out(tag: c                     t          | t          |           |          }t                      |j        _        t          |           |j        j        j        sJ |j        j        j        d         |fk    sJ d S r4   )r-   r5   r   r(   r6   r   r7   r8   rV   s       r#   test_accept_wordr^      st     tSYY
33E'+vvE$+2222+5a8XKGGGGGGr.   z"text, suggestion, expected, cursor)r/   r0   r0   r   )r1   r2   r2      c                     t          | ||          }|j        }t                      |_        t	          |           |j        j        sJ |j        j        d         |fk    sJ |j        |k    sJ d S r4   )r-   r(   r   r6   r   r7   r8   r'   )r&   r)   r9   r+   r,   r:   s         r#   test_accept_and_keep_cursorra      s     tVZ00E!FF5!!!$$$$'*xk9999!V++++++r.   c                     d} t          | t          |           d          }t                      |j        _        t          d          5 }t          |           |j        j        j        rJ |j        sJ 	 d d d            d S # 1 swxY w Y   d S )Nr0   r/   z?prompt_toolkit.key_binding.bindings.named_commands.forward_word)r-   r5   r   r(   r6   r   r   r7   )fullr,   forward_words      r#   test_autosuggest_token_emptyre      s    %DtSYY++E'+vvE$	I
 
 #	U'3::::"""""# # # # # # # # # # # # # # # # # #s   ,BB	Bc                     t                      } d| j        j        _        t                      | j        _        t                      }d|j        j        _        t                      |j        j        _        t          |            | j        j        	                                 t          |           |j        j        j        
                    t                     d S )Nz	some textr/   )r   r(   r*   r&   resetapplayoutfocusr   assert_called_onceassert_called_once_withr   )event_with_textevent_emptys     r#   test_reset_search_bufferro      s    ffO3>O"+0+/66O"(&&K/1K',#'66KO ((("(;;===$$$O 88HHHHHr.   c                      t                      } t                      }| |_        t                      }t	                      |_        t          |          J t          |          J dS )zHEnsure that swapping autosuggestions does not break with other providersN)r   get_ipythonr   r   r   r(   r   r   )provideripr,   s      r#   test_other_providersrt      s`    %''H	BBOFFE!88E!%((000#E**22222r.   c                  *  K   t                      t          g d          } t          |           t                      }|_        |                                 2 3 d {V }6 d_        d_        t          }t          }t                      }|_        fd} |            j        dk    sJ  ||            |            j        dk    sJ  ||            |            j        d	k    sJ  ||            |            j        dk    sJ  ||            |            j        d	k    sJ  ||            |            j        dk    sJ  ||            |            j        dk    sJ  ||            |            j        d	k    sJ d S )
N)very_averyvery_bvery_chistory_stringshistory   rw   c                  L                         j                  } | _        | S r=   get_suggestionr*   r)   r)   r:   rr   s    r#   r   z/test_navigable_provider.<locals>.get_suggestion   (    ,,VV_EE
&r.   _c_b_ar
   r   r   rq   r   loadr'   r&   r   r   r   r(   	r}   rs   _updownr,   r   r:   rr   s	          @@r#   test_navigable_providerr      s     .00H.T.T.TUUUGG$$$F	BBO<<>>       a " FFK	B#DFFE!E     
 > D(((( BuIII> D(((( BuIII> D(((( BuIII> D(((( 	DKKK> D((((DKKK> D((((DKKK> D((((DKKK> D((((((   A&c                  j  K   t                      t          ddg          } t          |           t                      }|_        |                                 2 3 d {V }6 d_        d_        t          }t          }t                      }|_        fd} |            j        dk    sJ  ||            |            j        d	k    sJ  ||            |            j        d
k    sJ  ||            |            j        d	k    sJ  ||            |            j        dk    sJ d S )Nzvery_a
very_bry   rz   r|   r~   rw   c                  L                         j                  } | _        | S r=   r   r   s    r#   r   zAtest_navigable_provider_multiline_entries.<locals>.get_suggestion+  r   r.   r   r   r   r   r   s	          @@r#   )test_navigable_provider_multiline_entriesr     s     .00H/?.JKKKGG$$$F	BBO<<>>       a " FFK	B#DFFE!E     
 > D((((BuIII> D((((BuIII> D((((DKKK> D((((DKKK> D((((((r   c                  H    t                      } t                      | _        | S r=   )r   r   default_buffer)sessions    r#   create_session_mockr   ?  s    ffG#XXGNr.   c                  r   t                      } d| _        t                      }|                     |           | j        dk    sJ |j        j                                         | j        dk    sJ t                      }|                     |           d| _        | j        dk    sJ |j        j                                         | j        dk    sJ d| _        |                                  |j        j                                         |j        j                                         | j        dk    sJ d S )N   r      rB   )r
   
skip_linesr   connectr   on_text_insertfire
disconnect)rr   	session_1	session_2s      r#   "test_navigable_provider_connectionr   E  s?   .00HH#%%IY!####+00222!#####%%IYH!####+00222!####H+00222+00222!######r.   c               #      K   t                      } t                      | _        t          |           | j        _        	 | V  d | _        d S # d | _        w xY wr=   )rq   r   pt_appr   key_bindings)rs   s    r#   ipython_with_promptr   _  sX      	BBI5b99BI			D	s   A 	Ac                 Z     t                      } fd|j        j        j        D             S )Nc                 *    g | ]}|j         k    |S  )handler).0bindingcommands     r#   
<listcomp>z,find_bindings_by_command.<locals>.<listcomp>l  s0       ?g%% 	%%%r.   )rq   r   r   bindings)r   rs   s   ` r#   find_bindings_by_commandr   j  s?    	B   y-6   r.   c                    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    sJ d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    sJ d S )Nr   !IPython:auto_suggest.accept_token)abcr   new_keysr   always)r   
new_filter)r   r   r5   r   listkeysfilter)r   originalmatcheds      r#   test_modify_unique_shortcutr   s  s   '55Hx==A 8___UU%! '|44Gw<<1
  OOO3333
  D!)9$:$:::::1: 22222 8xPP%! '|44Gw<<1
  OOO3333
  D!)9$:$:::::1: 2222222r.   c                     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   r5   r   r   r   s     r#   test_disable_shortcutr     s    &|44Gw<<1 8RHH%! '|44Gw<<1$&!&|44Gw<<1r.   c                 F   t          t                    }d |D             }|h dk    sJ t          j        t          d          5  ddgdg| _        d d d            n# 1 swxY w Y   ddgdd	g| _        t          t                    }d
 |D             }|h dk    sJ d S )Nc                 (    h | ]}|j         d          S r   r   r   ms     r#   	<setcomp>z4test_modify_shortcut_with_filters.<locals>.<setcomp>      ///!AF1I///r.   >   }"')]zMultiple shortcuts matchingr   IPython:auto_match.skip_overxr   z6focused_insert & auto_match & followed_by_single_quote)r   r   match_filterc                 (    h | ]}|j         d          S r   r   r   s     r#   r   z4test_modify_shortcut_with_filters.<locals>.<setcomp>  r   r.   >   r   r   r   r   r   )r   r   r   raises
ValueErrorr   )r   r   matched_keyss      r#   !test_modify_shortcut_with_filtersr     s   &y11G//w///L4444444	z)F	G	G	G 
 
6SEJJ)
%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 6T	
 	
%! 'y11G//w///L444444444s   AA#&A#c                      d S r=   r   r   r.   r#   example_commandr     s    Dr.   c                 (   t          t                    }t          |          dk    sJ t          j        t
          d          5  ddgdg| _        d d d            n# 1 swxY w Y   t          t                    }t          |          dk    sJ d S )Nr   zexample_command is not a knownr   r   r   r   )r   r   r5   r   r   r   r   r   s     r#   !test_add_shortcut_for_new_commandr     s    &77Gw<<1	z)I	J	J	J 
 
)u==)
%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 '77Gw<<1   AA"%A"c                     t          j        t          d          5  ddgdgdg| _        d d d            d S # 1 swxY w Y   d S )NzNo shortcuts matchingr   r   r   y)r   
match_keysr   )r   r   r   r   )r   s    r#   test_modify_shortcut_failurer     s    	z)@	A	A	A 
 
 :"e E )
%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   8<<c                    t          t                    }t          |          dk    sJ t          j        t
          d          5  dg ddg| _        d d d            n# 1 swxY w Y   ddgddg| _        t          t                    }t          |          dk    sJ g | _        t          t                    }t          |          dk    sJ d S )	Nr~   z"Cannot add a shortcut without keysr   r   Tr   r   creater   r@   )r   r   r5   r   r   r   r   r   s     r#   &test_add_shortcut_for_existing_commandr     s    &y11Gw<<1	z)M	N	N	N 
 
6BRVWW)
%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 3QUVV%! 'y11Gw<<1$&!&y11Gw<<1r   c                  l    t                      } | j        J ddgddg}|| _        | j        |k    sJ d S )Nr   r   Tr   )rq   r   r   )ipythonr   s     r#   )test_setting_shortcuts_before_pt_app_initr     sT    mmG>!!!2QUVVI "G	))))))r.   );r   r   r   r   r   r   r   r   r	   r
   r   r   %IPython.terminal.shortcuts.auto_matchr   IPython.terminal.shortcutsr   r   prompt_toolkit.historyr   prompt_toolkit.bufferr   prompt_toolkit.documentr   prompt_toolkit.auto_suggestr   prompt_toolkit.enumsr   unittest.mockr   r   r$   r-   markparametrizer;   r>   rF   rW   r[   r^   ra   re   ro   rt   r   r   r   r   fixturer   r   r   r   r   r   r   r   r   r   r   r.   r#   <module>r      s)                           < ; ; ; ; ; T T T T T T T T 2 2 2 2 2 2 ( ( ( ( ( ( , , , , , , > > > > > > / / / / / / % % % % % % % %' ' '    D@ : : : (( % % % &   = = =     :H H; :H     H H H    
 
H H
 
H (GC , , ,
# 
# 
#I I I 3 3 31) 1) 1)h#) #) #)L  $ $ $4     3 3 3.  5 5 5,	 	 		 	 	
 
 
  (* * * * *r.   