ó
‹²,]c           @   s¹  d  Z  d d l Z d d l m Z y d d l m Z m Z Wn' e k
 re d d l m Z m Z n Xd d l	 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
 l m Z d d l m Z e	 j d „  ƒ Z e	 j d „  ƒ Z e	 j d „  ƒ Z e	 j d „  ƒ Z e	 j d „  ƒ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d  „  Z- d! „  Z. e	 j/ j0 e d" d# ƒd$ „  ƒ Z1 d% „  Z2 d& „  Z3 e
 d' d( ƒ e	 j/ j0 e j4 j5 d) d ƒ d k oJe j7 d* ƒ d" d+ ƒd, „  ƒ ƒ Z8 e
 d' d( ƒ e	 j/ j0 e j9 d- k d" d. ƒd/ „  ƒ ƒ Z: e; d0 k rµe	 j< ƒ  n  d S(1   s   
Tests for editor.py
iÿÿÿÿN(   t   platform(   t   Mockt	   MagicMock(   t   flaky(   t   Qt(   t   QTextCursor(   t   setup_editor(   t   EditorStackt   EditorSplitter(   t   FindReplace(   t   PY2c         C   sU   t  d  g  ƒ } | j t ƒ  ƒ | j t ƒ  ƒ | j t ƒ  t ƒ  t ƒ  t ƒ  ƒ | S(   N(   R   t   Nonet   set_introspectorR   t   set_find_widgett   set_io_actions(   t   qtbott   editor_stack(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   base_editor_bot!   s
    "c         C   s;   |  } d } | j  d d | ƒ } | j | ƒ | | j f S(   s°   
    Set up EditorStack with CodeEditor containing some Python code.
    The cursor is at the empty line below the code.
    Returns tuple with EditorStack and CodeEditor.
    s   a = 1
print(a)

x = 2s   foo.pys   utf-8(   t   newt	   addWidgett   editor(   R   R   R   t   textt   finfo(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt
   editor_bot*   s
    c         C   sm   |  } d } | j  d d | ƒ } t d  d t ƒ} | j | ƒ | j | j ƒ | j | ƒ | | j | f S(   Ns    spam bacon
spam sausage
spam eggs   spam.pys   utf-8t   enable_replace(   R   R	   R   t   TrueR   t
   set_editorR   R   (   R   R   R   R   R   t   find_replace(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   editor_find_replace_bot;   s    c         C   sM   |  } d } | j  d d | ƒ } t d  d t ƒ} | j | ƒ | | j f S(   NsK   # %%
# 1 cell
# print(1)
# %%
# 2 cell
# print(2)
# %%
# 3 cell
# print(3)
s   cells.pys   utf-8R   (   R   R	   R   R   R   R   (   R   R   R   R   R   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   editor_cells_botI   s    	c         c   sE   t  d t ƒ  g  d t ƒ} |  j | ƒ | j ƒ  | V| j ƒ  d S(   s   Create editor splitter.t   firstN(   R   R   R   R   R   t   showt   destroy(   R   t   editor_splitter(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   editor_splitter_bot[   s
    
c      	   C   sî   |  \ } } | j  j j t ƒ d } | j | ƒ | j  j j d ƒ | j  j d t d t d t d t ƒ | j  j	 j
 ƒ  } | d k sŽ t ‚ | j  j j d ƒ | j  j d t d t d t d t ƒ | j  j	 j
 ƒ  } | d	 k sê t ‚ d
 S(   s(   Test for number matches in find/replace.s    test 
TEST 
Test 
tesT t   testt   changedt   forwardt   rehighlightt   multiline_replace_checks   1 of 1t   fails
   no matchesN(   t   find_widgett   case_buttont
   setCheckedR   t   set_textt   search_textt   add_textt   findt   Falset   number_matches_textR   t   AssertionError(   R   R   R   R   t   editor_text(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_find_number_matchesg   s     c         C   sà   |  \ } } | j  d ƒ | j ƒ  d } | j ƒ  | k sA t ‚ | j ƒ  | j ƒ  | k sc t ‚ | j  d ƒ | j t j t j ƒ x* t d ƒ D] } | j t j t j	 ƒ q“ W| j ƒ  d } | j ƒ  | k sÜ t ‚ d  S(   Ni   s   print(a)
a = 1

x = 2
i   s   print(a)
a = 1
x = 2

(
   t
   go_to_linet   move_line_upt   toPlainTextR2   t
   moveCursorR   t   Rightt
   MoveAnchort   ranget
   KeepAnchor(   R   R   R   t   expected_new_textt   i(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_move_current_line_up}   s    


c         C   sß   |  \ } } | j  d ƒ | j ƒ  d } | j ƒ  | k sA t ‚ | j ƒ  | j ƒ  | k sc t ‚ | j  d ƒ | j t j t j ƒ x* t d ƒ D] } | j t j t j	 ƒ q“ W| j ƒ  d } | j ƒ  | k sÛ t ‚ d  S(   Ni   s   a = 1
print(a)


x = 2i   i   s   print(a)
a = 1


x = 2(
   R5   t   move_line_downR7   R2   R8   R   R9   R:   R;   R<   (   R   R   R   R=   R>   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_move_current_line_downš   s    


c         C   s¬   |  \ } } | j  d ƒ | j ƒ  } | j t j t j ƒ | j t j t j ƒ | j | ƒ | j ƒ  d } | j	 ƒ  | k s† t
 ‚ | j ƒ  | j	 ƒ  | k s¨ t
 ‚ d  S(   Ni   s   print(a)

a = 1
x = 2
(   R5   t
   textCursort   movePositionR   t   DownR<   R9   t   setTextCursorR6   R7   R2   (   R   R   R   t   cursorR=   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_move_multiple_lines_up¹   s    

c         C   s¬   |  \ } } | j  d ƒ | j ƒ  } | j t j t j ƒ | j t j t j ƒ | j | ƒ | j ƒ  d } | j	 ƒ  | k s† t
 ‚ | j ƒ  | j	 ƒ  | k s¨ t
 ‚ d  S(   Ni   s   a = 1
print(a)


x = 2(   R5   RB   RC   R   RD   R<   R9   RE   R@   R7   R2   (   R   R   R   RF   R=   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_move_multiple_lines_downÏ   s    

c         C   s   |  \ } } | j  d ƒ | j d ƒ | j | j ƒ  } | j ƒ  Wd  QX| j sZ t ‚ | j d d k ss t ‚ | j ƒ  d k s‹ t ‚ d  S(   Ni   i   i    s   a = 1(   i   i    (	   R5   t   move_cursort
   waitSignalt   exec_in_extconsolet   run_selectiont   signal_triggeredR2   t   argst   get_cursor_line_column(   R   R   R   R   t   blocker(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_run_top_lineæ   s    c         C   s‚   |  \ } } | j  d ƒ | j | j ƒ  } | j ƒ  Wd  QX| j sM t ‚ | j d d k sf t ‚ | j ƒ  d k s~ t ‚ d  S(   Ni   i    s   x = 2(   i   i    (   R5   RJ   RK   RL   RM   R2   RN   RO   (   R   R   R   R   RP   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_run_last_nonempty_lineò   s    c         C   sX   |  \ } } | j  d ƒ | j | j ƒ  | j ƒ  Wd  QX| j ƒ  d k sT t ‚ d  S(   Ni   i    (   i   i    (   R5   t   assertNotEmittedRK   RL   RO   R2   (   R   R   R   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_run_empty_line_in_middleü   s
    c         C   sK   |  \ } } | j  | j ƒ  | j ƒ  Wd  QX| j ƒ  d k sG t ‚ d  S(   Ni   i    (   i   i    (   RS   RK   RL   RO   R2   (   R   R   R   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_run_last_line_when_empty  s    c         C   s³   |  \ } } | j  ƒ  | j ƒ  } | j | j ƒ  } | j ƒ  Wd  QX| j sV t ‚ | j d d k so t ‚ | | j ƒ  } | j ƒ  | k s— t ‚ | j	 ƒ  d k s¯ t ‚ d  S(   Ni    s   x = 2i   (   i   i    (
   t   stdkey_backspaceR7   RJ   RK   RL   RM   R2   RN   t   get_line_separatorRO   (   R   R   R   R   t   old_textRP   R=   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt    test_run_last_line_when_nonempty  s    
c         C   s®   |  \ } } | j  j j t ƒ d } | j | ƒ | j  j j d ƒ | j  j j d ƒ | j  j ƒ  | j  j ƒ  | j  j ƒ  | j  j ƒ  | j	 ƒ  } | d k sª t
 ‚ d  S(   Ns    test 
TEST 
Test 
tesT R#   t   passs    pass 
TEST 
Test 
tesT (   R)   R*   R+   R   R,   R-   R.   t   replace_textt   replace_findR7   R2   (   R   R   R   R   R3   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt    test_find_replace_case_sensitive  s    c         C   s”   |  \ } } } d } | j  ƒ  } | j ƒ  | j ƒ  | j | j d ƒ | j | j d ƒ | j | j t j ƒ | j  ƒ  d d !| k s t	 ‚ d  S(   Ns   ham bacon
spam sausage
spam eggt   spamt   hami    iÿÿÿÿ(
   R7   R   t   show_replacet	   keyClicksR-   R[   t   keyPressR   t
   Key_ReturnR2   (   R   R   R   R   t   finderR=   RX   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt"   test_replace_current_selected_line)  s    

c         C   so  |  \ } } } d } | j  | ƒ | j ƒ  | j j d ƒ | j | j t j ƒ | j ƒ  d	 k sj t ‚ | j | j t j ƒ | j ƒ  d
 k s˜ t ‚ | j | j t j ƒ | j ƒ  d k sÆ t ‚ | j | j t j d t j	 ƒ| j ƒ  d k sý t ‚ | j | j t j d t j	 ƒ| j ƒ  d k s4t ‚ | j | j t j d t j	 ƒ| j ƒ  d k skt ‚ d S(   sD   Test advance forward pressing Enter, and backwards with Shift+Enter.s     
spam 
spam 
spam R^   i   i   i   i   t   modifierN(   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (
   R,   R   R-   R.   Rb   R   Rc   RO   R2   t   ShiftModifier(   R   R   R   R   Rd   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_replace_enter_press7  s"    
c         C   sˆ   |  \ } } } d } | j  ƒ  | j ƒ  | j | j d ƒ | j | j d ƒ | j | j t j ƒ | j ƒ  d d !| k s„ t	 ‚ d S(   s@   Test that regex reserved characters are displayed as plain text.s'   .\[()]*test bacon
spam sausage
spam eggR^   s   .\[()]*testi    iÿÿÿÿN(
   R   R`   Ra   R-   R[   Rb   R   Rc   R7   R2   (   R   R   R   R   Rd   R=   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_replace_plain_regexU  s    

c         C   s»  |  \ } } } | j  ƒ  } | j ƒ  | j ƒ  | j | j d ƒ | j | j d ƒ | j j ƒ  s} | j | j t	 j
 ƒ n  | j | j t	 j
 ƒ | j  ƒ  | k s« t ‚ | j | j t	 j
 ƒ | j  ƒ  | k sÙ t ‚ | j | j t	 j
 ƒ | j  ƒ  | k st ‚ | j | j d ƒ | j | j d ƒ | j | j t	 j
 ƒ | j  ƒ  | k s[t ‚ | j | j t	 j
 ƒ | j  ƒ  | k s‰t ‚ | j | j t	 j
 ƒ | j  ƒ  | k s·t ‚ d S(   s5   Assert that replacing an invalid regexp does nothing.s   \t   anythingN(   R7   R   R`   Ra   R-   R[   t	   re_buttont	   isCheckedt
   mouseClickR   t
   LeftButtont   replace_buttonR2   t   replace_sel_buttont   replace_all_button(   R   R   R   R   Rd   RX   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_replace_invalid_regexc  s,    

c         C   s¿   |  \ } } } d } | j  | d ƒ | j ƒ  | j ƒ  | j  | j d ƒ | j  | j d ƒ | j ƒ  } | j t j ƒ | j	 ƒ  j
 ƒ  d k s™ t ‚ | j ƒ  | j
 ƒ  | k s» t ‚ d  S(   Ns=   spam bacon
spam sausage
spam egg
\n \t some escape characterss   \n \t escape characterst   escapes   some escape(   Ra   R   R`   R-   R[   RB   t   selectR   t   LineUnderCursort	   selectionR7   R2   t   replace_find_selection(   R   R   R   R   Rd   R=   RF   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt    test_selection_escape_characters„  s    


c         C   sä   |  \ } } | j  ƒ  d k s$ t ‚ | j d t ƒ | j  ƒ  d k sL t ‚ | j d t ƒ | j  ƒ  d k st t ‚ | j d t ƒ | j  ƒ  d	 k sœ t ‚ | j ƒ  | j  ƒ  d
 k s¾ t ‚ | j ƒ  | j  ƒ  d k sà t ‚ d  S(   Ni
   i    t   reversei   i   (   i
   i    (   i   i    (   i   i    (   i    i    (   i   i    (   i   i    (   RO   R2   t   advance_cellR   (   R   R   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_advance_cell›  s    

t   reasons*   Python2 does not support unicode very wellc         C   sø  |  } d } | j  d d | ƒ } | j | ƒ | j } | j d ƒ | j t j t j ƒ d | j ƒ  j	 ƒ  k sx t
 ‚ | j ƒ  d k s t
 ‚ | j d ƒ | j t j t j ƒ d | j ƒ  j	 ƒ  k sÑ t
 ‚ | j ƒ  d k sé t
 ‚ | j d ƒ | j t j t j ƒ d	 | j ƒ  j	 ƒ  k s*t
 ‚ | j ƒ  d	 k sBt
 ‚ | j d
 ƒ | j t j t j ƒ d | j ƒ  j	 ƒ  k sƒt
 ‚ | j ƒ  d k s›t
 ‚ | j d ƒ | j t j t j ƒ d | j ƒ  j	 ƒ  k sÜt
 ‚ | j ƒ  d k sôt
 ‚ d S(   s(   Test getting selected valid python word.sW   some words with non-ascii  characters
niÃ±o
garÃ§on
Î± alpha greek
123valid_python_words   foo.pys   utf-8i   t   somei   s   niÃ±oi   s   garÃ§oni   s   Î±i   t   123valid_python_wordt   valid_python_wordN(   R   R   R   R5   R8   R   t	   EndOfWordR<   RB   t   selectedTextR2   t   get_current_word(   R   R   R   R   R   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_get_current_word´  s2    	c         C   sL  |  } | j  ƒ  t j k s! t ‚ | j t j ƒ s9 t ‚ | j ƒ  sL t ‚ | j s\ t ‚ | j sl t ‚ | j	 | j
 j k s‡ t ‚ | j | j
 j k s¢ t ‚ | j s² t ‚ | j j sÄ t ‚ t | j t ƒ sÜ t ‚ | j
 j j | j ƒ | j
 j j ƒ  | j
 j j ƒ  | j ƒ  d k s*t ‚ | j d ƒ | j k sHt ‚ d S(   s   "Test EditorSplitter.__init__.i   i    N(   t   orientationR   t
   HorizontalR2   t   testAttributet   WA_DeleteOnCloset   childrenCollapsiblet   toolbar_listt	   menu_listt   register_editorstack_cbt   plugint   register_editorstackt   unregister_editorstack_cbt   unregister_editorstackt   menu_actionst   editorstackt
   isinstanceR   t   assert_called_witht   assert_not_calledt   clone_editorstackt   countt   widget(   R"   t   es(    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_editor_splitter_inità  s     c         C   so   |  \ } } } d } | j  | ƒ | j ƒ  | j ƒ  t d d ƒ | _ | j | j t j ƒ | j j	 ƒ  d S(   su   Test that tab works in find/replace dialog. Regression test for #3674.
    Mock testâ€”more isolated but less flimsy.s     
spam 
spam 
spam t   namet   focusNextChildN(
   R,   R   R`   R   R›   Rb   R-   R   t   Key_Tabt   assert_called_once_with(   R   R   R   R   Rd   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt.   test_tab_keypress_properly_caught_find_replaceù  s    

t   max_runsi   t   CIt   linuxs&   Fails on some Linux platforms locally.c         C   sÚ   |  \ } } } d } | j  | ƒ | j ƒ  | j ƒ  | j d ƒ | j j ƒ  | j d ƒ | j j ƒ  sr t ‚ | j j ƒ  sˆ t ‚ | j	 | j t
 j ƒ | j d ƒ | j j ƒ  sÁ t ‚ | j j ƒ  sÖ t ‚ d S(   sŽ   Test that tab works in find/replace dialog. Regression test for #3674.
    "Real world" testâ€”more comprehensive but potentially less robust.s     
spam 
spam 
spam id   N(   R,   R   R`   t   waitR-   t   setFocust   hasFocusR2   R[   Rb   R   Rœ   (   R   R   R   R   Rd   R   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt+   test_tab_moves_focus_from_search_to_replace  s    

t   nts   Fails on Linux and macOS.c         C   s‚   |  \ } } } | j  ƒ  | j ƒ  | j j ƒ  | j j d ƒ | j | j t j ƒ | j d ƒ | j	 j
 ƒ  d k s~ t ‚ d S(   sh   Check that text in the find box is copied to the replace box on tab
    keypress. Regression test #4482.s   This is some test text!iô  N(   R   R`   R-   R£   t   set_current_textt   keyClickR   Rœ   R¢   R[   t   currentTextR2   (   R   R   R   R   Rd   (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   test_tab_copies_find_to_replace  s    

t   __main__(=   t   __doc__t   ost   sysR    t   unittest.mockR   R   t   ImportErrort   mockt   pytestR   t   qtpy.QtCoreR   t
   qtpy.QtGuiR   t   spyder.utils.fixturesR   t   spyder.widgets.editorR   R   t   spyder.widgets.findreplaceR	   t   spyder.py3compatR
   t   fixtureR   R   R   R   R"   R4   R?   RA   RG   RH   RQ   RR   RT   RU   RY   R]   Re   Rh   Ri   Rr   Rx   R{   t   markt   skipifRƒ   R™   Rž   t   environt   getR   t
   startswithR¥   Rš   Rª   t   __name__t   main(    (    (    s?   lib/python2.7/site-packages/spyder/widgets/tests/test_editor.pyt   <module>	   s^   								
								!		!,		$.