o
    8c                     @   sb  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	d3ddZG dd deZej d3d d!Z!d4d#d$Z"d4d%d&Z#d5d'd(Z$i Z%d)d* Z&d+d, Z'd-d. Z(d/d0 Z)d1d2 Z*dS )6    )absolute_importN)exc)util)default)_expect_warnings)eq_)is_)is_false)is_not_)is_true)ne_	decorator   )sqla_compat)py3kc                 C   s6   t jsd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.

    NFzZException %r was correctly raised but did not set a cause, within context %r as its cause.)r   r   __context__	__cause____suppress_context__)	exception r   P/var/www/html/gps/gps/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_ok3      r$   c                 O   s   t | ||||ddS )NTmsgr   r   r   r'   r   r    kwargsr   r   r   assert_raises_message7   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   C   s   
r   c                   @   s   e Zd ZdZdS )_ErrorContainerN)__name__
__module____qualname__r-   r   r   r   r   r/   L   s    r/   c              
   c   s    t  }|rt d }z|V  d}W n@ | yS } z4||_d}|d ur7t|t|tjs7J d||f |r?|s?t	| t
t|d W Y d }~nd }~ww |sZJ dd S )Nr   FTz%r !~ %szutf-8z#Callable did not raise an exception)r/   sysexc_infor-   researchr   	text_typeUNICODEr   printencode)r   r'   r   r.   are_we_already_in_a_tracebacksuccesserrr   r   r   r,   P   s,   
 r,   Tc                 C   s   t | |dS )Nr   r,   )r   r   r   r   r   expect_raisesg   s   r?   c                 C   s   t | ||dS )Nr&   r>   )r   r'   r   r   r   r   expect_raises_messagek   r%   r@   c                 C   sz   t dd| } t dd| } t dd|}t dd|}tr&t dd|}nt dd|}| |ks;J |p9d| |f d S )Nz^\s+?|\n z {2,} z!Uuz%r != %r)r5   subr   )abr'   r   r   r   eq_ignore_whitespaceo   s    rG   c                 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)Tr#   )+
__future__r   
contextlibr5   r3   
sqlalchemyr   r]   r   sqlalchemy.enginer   sqlalchemy.testing.assertionsr   r   r   r	   r
   r   r   sqlalchemy.utilr   r   util.compatr   r   r"   r$   r*   r+   r   objectr/   contextmanagerr,   r?   r@   rG   _dialect_modsrQ   rU   r[   r_   rb   r   r   r   r   <module>   sH    
	


