
    [hz                       d dl mZ d dlmZ d dlZd dlmZ 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lmZ ddlmZ d Z ej!        d             Z"d Z#d Z$d Z%d Z&d Z'da(da)da*	 	 	 dId Z+ej!        	 	 	 	 	 dJd!            Z,d" Z-d# Z.d$ Z/dKd%Z0dLd&Z1dLd'Z2dLd(Z3dLd)Z4dLd*Z5dLd+Z6dLd,Z7dLd-Z8dLd.Z9dLd/Z:e:Z;dLd0Z<dLd1Z=e=Z>dLd2Z?dLd3Z@d4 ZAd5 ZBd6 ZCd7 ZDd8 ZEd9 ZFd: ZG	 dMd;ZH G d< d=          ZIej!        dMd>            ZJdNd?ZKdNd@ZL G dA dB          ZM G dC dD          ZN G dE dF          ZO G dG dH          ZPdS )O    )annotations)defaultdictN)copy)filterfalse   )	assertsql)config)engines)mock)db_spec)fail   )exc)schema)sql)types)util)default)url)LABEL_STYLE_TABLENAME_PLUS_COL	decoratorc                 2    t          t          j        | fi |S )a  Context manager which expects one or more warnings.

    With no arguments, squelches all SAWarning 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.

    )_expect_warnings_sqla_onlysa_exc	SAWarningmessageskws     l/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/testing/assertions.pyexpect_warningsr!   %   s     &f&6GGBGGG    c              /     K   t          |           }t          | t                    r |t          j                  sdV  dS t          |i |5  dV  ddd           dS # 1 swxY w Y   dS )zContext manager which expects one or more warnings on specific
    dialects.

    The expect version **asserts** that the warnings were in fact seen.

    N)r   
isinstancestrr	   _currentr!   )dbr   r   specs       r    expect_warnings_onr)   5   s       2;;D"c 44#8#8 h-"-- 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A  A$'A$c                 ,     t            fd            }|S )zDecorator form of expect_warnings().

    Note that emits_warning does **not** assert that the warnings
    were in fact seen.

    c                `    t          ddi5   | |i |cd d d            S # 1 swxY w Y   d S Nassert_F)r!   fnargsr   r   s      r    decoratezemits_warning.<locals>.decorateN   s    X6U66 	# 	#2t?r??	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#   #''r   r   r1   s   ` r    emits_warningr4   F   s/     # # # # Y# Or"   c                 2    t          t          j        | fi |S N)r   r   SADeprecationWarningr   s     r    expect_deprecatedr8   V   s)    %#X 13  r"   c                 2    t          t          j        | fi |S r6   )r   r   Base20DeprecationWarningr   s     r    expect_deprecated_20r;   \   s)    %' 57  r"   c                0     t            fd            }|S )aV  Mark a test as emitting a warning on a specific dialect.

    With no arguments, squelches all SAWarning failures.  Or pass one or more
    strings; these will be matched to the root of the warning description by
    warnings.filterwarnings().

    Note that emits_warning_on does **not** assert that the warnings
    were in fact seen.

    c                h    t          gR ddi5   | |i |cd d d            S # 1 swxY w Y   d S r,   )r)   )r/   r0   r   r'   r   s      r    r1   z"emits_warning_on.<locals>.decoraten   s    =H===E== 	# 	#2t?r??	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#   '++r   )r'   r   r1   s   `` r    emits_warning_onr?   b   s5     # # # # # Y# Or"   c                 ,     t            fd            }|S )a+  Mark a test as immune from fatal deprecation warnings.

    With no arguments, squelches all SADeprecationWarning failures.
    Or pass one or more strings; these will be matched to the root
    of the warning description by warnings.filterwarnings().

    As a special case, you may pass a function name prefixed with //
    and it will be re-written as needed to match the standard warning
    verbiage emitted by the sqlalchemy.util.deprecated decorator.

    Note that uses_deprecated does **not** assert that the warnings
    were in fact seen.

    c                `    t          ddi5   | |i |cd d d            S # 1 swxY w Y   d S r,   )r8   r.   s      r    r1   z!uses_deprecated.<locals>.decorate   s    8%88 	# 	#2t?r??	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#r2   r   r3   s   ` r    uses_deprecatedrB   v   s/      # # # # Y# Or"   TFc                ,    t          | ||||d          S )zSQLAlchemy internal use only _expect_warnings().

    Alembic is using _expect_warnings() directly, and should be updated
    to use this new interface.

    T)regex
