o
    hL                     @  sn  U d dl m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 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ dd Zdd Zdd Zdd Zdd Z	d4ddZG dd dZej	d5dd Z d6d"d#Z!	d7d$d%Z"d8d&d'Z#i Z$d(e%d)< d*d+ Z&d,d- Z'd.d/ Z(d0d1 Z)d2d3 Z*dS )9    )annotationsN)Any)Dict)exc)default)URL)_expect_warnings)eq_)is_)is_false)is_not_)is_true)ne_	decoratorc                 C  s,   | j | jur| jsJ d| | j f dS dS )aH  assert that any exception we're catching does not have a __context__
    without a __cause__, and that __suppress_context__ is never set.

    Python 3 will report nested as exceptions as "during the handling of
    error X, error Y occurred". That's not what we want to do.  we want
    these exceptions in a cause chain.

    FzZException %r was correctly raised but did not set a cause, within context %r as its cause.N)__context__	__cause____suppress_context__)	exception r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/alembic/testing/assertions.py _assert_proper_exception_context   s   r   c                 O  s   t | |||ddS )NTcheck_context_assert_raises
except_cls	callable_argskwr   r   r   assert_raises+   s   r!   c                 O  s   t | |||S Nr   r   r   r   r   assert_raises_context_ok/   s   r#   c                 O  s   t | ||||ddS )NT)msgr   r   r   r$   r   r   kwargsr   r   r   assert_raises_message3   s   r'   c                 O  s   t | ||||dS )N)r$   r   r%   r   r   r    assert_raises_message_context_ok9   s   r(   Fc                 C  sD   t | ||}||i | W d    |jS 1 sw   Y  |jS r"   )_expect_raiseserror)r   r   r   r&   r$   r   ecr   r   r   r   ?   s   
r   c                   @  s   e Zd ZU dZded< dS )_ErrorContainerNr   r*   )__name__
__module____qualname__r*   __annotations__r   r   r   r   r,   G   s   
 r,   c              
   c  s    t  }|rt d }z|V  d}W nQ | yd } zE||_d}|d urI|r6t||ks5J | d| nt|t|tjsIJ | d| |rQ|sQt| t	t|
d W Y d }~nd }~ww |skJ dd S )Nr   FTz != z !~ zutf-8z#Callable did not raise an exception)r,   sysexc_infor*   strresearchUNICODEr   printencode)r   r$   r   
text_exactr+   are_we_already_in_a_tracebacksuccesserrr   r   r   r)   K   s(    &r)   Tc                 C  s   t | |dS )Nr   r)   )r   r   r   r   r   expect_raisese   s   r>   c                 C  s   t | |||dS )N)r$   r   r9   r=   )r   r$   r   r9   r   r   r   expect_raises_messagei   s   r?   c                 C  sX   t dd| } t dd| } t dd|}t dd|}| |ks*J |p(d| |f d S )Nz^\s+?|\n z {2,} z%r != %r)r4   sub)abr$   r   r   r   eq_ignore_whitespaceq   s
    rE   zDict[Any, Any]_dialect_modsc                 C  sL   | d u s| dkrt  S t|   }| dkrd|_|S | dkr$d|_|S )Nr   
postgresqlTmssqlF)r   DefaultDialectr   createget_dialectimplicit_returninglegacy_schema_aliasing)namedr   r   r   _get_dialect}   s   rP   c                  O  s   t t| fi |S )a  Context manager which expects one or more warnings.

    With no arguments, squelches all SAWarnings emitted via
    sqlalchemy.util.warn and sqlalchemy.util.warn_limited.   Otherwise
    pass string expressions that will match selected warnings via regex;
    all non-matching warnings are sent through.

    The expect version **asserts** that the warnings were in fact seen.

    Note that the test suite sets SAWarning warnings to raise exceptions.

    )r   Warningmessagesr    r   r   r   expect_warnings   s   rT   c                    s   t  fdd}|S )zDecorator form of expect_warnings().

    Note that emits_warning does **not** assert that the warnings
    were in fact seen.

    c                   sH   t tg R ddi | |i |W  d    S 1 sw   Y  d S )Nassert_F)r   DeprecationWarning)fnr   r    rS   r   r   decorate   s   $z2emits_python_deprecation_warning.<locals>.decorater   )rS   rY   r   rX   r    emits_python_deprecation_warning   s   rZ   c                  O     t tj| fi |S r"   )r   sa_excSADeprecationWarningrR   r   r   r   expect_sqlalchemy_deprecated      r^   c                  O  r[   r"   )r   r\   RemovedIn20WarningrR   r   r   r   expect_sqlalchemy_deprecated_20   r_   ra   )NF)NFF)T)TFr"   )+
__future__r   
contextlibr4   r1   typingr   r   
sqlalchemyr   r\   sqlalchemy.enginer   r   sqlalchemy.testing.assertionsr   r	   r
   r   r   r   r   sqlalchemy.utilr   r   r!   r#   r'   r(   r   r,   contextmanagerr)   r>   r?   rE   rF   r0   rP   rT   rZ   r^   ra   r   r   r   r   <module>   sL    



	