ó
‹²,]c           @   sø  d  Z  d d l Z d d l Z d d l j Z d d l m Z d d l m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z d d l m Z e j e j e j ƒ  e j e ƒ ƒ ƒ Z e j e d ƒ Z e j e ƒ sè e j e ƒ n  d „  Z e j d „  ƒ Z e j d	 „  ƒ Z  d
 „  Z! d „  Z" d „  Z# e j$ j% d i d d 6e& d 6g d e& ƒd „  ƒ Z' e j$ j% d i d d 6e( d 6g d e& ƒd „  ƒ Z) e j$ j% d i d d 6e& d 6g d e& ƒd „  ƒ Z* e j$ j% d i d d 6e( d 6g d e& ƒd „  ƒ Z+ e j$ j% d i d d 6e( d 6g d e& ƒd „  ƒ Z, e j$ j% d d d g ƒ d „  ƒ Z- e j$ j% d i e( d 6g d e& ƒd „  ƒ Z. e j$ j% d i e& d 6g d e& ƒd  „  ƒ Z/ e j$ j% d i e& d! 6g d e& ƒd" „  ƒ Z0 e j$ j% d i d# d 6e& d 6g d e& ƒd$ „  ƒ Z1 d% „  Z2 d& „  Z3 d' „  Z4 d( „  Z5 e j$ j% d i e e j e ƒ e j e j e ƒ ƒ e g d) 6g d e& ƒd* „  ƒ Z6 e j$ j% d+ i d, d- 6g d e& ƒd. „  ƒ Z7 e8 d/ k rôe j9 d0 e j: e ƒ d1 d2 g ƒ n  d S(3   s   