search_msgr-   raise_on_any_unexpected)_expect_warnings)exc_clsr   rD   rE   r-   s        r    r   r      s-      $   r"   c           	   #    	
K   srd |D             nt          |          t          Wt          J t          J t                                         t                                         t          | fz  ad V  d S t                    x
aa| fard 	nt          j        		
fd}t          j
        d|          5  	 d V  d xaxaa|r.
r,J dd                    fd
D                       z              n;# d xaxaa|r.
r,J dd                    fd
D                       z              w xY wd d d            d S # 1 swxY w Y   d S )Nc                f    g | ].}t          j        |t           j        t           j        z            /S  )recompileIS).0msgs     r    
<listcomp>z$_expect_warnings.<locals>.<listcomp>   s,    DDDC2:c24"$;//DDDr"   c                &    t          d| z            )NzGot unexpected warning: %r)AssertionError)rQ   argr   s      r    	real_warnz#_expect_warnings.<locals>.real_warn   s    $%AC%GHHHr"   c                   t          | t                    rt          |           }t          |           } n|r	|d         }nd }|rt	          |t                    ss | g|R i |S d S ssd S D ]P}	r|                    |           sr|                    |           ss|| k    r
                    |            d S Qs | g|R i | d S d S Nr   )r$   _EXC_CLStyper%   
issubclasssearchmatchdiscard)rQ   rU   r   	exceptionfilter_filtersrF   rV   rD   rE   seensquelch_other_warningss        r    our_warnz"_expect_warnings.<locals>.our_warn   sN   #x(( ! II	#hh !F		 	 Jy($C$C - $9S53555"555F #: " 
/ 
/$+NN3$7$7")--"4"4 " '.nnLL)))EE- /Ic.C...2...../ /r"   zwarnings.warnzWarnings were not seen: %sz, c              3  4   K   | ]}d r|j         n|z  V  dS )z%rN)pattern)rP   srD   s     r    	<genexpr>z#_expect_warnings.<locals>.<genexpr>   sL       N N?@U 9		:N N N N N Nr"   )list_FILTERS_SEENrY   extendupdatesetwarningswarnr   patchjoin)rH   r   rD   rE   r-   rF   rc   rd   ra   rV   rb   s     `` `` @@@r    rG   rG      s       !
 !DD8DDDx..    ###   WWJ7||#u:" 	&I I I I !I	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/< Z22 		 		.2228 #  %ADII N N N NDHN N N E E &    /3228 #  %ADII N N N NDHN N N E E &       		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s*   ED7E8EEEEc                 "    t                       dS )zCheck things that have to be finalized at the end of a test suite.

    Hardcoded at the moment, a modular system can be built here
    to support things like PG prepared transactions, tables all
    dropped, etc.

    N)!_assert_no_stray_pool_connectionsrK   r"   r    global_cleanup_assertionsru      s     &'''''r"   c                 B    t           j                                         d S r6   )r
   testing_reaperassert_all_closedrK   r"   r    rt   rt     s    ,,.....r"   c                |    t          | |z            }t          || z
            |k     sJ d||dz  | fz              d S )Nz:Given int value %s is not within %d%% of expected value %sd   )intabs)expectedreceivedvariancedeviances       r    int_within_variancer   
  s[    8h&''HHx  8+++C3G  	,++++r"   c                T    t          j        || |          sJ |p| d|            d S )N !~ )rL   r]   )abrQ   flagss       r    eq_regexr     s:    8Aq%  <<#"<qqq!!)<<<<<<r"   c                4    | |k    sJ |p| d|            dS )z.Assert a == b, with repr messaging on failure. != NrK   r   r   rQ   s      r    eq_r     )    6663-11-66666r"   c                4    | |k    sJ |p| d|            dS )z.Assert a != b, with repr messaging on failure.z == NrK   r   s      r    ne_r     r   r"   c                4    | |k    sJ |p| d|            dS )z.Assert a <= b, with repr messaging on failure.r   NrK   r   s      r    le_r   #  r   r"   c                H    t          | |          sJ |p| d|            d S )Nz is not an instance of r$   r   s      r    is_instance_ofr   (  s6    aJJSJQQQ$JJJJJJr"   c                *    t          | d |           d S NrQ   )is_r   rQ   s     r    is_noner   ,  s    4Sr"   c                *    t          | d |           d S r   )is_notr   s     r    is_not_noner   0  s    
