σ
η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 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 e d
    Z d d  Z d   Z d e j f d     YZ d e f d     YZ d S(   s4    recording warnings during test function execution. i    (   t   absolute_import(   t   division(   t   print_functionN(   t   PYTEST_WARNS_UNKNOWN_KWARGS(   t
   WARNS_EXEC(   t   yield_fixture(   t   failc          c` s,   t    }  |   t j d  |  VWd QXd S(   sΖ   Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.

    See http://docs.python.org/library/warnings.html for information
    on warning categories.
    t   defaultN(   t   WarningsRecordert   warningst   simplefilter(   t   wrec(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   recwarn   s    	c         O` s8   t  } |  d k	 r" |  f | } n  t t t f | |  S(   sG  context manager that can be used to ensure a block of code triggers a
    ``DeprecationWarning`` or ``PendingDeprecationWarning``::

        >>> import warnings
        >>> def api_call_v2():
        ...     warnings.warn('use v3 of this api', DeprecationWarning)
        ...     return 200

        >>> with deprecated_call():
        ...    assert api_call_v2() == 200

    ``deprecated_call`` can also be used by passing a function and ``*args`` and ``*kwargs``,
    in which case it will ensure calling ``func(*args, **kwargs)`` produces one of the warnings
    types above.
    N(   t   Truet   Nonet   warnst   DeprecationWarningt   PendingDeprecationWarning(   t   funct   argst   kwargst   __tracebackhide__(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   deprecated_call"   s    c   	      N` s8  e  } | s\ | j d d  } | rL e j e j d e |   d d n  e |  d | Se	 | d e
  re j e d d | \ } e	 | e
  s  t  e j d  } | j j   } | j |  e |   * e j j |  j   } | | j | UWd QXn. | d } e |    | | d |   SWd QXd S(	   sΩ  Assert that code raises a particular class of warning.

    Specifically, the parameter ``expected_warning`` can be a warning class or
    sequence of warning classes, and the inside the ``with`` block must issue a warning of that class or
    classes.

    This helper produces a list of :class:`warnings.WarningMessage` objects,
    one for each warning raised.

    This function can be used as a context manager, or any of the other ways
    ``pytest.raises`` can be used::

        >>> with warns(RuntimeWarning):
        ...    warnings.warn("my warning", RuntimeWarning)

    In the context manager form you may use the keyword argument ``match`` to assert
    that the exception matches a text or regex::

        >>> with warns(UserWarning, match='must be 0 or None'):
        ...     warnings.warn("value must be 0 or None", UserWarning)

        >>> with warns(UserWarning, match=r'must be \d+$'):
        ...     warnings.warn("value must be 42", UserWarning)

        >>> with warns(UserWarning, match=r'must be \d+$'):
        ...     warnings.warn("this is not here", UserWarning)
        Traceback (most recent call last):
          ...
        Failed: DID NOT WARN. No warnings of type ...UserWarning... was emitted...

    t   matchR   t
   stackleveli   t
   match_expri    i   N(   R   t   popR   R	   t   warnR   t   formatt   sortedt   WarningsCheckert
   isinstancet   strR   t   AssertionErrort   syst	   _getframet   f_localst   copyt   updatet   _pytestt   _codet   Sourcet   compilet	   f_globals(	   t   expected_warningR   R   R   R   t   codet   framet   locR   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR   8   s(     "	
R   c           B` sh   e  Z d  Z d   Z e d    Z d   Z d   Z d   Z e	 d  Z
 d   Z d   Z d	   Z RS(
   s^   A context manager to record raised warnings.

    Adapted from `warnings.catch_warnings`.
    c         C` s/   t  t |   j d t  t |  _ g  |  _ d  S(   Nt   record(   t   superR   t   __init__R   t   Falset   _enteredt   _list(   t   self(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR2   w   s    	c         C` s   |  j  S(   s   The list of recorded warnings.(   R5   (   R6   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   list|   s    c         C` s   |  j  | S(   s    Get a recorded warning by index.(   R5   (   R6   t   i(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   __getitem__   s    c         C` s   t  |  j  S(   s&   Iterate through the recorded warnings.(   t   iterR5   (   R6   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   __iter__   s    c         C` s   t  |  j  S(   s    The number of recorded warnings.(   t   lenR5   (   R6   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   __len__   s    c         C` s\   x? t  |  j  D]. \ } } t | j |  r |  j j |  Sq Wt } t d |   d S(   s>   Pop the first recorded warning, raise exception if not exists.s   %r not found in warning listN(   t	   enumerateR5   t
   issubclasst   categoryR   R   R!   (   R6   t   clsR8   t   wR   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR      s
    c         C` s   g  |  j  (d S(   s$   Clear the list of recorded warnings.N(   R5   (   R6   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   clear   s    c         ` s     j  r" t } t d     n  t t    j     _ t j d  t	 j
 r~ d  d   f d  } | t j t _   _ n    S(   Ns   Cannot enter %r twicet   alwaysi   c         ` sΎ   t  |  t  r |  j } n  | d  k r0 t } n  t | t  sE t  t j |  j	 } d | k r£ | d } d  | d <z   j
 |  | | d  SWd  | | d <Xn   j
 |  | | d  Sd  S(   Nt   __warningregistry__i   (   R   t   Warningt	   __class__R   t   UserWarningR?   R!   R"   R#   R+   t   _saved_warn(   t   messageR@   R   R+   t   orig(   R6   (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR   ₯   s    	

(   R4   R   t   RuntimeErrorR1   R   t	   __enter__R5   R	   R
   t   sixt   PY2R   R   RI   (   R6   R   R   (    (   R6   s.   lib/python2.7/site-packages/_pytest/recwarn.pyRM      s    		c         G` s]   |  j  s" t } t d |    n  t j r: |  j t _ n  t t	 |   j
 |   t |  _  d  S(   Ns%   Cannot exit %r without entering first(   R4   R   RL   RN   RO   RI   R	   R   R1   R   t   __exit__R3   (   R6   t   exc_infoR   (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyRP   Ύ   s    		(   t   __name__t
   __module__t   __doc__R2   t   propertyR7   R9   R;   R=   RF   R   RC   RM   RP   (    (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR   q   s   						%R   c           B` s    e  Z d d d   Z d   Z RS(   c         C` sΊ   t  t |   j   d } t | t  rd xy | D]. } t j |  s/ t | t |    q/ q/ Wn@ t j |  r | f } n% | d  k	 r€ t | t |    n  | |  _
 | |  _ d  S(   NsD   exceptions must be old-style classes or derived from Warning, not %s(   R1   R   R2   R   t   tuplet   inspectt   isclasst	   TypeErrort   typeR   R,   R   (   R6   R,   R   t   msgt   exc(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR2   Ν   s     	c         ` s7  t  t    j |   t } t d   | D  r3  j d  k	 r3t   f d     D  s t } t d j	   j g    D] } | j
 ^ qy   q0  j d  k	 r0x   D]F } t | j   j  r« t j   j  j t | j
   rρ Pqρ q« q« Wt d j	   j   j g    D] } | j
 ^ q  q0q3n  d  S(   Nc         s` s   |  ] } | d  k Vq d  S(   N(   R   (   t   .0t   a(    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pys	   <genexpr>γ   s    c         3` s$   |  ] } t  | j   j  Vq d  S(   N(   R?   R@   R,   (   R]   t   r(   R6   (    s.   lib/python2.7/site-packages/_pytest/recwarn.pys	   <genexpr>ε   s    sV   DID NOT WARN. No warnings of type {} was emitted. The list of emitted warnings is: {}.sf   DID NOT WARN. No warnings of type {} matching ('{}') was emitted. The list of emitted warnings is: {}.(   R1   R   RP   R   t   allR,   R   t   anyR   R   RJ   R   R?   R@   t   reR*   t   searchR    (   R6   RQ   R   t   eachR_   (    (   R6   s.   lib/python2.7/site-packages/_pytest/recwarn.pyRP   έ   s&    )$N(   RR   RS   R   R2   RP   (    (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyR   Μ   s   (   RT   t
   __future__R    R   R   RW   Rb   R"   R	   RN   t   _pytest._codeR'   t   _pytest.deprecatedR   R   t   _pytest.fixturesR   t   _pytest.outcomesR   R   R   R   R   t   catch_warningsR   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/recwarn.pyt   <module>   s$   	9[