o
    ¨D®f—  ã                   @  sj  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 d5d d!„ƒZ!d6d#d$„Z"d6d%d&„Z#d7d'd(„Z$i Z%d)e&d*< d+d,„ Z'd-d.„ Z(d/d0„ Z)d1d2„ Z*d3d4„ Z+dS )8é    )Ú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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   úS/home/ubuntu/webapp/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_ok0   ó   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  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/   H   s   
 r/   c              
   c  s¶    t ƒ }|rt ¡ d }z|V  d}W n? | yR } z3||_d}|d ur7t |t|ƒtj¡s7J |› d|› ƒ‚|r?|s?t|ƒ t	t|ƒ 
d¡ƒ W Y d }~nd }~ww |sYJ 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.   Ú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_raisesa   s   r@   c                 C  s   t | ||dS )Nr&   r?   )r   r'   r   r   r   r   Úexpect_raises_messagee   r%   rA   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)r6   Úsub)ÚaÚbr'   r   r   r   Úeq_ignore_whitespacei   s
    rG   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_urlÚget_dialectÚimplicit_returningÚlegacy_schema_aliasing)ÚnameÚdr   r   r   Ú_get_dialectu   s   þrR   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   rV   c                    s   t ‡ fdd„ƒ}|S )z„Decorator 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!   ©rU   r   r   Údecorateš   s   $ÿz2emits_python_deprecation_warning.<locals>.decorater   )rU   r[   r   rZ   r   Ú emits_python_deprecation_warning’   s   r\   c                  O  ó   t tj| fi |¤ŽS r#   )r   Úsa_excÚSADeprecationWarningrT   r   r   r   Úexpect_sqlalchemy_deprecated¢   ó   r`   c                  O  r]   r#   )r   r^   ÚRemovedIn20WarningrT   r   r   r   Úexpect_sqlalchemy_deprecated_20¦   ra   rc   )NF)Tr#   ),Ú
__future__r   Ú
contextlibr6   r4   Útypingr   r   Ú
sqlalchemyr   r^   Úsqlalchemy.enginer   Úsqlalchemy.testing.assertionsr   r   r	   r
   r   r   r   Úsqlalchemy.utilr   Úutilr   r   r"   r$   r*   r+   r   r/   Úcontextmanagerr,   r@   rA   rG   rH   r3   rR   rV   r\   r`   rc   r   r   r   r   Ú<module>   sH    
ÿ


	