ó
…¾^Yc           @` sÛ   d  Z  d d l m Z m Z 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 m Z e d „  ƒ Z d d „ Z d e f d „  ƒ  YZ 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_importt   divisiont   print_functionN(   t   yield_fixturec          c` s,   t  ƒ  }  |   t j d ƒ |  VWd QXd S(   s  Return a WarningsRecorder instance that provides these methods:

    * ``pop(category=None)``: return last warning matching the category.
    * ``clear()``: clear list of warnings

    See http://docs.python.org/library/warnings.html for information
    on warning categories.
    t   defaultN(   t   WarningsRecordert   warningst   simplefilter(   t   wrec(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   recwarn   s    
	c         O` s4   |  s t  ƒ  St } t  ƒ   |  | | Ž  SWd QXd 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   _DeprecatedCallContextt   True(   t   funct   argst   kwargst   __tracebackhide__(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   deprecated_call   s
    
R
   c           B` s5   e  Z d  Z d „  Z d „  Z d d „ Z d „  Z RS(   sJ   Implements the logic to capture deprecation warnings as a context manager.c         C` s=   g  |  _  t j |  _ t j |  _ |  j t _ |  j t _ d  S(   N(   t   _captured_categoriesR   t   warnt	   _old_warnt   warn_explicitt   _old_warn_explicitt   _warn_explicitt   _warn(   t   self(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt	   __enter__8   s
    	c         O` s   |  j  j | ƒ d  S(   N(   R   t   append(   R   t   messaget   categoryR   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR   ?   s    c         O` s9   t  | t ƒ r% |  j j | j ƒ n |  j j | ƒ d  S(   N(   t
   isinstancet   WarningR   R   t	   __class__(   R   R   R   R   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR   B   s    c         ` sq   |  j  t _ |  j t _ | d  k rm t t f ‰  t ‡  f d †  |  j	 Dƒ ƒ sm t
 } d } t | ƒ ‚ qm n  d  S(   Nc         3` s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t
   issubclass(   t   .0t   c(   t   deprecation_categories(    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pys	   <genexpr>N   s    s?   Did not produce DeprecationWarning or PendingDeprecationWarning(   R   R   R   R   R   t   Nonet   DeprecationWarningt   PendingDeprecationWarningt   anyR   R   t   AssertionError(   R   t   exc_typet   exc_valt   exc_tbR   t   msg(    (   R#   s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   __exit__H   s    N(   t   __name__t
   __module__t   __doc__R   R   R$   R   R-   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR
   5   s
   		c         O` sß   t  |  ƒ } | s | St | d t ƒ r³ | \ } t | t ƒ sG t ‚ t j d ƒ } | j j ƒ  } | j | ƒ | 6 t	 j
 j | ƒ j ƒ  } t j j | | j | ƒ Wd QXn( | d } |  | | d | Ž  SWd QXd S(   sG  Assert that code raises a particular class of warning.

    Specifically, the input @expected_warning can be a warning class or
    tuple of warning classes, and the code must return that warning
    (if a single class) or one of those warnings (if a tuple).

    This helper produces a list of ``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)
    i    i   N(   t   WarningsCheckerR   t   strR(   t   syst	   _getframet   f_localst   copyt   updatet   _pytestt   _codet   Sourcet   compilet   pyt   builtint   exec_t	   f_globals(   t   expected_warningR   R   t   wcheckt   codet   framet   locR   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   warnsT   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(   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyRH   }   s    	c         C` s   |  j  S(   s   The list of recorded warnings.(   RK   (   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   list‚   s    c         C` s   |  j  | S(   s    Get a recorded warning by index.(   RK   (   R   t   i(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   __getitem__‡   s    c         C` s   t  |  j ƒ S(   s&   Iterate through the recorded warnings.(   t   iterRK   (   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   __iter__‹   s    c         C` s   t  |  j ƒ S(   s    The number of recorded warnings.(   t   lenRK   (   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_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	   enumerateRK   R    R   t   popR   R(   (   R   t   clsRM   t   wR   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyRT   “   s
    c         C` s   g  |  j  (d S(   s$   Clear the list of recorded warnings.N(   RK   (   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   clear›   s    c         C` sK   |  j  r" t } t d |  ƒ ‚ n  t t |  ƒ j ƒ  |  _ t j d ƒ |  S(   Ns   Cannot enter %r twicet   always(	   RJ   R   t   RuntimeErrorRG   R   R   RK   R   R   (   R   R   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR   Ÿ   s    	c         G` s<   |  j  s" t } t d |  ƒ ‚ n  t t |  ƒ j | Œ  d  S(   Ns%   Cannot exit %r without entering first(   RJ   R   RY   RG   R   R-   (   R   t   exc_infoR   (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR-   §   s    	(   R.   R/   R0   RH   t   propertyRL   RN   RP   RR   R   RT   RW   R   R-   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR   w   s   						R1   c           B` s   e  Z 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(   RG   R1   RH   R   t   tuplet   inspectt   isclasst	   TypeErrort   typeR$   R@   (   R   R@   R,   t   exc(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyRH   ¯   s     c         ` s©   t  t ˆ  ƒ j | Œ  t d „  | Dƒ ƒ r¥ ˆ  j d  k	 r¥ t ‡  f d †  ˆ  Dƒ ƒ s¢ t } d d l m	 } | d j
 ˆ  j g  ˆ  D] } | j ^ qƒ ƒ ƒ q¢ q¥ n  d  S(   Nc         s` s   |  ] } | d  k Vq d  S(   N(   R$   (   R!   t   a(    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pys	   <genexpr>Ã   s    c         3` s$   |  ] } t  | j ˆ  j ƒ Vq d  S(   N(   R    R   R@   (   R!   t   r(   R   (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pys	   <genexpr>Å   s   i    (   t   failsX   DID NOT WARN. No warnings of type {0} was emitted. The list of emitted warnings is: {1}.(   RG   R1   R-   t   allR@   R$   R'   R   t   _pytest.runnerRd   t   formatR   (   R   RZ   R   Rd   t   each(    (   R   s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR-   ¿   s    	N(   R.   R/   R$   RH   R-   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyR1   ®   s   (   R0   t
   __future__R    R   R   R]   t   _pytest._codeR8   R<   R3   R   t   _pytest.fixturesR   R	   R$   R   t   objectR
   RE   t   catch_warningsR   R1   (    (    (    s/   /tmp/pip-build-hU8Cw8/pytest/_pytest/recwarn.pyt   <module>   s   	#7