o
    oh4                     @   sJ  U d 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ZddlZddl	m
Z
mZ ddlmZ ddlmZ edddkZzddlZeedd	ZW n eyV   d	ZY nw ee
e
ge
f ed
< ee
ge
f ed< ee
ge
f ed< ee
ge
f ed< ee
ge
f ed< ee
ge
f ed< ee
ge
f ed< erejZejZejjZejjZejjZejjZejjZddlm Z  nKG dd dZ!d2dd
ZG d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d#d Zd$d Zej'd%d&d'd(d)Z(d*d+ Z)ej'd,d- Z*d.d/ Z+d0d1 Z,dS )3z$py.test hacks to support XFAIL/XPASS    N)AnyCallable)SymPyDeprecationWarning)ignore_warningsCItrue_running_pytestFraisesXFAILskipSKIPslowtooslownocache_fail)Failedc                   @   s   e Zd Zdd Zdd ZdS )ExceptionInfoc                 C   
   || _ d S N)value)selfr    r   h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/testing/pytest.py__init__5      
zExceptionInfo.__init__c                 C   s   d | jS )Nz<ExceptionInfo {!r}>)formatr   r   r   r   r   __repr__8      zExceptionInfo.__repr__N)__name__
__module____qualname__r   r   r   r   r   r   r   4   s    r   c              
   C   sp   |du rt | S t|r+z|  W td | y* } z
t|W  Y d}~S d}~ww t|tr4tdtd)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.testing.pytest import raises

        >>> raises(ZeroDivisionError, lambda: 1/0)
        <ExceptionInfo ZeroDivisionError(...)>
        >>> 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

        N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callabler   r   
isinstancestr	TypeError)expectedExceptioncodeer   r   r   r	   <   s"   6
c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r"   c                 C   r   r   )r'   )r   r'   r   r   r   r      r   zRaisesContext.__init__c                 C   s   d S r   r   r   r   r   r   	__enter__   s   zRaisesContext.__enter__c                 C   s   |d u rt dt|| jS )Nr!   )r   
issubclassr'   )r   exc_type	exc_value	tracebackr   r   r   __exit__   s   zRaisesContext.__exit__N)r   r   r    r   r*   r/   r   r   r   r   r"      s    r"   c                   @      e Zd ZdS )XFailNr   r   r    r   r   r   r   r1          r1   c                   @   r0   )XPassNr2   r   r   r   r   r4      r3   r4   c                   @   r0   )SkippedNr2   r   r   r   r   r5      r3   r5   c                   @   r0   )r   Nr2   r   r   r   r   r      r3   r   c                    s    fdd}t | }|S )Nc               
      sP   z   W n t y" }  zt| }|dkrt jtdd } ~ ww t j)NTimeout)	Exceptionr%   r1   r   r5   r4   )r)   messagefuncr   r   wrapper   s   


zXFAIL.<locals>.wrapper	functoolsupdate_wrapper)r:   r;   r   r9   r   r
      s   c                 C   s   t | r   r5   )r%   r   r   r   r         c                        fdd}|S )z0Similar to ``skip()``, but this is a decorator. c                    s    fdd}t || }|S )Nc                      s   t  r   r?   r   reasonr   r   func_wrapper   r@   z+SKIP.<locals>.wrapper.<locals>.func_wrapperr<   r:   rD   rB   r   r   r;      s   zSKIP.<locals>.wrapperr   )rC   r;   r   rB   r   r         c                    s(   d _  fdd}t| } |_|S )NTc                      s
      d S r   r   r   r9   r   r   rD      r   zslow.<locals>.func_wrapper)_slowr=   r>   __wrapped__rE   r   r9   r   r      s
   c                 C   s*   d| _ d| _dd }t|| }| |_|S )NTc                   S   s   t d d S )NzToo slow)r   r   r   r   r   rD      r   ztooslow.<locals>.func_wrapper)rG   _tooslowr=   r>   rH   rE   r   r   r   r      s   c                 C   s   | S )zBDummy decorator for marking tests that fail when cache is disabledr   r9   r   r   r   r      s    T)matchtest_stacklevelc                #   s   t jdd}t d t jd d |V  W d   n1 s!w   Y  t fdd|D s@d	 d
d |D f }t||D ]#}t|j sLJ t	|tj
t|jsetd j d|dqB|rt D ]}|j}tj|d }|dr n|dkr dS qltd|D ]}|j|krd|j d|j d| ddd}t|q tkr
tt}	|	jjjd d d d }
|
 sdS g }|D ]	}||jj  qt!|
dd}|" }W d   n1 sw   Y  |D ]}d| d|vr	td |d!|
 d"qdS dS )#a  
    Like raises but tests that warnings are emitted.

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

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

    >>> 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: [].

    ``test_stacklevel`` makes it check that the ``stacklevel`` parameter to
    ``warn()`` is set so that the warning shows the user line of code (the
    code under the warns() context manager). Set this to False if this is
    ambiguous or if the context manager does not test the direct user code
    that emits the warning.

    If the warning is a ``SymPyDeprecationWarning``, this additionally tests
    that the ``active_deprecations_target`` is a real target in the
    ``active-deprecations.md`` file.

    T)recorderroralways)categoryNc                 3   s    | ]	}t |j V  qd S r   )r+   rP   .0w
