ó
¾^Yc           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l Z d   Z d   Z d d d     YZ	 d d d	     YZ
 d
   Z d   Z d   Z d   Z d S(   s6    interactive debugging with PDB, the Python Debugger. i    (   t   absolute_importt   divisiont   print_functionNc         C` sQ   |  j  d  } | j d d d d d d d | j d	 d d
 d d d d d  S(   Nt   generals   --pdbt   destt   usepdbt   actiont
   store_truet   helps0   start the interactive Python debugger on errors.s   --pdbclst
   usepdb_clst   metavars   modulename:classnamesq   start a custom interactive Python debugger on errors. For example: --pdbcls=IPython.terminal.debugger:TerminalPdb(   t   getgroupt
   _addoption(   t   parsert   group(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   pytest_addoption   s    c         ` są   |  j  d  rP |  j  d  j d  \ } } t |  t t j | |  } n	 t j } |  j  d  r |  j j	 t
   d  n  t j t j f     f d   } t j t _ |  j t _ |  t _ | t _ |  j j |  d  S(   NR	   t   :R   t	   pdbinvokec           ` s+     \ t  _ t _ d  t _ t  j t _ d  S(   N(   t   pdbt	   set_tracet	   pytestPDBt   _pluginmanagert   Nonet   _configt   Pdbt   _pdb_cls(    (   t   old(    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   fin    s    	(   t   getvaluet   splitt
   __import__t   getattrt   syst   modulesR   R   t   pluginmanagert   registert	   PdbInvokeR   R   R   R   R   t   _cleanupt   append(   t   configt   modnamet	   classnamet   pdb_clsR   (    (   R   s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   pytest_configure   s    
			R   c           B` s2   e  Z d  Z d Z d Z e j Z e	 d    Z
 RS(   s)    Pseudo PDB that defers to the real pdb. c         C` s·   d d l  } t j   j } |  j d k	 r  |  j j d  } | rU | j d t  n  | j	 j
 |  j  } | j   | j d d  |  j j j d |  j  n  |  j   j |  d S(   s<    invoke PDB set_trace debugging, dropping any IO capturing. i    Nt   capturemanagert   in_t   >s'   PDB set_trace (IO-capturing turned off)R'   (   t   _pytest.configR    t	   _getframet   f_backR   R   t	   getplugint   suspendcapturet   TrueR'   t   create_terminal_writerR   t   linet   sept   hookt   pytest_enter_pdbR   R   (   t   clst   _pytestt   framet   capmant   tw(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyR   1   s    
N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   t   classmethodR   (    (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyR   +   s
   	R$   c           B` s   e  Z d    Z d   Z RS(   c         C` sm   | j  j j d  } | rV | j d t  \ } } t j j |  t j j |  n  t | | j	 |  d  S(   NR,   R-   (
   R'   R"   R2   R3   R4   R    t   stdoutt   writet
   _enter_pdbt   excinfo(   t   selft   nodet   callt   reportR=   t   outt   err(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   pytest_exception_interactB   s    c         C` s[   x> t  |  j d  D]' } t j j d |  t j j   q Wt |  } t |  d  S(   Ns   
s   INTERNALERROR> %s
(   t   strR   R    t   stderrRD   t   flusht   _postmortem_tracebackt   post_mortem(   RG   t   excreprRF   R6   t   tb(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   pytest_internalerrorJ   s
    (   R?   R@   RM   RU   (    (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyR$   A   s   	c         C` sr   |  j  j j d  j } | j   | j d d  | j |  | j d d  t |  } t |  t	 | _
 | S(   Nt   terminalreporterR.   t	   tracebacks   entering PDB(   R'   R"   R2   t   _twR6   R7   t
   toterminalRQ   RR   R4   t	   _pdbshown(   RH   RF   t   repR>   RT   (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyRE   R   s    

	c         C` s?   d d l  m } t |  j |  r0 |  j j d S|  j d Sd  S(   Ni    (   t   UnexpectedExceptioni   (   t   doctestR\   t
   isinstancet   valuet   exc_infot   _excinfo(   RF   R\   (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyRQ   a   s    c         C` sQ   t  d t |   d  } x1 | rL |  | d j j d t  rL | d 8} q W| S(   Ni    i   t   __tracebackhide__(   t   maxt   lent   f_localst   gett   False(   t   stackt   i(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   _find_last_non_hidden_framek   s    &c         C` s@   d t  j f d     Y} |   } | j   | j d  |   d  S(   NR   c           B` s   e  Z d    Z RS(   c         S` sC   t  j j |  | |  \ } } | d  k r9 t |  } n  | | f S(   N(   R   R   t	   get_stackR   Rj   (   RG   t   ft   tRh   Ri   (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyRk   t   s    (   R?   R@   Rk   (    (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyR   s   s   (   R   R   t   resett   interactionR   (   Rm   R   t   p(    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyRR   r   s    	
(    (    (   RA   t
   __future__R    R   R   R   R    R   R+   R   R$   RE   RQ   Rj   RR   (    (    (    s1   /tmp/pip-build-hU8Cw8/pytest/_pytest/debugging.pyt   <module>   s   				
	