U
    ^g%iW                     @  sh  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d5ddZG dd dZej d6d d!Z!d7d#d$Z"d8d%d&Z#d9d'd(Z$i Z%d)e&d*< d+d, Z'd-d. Z(d/d0 Z)d1d2 Z*d3d4 Z+dS ):    )annotationsN)Any)Dict)exc)default)_expect_warnings)eq_)is_)is_false)is_not_)is_true)ne_	decorator   )sqla_compatc                 C  s,   | j | jk	r(| js(ds(td| | j f 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__AssertionError)	exception r   Y/var/www/html/api-medvista/venv/lib/python3.8/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_ok0   s    r%   c                 O  s   t | ||||ddS )NT)msgr   r   r   r&   r    r!   kwargsr   r   r   assert_raises_message4   s         r)   c                 O  s   t | ||||dS )N)r&   r   r'   r   r   r    assert_raises_message_context_ok:   s    r*   Fc              	   C  s(   t | ||}||| W 5 Q R X |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.   H   s   
r.   c              
   c  s   t  }|rt d }z|V  d}W n | k
r } z||_d}|d k	r|rlt||kst| d| n&t|t|tjst| d| |r|st	| t
t|d W 5 d }~X Y nX |stdd S )Nr   FTz != z !~ zutf-8z#Callable did not raise an exception)r.   sysexc_infor,   strr   researchUNICODEr   printencode)r   r&   r   
text_exactr-   Zare_we_already_in_a_tracebacksuccesserrr   r   r   r+   L   s"     &$r+   Tc                 C  s   t | |dS )Nr   r+   )r   r   r   r   r   expect_raisesf   s    r?   c                 C  s   t | |||dS )N)r&   r   r;   r>   )r   r&   r   r;   r   r   r   expect_raises_messagej   s       r@   c                 C  sX   t dd| } t dd| } t dd|}t dd|}| |ksTt|pPd| |f d S )Nz^\s+?|\n z {2,} z%r != %r)r6   subr   )abr&   r   r   r   eq_ignore_whitespacer   s
    rF   zDict[Any, Any]_dialect_modsc                 C  sN   | d ks| dkrt  S t|   }| dkr8d|_n| dkrFd|_|S d S )Nr   
postgresqlTZmssqlF)r   ZDefaultDialectr   Z_create_urlget_dialectZimplicit_returningZlegacy_schema_aliasing)namedr   r   r   _get_dialect~   s    rL   c                  O  s   t t| f|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    rP   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              
     s6   t tf ddi | ||W  5 Q R  S Q R X d S )NZassert_F)r   DeprecationWarning)fnr!   r"   rO   r   r   decorate   s    z2emits_python_deprecation_warning.<locals>.decorater   )rO   rT   r   rS   r    emits_python_deprecation_warning   s    rU   c                  O  s   t tj| f|S r$   )r   sa_excZSADeprecationWarningrN   r   r   r   expect_sqlalchemy_deprecated   s    rW   c                  O  s   t tj| f|S r$   )r   rV   ZRemovedIn20WarningrN   r   r   r   expect_sqlalchemy_deprecated_20   s    rX   )NF)NFF)T)TF)N),
__future__r   
contextlibr6   r3   typingr   r   Z
sqlalchemyr   rV   Zsqlalchemy.enginer   Zsqlalchemy.testing.assertionsr   r   r	   r
   r   r   r   Zsqlalchemy.utilr   utilr   r   r#   r%   r)   r*   r   r.   contextmanagerr+   r?   r@   rF   rG   r2   rL   rP   rU   rW   rX   r   r   r   r   <module>   sT       
     
   

	