σ
ηiυ\c           @` s  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 m Z d  d l Z d  d l	 m
 Z
 d Z d   Z d	   Z d
   Z e d    Z d   Z e j d e d e  d    Z e j d e d e  d    Z e j d e  d    Z d   Z d S(   i    (   t   absolute_import(   t   division(   t   print_functionN(   t   contextmanager(   t   compats(   -Walways::pytest.RemovedInPytest4Warningc   	      C` s-  | j  d  } t |  d k r: |  j d | f   n  x# t |  d k  r_ | j d  q= Wg  | D] } | j   ^ qg \ } } } } } |  j |  } |  j |  } | r
y% t |  } | d k  rΦ t  n  Wqt t	 f k
 r|  j d | f   qXn d } |  j
 | | | | |  d S(   sP   
    Copy of the warning._setoption function but does not escape arguments.
    t   :i   s   too many fields (max 5): %rt    i    s   invalid lineno %rN(   t   splitt   lent   _OptionErrort   appendt   stript
   _getactiont   _getcategoryt   intt
   ValueErrort   OverflowErrort   filterwarnings(	   t   wmodt   argt   partst   st   actiont   messaget   categoryt   modulet   lineno(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt
   _setoption   s"    .c         C` sH   |  j  d  } | j d d d d d d |  j d d	 d
 d d d  S(   Ns   pytest-warningss   -Ws   --pythonwarningsR   R
   t   helps=   set which warnings to report, see -W option of python itself.R   t   typet   linelistsc   Each line specifies a pattern for warnings.filterwarnings. Processed after -W and --pythonwarnings.(   t   getgroupt	   addoptiont   addini(   t   parsert   group(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   pytest_addoption(   s    c         C` s   |  j  d d  d  S(   Nt   markerss   filterwarnings(warning): add a warning filter to the given test. see https://docs.pytest.org/en/latest/warnings.html#pytest-mark-filterwarnings (   t   addinivalue_line(   t   config(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   pytest_configure9   s    c   
      c` sR  |  j  d  p g  } |  j d  } t j d t  } t j sk t j d d t t j d d t	 n  t j d d t
 j x | D] } t t |  q Wx | D] } t j |  q¦ W| d k	 r
x> | j d d  D]' } x | j D] } t t |  qμ Wqά Wn  d Vx6 | D]. }	 | j j d	 t d
 |	 d | d |   qWWd QXd S(   sς   
    Context manager that catches warnings generated in the contained execution block.

    ``item`` can be None if we are not in the context of an item execution.

    Each warning captured triggers the ``pytest_warning_captured`` hook.
    t   pythonwarningsR   t   recordt   alwaysR   t   errort   nameNt   kwargst   warning_messaget   whent   item(   t	   getoptiont   getinit   warningst   catch_warningst   Truet   syst   warnoptionsR   t   DeprecationWarningt   PendingDeprecationWarningt   pytestt   RemovedInPytest4WarningR   t   Nonet   iter_markerst   argst   pytest_warning_capturedt   call_historict   dict(
   R'   t   ihookR0   R1   t   cmdline_filterst
   inifilterst   logR   t   markR/   (    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   catch_warnings_for_itemA   s&    		c         C` sπ   |  j  } t } t j r t d   | j D  r g  } x? | j D]4 } | j t | t j  rn t j	 |  n |  qA Wt
 | j  | k } | | _ n  t j | |  j |  j |  j |  j  } | rμ t j d j t j |   t  n  | S(   sΘ   Convert a warnings.WarningMessage to a string.

    This takes lot of unicode shenaningans into account for Python 2.
    When Python 2 support is dropped this function can be greatly simplified.
    c         s` s!   |  ] } t  | t j  Vq d  S(   N(   t
   isinstanceR   t   UNICODE_TYPES(   t   .0t   m(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pys	   <genexpr>r   s    s^   Warning is using unicode non convertible to ascii, converting to a safe representation:
  {!r}(   R   t   FalseR   t   _PY2t   anyR?   R
   RI   RJ   t   ascii_escapedt   listR4   t   formatwarningR   t   filenameR   t   linet   warnt   formatt   safe_strt   UnicodeWarning(   R/   t   warn_msgt   unicode_warningt   new_argsRL   t   msg(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   warning_record_to_strj   s*    	",
t   hookwrappert   tryfirstc      	   c` s7   t  d |  j d |  j d d d |   
 d  VWd  QXd  S(   NR'   RC   R0   t   runtestR1   (   RH   R'   RC   (   R1   (    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   pytest_runtest_protocol   s    "c      	   c` s=   |  j  } t d | d | j d d d d   
 d  VWd  QXd  S(   NR'   RC   R0   t   collectR1   (   R'   RH   t   hookR=   (   t   sessionR'   (    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   pytest_collection   s    	c      	   c` s=   |  j  } t d | d | j d d d d   
 d  VWd  QXd  S(   NR'   RC   R0   R1   (   R'   RH   Rc   R=   (   t   terminalreporterR'   (    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   pytest_terminal_summary   s    	c      
   C` st   t  j d t  0 } t  j d t |    t  j |  d | Wd QX| j j d t d | d d d	 d
 d   d S(   sΪ  
    This function should be used instead of calling ``warnings.warn`` directly when we are in the "configure" stage:
    at this point the actual options might not have been set, so we manually trigger the pytest_warning_captured
    hook so we can display this warnings in the terminal. This is a hack until we can sort out #2891.

    :param warning: the warning instance.
    :param hook: the hook caller
    :param stacklevel: stacklevel forwarded to warnings.warn
    R*   R+   t
   stacklevelNR.   R/   i    R0   R'   R1   (
   R4   R5   R6   t   simplefilterR   RU   R@   RA   RB   R=   (   t   warningRc   Rh   t   records(    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   _issue_warning_captured₯   s
    
(   t
   __future__R    R   R   R7   R4   t
   contextlibR   R;   t   _pytestR   t   SHOW_PYTEST_WARNINGS_ARGR   R$   R(   RH   R]   t   hookimplR6   Ra   Re   Rg   Rl   (    (    (    s/   lib/python2.7/site-packages/_pytest/warnings.pyt   <module>   s"   			)	!!!		