warningclsr   r   	<genexpr>   s    zwarns.<locals>.<genexpr>z^Failed: DID NOT WARN. No warnings of type %s was emitted. The list of emitted warnings is: %s.c                 S   s   g | ]}|j qS r   r8   rQ   r   r   r   
<listcomp>   s    zwarns.<locals>.<listcomp>z?Failed: WRONG MESSAGE. A warning with of the correct category (z:) was issued, but it did not match the given match regex ()   test_z
doctest.pyzDCould not find the file for the given warning to test the stacklevelzFailed: Warning has the wrong stacklevel. The warning stacklevel needs to be
set so that the line of code shown in the warning message is user code that
calls the deprecated code (the current stacklevel is showing code from
z (line z), expected 
 docsrcexplanationzactive-deprecations.mdzutf-8)encoding(z)=zThe active deprecations target zJ does not appear to be a valid target in the active-deprecations.md file (z).)#warningscatch_warningssimplefilterfilterwarningsanyr   r+   rP   recompileIrK   r%   r8   r   inspectstackfilenameospathsplit
startswithRuntimeErrorlinenoreplacer   pathlibPath__file__parentexistsappendactive_deprecations_targetopenread)rU   rK   rL   warnrecmsgrS   fthisfilefile	this_fileactive_deprecations_filetargetstexttargetr   rT   r   warns   s|   





r   c                    s*   ddl m   fdd}t|}|S )a8  
    Decorator used to run the test twice: the first time `e^x` is represented
    as ``Pow(E, x)``, the second time as ``exp(x)`` (exponential object is not
    a power).

    This is a temporary trick helping to manage the elimination of the class
    ``exp`` in favor of a replacement by ``Pow(E, ...)``.
    r   )_exp_is_powc                      sb    d   W d    n1 sw   Y   d   W d    d S 1 s*w   Y  d S )NTFr   r   r   r:   r   r   	func_wrap;  s   

"z _both_exp_pow.<locals>.func_wrap)sympy.core.parametersr   r=   r>   )r:   r   r;   r   r   r   _both_exp_pow0  s   	r   c                   c   s6    t t dV  W d   dS 1 sw   Y  dS )a:  
    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``.

    .. note::

       ``warns_deprecated_sympy()`` is only intended for internal use in the
       SymPy test suite to test that a deprecation warning triggers properly.
       All other code in the SymPy codebase, including documentation examples,
       should not use deprecated behavior.

       If you are a user of SymPy and you want to disable
       SymPyDeprecationWarnings, use ``warnings`` filters (see
       :ref:`silencing-sympy-deprecation-warnings`).

    >>> from sympy.testing.pytest import warns_deprecated_sympy
    >>> from sympy.utilities.exceptions import sympy_deprecation_warning
    >>> with warns_deprecated_sympy():
    ...     sympy_deprecation_warning("Don't use",
    ...        deprecated_since_version="1.0",
    ...        active_deprecations_target="active-deprecations")

    >>> 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: [].

    .. note::

       Sometimes the stacklevel test will fail because the same warning is
       emitted multiple times. In this case, you can use
       :func:`sympy.utilities.exceptions.ignore_warnings` in the code to
       prevent the ``SymPyDeprecationWarning`` from being emitted again
       recursively. In rare cases it is impossible to have a consistent
       ``stacklevel`` for deprecation warnings because different ways of
       calling a function will produce different call stacks.. In those cases,
       use ``warns(SymPyDeprecationWarning)`` instead.

    See Also
    ========
    sympy.utilities.exceptions.SymPyDeprecationWarning
    sympy.utilities.exceptions.sympy_deprecation_warning
    sympy.utilities.decorator.deprecated

    N)r   r   r   r   r   r   warns_deprecated_sympyE  s   
5"r   c                  C   s$   zddl } W dS  ty   Y dS w )zTest if running under pyodide.r   NFT)
pyodide_jsImportError)r   r   r   r   _running_under_pyodide~  s   
r   c                    rA   )z2Decorator to skip a test if running under pyodide.c                    s   t   fdd}|S )Nc                      s   t  rt   S r   )r   r   r   )r8   	test_funcr   r   test_wrapper  s   z;skip_under_pyodide.<locals>.decorator.<locals>.test_wrapper)r=   wraps)r   r   rW   )r   r   	decorator  s   z%skip_under_pyodide.<locals>.decoratorr   )r8   r   r   rW   r   skip_under_pyodide  rF   r   r   )-__doc__sysrh   r=   rn   
contextlibrc   rk   ru   typingr   r   sympy.utilities.exceptionsr   r   getenvON_CIpytestgetattr
USE_PYTESTr   __annotations__r	   r   markxfailr
   r   r   r   r   _pytest.outcomesr   r   r"   r7   r1   r4   r5   contextmanagerr   r   r   r   r   r   r   r   r   <module>   sn    
I
\
8