Tests for findinfiles.py
iÿÿÿÿN(   t   Qt(	   t   FindInFilesWidgett   SearchInComboBoxt   EXTERNAL_PATHSt   SELECT_OTHERt   CWDt
   CLEAR_LISTt   PROJECTt	   FILE_PATHt   QMessageBox(   t   PY2u   Ã¨Ã¡Ã¯Ã¼ Ã˜Î±Ã´Ã¥ å­—åˆ†è¯¯c         C   sƒ   i  } xv |  j  ƒ  D]h } | \ } } } t j | ƒ } | | k rP g  | | <n  | | j | | f ƒ t | | ƒ | | <q W| S(   s|   
    Transform result representation from the output of the widget to the
    test framework comparison representation.
    (   t   valuest   ospt   basenamet   appendt   sorted(   t   resultst   matchest   resultt   filet   linet   colt   filename(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   process_search_results    s    c         C   ss   t  | d t ƒ r | j } n d } | r< t d |  } n t d ƒ } | j d d ƒ |  j | ƒ | j ƒ  | S(   s   Set up find in files widget.t   parami€  ià  N(   t   getattrt   FalseR   t   NoneR   t   resizet	   addWidgett   show(   t   qtbott   requestR   t   widget(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   findinfiles0   s    
c         C   sÞ   d d l  m } t | d t ƒ r. | j } n d } | r^ | j d ƒ r^ | j d ƒ | _ n  t t	 j
 t ƒ t	 j
 t	 j
 t ƒ ƒ t	 j
 t	 j
 t	 j
 t ƒ ƒ ƒ t	 j
 t ƒ t	 j t d ƒ g } t | ƒ } |  j | ƒ | S(   s!   Set up SearchInComboBox combobox.iÿÿÿÿ(   R"   R   t   max_history_patht   path_that_does_not_existN(   t   spyder.widgetsR"   R   R   R   R   t   gett   MAX_PATH_HISTORYt   LOCATIONR   t   dirnamet   joinR   R   (   R   R    R"   R   t   external_path_historyt   searchin_combobox(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyR,   C   s    c          C   sC   i d d d g d 6d d d g d
 6d d d d d d g d 6}  |  S(    Ni   i    i   i   i   s   spam.txti   i   i   s   spam.pyi	   i   i   i   i   i   i
   i   s   spam.cpp(   i   i    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i	   (   i   i   (   i   i   (   i   i   (   i   i
   (   i   i   (    (   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   expected_results]   s
    c       	   C   s0   i d
 g d 6d d d d d d d g d	 6}  |  S(   Ni   i
   s   spam.txti    i   i   i   i	   s   ham.txt(   i   i
   (   i   i    (   i   i
   (   i   i    (   i   i    (   i   i   (   i	   i    (   i
   i    (    (   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt!   expected_case_unsensitive_resultsf   s    c         C   sz   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t ƒ  | k sv t ‚ d S(   sº   
    Test the find in files utility by searching a string located on a set of
    known files.

    The results of the test should be equal to the expected search result
    values.
    t   spamt   dataN(   t   set_search_textt   find_optionst   set_directoryR   R*   R(   t   findt
   waitSignalt   sig_finishedt   waitR   t   result_browserR0   R-   t   AssertionError(   R"   R   t   blockerR   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_find_in_files_searchm   s    

R"   s   \.py$t   excludet   exclude_regexpt   indirectc         C   s³   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t } x9 | D]1 } t j | ƒ \ } } | d k rn t } Pqn qn W| s¯ t ‚ d  S(   NR/   R0   s   .py(   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   t   Truet   splitextR   R9   (   R"   R   R:   R   t   files_filteredR   R   t   ext(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_exclude_extension_regex~   s    

s   *.pyc         C   s³   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t } x9 | D]1 } t j | ƒ \ } } | d k rn t } Pqn qn W| s¯ t ‚ d  S(   NR/   R0   s   .py(   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R?   R@   R   R9   (   R"   R   R:   R   RA   R   R   RB   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_exclude_extension_string‘   s    

t    c         C   sz   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t ƒ  | k sv t ‚ d  S(   NR/   R0   (   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R-   R9   (   R"   R   R:   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt"   test_exclude_extension_empty_regex¤   s    

c         C   sz   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t ƒ  | k sv t ‚ d  S(   NR/   R0   (   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R-   R9   (   R"   R   R:   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt'   test_exclude_extension_string_no_regexp±   s    

s   *.py, *.cppc         C   s³   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } t } x9 | D]1 } t j | ƒ \ } } | d k rn t } Pqn qn W| s¯ t ‚ d  S(   NR/   R0   s   .pys   .cpp(   s   .pys   .cpp(   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R?   R@   R   R9   (   R"   R   R:   R   RA   R   R   RB   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt&   test_exclude_extension_multiple_string¾   s    

t
   line_inputt   nnnnns   Ã±andÃºc         C   sz   d } d } t  r$ | j d ƒ } n | } d | |  | | | !| | f } |  j j | | | ƒ } | | k sv t ‚ d S(   sL   
    Issue: 6218 - checking if truncate_result raise UnicodeDecodeError
    i   i   s   utf-8u   %s<b>%s</b>%sN(   R
   t   decodeR8   t   truncate_resultR9   (   R"   R   RI   t   slice_startt	   slice_endt   line_input_expectedt   expected_resultt   truncated_line(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt)   test_truncate_result_with_different_inputÑ   s    
	t   case_sensitivec         C   s   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } | GHt ƒ  | k s{ t ‚ d  S(   Nt   hamR0   (   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R.   R9   (   R"   R   R:   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_case_unsensitive_searchí   s    

c         C   s†   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  | j |  j ƒ } | j	 ƒ  t
 |  j j ƒ } | GH| i d g d 6k s‚ t ‚ d  S(   Nt   HaMR0   i	   i    s   ham.txt(   i	   i    (   R1   R2   R3   R   R*   R(   R4   R5   R6   R7   R   R8   R0   R9   (   R"   R   R:   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_case_sensitive_searchû   s    

t   search_text_regexpc         C   sa   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  |  j j j ƒ  } |  j j	 | k s] t
 ‚ d  S(   Ns   \R0   (   R1   R2   R3   R   R*   R(   R4   t   search_textt   toolTipt   REGEX_ERRORR9   (   R"   R   t   tooltip(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_search_regexp_error	  s
    
s   \c         C   sa   |  j  d ƒ |  j j t j t d ƒ ƒ |  j ƒ  |  j j j ƒ  } |  j j	 | k s] t
 ‚ d  S(   Nt   fooR0   (   R1   R2   R3   R   R*   R(   R4   t   exclude_patternRZ   R[   R9   (   R"   R   R\   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_exclude_regexp_error  s
    
c         C   si  |  j  ƒ  t t j t j t ƒ ƒ t j t j t j t ƒ ƒ ƒ t j t ƒ g } |  j ƒ  t | ƒ t k st t ‚ |  j ƒ  | k sŒ t ‚ x9 t	 | ƒ D]+ \ } } | |  j
 | t ƒ k s™ t ‚ q™ Wt } | j d d | ƒ|  j t ƒ | j | ƒ |  j ƒ  t | ƒ t k st ‚ |  j ƒ  | k s5t ‚ |  j ƒ  |  j ƒ  d k sWt ‚ t } | j d d | ƒ|  j t ƒ | j d ƒ | j | ƒ |  j ƒ  t | ƒ t k s¹t ‚ |  j ƒ  | k sÑt ‚ |  j ƒ  |  j ƒ  d k sót ‚ | j d d d ƒ|  j t ƒ |  j ƒ  t | ƒ t k s5t ‚ |  j ƒ  | k sMt ‚ |  j ƒ  t k set ‚ d S(   s¼   
    Test that the external_path_history is added correctly to the
    combobox and test that adding new external path to the combobox
    with the QFileDialog is working as expected.
    s/   spyder.widgets.findinfiles.getexistingdirectoryt   return_valuei   i    RE   N(   R   R(   R   R)   t   countt   lenR   R9   t   get_external_pathst	   enumeratet   itemTextt   NONASCII_DIRt   patcht   setCurrentIndexR   R   t   currentIndext   popR   (   R,   t   mockerR-   t   iRP   t   new_path(    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_add_external_paths!  s@    
"#"""""c         C   sB  |  j  ƒ  | j j t d d t j ƒ|  j t ƒ t t j	 t j	 t ƒ ƒ t j	 t j	 t j	 t ƒ ƒ ƒ t j	 t ƒ g } |  j
 ƒ  t | ƒ t k s t ‚ |  j ƒ  | k sµ t ‚ |  j ƒ  t k sÍ t ‚ | j j t d d t j ƒ|  j t ƒ |  j
 ƒ  t k st ‚ |  j ƒ  g  k s&t ‚ |  j ƒ  t k s>t ‚ d S(   s[   
    Test the option in the searchin combobox to clear the list of
    external paths.
    t   questionRa   N(   R   Rh   t   objectR	   t   NoRi   R   R(   R   R)   Rb   Rc   R   R9   Rd   Rj   R   t   Yes(   R,   Rl   R-   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_clear_this_listZ  s    
"c         C   sW  |  j  ƒ  t t j t j t ƒ ƒ t j t j t j t ƒ ƒ ƒ t j t ƒ g } |  j ƒ  |  j ƒ  t k st t ‚ |  j ƒ  j ƒ  j	 ƒ  t k s˜ t ‚ xR t
 t ƒ D]D } |  j ƒ  j |  j ƒ  j | d ƒ ƒ | j |  j ƒ  t j ƒ q¥ W|  j ƒ  t | ƒ t k st ‚ |  j ƒ  | k s't ‚ |  j ƒ  t k s?t ‚ |  j ƒ  j |  j ƒ  j t d ƒ ƒ | j |  j ƒ  t j ƒ | j d ƒ |  j ƒ  t | ƒ t k s¬t ‚ |  j ƒ  | k sÄt ‚ |  j ƒ  t k sÜt ‚ |  j ƒ  j ƒ  j	 ƒ  t k s t ‚ |  j ƒ  j |  j ƒ  j t d d ƒ ƒ | j |  j ƒ  t j ƒ | j d ƒ |  j ƒ  t | ƒ t k sqt ‚ |  j ƒ  | k s‰t ‚ |  j ƒ  t d k s¥t ‚ |  j ƒ  j ƒ  j	 ƒ  t d k sÍt ‚ |  j ƒ  j |  j ƒ  j |  j ƒ  d d ƒ ƒ | j |  j ƒ  t j ƒ | j ƒ  |  j ƒ  t | ƒ t k sAt ‚ |  j ƒ  | k sYt ‚ |  j ƒ  |  j ƒ  d k s{t ‚ |  j ƒ  j ƒ  j	 ƒ  |  j ƒ  d k s©t ‚ |  j ƒ  j |  j ƒ  j t d ƒ ƒ | j |  j ƒ  t j ƒ |  j ƒ  t k sÿt ‚ |  j ƒ  g  k st ‚ |  j ƒ  t k s/t ‚ |  j ƒ  j ƒ  j	 ƒ  t k sSt ‚ d S(   s|   
    Test that the selected external path in the combobox view is removed
    correctly when the Delete key is pressed.
    i    i   N(   R   R(   R   R)   t	   showPopupRj   R   R9   t   viewt   rowt   rangeR   Ri   t   modelt   indext   keyPressR    t
   Key_DeleteRb   Rc   Rd   Rk   (   R,   R   Rl   R-   Rm   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_delete_pathy  s^    

$""$"(#
""c         C   s^  |  j  } | j } |  j ƒ  | j ƒ  j t d ƒ j ƒ  t k sF t ‚ | j	 d k s[ t ‚ | j	 d k sp t ‚ t } | j | ƒ | j ƒ  j t d ƒ j ƒ  t k s­ t ‚ | j	 | k sÂ t ‚ | j	 | k s× t ‚ | j t ƒ | j ƒ  | j ƒ  j t d ƒ j ƒ  t k st ‚ | j	 d k s-t ‚ | j	 d k sBt ‚ | j ƒ  t k sZt ‚ d S(   s_   
    Test setting the project path of the SearchInComboBox from the
    FindInFilesWidget.
    i    N(   R2   t   path_selection_comboR   Ry   t   itemR   t	   isEnabledR   R9   t   project_pathR   Rg   t   set_project_pathR?   Ri   t   disable_project_searchRj   R   (   R"   R   R2   R~   R   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_set_project_pathÃ  s"    		
**
*R+   c   
      C   s%  t  t j t  ƒ t j t j t  ƒ ƒ t g } |  j } | j } |  j ƒ  t } t } t j | d ƒ } | j | ƒ | j	 | k s‰ t
 ‚ | j	 | k sž t
 ‚ | j | ƒ | j | k sÀ t
 ‚ | j | k sÕ t
 ‚ | j | ƒ | j | k s÷ t
 ‚ | j | k st
 ‚ | j t ƒ | j ƒ  | k s1t
 ‚ | j ƒ  t k sIt
 ‚ | j t ƒ | j ƒ  | k snt
 ‚ | j ƒ  t k s†t
 ‚ | j t ƒ | j ƒ  | k s«t
 ‚ | j ƒ  t k sÃt
 ‚ x[ t | ƒ D]M \ } }	 | j t | ƒ | j ƒ  |	 k st
 ‚ | j ƒ  t k sÐt
 ‚ qÐWd S(   s®   
    Test that the expected search path is returned for the corresponding
    option selected in the SearchInComboBox. This test is done using the
    FindInFilesWidget.
    s   spam.pyN(   R(   R   R)   Rg   R2   R~   R   R*   R3   t   pathR9   R‚   R   t   set_file_patht	   file_pathRi   R   t   get_current_searchpatht   is_file_searchR   R   R   R?   Re   R   (
   R"   R   t   external_pathsR2   R~   t	   directoryR   R‡   Rm   R…   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_current_search_pathá  s@    			
R,   i   R#   c         C   s   |  j  ƒ  t j t j t ƒ ƒ t j t j t j t ƒ ƒ ƒ t j t ƒ g } |  j ƒ  t | ƒ t k sq t ‚ |  j ƒ  | k s‰ t ‚ d S(   sN   
    Test that the specified maximum number of external path is observed.
    N(	   R   R   R)   R(   Rb   Rc   R   R9   Rd   (   R,   Rl   R-   (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   test_max_history!  s    
"t   __main__s   -xs   -vs   -rw(;   t   __doc__t   ost   pytestt   os.pathR…   R   t   qtpy.QtCoreR    t   spyder.widgets.findinfilesR   R   R   R   R   R   R   R   R	   t   spyder.py3compatR
   t   realpathR*   t   getcwdR)   t   __file__R(   Rg   t   existst   makedirsR   t   fixtureR"   R,   R-   R.   R;   t   markt   parametrizeR?   RC   R   RD   RF   RG   RH   RR   RU   RW   R]   R`   Ro   Rt   R}   R„   RŒ   R   t   __name__t   mainR   (    (    (    sD   lib/python2.7/site-packages/spyder/widgets/tests/test_findinfiles.pyt   <module>	   sv   @*					$		9		J	;