o
    @jW                     @  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	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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   i/var/www/www-root/data/www/ai-bot.pdev.uz/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   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  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 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*   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s*J |p(d| |f d S )Nz^\s+?|\n z {2,} z%r != %r)r5   sub)abr%   r   r   r   eq_ignore_whitespacer   s
    rF   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_dialect~   s   rQ   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   rU   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!   rT   r   r   decorate   s   $z2emits_python_deprecation_warning.<locals>.decorater   )rT   rZ   r   rY   r    emits_python_deprecation_warning   s   r[   c                  O     t tj| fi |S r#   )r   sa_excSADeprecationWarningrS   r   r   r   expect_sqlalchemy_deprecated      r_   c                  O  r\   r#   )r   r]   RemovedIn20WarningrS   r   r   r   expect_sqlalchemy_deprecated_20   r`   rb   )NF)NFF)T)TFr#   ),
__future__r   
contextlibr5   r2   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?   r@   rF   rG   r1   rQ   rU   r[   r_   rb   r   r   r   r   <module>   sL    



	