1dr"   c                D    t          t          |           d|           d S )NTr   r   boolr   s     r    is_truer   4  s#    Q3r"   c                D    t          t          |           d|           d S )NFr   r   r   s     r    is_falser   8  s#    QC      r"   c                0    | |u sJ |p| d|            dS )z.Assert a is b, with repr messaging on failure.z is not NrK   r   s      r    r   r   <  )    66631AAAqq166666r"   c                0    | |usJ |p| d|            dS )z2Assert a is not b, with repr messaging on failure.z is NrK   r   s      r    r   r   A  s)    A:::s1AAAqq1:::::r"   c                0    | |v sJ |p| d|            dS )z.Assert a in b, with repr messaging on failure.z not in NrK   r   s      r    in_r   J  r   r"   c                0    | |vsJ |p| d|            dS )z2Assert a in not b, with repr messaging on failure.z is in NrK   r   s      r    not_inr   O  s)    A:::s4qqq!!4:::::r"   c                R    |                      |          sJ |p| d|            dS )z>Assert a.startswith(fragment), with repr messaging on failure.z does not start with N)
startswith)r   fragmentrQ   s      r    startswith_r   X  sL    <<!!  3 $	+     r"   c                <   t          j        dd|           } t          j        dd|           } t          j        dd|           } t          j        dd|          }t          j        dd|          }t          j        dd|          }| |k    sJ |p| d|            d S )Nz^\s+?|\n z {2,} z\tr   )rL   subr   s      r    eq_ignore_whitespacer   `  s    
{B""A
xa  A
ub!A
{B""A
xa  A
ub!A6663-11-66666r"   c                `    | j         | j        ur| j        sJ d| d| j         d            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.

    Fz
Exception z> was correctly raised but did not set a cause, within context z as its cause.N)__context__	__cause____suppress_context__)r_   s    r     _assert_proper_exception_contextr   k  s`     	Y%888. 	9	
 	
 yy)///1	
 	
 	
 	9888r"   c                *    t          | |||d          S )NTcheck_context_assert_raises
except_cls	callable_r0   r   s       r    assert_raisesr     s    *irNNNNr"   c                &    t          | |||          S r6   r   r   s       r    assert_raises_context_okr     s    *ir:::r"   c                ,    t          | ||||d          S )NTrQ   r   r   r   rQ   r   r0   kwargss        r    assert_raises_messager     s&    ItVD   r"   c                h    t          | dg          5   ||i |cddd           S # 1 swxY w Y   dS )a  legacy adapter function for functions that were previously using
    assert_raises with SAWarning or similar.

    has some workarounds to accommodate the fact that the callable completes
    with this approach rather than stopping at the exception raise.


    z.*Nr   )r   r   r0   r   s       r    assert_warnsr     s     
$J	7	7 * *y$)&))* * * * * * * * * * * * * * * * * *r>   c                n    t          | |gdd          5   ||i |cddd           S # 1 swxY w Y   dS )aq  legacy adapter function for functions that were previously using
    assert_raises with SAWarning or similar.

    has some workarounds to accommodate the fact that the callable completes
    with this approach rather than stopping at the exception raise.

    Also uses regex.search() to match the given message to the error string
    rather than regex.match().

    TF)rE   rD   Nr   r   s        r    assert_warns_messager     s     
$		
 
 
 * * y$)&))* * * * * * * * * * * * * * * * * *s   *..c                *    t          | ||||          S r   r   r   s        r     assert_raises_message_context_okr     s     *iv3GGGGr"   c                r    t          | ||          5 } ||i | d d d            n# 1 swxY w Y   |j        S r6   )_expect_raiseserror)r   r   r0   r   rQ   r   ecs          r    r   r     s     

C	7	7 #2	4"6"""# # # # # # # # # # # # # # #8Os   	'++c                      e Zd ZdZdS )_ErrorContainerN)__name__
__module____qualname__r   rK   r"   r    r   r     s        EEEr"   r   c              #  \  K   t          | t                    rt          | t                    st          | t                    rt	          d          t                      }|rt          j                    d         }	 |V  d}n# | $ r}||_        d}|>t          |          }t          j        ||t          j                  sJ |d|            |r|st          |           t          t          |                              d                     Y d }~nd }~ww xY w~|s
J d            d S )NzCUse expect_warnings for warnings, not expect_raises / assert_raisesr   FTr   utf-8z#Callable did not raise an exception)r$   rZ   r[   Warning	TypeErrorr   sysexc_infor   r%   rL   r\   UNICODEr   printencode)r   rQ   r   r   are_we_already_in_a_tracebacksuccesserrerror_as_strings           r    r   r     s      	:t$$
z7++
 j'**

 ,
 
 	
 
		B :(+q(9%( ( ( (? "#hhO9S/2:>>  A     	2!> 	2,S111c#hhoog&&''''''''(( 	 99999999s   ;B DBDDc                $    t          | |          S )Nr   r   )r   r   s     r    expect_raisesr     s    *MBBBBr"   c                &    t          | ||          S )Nr   r   )r   rQ   r   s      r    expect_raises_messager     s    *#]KKKKr"   c                  >    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdS )AssertsCompiledSQLNFTc           	     h  /01234 |r"t          j                    |_        |_        n|rd n׉t	          | dd           t
          j        j        ndk    sdk    r=dk    rt          j                    nt          j        d          |_        |_        ngdk    rt          j                    nMt          t                    r8t          j                                                                                  |r|_        i }i }|r||d<   |t!          |          |d<   |rd|d	<   |rd|d
<   |rd|d<   |rd|d<   |rd|d<   |st	          | dd          rt"          j        |d<   ddlm} t          ||j                  r"|                                }t.          |_        |}|r||d<    G d d          / G /fdd          }  ||          j        d6di|0t          |t4          j                  r|j        }|rt;          |           n+|                                }|rt;          |d                    t?          t	          0di                     }|                     d          !                    dd          }tE          dt          0          z   |z                        d                     tG          j$        ddt          0                    }tK          |||d |d!           |R|r-0&                    |d"          1tK          1j'        |           n#tK          0(                    |          |           |	|rF0&                    |d"          1tK          tS          1fd#1j*        D                       |	           nE0(                    |d"          3tK          tS          3fd$0j*        D                       |	           |
tK          0j+        |
           |!tK          0fd%0j,        D             |           |!tK          0fd&0j-        D             |           |rt	          0dd           rڈfd'} |d(d          }  |j        d6d| i|}!tG          j$        ddt          |!                    } |dd          }" |j        d6d|"i|}#t!          |#j*                  }$|#j.        }%|#j-        |#j,        z  D ]!}&|#j/        |&         22|$v r2fd)|$D             }$"g 4ta          t                     }'|$D ]}(	 |(|'v r|'|(         d*         })nd})|%1                    |(|(          }*|2                    d+|*d,|)          d-z   }+43                    |+           |'|(         3                    |+           |# th          $ r d.|(d/|},J |,            w xY wtk          4fd0tm          d1to          4                    D                       }-d2 tq          ts          4|$                    D             }.d3|$d4|.d5|},tu          |-|,           d S d S d S )7N__dialect__r   default_qmarkqmarkdefault_enhancedschema_translate_mapcolumn_keysTliteral_bindsrender_postcompile"use_literal_execute_for_simple_intfor_executemanyrender_schema_translateassert_from_lintingFlintingr   )ormcompile_kwargsc                      e Zd Zd ZdS )5AssertsCompiledSQL.assert_compile.<locals>.DontAccessc                     t          d          )Nz=compiler accessed .statement; use compiler.current_executable)NotImplementedError)selfkeys     r    __getattribute__zFAssertsCompiledSQL.assert_compile.<locals>.DontAccess.__getattribute__O  s    )2  r"   N)r   r   r   r  rK   r"   r    
DontAccessr   N  s#            r"   r  c                  H    e Zd Zd Zed             Zd Zd Zd Z fdZ	dS )>AssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccessc                $   || _         i | _        t          |dd          | _        | j        rb|j        | _        t          |d          r|j        | _        t          |d          r|j        | _        t          |d          r|j        | _        d S d S d S )Nsupports_executionF
_returning_inline_return_defaults)	test_statement_annotationsgetattrr  _execution_optionshasattrr  r	  r
  )r   r  s     r    __init__zGAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess.__init__V  s    &4#$&!*1"$8%+ +' * P.<.OD+~|<< D*8*C~y99 >'5'=~/ABB P0>0O---P PP Pr"   c                    | j         j        S r6   )r  _variant_mappingr   s    r    r  zOAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess._variant_mappingg  s    *;;r"   c                4    | j                                         S r6   )r  _default_dialectr  s    r    r  zOAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess._default_dialectk  s    *;;===r"   c                6     | j         j        j        | fd|i|S )Ndialect)r  rM   __func__r   r  r   s      r    rM   zFAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess.compilen  s7    ;t*2; ")-/  r"   c                4     | j         j        j        | |fi |S r6   )r  	_compilerr  r  s      r    r  zHAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess._compilers  s1    =t*4=' %'  r"   c                    t          |d          rVt          j                            |d                       5   | j        j        |fi |cd d d            S # 1 swxY w Y   d S  | j        j        |fi |S )N	statement)r  r   rq   objectr  _compiler_dispatch)r   compilerr   r  s      r    r  zQAssertsCompiledSQL.assert_compile.<locals>.CheckCompilerAccess._compiler_dispatchx  s    8[11 
** +zz||     Ft2E$   (.                     B4.A  $*  s   AA"AN)
r   r   r   r  propertyr  r  rM   r  r  )r  s   r    CheckCompilerAccessr  U  s        P P P" < < X<> > >  
  
      r"   r"  r  paramsr   asciiignorez
SQL String:
z[\n\t]r   r   z on dialect )escape_namesc                *    g | ]}j         |         S rK   )
parameters)rP   xexpanded_states     r    rR   z5AssertsCompiledSQL.assert_compile.<locals>.<listcomp>  s1        ! +5a8  r"   c                     g | ]
}|         S rK   rK   )rP   r)  ps     r    rR   z5AssertsCompiledSQL.assert_compile.<locals>.<listcomp>  s    777A1Q4777r"   c                6    i | ]}j         |         |j        S rK   
bind_nameseffective_valuerP   r   cs     r    
<dictcomp>z5AssertsCompiledSQL.assert_compile.<locals>.<dictcomp>  4        LOQ%6  r"   c                6    i | ]}j         |         |j        S rK   r.  r1  s     r    r3  z5AssertsCompiledSQL.assert_compile.<locals>.<dictcomp>  r4  r"   c                B    t                    }| |_        ||_        |S r6   )r   
paramstyle
positional)r7  r8  cpr  s      r    get_dialectz6AssertsCompiledSQL.assert_compile.<locals>.get_dialect  s!    ']] * *	r"   pyformatc                     g | ]
}|k    |S rK   rK   )rP   vnames     r    rR   z5AssertsCompiledSQL.assert_compile.<locals>.<listcomp>  s    ===A199a999r"   z%(z)sr   zExpected to find bindparam z in c              3  B   K   | ]}|d z
           |         k     V  dS )r   NrK   )rP   i	positionss     r    rh   z4AssertsCompiledSQL.assert_compile.<locals>.<genexpr>  sI         !a% 9Q</     r"   r   c                    g | ]\  }}|S rK   rK   )rP   _r=  s      r    rR   z5AssertsCompiledSQL.assert_compile.<locals>.<listcomp>  s    EEEdaEEEr"   zOrder of parameters z+ does not match the order in the statement z. Statement rK   );r   DefaultDialectsupports_default_valuessupports_default_metavaluer  r	   r'   r  StrCompileDialectr$   r%   r   URLcreater:  default_schema_nameri   r   FROM_LINTING
sqlalchemyr   Query_statement_20r   _label_stylerM   sqltypes
TypeEngine_static_cache_keyhash_generate_cache_keyreprr   decoder   rL   r   r   construct_expanded_stater(  construct_paramstuplepositiontupprefetchliteral_execute_paramspost_compile_paramsescaped_bind_namesr/  r   getindexappend
ValueErrorallrangelensortedzipr   )5r   clauseresultr#  checkparamsr   check_literal_executecheck_post_paramr  checkpositionalcheck_prefetchuse_default_dialectallow_dialect_selectrF  rG  r   r   r   r   rK  from_lintingcheck_param_orderr   r   r   r   stmtr"  cache_key_no_warnings	param_strccr:  pyformat_dialect
pyformat_cqmark_dialectqmark_cvaluesescaped
post_parampos_by_valuer=  startescposrQ   orderedr}   r  r2  r*  r>  r,  rB  s5           `                                      @@@@@@r    assert_compilez!AssertsCompiledSQL.assert_compile  sM   2  	B,..G.EG+1KG..! 	BGG!$t<< )+I%%O)C)Ci''%466GG%4W==G2I/5O22...!355GS)) B'..11==??AA 	>*=G' 	>)=B%& $VB} 	3.2N?+ 	837N/0- 	HCGN?@ 	)$(B !" 	1,0B() 	-74)>FF 	-,ByM""""""fci(( 	''))D >DF 	2#1B 	 	 	 	 	 	 	 	.	 .	 .	 .	 .	 .	 .	 .	 .	 .	f 0''/FFF2FFfh122 	/$*$<!$ ,*+++$*$>$>$@$@!$ /*1-...Hb1122	$$W--44WhGG	 3q66)I5==gFFGGGVIr3q66**BBBBHIII"! =!"!;!; "< " " N-{;;;;A&&v..<<<&! K!"!;!; "< " "    %3%?    $    &&vE&BBE777777788/JJJ%
N+++ ,   5   &   '   2   !    3	"Hd!;!; 3	"      +{:u=='GG0@GBGGJ6)RZ99D'K66M$fnAA]AbAAG'-..F0G +g.LL> >
 )*56>>=======FI&t,,L & &&L(( ,Q 3 !!++a++C***###%7??!CC$$S))) O**3////! & & & &CD11ddKC%#%%%&     q#i..11    G
 FEfSF-C-C&D&DEEEHH 8>vvxxxO 
 GS!!!!!g3	" 3	" 3	" 3	"s   A8VV3)NNFNNNNNFFTTFFNFNFTF)r   r   r   r  rK   r"   r    r   r     sl        
 "!" $#' ! % +0/D" D" D" D" D" D"r"   r   c                       e Zd Z	 	 ddZd ZdS )ComparesTablesFTc                    t          |j                  t          |j                  k    sJ t          |j        |j                  D ]b\  }}t          |j        |j                   ||j        |j                 u sJ |r4t          |j        |j                   t          |j        |j                   |rCd}t          |j        t          |j                            sJ ||j        |j        fz              n| 	                    ||           t          |j        t          j                  r$t          |j        j        |j        j                   |r.t          d |j        D             d |j        D                        |j        r!t          |j        t          j                  sJ d|rOt          |j                  t          |j                  k    sJ |j        D ]}|j        j        |j                 J d S d S )Nz)Type '%s' doesn't correspond to type '%s'c                &    h | ]}|j         j        S rK   columnr>  rP   fs     r    	<setcomp>z5ComparesTables.assert_tables_equal.<locals>.<setcomp>  s    ;;;qQX];;;r"   c                &    h | ]}|j         j        S rK   r  r  s     r    r  z5ComparesTables.assert_tables_equal.<locals>.<setcomp>  s    EEEqQX]EEEr"   )rf  r2  rh  r   r>  primary_keynullabler$   rZ   assert_types_baserQ  Stringlengthforeign_keysserver_defaultr   FetchedValuecolumns)r   tablereflected_tablestrict_typesstrict_constraintsr2  reflected_crQ   s           r    assert_tables_equalz"ComparesTables.assert_tables_equal  s@    57||s?#4555555!%'?+<== 	 	NA{()))/"3AF";;;;;! 6AM;#:;;;AJ 4555 7A!+"2DLLAA  3$FJ D    
 &&{A666!&(/22 <AFM;#3#:;;;! ;;AN;;;EEK,DEEE    !.0C      	Ou())S1L-M-MMMMM& O O&2:16BNNNN	O 	OO Or"   c                    |j                             |j                   s#J d|j        d|j         d|j         d            d S )Nz
On column z, type 'z' doesn't correspond to type '')rZ   _compare_type_affinityr>  )r   c1c2s      r    r  z ComparesTables.assert_types_base(  sf    w--G
 
 	
 	
 	
 GGGGGGGGG
	
 	
 	
 	
 	
r"   N)FT)r   r   r   r  r  rK   r"   r    r  r    sD        
 )O )O )O )OV
 
 
 
 
r"   r  c                      e Zd Zd Zd Zd Zd ZddZd Zd Z	d	 Z
ej        d
             Zd Zej        d             ZdS )AssertsExecutionResultsc                    t          |          }t          t          |                     |                     |||           d S r6   )ri   r   rV  assert_list)r   rj  class_objectss       r    assert_resultz%AssertsExecutionResults.assert_result3  s?    fd6ll11111r"   c                   |                      t          |          t          |          k    d|j        z              t          dt          |                    D ]%}|                     |||         ||                    &d S )Nz9result list is not the same size as test list, for class r   )r-   rf  r   re  
assert_row)r   rj  r  list_rA  s        r    r  z#AssertsExecutionResults.assert_list8  s    KK3u::%o	
 	
 	
 q#e**%% 	9 	9AOOFF1IuQx8888	9 	9r"   c                :   |                      |j        |u dt          |          z              |                                D ]\  }}t	          |t
                    rt	          |d         t                    r2|                     t          ||          |d         |d                    g| 	                    |d         t          ||          |d                    |                      t          ||          |k    d|dt          ||          d|           d S )Nzitem class is not r   r   z
attribute z value z does not match )
r-   	__class__rV  itemsr$   rZ  ri   r  r  r  )r   r  rowobjdescr  values         r    r  z"AssertsExecutionResults.assert_rowB  s+   &(<tF||(K	
 	
 	
 **,, 	 	JC%'' 
eAh-- N$$WVS%9%958U1XNNNNOOE!Hgfc.B.BE!HMMMMFC((E11ssGFC0000%%9   	 	r"   c           	     p   	
  G d dt                     
t          j        |          }
fd|D             }t          fd|          D ]/}t	          dt          |          j        dj        d           0t          |          t          |          k    r0t	          dt          |          dt          |          d           t                      		 fd	}|D ]R}|D ]%} |||          r|	                    |            n)&t	          d
j        dt          |          d           SdS )zAs assert_result, but the order of objects is not considered.

        The algorithm is very expensive but not a big deal for the small
        numbers of rows that the test suite manipulates.
        c                      e Zd Zd ZdS )FAssertsExecutionResults.assert_unordered_result.<locals>.immutabledictc                     t          |           S r6   )idr  s    r    __hash__zOAssertsExecutionResults.assert_unordered_result.<locals>.immutabledict.__hash__[  s    $xxr"   N)r   r   r   r  rK   r"   r    immutabledictr  Z  s#                 r"   r  c                &    h | ]} |          S rK   rK   )rP   er  s     r    r  zBAssertsExecutionResults.assert_unordered_result.<locals>.<setcomp>_  s#    777MM!$$777r"   c                $    t          |           S r6   r   )oclss    r    <lambda>zAAssertsExecutionResults.assert_unordered_result.<locals>.<lambda>a  s    :a+=+= r"   zUnexpected type "z", expected ""zUnexpected object count "c                   |                                 D ]o\  }}t          |t                    r=	  j        t	          | |          |d         g|d         R   E# t
          $ r Y  dS w xY wt	          | |          |k    r dS pdS )Nr   r   FT)r  r$   rZ  assert_unordered_resultr  rT   )objr(   r  r  NOVALUEr   s       r    _compare_itemzFAssertsExecutionResults.assert_unordered_result.<locals>._compare_itemo  s    "jjll 
% 
%
UeU++ 	%%44#C--uQx:?(     * % % %$uuu% sC11U::$uu ;4s   )A
A*)A*z	Expected z instance with attributes z not found.T)dictr   IdentitySetr   r   rZ   r   rf  r  removerV  )r   rj  r  r}   foundwrongr  expected_item
found_itemr  r  s   ` `      @@r    r  z/AssertsExecutionResults.assert_unordered_resultS  s   	  	  	  	  	 D 	  	  	   ((7777h777 !=!=!=!=uEE 	 	ED;;'''7   
 u::X&&Du::::s8}}}}.  
 ((	 	 	 	 	 	 & 		 		M#  
 =];; LL,,,E |||T-%8%8%8%8:   tr"   Nc                :    |ddl m} t          j        |          S )Nr   )r'   )r   r'   r   assert_engine)r   r'   s     r    sql_execution_asserterz.AssertsExecutionResults.sql_execution_asserter  s*    :""""""&r***r"   c                    |                      |          5 } |            }d d d            n# 1 swxY w Y    |j        |  |S r6   r  r-   )r   r'   r   rulesasserterrj  s         r    assert_sql_executionz,AssertsExecutionResults.assert_sql_execution  s    ((,, 	!Y[[F	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!%  s   -11c                    g }|D ]e}t          |t                    r+t          j        d |                                D              }nt          j        | }|                    |           f | j        ||g|R  S )Nc                >    g | ]\  }}t          j        ||          S rK   )r   CompiledSQL)rP   kr=  s      r    rR   z6AssertsExecutionResults.assert_sql.<locals>.<listcomp>  s)    KKKdai+Aq11KKKr"   )r$   r  r   AllOfr  r  rb  r  )r   r'   r   r  newrulesrulenewrules          r    
assert_sqlz"AssertsExecutionResults.assert_sql  s     	% 	%D$%% 7#/KKdjjllKKK $/6OOG$$$$(t(YBBBBBr"   c                T    |                      ||t          j        |                    S r6   )r  r   CountStatements)r   r'   r   counts       r    assert_sql_countz(AssertsExecutionResults.assert_sql_count  s,    ((	94U;;
 
 	
r"   c              '     K   |                      |          5 }d V  d d d            n# 1 swxY w Y    |j        |  d S r6   r  )r   r'   r  r  s       r    assert_executionz(AssertsExecutionResults.assert_execution  s      ((,, 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%    s   )--c                R    |                      |t          j        |                    S r6   )r  r   r  )r   r'   r  s      r    assert_statement_countz.AssertsExecutionResults.assert_statement_count  s#    $$R)B5)I)IJJJr"   c              #     K    fdt          ||          D             }g }|D ]-\  }}}|                    |                                           .	 d V  t          ||          D ]G\  }\  }}}|                    d d d            |                    t          j        |                     Hd S # t          ||          D ]G\  }\  }}}|                    d d d            |                    t          j        |                     Hw xY w)Nc                F    g | ]\  }}                     |          ||fS rK   )r  )rP   r'   r  r   s      r    rR   zKAssertsExecutionResults.assert_statement_count_multi_db.<locals>.<listcomp>  sB     
 
 
U ((,,b%8
 
 
r"   )rh  rb  	__enter____exit__r-   r   r  )	r   dbscountsrecs	assertersctxr'   r  r  s	   `        r    assert_statement_count_multi_dbz7AssertsExecutionResults.assert_statement_count_multi_db  sV     
 
 
 
"3//
 
 
 	" 	. 	.NCUS]]__----	CEEE.1)T.B.B C C**3ET4...  !:5!A!ABBBBC Cc)T.B.B C C**3ET4...  !:5!A!ABBBBCs   B1 1ADr6   )r   r   r   r  r  r  r  r  r  r  r  
contextlibcontextmanagerr  r  r  rK   r"   r    r  r  2  s        2 2 2
9 9 9  "4 4 4l+ + + +  C C C
 
 

 ! ! !
K K K C C C C Cr"   r  c                      e Zd Zd	dZdS )
ComparesIndexesr  schema.Tabler}   ri   dialect_namer%   c                B   t          t          |j                  t          |                     d |j        D             }|D ]Z}||d                  }t          |j        |d                    d |d         D             }t          t          |j                  t          |                     |D ]}t          ||j        v            |                    d          }	|	rit          t          |j                  t          |	                     t          |j        |	|d                   D ]\  }
}}|t          |
j	        |           |                    d          r=| d|d         v r0t          |j
        |         d	         |d         | d                    \d S )
Nc                    i | ]
}|j         |S rK   )r>  )rP   idxs     r    r3  zEComparesIndexes.compare_table_index_with_expected.<locals>.<dictcomp>  s    ;;;cCHc;;;r"   r>  uniquec                    g | ]}||S r6   rK   )rP   r2  s     r    rR   zEComparesIndexes.compare_table_index_with_expected.<locals>.<listcomp>  s    DDD!amAmmmr"   column_namesexpressionsdialect_options_includeinclude)r   rf  indexesr  r  r   r`  r  rh  textr  )r   r  r}   r  idx_dictexpr  colsr2  exprsidx_expexprcols                r    !compare_table_index_with_expectedz1ComparesIndexes.compare_table_index_with_expected  s    	CH...;;U];;; 	 	C3v;'C
CM***DDs>2DDDDCK  #d)),,, * *S[())))GGM**E 0C((#e**555*-OUC,?+ + 0 0&GT3 {GL$///)**#---5F1GGG'5i@)*l+D+D+DE  '	 	r"   N)r  r  r}   ri   r  r%   )r   r   r   r	  rK   r"   r    r  r    s(             r"   r  )TFT)TFTFFrX   r6   )NF)T)Q
__future__r   collectionsr   r  r   	itertoolsr   rL   r   ro   r   r   r	   r
   r   
exclusionsr   r   r   r   r   r   r   r   rQ  enginer   r   sql.selectabler   r   r!   r  r)   r4   r8   r;   r?   rB   rj   rk   rY   r   rG   ru   rt   r   r   r   r   r   r   r   r   r   r   r   r   is_not_r   r   not_in_r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  rK   r"   r    <module>r     s   # " " " " " # # # # # #           ! ! ! ! ! ! 				 



                                                                                      ; ; ; ; ; ;      H H H              (  0     .  ! M M M M`( ( (/ / /  = = = =. . . .
. . . .
. . . .
K K K K             ! ! ! !2 2 2 2
2 2 2 2 2 2 2 2
5 5 5 5    . . . .
 
 
*O O O; ; ;  
* 
* 
** * *(H H H BG           ': ': ': ':TC C C CL L L LE" E" E" E" E" E" E" E"P3
 3
 3
 3
 3
 3
 3
 3
lLC LC LC LC LC LC LC LC^         r"   