ó
‹²,]c           @   s  d  Z  y d d l m Z Wn! e k
 r= d d l 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 j j j Z d „  Z d e d e d „ Z e j d	 „  ƒ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k re j ƒ  n  d S(   s   
Tests for breakpoints.
iÿÿÿÿ(   t   MockN(   t   QTextCursor(   t   version_info(   t   to_text_stringc         C   s:   |  j  j ƒ  t d k r) |  j j ƒ  n  |  j j ƒ  d S(   s   Reset signal mocks.i   N(   i   (   t   linenumberareat
   reset_mockR   t   sig_flags_changedt   breakpoints_changed(   t   editor(    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   reset_emits   s    c         C   sÁ   | j  ƒ  } | j | k s! t ‚ | j | k s6 t ‚ | r~ |  j j j ƒ  t d k rk |  j j	 j ƒ  n  |  j
 j	 j ƒ  n? |  j j j ƒ  t d k r­ |  j j	 j ƒ  n  |  j
 j	 j ƒ  d S(   s  Run the tests for call to add_remove_breakpoint.

    Args:
        editor: CodeEditor instance.
        block: Block of text.
        bp: Is breakpoint active?
        bpc: Condition set for breakpoint.
        emits: Boolean to test if signals were emitted?
    i   N(   i   (   i   (   t   userDatat
   breakpointt   AssertionErrort   breakpoint_conditionR   t   updatet   assert_called_withR   R   t   emitR   t   assert_not_called(   R   t   blockt   bpt   bpct   emitst   data(    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   editor_assert_helper$   s    
c         C   sœ   t  j d d ƒ } d } d } | j d d d | d | ƒ t ƒ  | _ t d k ra t ƒ  | _ n t d d	 ƒ | _ t ƒ  | _	 d
 } | j
 | ƒ | |  f S(   s,   Create code editor with default Python code.t   parentt    i   t   languaget   Pythont   indent_charst   tab_stop_width_spacest   return_valuei   sA   def f1(a, b):
"Double quote string."

    c = a * b
    return c
Ns       (   i   (   t
   codeeditort
   CodeEditort   Nonet   setup_editorR    R   R   R   t   get_linenumberarea_widthR   t   set_text(   t   qtbotR   R   R   t   text(    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   code_editor_bot?   s    c      	   C   sy  |  \ } } | j  } | j j t j d ƒ | j d ƒ | j ƒ  j ƒ  } | j d ƒ t
 | ƒ | ƒ  | st t ‚ | j ƒ  s‡ t ‚ | j j j ƒ  t d k r¶ | j j j ƒ  n  | j j j ƒ  | j d ƒ t
 | ƒ | ƒ  t | | d t d d d t ƒt
 | ƒ | ƒ  t | | d t d d d t ƒt
 | ƒ | j d ƒ | j ƒ  j ƒ  } | ƒ  t | | d t d d d t ƒt
 | ƒ | j ƒ  j d ƒ } | d	 d d
 d ƒ t | | d t d d d t ƒt
 | ƒ d t f t j j _ | d	 d d t ƒ t | | d t d d d t ƒd t f t j j _ t
 | ƒ | d	 d d t ƒ t | | d t d d d t ƒd S(   s(   Test CodeEditor.add_remove_breakpoint().t   getTexti   i   R   R   R   R   i   t   line_numbert	   conditions   a > 50s   a == 42t   edit_conditionN(   i   (   t   add_remove_breakpointt   patcht   objectR   t   QInputDialogt
   go_to_linet
   textCursorR   t   set_languageR!   R	   R   R
   R   R   R   R   R   R   R   R   t   Truet   Falset   documentt   findBlockByLineNumberR(   R   (   R'   t   mockerR   R%   t   arbR   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   test_add_remove_breakpoint[   sL    	






c      	   C   s  |  \ } } | j  } | j j t j d ƒ d } | j ƒ  j | d ƒ } t | ƒ d t f t j j	 _
 | d | d t ƒ | j ƒ  } | s• t ‚ | j j j ƒ  t d k rÄ | j j j ƒ  n  | j j j ƒ  t | ƒ d t f t j j	 _
 | d | d t ƒ t | | d t d	 d d
 t ƒt | ƒ d t f t j j	 _
 | d | d t ƒ t | | d t d	 d d
 t ƒt | ƒ | d | ƒ t | | d t d	 d d
 t ƒt | ƒ d t f t j j	 _
 | d | d t ƒ t | | d t d	 d d
 t ƒd S(   s/   Test add/remove breakpoint with edit_condition.R(   i   i   s   b == 1R)   R+   i   R   R   R   s   b == 9N(   i   (   R,   R-   R.   R   R/   R5   R6   R	   R4   R(   R   R3   R
   R   R   R   R   R   R   R   R   R   R!   (   R'   R7   R   R%   R8   t
   linenumberR   R   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt.   test_add_remove_breakpoint_with_edit_condition˜   s:    	




c         C   s¬   |  \ } } | j  } | j } | ƒ  g  k s3 t ‚ d d d d g } | j | ƒ | ƒ  d d d g k sp t ‚ | d d d d	 ƒ | d d ƒ | ƒ  d g k s¨ t ‚ d
 S(   s    Test CodeEditor.get_breakpoints.i   i   i   s   a > 1i   s   c == 10R)   R*   s   a < bN(   i   N(   i   N(   i   s   a > 1(   i   s   c == 10(   i   N(   i   s   a > 1(   i   s   c == 10(   i   s   c == 10(   R,   t   get_breakpointsR   R!   t   set_breakpoints(   R'   R   R%   R8   t   gbR   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   test_get_breakpointsÊ   s    		c         C   sØ   |  \ } } t  | j ƒ d k s' t ‚ d d g } | j | ƒ | j ƒ  | k sX t ‚ t  | j ƒ d k ss t ‚ | j ƒ  | j ƒ  g  k s• t ‚ t  | j ƒ d k s° t ‚ x! | j D] } | j sº t ‚ qº Wd S(   s"   Test CodeEditor.clear_breakpoints.i    i   i   i   N(   i   N(   i   N(   t   lent   blockuserdata_listR   R!   R=   R<   t   clear_breakpointsR   (   R'   R   R%   R   R   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   test_clear_breakpointsÞ   s    
c         C   sÃ   |  \ } } | j  g  ƒ | j ƒ  g  k s1 t ‚ d d	 g } | j  | ƒ | j ƒ  | k sb t ‚ | j d j sx t ‚ d
 d g } | j  | ƒ | j ƒ  | k s© t ‚ | j d j s¿ t ‚ d S(   s    Test CodeEditor.set_breakpoints.i   s   a > bi   i    i   s   c == 50N(   i   s   a > b(   i   N(   i   N(   i   s   c == 50(   R=   R<   R   R!   RA   R   (   R'   R   R%   R   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   test_set_breakpointsò   s    c         C   sJ   |  \ } } t  | ƒ | j j j ƒ  | j ƒ  j ƒ  | j j j ƒ  d S(   s#   Test CodeEditor.update_breakpoints.N(   R	   R   R   R   R1   t   insertBlockR   (   R'   R   R%   (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   test_update_breakpoints  s
    
t   __main__(   t   __doc__t   unittest.mockR    t   ImportErrort   mockt   pytestt
   qtpy.QtGuiR   t   spyderR   t   spyder.py3compatR   t$   spyder.widgets.sourcecode.codeeditort   widgetst
   sourcecodeR   R	   R!   R4   R3   R   t   fixtureR'   R9   R;   R?   RC   RD   RF   t   __name__t   main(    (    (    sO   lib/python2.7/site-packages/spyder/widgets/sourcecode/tests/test_breakpoints.pyt   <module>	   s(   		=	2				
