gzddlmZddlmZddlZddlmZddlmZddlZddl Z ddl Z ddl m Z ddl m Z dd l mZdd l mZdd lmZdd lmZd dl mZd dl mZd dl mZd dl mZd dl mZd dlmZd dlmZd dlmZd dlmZdZ ejBdZ"dZ#dZ$dZ%dZ&dZ'da(da)da* dGdZ+ejB dHdZ,d Z-d!Z.d"Z/dId#Z0dId$Z1dId%Z2dId&Z3dId'Z4dId(Z5dId)Z6dId*Z7dId+Z8dId,Z9dId-Z:e:Z;dId.ZdId0Z?dId1Z@d2ZAd3ZBd4ZCd5ZDd6ZEd7ZFd8ZG dJd9ZHGd:d;ZIejBdJd<ZJdKd=ZKdKd>ZLGd?d@ZMGdAdBZNGdCdDZOGdEdFZPy)L) annotations) defaultdictN)copy) filterfalse) assertsql)config)engines)mock)db_spec)fail)exc)schema)sql)types)util)default)url)LABEL_STYLE_TABLENAME_PLUS_COL decoratorc8ttj|fi|S)aContext 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_onlysa_exc SAWarningmessageskws N/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/testing/assertions.pyexpect_warningsr!%s &f&6&6 GB GGc/Kt|}t|tr|tjsdyt |i|5ddddy#1swYyxYww)zContext manager which expects one or more warnings on specific dialects. The expect version **asserts** that the warnings were in fact seen. N)r isinstancestrr _currentr!)dbrrspecs r expect_warnings_onr)5sD 2;D"c4#8 h -" - . - -sAAA AAAc$tfd}|S)zDecorator form of expect_warnings(). Note that emits_warning does **not** assert that the warnings were in fact seen. cVtddi5||i|cdddS#1swYyxYwNassert_F)r!fnargsrrs r decoratezemits_warning..decorateNs' X 6U 6t?r?7 6 6(rrr1s` r emits_warningr4Fs## Or"c8ttj|fi|SN)rrSADeprecationWarningrs r expect_deprecatedr8Vs" %##X 13 r"c8ttj|fi|Sr6)rrBase20DeprecationWarningrs r expect_deprecated_20r;\s" %'' 57 r"c(tfd}|S)aVMark 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^tgddi5||i|cdddS#1swYyxYwr,)r))r/r0rr'rs r r1z"emits_warning_on..decoratens,  =H =E =t?r?> = =#,r)r'rr1s`` r emits_warning_onr?bs## Or"c$tfd}|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. cVtddi5||i|cdddS#1swYyxYwr,)r8r.s r r1z!uses_deprecated..decorates'  8% 8t?r?9 8 8r2rr3s` r uses_deprecatedrBvs ## Or"c$t|||||dS)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_clsrrDrEr-s r rrs#  $  r"c # KsrD|Dcgc]7}tj|tjtjz9c} n t | t It JtJt j t j t|fz adyt x a a|fard ntj   fd}tjd|5 ddxaxaa|r$ r"Jddjfd Dzdddycc}w#dxaxaa|r% r"Jddjfd DzwwxYw#1swYyxYww)Nctd|z)NzGot unexpected warning: %r)AssertionError)msgargrs r real_warnz#_expect_warnings..real_warns$%AC%GHHr"cbt|trt|}t|}n |r|d}nd}|rt |ts s |g|i|SyssyD]C} r|j |sr|j |s r,||k(s2 j|y s |g|i|yy)Nr)r$_EXC_CLStyper% issubclasssearchmatchdiscard) rLrMr exceptionfilter_filtersrFrNrDrEseensquelch_other_warningss r our_warnz"_expect_warnings..our_warns#x( I #hF  Jy($C-$S535"55#:"GNN3$7'--"4!gnLL)#.c.C.2..r"z warnings.warnzWarnings were not seen: %sz, c3DK|]}dr |jn|zyw)z%rN)pattern).0srDs r z#_expect_warnings..s#NDHqU :Ds )recompileISlist_FILTERS_SEENrPextendupdatesetwarningswarnr patchjoin) rHrrDrEr-rFrZrLr[rXrNrYs `` `` @@@r rGrGs ;CD8C2::c244"$$;/8Dx.   ###  WWJ 7|#u: " I! I / /<ZZ 2 .2228#%ADIINDHNE&83 2qEx/3228#%ADIINDHNE&8t 3 2sA E35351"55>r"c.||k(sJ|xs|d|y)z.Assert a == b, with repr messaging on failure. != Nrqrs r eq_r 6-3-1--6r"c.||k7sJ|xs|d|y)z.Assert a != b, with repr messaging on failure.z == Nrqrs r ne_rrr"c.||ksJ|xs|d|y)z.Assert a <= b, with repr messaging on failure.rNrqrs r le_r#rr"c<t||sJ|xs|d|y)Nz is not an instance of r$rs r is_instance_ofr(s! a JSJQ$JJ r"c t|d|yNrL)is_rrLs r is_noner,s4Sr"c t|d|yr)is_notrs r is_not_noner0s 1dr"c2tt|d|y)NTrrboolrs r is_truer4sQ3r"c2tt|d|y)NFrrrs r is_falser8sQC r"c,||usJ|xs|d|y)z.Assert a is b, with repr messaging on failure.z is not Nrqrs r rr< 6131Aq116r"c,||usJ|xs|d|y)z2Assert a is not b, with repr messaging on failure.z is Nrqrs r rrAs A:1s1Aq11:r"c,||vsJ|xs|d|y)z.Assert a in b, with repr messaging on failure.z not in Nrqrs r in_rJrr"c,||vsJ|xs|d|y)z2Assert a in not b, with repr messaging on failure.z is in Nrqrs r not_inrOs A:4s4q!44:r"cF|j|sJ|xs|d|y)z>Assert a.startswith(fragment), with repr messaging on failure.z does not start with N) startswith)rfragmentrLs r startswith_rXs- << !3$ + !r"cBtjdd|}tjdd|}tjdd|}tjdd|}tjdd|}tjdd|}||k(sJ|xs|d|y)Nz^\s+?|\nz {2,} z\tr)rasubrs r eq_ignore_whitespacer`s {B"A xa A ub!A {B"A xa A ub!A 6-3-1--6r"c~|j|jur%|jsJd|d|jdyy)aHassert 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. z Exception z> was correctly raised but did not set a cause, within context z as its cause.N) __context__ __cause____suppress_context__)rVs r _assert_proper_exception_contextrksI Y%8%88.. )// 1 u/ 9r"c"t||||dS)NT check_context_assert_raises except_cls callable_r0rs r assert_raisesrs *ir NNr"ct||||Sr6rrs r assert_raises_context_okrs *ir ::r"c$t|||||dS)NTrLrrrrLrr0kwargss r assert_raises_messagers ItVD r"cXt|dg5||i|cdddS#1swYyxYw)alegacy 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.*Nr)rrr0rs r assert_warnsrs) $J 7$)&) 8 7 7s )c^t||gdd5||i|cdddS#1swYyxYw)aqlegacy 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)rErDNrrs r assert_warns_messagers9 $    $)&)    r>c"t|||||Srrrs r assert_raises_message_context_okrs *iv3 GGr"ct|||5}||i|ddd|jS#1swYjSxYwr6)_expect_raiseserror)rrr0rrLrecs r rrs<  C 724"6" 8 88O 8 88Os +?ceZdZdZy)_ErrorContainerN)__name__ __module__ __qualname__rrqr"r rrs Er"rc#Kt|trt|tst|tr t dt }|rt jd} |d}~|sJdy#|$r}||_d}| A > !> ,S 1 c#hoog&'' (s1AC>"A3( C>3C;8A9C61C>6C;;C>ct||S)Nrr)rrs r expect_raisesrs *M BBr"ct|||S)Nrr)rrLrs r expect_raises_messagers *#] KKr"c<eZdZ ddZy)AssertsCompiledSQLNc H 67| r#tj| _|_n| rdnω t |ddt j jndk(sdk(r>dk(rtjntjd| _|_n[dk(rtjnAttr1tjjj|r|_i}i}|r||d<|t!||d<|rd|d <|rd|d <|rd|d <|rd|d <|rd|d <|s t |ddrt"j$|d<ddlm}t||j*r|j-}t.|_|}|r||d<Gdd6G6fdd}||j2d0di|}t|t4j6r|j8}|r,t;|n |j=}|rt;|dt?t |di}|jAdjCdd}tEdt|z|zjAdtGjHddt|}tK|||d |d!|G|r*|jM|d"} tK| jN|ntK|jQ||| |rN|jM|d"} tKtS| jTD!cgc]}!| jN|!c}!| nC|jQ|d"}"tKtS|jTD!cgc]}!|"|! c}!| | tK|jV| |.DontAccessctd)Nz=compiler accessed .statement; use compiler.current_executable)NotImplementedError)selfkeys r __getattribute__zFAssertsCompiledSQL.assert_compile..DontAccess.__getattribute__Os)2r"N)rrrrrqr"r DontAccessrNs r"rc@eZdZdZedZdZdZdZfdZ y)>AssertsCompiledSQL.assert_compile..CheckCompilerAccessc0||_i|_t|dd|_|jrj|j|_t |dr|j |_t |dr|j|_t |dr|j|_yyy)Nsupports_executionF _returning_inline_return_defaults) test_statement _annotationsgetattrr_execution_optionshasattrrrr)rrs r __init__zGAssertsCompiledSQL.assert_compile..CheckCompilerAccess.__init__Vs&4#$&!*1"$8%+'**.<.O.OD+~|<*8*C*C~y9'5'='= ~/AB0>0O0O-C+r"c.|jjSr6)r_variant_mappingrs r rzOAssertsCompiledSQL.assert_compile..CheckCompilerAccess._variant_mappinggs**;;;r"c6|jjSr6)r_default_dialectrs r rzOAssertsCompiledSQL.assert_compile..CheckCompilerAccess._default_dialectks**;;==r"cT|jjj|fd|i|S)Ndialect)rrb__func__rrrs r rbzFAssertsCompiledSQL.assert_compile..CheckCompilerAccess.compilens6;t**22;;")-/r"cR|jjj||fi|Sr6)r _compilerrrs r rzHAssertsCompiledSQL.assert_compile..CheckCompilerAccess._compilerss0=t**44=='%'r"ct|drMtjj|d5|jj |fi|cdddS|jj |fi|S#1swYyxYw)N statement)r r rmobjectr_compiler_dispatch)rcompilerrrs r rzQAssertsCompiledSQL.assert_compile..CheckCompilerAccess._compiler_dispatchxs8[1** +z| Ft22EE$ (. B4..AA $*s A88BN) rrrr propertyrrrbrr)rsr CheckCompilerAccessrUs1 P" < < >    r"rrparamsrasciiignorez SQL String: z[\n\t]rrz on dialect ) escape_namesc:t}||_||_|Sr6)r paramstyle positional)r$r%cprs r get_dialectz6AssertsCompiledSQL.assert_compile..get_dialects'] * *  r"pyformatz%(z)srzExpected to find bindparam z in c3:K|]}|dz |kyw)rNrq)r^i positionss r r`z4AssertsCompiledSQL.assert_compile..s+1A!a% 9Q</1srzOrder of parameters z+ does not match the order in the statement z . Statement rq)F,,ByM" fcii ('')D >D F #1B   . . f 0  ' / / F F2 F fh11 2$*$<$< !$*+$*$>$>$@ !$*1-.Hb12 $$W-44WhG   3q6)I5==gFG VVIr3q6 * BBHI  "!!"!;!;"<"N--{;A&&v. <  &!!"!;!;"<"&4%?%?%?+55a8%? $&&vE&BE7A1Q478/J  %  N + , 555LLOQ%6%665&    ' 222LLOQ%6%662!   Hd!;  +:u= 'G0@GBGJ66)RZ9D'6M$fnnA]AbAG'--.F00G++g.L.LL))*56>)/=A19aF= M I&t,L &L( ,Q 3 !!++a+C**#%7?!CC$$S) O**3/q#i.1G '-SF-C&DE&Dda&DHE8>xO  GS !g"< 98 8>"&CDdKC%#%5&Fs77W)  W. !W3!W86 W=W= AX XX)NNFNNNNNFFTTFFNFNFTF)rrrrvrqr"r rrsF "!" $#' ! % +0/D"r"rceZdZ ddZdZy)ComparesTablesc2t|jt|jk(sJt|j|jD]\}}t|j|j||j|jusJ|r@t|j |j t|j |j |rKd}t|jt|js2J||j|jfz|j||t|jtjr4t|jj|jj|rdt|jDchc]}|jjc}|jDchc]}|jjc}|jst|jt j"rJ|rdt|j t|j k(sJ|j D]'}|j j$|j'Jyycc}wcc}w)Nz)Type '%s' doesn't correspond to type '%s')rQr`rSrrn primary_keynullabler$rQassert_types_baser9Stringlength foreign_keyscolumnserver_defaultr FetchedValuecolumns) rtablereflected_table strict_typesstrict_constraintsr` reflected_crLfs r assert_tables_equalz"ComparesTables.assert_tables_equals 577|s?#4#45555!%''?+<+<=NA{  (( )/"3"3AFF";; ;;!AMM;#:#:;AJJ 4 45A!+"2"2DLA3$$FFJDA &&{A6!&&(//2AFFMM;#3#3#:#:;!,-NN;NqQXX]]N;,7,D,DE,DqQXX]],DE!..0C0C5>< u(()S1L1L-MM MM&&&22::166BNNN' <Es J J c|jj|js/Jd|jd|jd|jdy)Nz On column z, type 'z' doesn't correspond to type '')rQ_compare_type_affinityrn)rc1c2s r r|z ComparesTables.assert_types_base(sFww-- GG   GG GG GG   r"N)FT)rrrrr|rqr"r rxrxs  )OV r"rxceZdZdZdZdZdZd dZdZdZ d Z e jd Z d Ze jd Zy)AssertsExecutionResultscht|}tt||j|||yr6)rerr> assert_list)rrUclass_objectss r assert_resultz%AssertsExecutionResults.assert_result3s)f d6l 1r"c|jt|t|k(d|jztdt|D]}|j |||||y)Nz9result list is not the same size as test list, for class r)r-rQrrP assert_row)rrUrlist_r+s r rz#AssertsExecutionResults.assert_list8s^ K3u: % oo  q#e*%A OOFF1IuQx 8&r"c |j|j|udt|z|jD]\}}t |t r[t |dt r$|jt|||d|dM|j|dt|||dq|jt|||k(d|dt||d|y)Nzitem class is not rrz attribute z value z does not match ) r- __class__r>itemsr$rCrerr r)rrrowobjdescrvalues r rz"AssertsExecutionResults.assert_rowBs    &(.immutabledictct|Sr6)idrs r __hash__zOAssertsExecutionResults.assert_unordered_result..immutabledict.__hash__[s $xr"N)rrrrrqr"r immutabledictrZs r"rct|Sr6r)oclss r zAAssertsExecutionResults.assert_unordered_result..as :a+=r"zUnexpected type "z ", expected ""zUnexpected object count "c|jD]M\}}t|tr& jt |||dg|d._compare_itemos"jjl UeU+%444#C-uQx:?( sC1U:$+ *%$%s$A## A0/A0z Expected z instance with attributes z not found.T) dictr IdentitySetrr rQrrQrremover>) rrUrrzrfoundewrongr expected_item found_itemrs ` ` @r rz/AssertsExecutionResults.assert_unordered_resultSs D   (.67hM!$h7 !=uEE ;''7 F u:X & u:s8}.  ( &M#  ];LL,$ ||T-%8: &Q8sDNc<|ddlm}tj|S)Nr)r')rr'r assert_engine)rr's r sql_execution_asserterz.AssertsExecutionResults.sql_execution_asserters : "&&r**r"c~|j|5}|}dddj|S#1swYxYwr6rr-)rr'rrulesasserterrUs r assert_sql_executionz,AssertsExecutionResults.assert_sql_executions<  ( ( ,[F-%  - ,s3<c >g}|D]}}t|trHtj|j Dcgc]\}}tj ||c}}}ntj |}|j ||j||g|Scc}}wr6)r$rrAllOfr CompiledSQLrMr) rr'rrnewrulesrulekronewrules r assert_sqlz"AssertsExecutionResults.assert_sqlsD$%#//>BjjlKldai++Aq1lK$//6 OOG $)t((YBBB Ls B cN|j||tj|Sr6)rrCountStatements)rr'rcounts r assert_sql_countz(AssertsExecutionResults.assert_sql_counts'((  944U;  r"c'~K|j|5}ddddj|y#1swYxYwwr6r)rr'rrs r assert_executionz(AssertsExecutionResults.assert_executions6  ( ( , -% - ,s=1=:=cL|j|tj|Sr6)rrr)rr'rs r assert_statement_countz.AssertsExecutionResults.assert_statement_counts $$R)B)B5)IJJr"c# Kt||Dcgc]\}}|j|||f}}}g}|D]%\}}}|j|j' dt||D]@\}\}}}|j ddd|j t j|Bycc}}w#t||D]@\}\}}}|j ddd|j t j|BwxYwwr6)rSrrM __enter____exit__r-rr) rdbscountsr'rrecs assertersctxrs r assert_statement_count_multi_dbz7AssertsExecutionResults.assert_statement_count_multi_dbs #3/ / U ( ( ,b% 8/   "NCU   S]]_ -# C .1)T.B**3E T4.  !:!:5!AB/C /2)T.B**3E T4.  !:!:5!AB/Cs)DB4/D B:$AD:AD  Dr6)rrrrrrrrrrr contextlibcontextmanagerrrrrqr"r rr2sh2 9"4l+  C !! K C Cr"rc eZdZ ddZy)ComparesIndexesc0tt|jt||jDcic]}|j|}}|D]:}||d}t|j|d|dDcgc]}|| }}tt|j t||D]}t ||j v|jd} | rdtt|jt| t|j| |dD]\} } } |  t| j| !|jds |d|dvst|j|d|d|d=ycc}wcc}w)Nrnunique column_names expressionsdialect_options_includeinclude) rrQindexesrnrrrrKrrStextr) rrrz dialect_nameidxidx_dictexpr`colsexprsidx_expexprcols r !compare_table_index_with_expectedz1ComparesIndexes.compare_table_index_with_expectedsx C H .-2]];]cCHHcM];C3v;'C  CM *">2D2!amA2DD CKK #d) ,S[[()GGM*EC(#e*5*-OOUC,?+>3{GLL$/ + )*#nH-5F1GG'' 5i@)*l^8+DE'<EsF;FFN)rz schema.Tablerzrerr%)rrrrrqr"r rrs!-1ADr"r)TFT)TFTFFr6)NF)T)Q __future__r collectionsrrr itertoolsrrarrkrrr r r exclusionsr rr rrrrrr9enginerrsql.selectablerrr!rr)r4r8r;r?rBrfrgrPrrGrrrpr~rrrrrrrrrrris_not_rrnot_in_rrrrrrrrrrrrrrrrxrrrqr"r rs##!  ; H        (0      .   ! MM`(/6. . . K !2 2 2 5 . *O; **(HBG ':':TCLE"E"P3 3 lLCLC^r"