a
    g	g                     @  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ur(| js(ds(J 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__)	exception r   ]/var/www/html/llm_bihealth/app/venv/lib/python3.9/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 | ||}||i | W d    n1 s00    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.   I   s   
r.   c              
   c  s   t  }|rt d }z|V  d}W n~ | y } zf||_d}|d urlt|t|tjslJ | d| |r||s|t| t	t|
d W Y d }~n
d }~0 0 |sJ dd S )Nr   FTz !~ zutf-8z#Callable did not raise an exception)r.   sysexc_infor,   researchstrUNICODEr   printencode)r   r&   r   r-   Zare_we_already_in_a_tracebacksuccesserrr   r   r   r+   M   s    &(r+   Tc                 C  s   t | |dS )Nr   r+   )r   r   r   r   r   expect_raisesb   s    r>   c                 C  s   t | ||dS )Nr%   r=   )r   r&   r   r   r   r   expect_raises_messagef   s    r?   c                 C  sX   t dd| } t dd| } t dd|}t dd|}| |ksTJ |pPd| |f d S )Nz^\s+?|\n z {2,} z%r != %r)r5   sub)abr&   r   r   r   eq_ignore_whitespacej   s
    rE   zDict[Any, Any]_dialect_modsc                 C  sN   | d u s| dkrt  S t|   }| dkr8d|_n| dkrFd|_|S d S )Nr   Z
postgresqlTZmssqlF)r   ZDefaultDialectr   Z_create_urlget_dialectZimplicit_returningZlegacy_schema_aliasing)namedr   r   r   _get_dialectw   s    rJ   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    rN   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:0    Y  d S )NZassert_F)r   DeprecationWarning)fnr    r!   rM   r   r   decorate   s    z2emits_python_deprecation_warning.<locals>.decorater   )rM   rR   r   rQ   r    emits_python_deprecation_warning   s    rS   c                  O  s   t tj| fi |S r#   )r   sa_excZSADeprecationWarningrL   r   r   r   expect_sqlalchemy_deprecated   s    rU   c                  O  s   t tj| fi |S r#   )r   rT   ZRemovedIn20WarningrL   r   r   r   expect_sqlalchemy_deprecated_20   s    rV   )NF)NF)T)T)N),
__future__r   
contextlibr5   r3   typingr   r   Z
sqlalchemyr   rT   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?   rE   rF   r2   rJ   rN   rS   rU   rV   r   r   r   r   <module>   sF    
	



