ó
‹²,]c           @   sm  d  Z  d d l m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 dm d e
 e d	 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 j d dn do dp dq dr ds dt du g ƒ d. „  ƒ Z d/ „  Z e j j d0 d1 d2 d3 d d4 d5 d6 d7 g ƒ e j j d dv dw dx dy dz d{ d| d} d~ d d€ d g ƒ dR „  ƒ ƒ Z  e j j dS d‚ dƒ d„ d… d† d‡ dˆ d‰ dŠ g	 ƒ d[ „  ƒ Z! e j j d0 d1 d2 d3 d d4 d5 d6 d7 g ƒ e j j d d‹ g ƒ d_ „  ƒ ƒ Z" e j j d dŒ d dŽ d g ƒ dk „  ƒ Z# e$ dl k rie j% ƒ  n  d S(   s#   
Tests for the autoindent features
iÿÿÿÿ(   t   QTextCursorN(   t   qapplication(   t   to_text_string(   t
   CodeEditort    i   t   Pythonc         C   sÎ   t  ƒ  } t d d ƒ } | j d | d | d | ƒ | j |  ƒ | j ƒ  } | j t j ƒ | r¡ |  j	 t
 ƒ }	 t |	 d j ƒ  ƒ }
 | j t j d |
 ƒn  | j | ƒ | j d | ƒ t | j ƒ  ƒ S(	   s/   Return text with last line's indentation fixed.t   parentt   languaget   indent_charst   tab_stop_width_spacesiÿÿÿÿt   nt   forwardN(   R   R   t   Nonet   setup_editort   set_textt
   textCursort   movePositionR    t   Endt
   splitlinest   Truet   lent   lstript   Leftt   setTextCursort
   fix_indentR   t   toPlainText(   t   textR   R	   t   solR   R   t   appt   editort   cursort   linest   repeat(    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   get_indent_fix   s    	c          C   s"   t  d ƒ }  |  d k s t ‚ d  S(   Ns   this_tuple = (1, 2)
(   R!   t   AssertionError(   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_simple_tuple-   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   
def function():
s   
def function():
    (   R!   R"   t   repr(   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_def_with_newline2   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   def function():
    # Comment
s"   def function():
    # Comment
    (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_def_with_indented_comment7   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   def function():
    print []
s!   def function():
    print []
    (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_brackets_alone<   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   def function():
s   def function():
    (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_simple_defA   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   open_parenthesis(
s   open_parenthesis(
        (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_open_parenthesisF   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   open_bracket[
s   open_bracket[
        (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_open_bracketK   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   open_curly{
s   open_curly{
        (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_open_curlyP   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   parenthesis_w_item = (1,
s/   parenthesis_w_item = (1,
                      (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_align_on_parenthesisU   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   bracket_w_item = (1,
s'   bracket_w_item = (1,
                  (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_align_on_bracket[   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   curly_w_item = (1,
s#   curly_w_item = (1,
                (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_align_on_curlya   s    c          C   s@   d }  d } t  |  d t ƒ}  |  | k s< t t |  ƒ ƒ ‚ d  S(   Ns?       def foo(bar):
        generic = bar
    
    keep_unindent
R   (   R!   R   R"   R$   (   R   t   correct_text(    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_keep_unindenth   s    c          C   s@   d }  d } t  |  d t ƒ}  |  | k s< t t |  ƒ ƒ ‚ d  S(   NsA       for x in range(n):
        increment += 1
  
  keep_unindent
sC       for x in range(n):
        increment += 1
  
    keep_unindent
R   (   R!   R   R"   R$   (   R   R/   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_keep_unindent_fix_indentv   s    c          C   s4   d }  t  |  ƒ }  |  d k s0 t t |  ƒ ƒ ‚ d  S(   Ns        def f(x):
        return x

(   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_keep_unindent_if_blank„   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   import numpy(   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_first_line   s    s   text_input, expected, test_texts   tags = ['(a)', '(b)', '(c)']
t   test_commented_bracketss*   s = a[(a['a'] == l) & (a['a'] == 1)]['a']
t   test_balanced_bracketss   a = (a  #  some comment
s   a = (a  #  some comment
     t   test_inline_comments   len(a) == 1
t,   test_balanced_brackets_not_ending_in_brackets   x = f(
s   x = f(
      t*   test_short_open_bracket_not_hanging_indents   def some_func():
    return 10
t   test_returns"   def some_func():
    returns = 10
s&   def some_func():
    returns = 10
    t   test_return_not_keywords&   foo = 1  # Comment open parenthesis (
s   test_comment_with parenthesisc         C   s(   t  |  ƒ } | | k s$ t | ƒ ‚ d  S(   N(   R!   R"   (   t
   text_inputt   expectedt	   test_textR   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_indentation_with_spaces•   s    c          C   s.   t  d ƒ }  |  d k s* t t |  ƒ ƒ ‚ d  S(   Ns   def function():
# Comment
s   def function():
# Comment
    (   R!   R"   R$   (   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt    test_def_with_unindented_comment«   s    R	   i   i   i   i   i   i   i   s   this_tuple = (1, 2)
s   simple tuples   
def function():
s   
def function():
	s   def with new lines   def function():
	# Comment
s   def function():
	# Comment
	s   test with indented comments   def function():
	print []
s   def function():
	print []
	s   test brackets alones   
some_long_name = {
s   
some_long_name = {
		s!   indentation after opening brackets   def function():
s   def function():
	s   test simple defs   open_parenthesis(
s   open_parenthesis(
		s   open parenthesiss   def some_func():
	return 10
s   def some_func():
	returns = 10
s    def some_func():
	returns = 10
	s   def function():
# Comment
s   def function():
# Comment
	R?   c         C   s4   t  |  d d d | ƒ} | | k s0 t | ƒ ‚ d  S(   NR   s   	R	   (   R!   R"   (   R;   R<   R=   R	   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_indentation_with_tabs²   s    	s+   text_input, expected, tab_stop_width_spacess   print(
)s
   print(
		)s   print(
	  )s
   print(
	 )s	   print(
	)s   print(
      )s   a = (a  #  some comment
	 c         C   s4   t  |  d d d | ƒ} | | k s0 t | ƒ ‚ d S(   sC   Simple parenthesis indentation test with different tab stop widths.R   s   	R	   N(   R!   R"   (   R;   R<   R	   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt&   test_indentation_with_tabs_parenthesisÒ   s    	s   	x = 1s   x = 1s   simple testc         C   s:   t  |  d d d | d t ƒ} | | k s6 t | ƒ ‚ d  S(   NR   s   	R	   R   (   R!   t   FalseR"   (   R;   R<   R=   R	   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_unindentation_with_tabsç   s    	s   hola
s   witout indentations     hola
s	     hola
  s   some indentations   	hola
s   	hola
	s   tab indentations     hola(
s
     hola(
  s   line with parenthesisc         C   s.   t  |  d d  ƒ} | | k s* t | ƒ ‚ d  S(   NR   (   R!   R   R"   (   R;   R<   R=   R   (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   test_simple_indentationø   s    
t   __main__s       (   s   tags = ['(a)', '(b)', '(c)']
s   tags = ['(a)', '(b)', '(c)']
R4   (   s*   s = a[(a['a'] == l) & (a['a'] == 1)]['a']
s*   s = a[(a['a'] == l) & (a['a'] == 1)]['a']
R5   (   s   a = (a  #  some comment
s   a = (a  #  some comment
     R6   (   s   len(a) == 1
s   len(a) == 1
R7   (   s   x = f(
s   x = f(
      R8   (   s   def some_func():
    return 10
s   def some_func():
    return 10
R9   (   s"   def some_func():
    returns = 10
s&   def some_func():
    returns = 10
    R:   (   s&   foo = 1  # Comment open parenthesis (
s&   foo = 1  # Comment open parenthesis (
s   test_comment_with parenthesis(   s   this_tuple = (1, 2)
s   this_tuple = (1, 2)
s   simple tuple(   s   
def function():
s   
def function():
	s   def with new line(   s   def function():
	# Comment
s   def function():
	# Comment
	s   test with indented comment(   s   def function():
	print []
s   def function():
	print []
	s   test brackets alone(   s   
some_long_name = {
s   
some_long_name = {
		s!   indentation after opening bracket(   s   def function():
s   def function():
	s   test simple def(   s   open_parenthesis(
s   open_parenthesis(
		s   open parenthesis(   s   tags = ['(a)', '(b)', '(c)']
s   tags = ['(a)', '(b)', '(c)']
R4   (   s*   s = a[(a['a'] == l) & (a['a'] == 1)]['a']
s*   s = a[(a['a'] == l) & (a['a'] == 1)]['a']
R5   (   s   def some_func():
	return 10
s   def some_func():
	return 10
R9   (   s   def some_func():
	returns = 10
s    def some_func():
	returns = 10
	R:   (   s   def function():
# Comment
s   def function():
# Comment
	R?   (   s   print(
)s
   print(
		)i   (   s   print(
)s
   print(
		)i   (   s   print(
)s
   print(
		)i   (   s   print(
)s   print(
	  )i   (   s   print(
)s
   print(
	 )i   (   s   print(
)s	   print(
	)i   (   s   print(
)s   print(
      )i   (   s   print(
)s   print(
      )i   (   s   a = (a  #  some comment
s   a = (a  #  some comment
	 i   (   s   	x = 1s   x = 1s   simple test(   s   hola
s   hola
s   witout indentation(   s     hola
s	     hola
  s   some indentation(   s   	hola
s   	hola
	s   tab indentation(   s     hola(
s
     hola(
  s   line with parenthesis(&   t   __doc__t
   qtpy.QtGuiR    t   pytestt   spyder.utils.qthelpersR   t   spyder.py3compatR   t$   spyder.widgets.sourcecode.codeeditorR   RB   R   R!   R#   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R0   R1   R2   R3   t   markt   parametrizeR>   R?   R@   RA   RC   RD   t   __name__t   main(    (    (    sN   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_autoindent.pyt   <module>	   sª   																      	*	        		
*			