ó
çiõ\c           @` s  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z d d l m Z d d	 l m Z d
 „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d S(   s6    interactive debugging with PDB, the Python Debugger. i    (   t   absolute_import(   t   division(   t   print_functionN(   t   UnexpectedException(   t   outcomes(   t   hookimpl(   t
   UsageErrorc         C` sO   y |  j  d ƒ \ } } Wn) t k
 rD t j d j |  ƒ ƒ ‚ n X| | f S(   s#   Validate syntax of --pdbcls option.t   :s-   {!r} is not in the format 'modname:classname'(   t   splitt
   ValueErrort   argparset   ArgumentTypeErrort   format(   t   valuet   modnamet	   classname(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   _validate_usepdb_cls   s    c      
   C` sv   |  j  d ƒ } | j d d d d d d d ƒ| j d	 d d
 d d d t d d ƒ| j d d d d d d d ƒd  S(   Nt   generals   --pdbt   destt   usepdbt   actiont
   store_truet   helpsE   start the interactive Python debugger on errors or KeyboardInterrupt.s   --pdbclst
   usepdb_clst   metavars   modulename:classnamet   typesq   start a custom interactive Python debugger on errors. For example: --pdbcls=IPython.terminal.debugger:TerminalPdbs   --tracet   traces)   Immediately break when running each test.(   t   getgroupt
   _addoptionR   (   t   parsert   group(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   pytest_addoption   s"    c         C` s°   |  j  d ƒ r( |  j j t ƒ  d ƒ n  |  j  d ƒ rP |  j j t ƒ  d ƒ n  t j j t j	 t j
 t j f ƒ t j	 t _	 |  j t _
 |  t _ d „  } |  j j | ƒ d  S(   NR   t   pdbtraceR   t	   pdbinvokec           S` s%   t  j j ƒ  \ t _ t  _ t  _ d  S(   N(   t	   pytestPDBt   _savedt   popt   pdbt	   set_tracet   _pluginmanagert   _config(    (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   finC   s    (   t   getvaluet   pluginmanagert   registert   PdbTracet	   PdbInvokeR"   R#   t   appendR%   R&   R'   R(   t   _cleanup(   t   configR)   (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   pytest_configure4   s    			R"   c           B` sw   e  Z d  Z d Z d Z g  Z d Z d Z e	 d „  ƒ Z
 e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z RS(   s)    Pseudo PDB that defers to the real pdb. i    c         C` s   | r | j  ƒ  St S(   N(   t   is_capturingt   False(   t   clst   capman(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   _is_capturingV   s    
c         C` s0  |  j  s t j S|  j  j d ƒ } |  j rI |  j d | k rI |  j d S| r| \ } } ya t | ƒ t j | } | j d ƒ } t	 | | d ƒ } x! | d D] } t	 | | ƒ } q¢ WWqt
 k
 rþ }	 d j | | f ƒ }
 t d j |
 |	 ƒ ƒ ‚ qXn	 t j } |  j | | ƒ } | | f |  _ | S(   NR   i    i   t   .R   s#   --pdbcls: could not import {!r}: {}(   R(   R%   t   PdbR*   t   _wrapped_pdb_clst
   __import__t   syst   modulesR   t   getattrt	   Exceptiont   joinR   R   t   _get_pdb_wrapper_class(   R5   R6   R   R   R   t   modt   partst   pdb_clst   partt   excR   t   wrapped_cls(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   _import_pdb_cls\   s,    	
	c         ` s8   d d  l  ‰ d | t f ‡  ‡ ‡ ‡ f d †  ƒ  Y‰  ˆ  S(   Ni    t   PytestPdbWrapperc           ` s   e  Z ˆ Z e Z ‡  ‡ f d  †  Z ‡  ‡ ‡ f d †  Z e Z Z ‡  ‡ f d †  Z	 e	 Z
 e	 Z ‡  f d †  Z ‡  f d †  Z RS(   c         ` s:   ˆ j  d 7_  t ˆ  |  ƒ j | ƒ } ˆ j  d 8_  | S(   Ni   (   t   _recursive_debugt   supert   do_debug(   t   selft   argt   ret(   RI   R5   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRL   ‡   s    c         ` sã   t  ˆ  |  ƒ j | ƒ } ˆ j d k r· ˆ j j ˆ j ƒ } | j ƒ  |  j } t j	 | ƒ } | r¤ | d k rƒ | j
 d d ƒ n | j
 d d | ƒ | j ƒ  q· | j
 d d ƒ n  ˆ j j j d ˆ j d |  ƒ t |  _ | S(	   Ni    t   globalt   >s#   PDB continue (IO-capturing resumed)s*   PDB continue (IO-capturing resumed for %s)s   PDB continueR1   R%   (   RK   t   do_continueRJ   R1   t   create_terminal_writerR(   t   linet   _pytest_capmanR"   R7   t   sept   resumeR'   t   hookt   pytest_leave_pdbt   Truet
   _continued(   RM   RN   RO   t   twR6   t	   capturing(   RI   t   _pytestR5   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRR      s$    
		c         ` s;   t  ˆ  |  ƒ j | ƒ } ˆ j d k r7 t j d ƒ n  | S(   s  Raise Exit outcome when quit command is used in pdb.

                This is a bit of a hack - it would be better if BdbQuit
                could be handled, but this would require to wrap the
                whole pytest run, and adjust the report etc.
                i    s   Quitting debugger(   RK   t   do_quitRJ   R   t   exit(   RM   RN   RO   (   RI   R5   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR_   §   s    c         ` sQ   t  ˆ  |  ƒ j | | ƒ } | rM |  j rM |  j rM |  j j d t ƒ qM n  | S(   sŽ   Suspend on setup().

                Needed after do_continue resumed, and entering another
                breakpoint again.
                t   in_(   RK   t   setupR[   RU   t   suspend_global_captureRZ   (   RM   t   ft   tbRO   (   RI   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRb   ¸   s
    	c         ` s‡   t  ˆ  |  ƒ j | | ƒ \ } } | d  k r} t d t | ƒ d ƒ } x4 | ry | | d j j d t ƒ ry | d 8} qI Wn  | | f S(   Ni    i   t   __tracebackhide__(   RK   t	   get_stackt   Nonet   maxt   lent   f_localst   getR4   (   RM   Rd   t   tt   stackt   i(   RI   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRg   Æ   s    !&(   t   __name__t
   __module__RU   R4   R[   RL   RR   t   do_ct   do_contR_   t   do_qt   do_exitRb   Rg   (    (   RI   R^   R6   R5   (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRI   ƒ   s   
(   t   _pytest.configt   object(   R5   RD   R6   (    (   RI   R^   R6   R5   s0   lib/python2.7/site-packages/_pytest/debugging.pyRA      s    (Lc   
      O` sp  d d l  } |  j d k	 r0 |  j j d ƒ } n d } | rO | j d t ƒ n  |  j r,| j j |  j ƒ } | j	 ƒ  |  j
 d k r,| j d d ƒ } | d k	 r· | j d | ƒ q)|  j | ƒ } | d k rì | j d d | f ƒ q)| r| j d d	 | | f ƒ q)| j d d
 | f ƒ q,n  |  j | ƒ |   }	 |  j rl|  j j j d |  j d |	 ƒ n  |	 S(   s6    Initialize PDB debugging, dropping any IO capturing. i    Nt   capturemanagerRa   t   headerRQ   RP   s    PDB %s (IO-capturing turned off)s'   PDB %s (IO-capturing turned off for %s)s   PDB %sR1   R%   (   Rv   R'   Rh   t	   getplugint   suspendRZ   R(   R1   RS   RT   RJ   R$   RV   R7   RH   RX   t   pytest_enter_pdb(
   R5   t   methodt   argst   kwargsR^   R6   R\   Ry   R]   t   _pdb(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt	   _init_pdbÑ   s4    	
	"c         O` s5   t  j ƒ  j } |  j d | | Ž } | j | ƒ d S(   sB   Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing.R&   N(   R<   t	   _getframet   f_backR   R&   (   R5   R~   R   t   frameR€   (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR&   ù   s    N(   Rp   Rq   t   __doc__Rh   R'   R(   R#   RJ   R:   t   classmethodR7   RH   RA   R   R&   (    (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR"   M   s   #R(R.   c           B` s   e  Z d  „  Z d „  Z RS(   c         C` sw   | j  j j d ƒ } | r` | j d t ƒ | j ƒ  \ } } t j j | ƒ t j j | ƒ n  t	 | | j
 | ƒ d  S(   NRx   Ra   (   R1   R+   Rz   Rc   RZ   t   read_global_captureR<   t   stdoutt   writet
   _enter_pdbt   excinfo(   RM   t   nodet   callt   reportR6   t   outt   err(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   pytest_exception_interact  s    c         C` s   t  | ƒ } t | ƒ d  S(   N(   t   _postmortem_tracebackt   post_mortem(   RM   t   excreprR‹   Re   (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   pytest_internalerror  s    (   Rp   Rq   R‘   R•   (    (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR.     s   		R-   c           B` s    e  Z e d  e ƒ d „  ƒ Z RS(   t   hookwrapperc         c` s   t  | ƒ d  Vd  S(   N(   t   _test_pytest_function(   RM   t
   pyfuncitem(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   pytest_pyfunc_call  s    
(   Rp   Rq   R   RZ   R™   (    (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR-     s   c         C` s‡   t  j d ƒ } |  j } | j |  _ d |  j j k rE t d ƒ ‚ n  | |  j d <t |  j j ƒ } | j	 d ƒ t
 | ƒ |  j _ d  S(   Nt   runcallt   funcs0   --trace can't be used with a fixture named func!(   R"   R   t   objRš   t   _fixtureinfot   argnamesR	   t   funcargst   listR/   t   tuple(   R˜   R€   t   testfunctiont   new_list(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR—     s    	c         C` s  |  j  j j d ƒ j } | j ƒ  |  j  j j } x‘ d | j f d | j f d | j	 f f D]e \ } } | | d f k r\ | r\ | j
 d d | ƒ | d d	 k r± | d  } n  | j | ƒ q\ q\ W| j
 d d
 ƒ | j | ƒ | j
 d d ƒ t | ƒ } t | _ t | ƒ | S(   Nt   terminalreporterRˆ   t   stderrt   logt   allRQ   s	   captured iÿÿÿÿs   
t	   tracebacks   entering PDB(   R1   R+   Rz   t   _twRT   t   optiont   showcapturet	   capstdoutt	   capstderrt   caplogRV   t
   toterminalR’   RZ   t	   _pdbshownR“   (   RŒ   R‹   t   repR\   R«   t   sectionnamet   contentRe   (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyRŠ   #  s&    
	
c         C` s/   t  |  j t ƒ r  |  j j d S|  j d Sd  S(   Ni   (   t
   isinstanceR   R   t   exc_infot   _excinfo(   R‹   (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR’   @  s    c         C` sF   t  j d ƒ } | j ƒ  | j d  |  ƒ | j rB t j d ƒ n  d  S(   NR“   s   Quitting debugger(   R"   R   t   resett   interactionRh   t   quittingR   R`   (   Rm   t   p(    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyR“   I  s
    
	(   R…   t
   __future__R    R   R   R
   R%   R<   t   doctestR   R^   R   Rv   R   t   _pytest.config.exceptionsR   R   R   R2   Rw   R"   R.   R-   R—   RŠ   R’   R“   (    (    (    s0   lib/python2.7/site-packages/_pytest/debugging.pyt   <module>   s(   			´				