o
    ‹ågL  ã                   @  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   úV/var/www/html/flaskapp/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 )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    ©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    
ÿÿ

ÿ
	