B
    [                 @   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mZ y(ddl	Z	ddl
mZmZ eeddZW n ek
rx   dZY nX eddZesdd	d
ZG dd deZG dd deZG dd deZG dd deZdd Zdd Zdd Zdd Zne	jjjZe	jjjZdd ZdS )z$py.test hacks to support XFAIL/XPASS    )print_functiondivisionN)get_function_name)skipraisesZ_running_pytestFZTRAVIS_BUILD_NUMBERc             C   sb   |dkrt | S t|rBy
|  W n | k
r6   dS X tdnt|trVtdntddS )a  
        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):
        ...
        AssertionError: DID NOT RAISE

        >>> with raises(ZeroDivisionError):
        ...     n = 1/0
        >>> with raises(ZeroDivisionError):
        ...     n = 1/2
        Traceback (most recent call last):
        ...
        AssertionError: 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

        NzDID NOT RAISEz'raises(xxx, "code")' has been phased out; change 'raises(xxx, "expression")' to 'raises(xxx, lambda: expression)', 'raises(xxx, "statement")' to 'with raises(xxx): statement'z1raises() expects a callable for the 2nd argument.)RaisesContextcallableAssertionError
isinstancestr	TypeError)expectedExceptioncode r   5lib/python3.7/site-packages/sympy/utilities/pytest.pyr      s    5


r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )r   c             C   s
   || _ d S )N)r   )selfr   r   r   r   __init__^   s    zRaisesContext.__init__c             C   s   d S )Nr   )r   r   r   r   	__enter__a   s    zRaisesContext.__enter__c             C   s   |d krt dt|| jS )NzDID NOT RAISE)r	   
issubclassr   )r   exc_type	exc_value	tracebackr   r   r   __exit__d   s    zRaisesContext.__exit__N)__name__
__module____qualname__r   r   r   r   r   r   r   r   ]   s   r   c               @   s   e Zd ZdS )XFailN)r   r   r   r   r   r   r   r   i   s   r   c               @   s   e Zd ZdS )XPassN)r   r   r   r   r   r   r   r   l   s   r   c               @   s   e Zd ZdS )SkippedN)r   r   r   r   r   r   r   r   o   s   r   c                s    fdd}t | }|S )Nc           
      sd   y
   W nH t k
rR }  z*t| }|dkr:tt ntdW d d } ~ X Y nX tt d S )NZTimeout)	Exceptionr   r   r   r   r   )emessage)funcr   r   wrappers   s    
zXFAIL.<locals>.wrapper)	functoolsupdate_wrapper)r"   r#   r   )r"   r   XFAILr   s    r&   c             C   s   t | d S )N)r   )r   r   r   r   r      s    r   c                s    fdd}|S )z2Similar to :func:`skip`, but this is a decorator. c                s    fdd}t || }|S )Nc                  s   t  d S )N)r   r   )reasonr   r   func_wrapper   s    z+SKIP.<locals>.wrapper.<locals>.func_wrapper)r$   r%   )r"   r(   )r'   r   r   r#      s    zSKIP.<locals>.wrapperr   )r'   r#   r   )r'   r   SKIP   s    r)   c                s(   d _  fdd}t| } |_|S )NTc                  s
      d S )Nr   r   )r"   r   r   r(      s    zslow.<locals>.func_wrapper)Z_slowr$   r%   __wrapped__)r"   r(   r   )r"   r   slow   s
    r+   c                s    fdd}|S )Nc                s   t |  fdd}|S )Nc                 s   t   d S )N)r   )argskwargs)r'   r   r   inner   s    z%SKIP.<locals>.skipping.<locals>.inner)r$   wraps)r"   r.   )r'   r   r   skipping   s    zSKIP.<locals>.skippingr   )r'   r0   r   )r'   r   r)      s    )N)__doc__Z
__future__r   r   sysr$   osZsympy.core.compatibilityr   pyZpy.testr   r   getattrZ
USE_PYTESTImportErrorgetenvZ	ON_TRAVISobjectr   r   r   r   r   r&   r)   r+   ZtestZmarkZxfailr   r   r   r   <module>   s2   

H


