ó
¡¼™\c           @  s
  d  Z  d d l 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
 m Z d d l m Z yX d d l Z d d l m Z d d l m Z d d l m Z m Z e e d	 e ƒ Z Wn e k
 rï e Z n Xe j d
 d ƒ Z e s»d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e f d „  ƒ  YZ d „  Z# d „  Z d „  Z$ d „  Z% e j& d „  ƒ Z n' e j' j( j) Z# e j' j( j% Z% d „  Z$ e j& d „  ƒ Z* e j& d „  ƒ Z+ d S(   s$   py.test hacks to support XFAIL/XPASSiÿÿÿÿ(   t   print_functiont   divisionN(   t   get_function_namet   string_types(   t   SymPyDeprecationWarning(   t   raises(   t   warns(   t   skipt   Failedt   _running_pytestt   TRAVIS_BUILD_NUMBERc         C  s   | d k r t |  ƒ St | ƒ rQ y | ƒ  Wn |  k
 rA d SXt d ƒ ‚ n* t | t ƒ ro t d ƒ ‚ n t d ƒ ‚ d S(   sµ  
        Tests that ``code`` raises the exception ``expectedException``.

        ``code`` may be a callable, such as a lambda expression or function
        name.

        If ``code`` is not given or None, ``raises`` will return a context
        manager for use in ``with`` statements; the code to execute then
        comes from the scope of the ``with``.

        ``raises()`` does nothing if the callable raises the expected exception,
        otherwise it raises an AssertionError.

        Examples
        ========

        >>> from sympy.utilities.pytest import raises

        >>> raises(ZeroDivisionError, lambda: 1/0)
        >>> raises(ZeroDivisionError, lambda: 1/2)
        Traceback (most recent call last):
        ...
        Failed: DID NOT RAISE

        >>> with raises(ZeroDivisionError):
        ...     n = 1/0
        >>> with raises(ZeroDivisionError):
        ...     n = 1/2
        Traceback (most recent call last):
        ...
        Failed: DID NOT RAISE

        Note that you cannot test multiple statements via
        ``with raises``:

        >>> with raises(ZeroDivisionError):
        ...     n = 1/0    # will execute and raise, aborting the ``with``
        ...     n = 9999/0 # never executed

        This is just what ``with`` is supposed to do: abort the
        contained statement sequence at the first exception and let
        the context manager deal with the exception.

        To test multiple statements, you'll need a separate ``with``
        for each:

        >>> with raises(ZeroDivisionError):
        ...     n = 1/0    # will execute and raise
        >>> with raises(ZeroDivisionError):
        ...     n = 9999/0 # will also execute and raise

        Ns   DID NOT RAISEs¯   'raises(xxx, "code")' has been phased out; change 'raises(xxx, "expression")' to 'raises(xxx, lambda: expression)', 'raises(xxx, "statement")' to 'with raises(xxx): statement's1   raises() expects a callable for the 2nd argument.(   t   Nonet   RaisesContextt   callableR   t
   isinstanceR   t	   TypeError(   t   expectedExceptiont   code(    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR      s    5
R   c           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s   | |  _  d  S(   N(   R   (   t   selfR   (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   __init__c   s    c         C  s   d  S(   N(   R   (   R   (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt	   __enter__f   s    c         C  s+   | d  k r t d ƒ ‚ n  t | |  j ƒ S(   Ns   DID NOT RAISE(   R   R   t
   issubclassR   (   R   t   exc_typet	   exc_valuet	   traceback(    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   __exit__i   s    (   t   __name__t
   __module__R   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   b   s   		t   XFailc           B  s   e  Z RS(    (   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   n   s   t   XPassc           B  s   e  Z RS(    (   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   q   s   t   Skippedc           B  s   e  Z RS(    (   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   t   s   R   c           B  s   e  Z RS(    (   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   w   s   c           s%   ‡  f d †  } t  j | ˆ  ƒ } | S(   Nc            sp   y ˆ  ƒ  WnL t  k
 rY }  t |  ƒ } | d k rJ t t ˆ  ƒ ƒ ‚ qZ t d ƒ ‚ n Xt t ˆ  ƒ ƒ ‚ d  S(   Nt   Timeout(   t	   Exceptiont   strR   R   R   R   (   t   et   message(   t   func(    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   wrapper{   s    (   t	   functoolst   update_wrapper(   R$   R%   (    (   R$   s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   XFAILz   s    c         C  s   t  |  ƒ ‚ d  S(   N(   R   (   R!   (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   ‰   s    c           s   ‡  f d †  } | S(   s2   Similar to :func:`skip`, but this is a decorator. c           s%   ‡  f d †  } t  j | |  ƒ } | S(   Nc             s   t  ˆ  ƒ ‚ d  S(   N(   R   (    (   t   reason(    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   func_wrapper   s    (   R&   R'   (   R$   R*   (   R)   (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR%   Ž   s    (    (   R)   R%   (    (   R)   s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   SKIPŒ   s    c           s7   t  ˆ  _ ‡  f d †  } t j | ˆ  ƒ } ˆ  | _ | S(   Nc             s   ˆ  ƒ  d  S(   N(    (    (   R$   (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR*   š   s    (   t   Truet   _slowR&   R'   t   __wrapped__(   R$   R*   (    (   R$   s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   slow—   s
    		c         +  sÀ   | j  d d ƒ } | r+ t d | ƒ ‚ n  t j d t ƒ , } t j d ƒ t j d | ˆ  ƒ d VWd QXt ‡  f d †  | Dƒ ƒ s¼ d	 ˆ  g  | D] } | j ^ q” f } t	 | ƒ ‚ n  d S(
   sÓ  Like raises but tests that warnings are emitted.

        >>> from sympy.utilities.pytest import warns
        >>> import warnings

        >>> with warns(UserWarning):
        ...     warnings.warn('deprecated', UserWarning)

        >>> with warns(UserWarning):
        ...     pass
        Traceback (most recent call last):
        ...
        Failed: DID NOT WARN. No warnings of type UserWarning        was emitted. The list of emitted warnings is: [].
        t   matcht    s   Invalid keyword arguments: %st   recordt   ignoret   alwaysNc         3  s!   |  ] } t  | j ˆ  ƒ Vq d  S(   N(   R   t   category(   t   .0t   w(   t
   warningcls(    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pys	   <genexpr>¿   s    s^   Failed: DID NOT WARN. No warnings of type %s was emitted. The list of emitted warnings is: %s.(
   t   popR   t   warningst   catch_warningsR,   t   simplefiltert   filterwarningst   anyR#   R   (   R8   t   kwargsR0   t   warnrecR7   t   msg(    (   R8   s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR   ¡   s    #c           s   ‡  f d †  } | S(   Nc           s"   t  j |  ƒ ‡  f d †  ƒ } | S(   Nc            s   t  ˆ  ƒ d  S(   N(   R   (   t   argsR?   (   R)   (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   innerÍ   s    (   R&   t   wraps(   R$   RC   (   R)   (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   skippingÌ   s    (    (   R)   RE   (    (   R)   s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyR+   Ë   s    c           c  s   t  t ƒ 
 d VWd QXd S(   sn  Shorthand for ``warns(SymPyDeprecationWarning)``

    This is the recommended way to test that ``SymPyDeprecationWarning`` is
    emitted for deprecated features in SymPy. To test for other warnings use
    ``warns``. To suppress warnings without asserting that they are emitted
    use ``ignore_warnings``.

    >>> from sympy.utilities.pytest import warns_deprecated_sympy
    >>> from sympy.utilities.exceptions import SymPyDeprecationWarning
    >>> import warnings

    >>> with warns_deprecated_sympy():
    ...     SymPyDeprecationWarning("Don't use", feature="old thing",
    ...         deprecated_since_version="1.0", issue=123).warn()

    >>> with warns_deprecated_sympy():
    ...     pass
    Traceback (most recent call last):
    ...
    Failed: DID NOT WARN. No warnings of type     SymPyDeprecationWarning was emitted. The list of emitted warnings is: [].
    N(   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   warns_deprecated_sympyÕ   s    c         c  s|   t  j d t ƒ  } t  j d |  ƒ d VWd QXxE | D]= } t | j |  ƒ s7 t  j | j | j | j | j	 ƒ q7 q7 Wd S(   st  Context manager to suppress warnings during tests.

    This function is useful for suppressing warnings during tests. The warns
    function should be used to assert that a warning is raised. The
    ignore_warnings function is useful in situation when the warning is not
    guaranteed to be raised (e.g. on importing a module) or if the warning
    comes from third-party code.

    When the warning is coming (reliably) from SymPy the warns function should
    be preferred to ignore_warnings.

    >>> from sympy.utilities.pytest import ignore_warnings
    >>> import warnings

    Here's a warning:

    >>> with warnings.catch_warnings():  # reset warnings in doctest
    ...     warnings.simplefilter('error')
    ...     warnings.warn('deprecated', UserWarning)
    Traceback (most recent call last):
      ...
    UserWarning: deprecated

    Let's suppress it with ignore_warnings:

    >>> with warnings.catch_warnings():  # reset warnings in doctest
    ...     warnings.simplefilter('error')
    ...     with ignore_warnings(UserWarning):
    ...         warnings.warn('deprecated', UserWarning)

    (No warning emitted)
    R2   R4   N(
   R:   R;   R,   R<   R   R5   t   warn_explicitR#   t   filenamet   lineno(   R8   R@   R7   (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   ignore_warningsð   s    #(,   t   __doc__t
   __future__R    R   t   sysR&   t   ost
   contextlibR:   t   sympy.core.compatibilityR   R   t   sympy.utilities.exceptionsR   t   pyt   _pytest.python_apiR   t   _pytest.recwarnR   t   _pytest.outcomesR   R   t   getattrt   Falset
   USE_PYTESTt   ImportErrort   getenvR   t	   ON_TRAVISt   objectR   R    R   R   R   R(   R+   R/   t   contextmanagert   testt   markt   xfailRF   RJ   (    (    (    s5   lib/python2.7/site-packages/sympy/utilities/pytest.pyt   <module>   sD   
H				
'	
