idVVddlmZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z dd l mZd d lmZd d lmZd d lmZd dlmZd dlmZd dlm Z d dlmZd dlmZd dl mZd dl mZdZejdZdZdZdZ dZ!ej d9dZ"dZ#da$dZ%d:dZ&d:d Z'd:d!Z(d:d"Z)d:d#Z*d:d$Z+d:d%Z,d:d&Z-d:d'Z.e.Z/d:d(Z0d:d)Z1e1Z2d:d*Z3d:d+Z4d,Z5d-Z6d.Z7d/Z8d0Z9d1Z: d;d2Z;Gd3d4e<Z=Gd5d6e<Z>Gd7d8e<Z?dS)<)absolute_importN) assertsql)config)mock)util)db_spec)fail)exc)pool)schema)sql)types)default)url)compat decoratorc2ttj|fi|S)aContext 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. )_expect_warningssa_exc SAWarningmessageskws R/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/testing/assertions.pyexpect_warningsr!s F,h = =" = ==c/Kt|}t|tjr|tjsdVdSt |i|5dVddddS#1swxYwYdS)zContext manager which expects one or more warnings on specific dialects. The expect version **asserts** that the warnings were in fact seen. N)r isinstancer string_typesr_currentr)dbrrspecs rexpect_warnings_onr&1s 2;;D"d'((fo1F1F  h -" - -   EEE                  sA%%A),A)c,tfd}|S)zDecorator form of expect_warnings(). Note that emits_warning does **not** assert that the warnings were in fact seen. c`tddi5||i|cdddS#1swxYwYdSNassert_F)rfnargsrrs rdecoratezemits_warning..decorateJs X 6U 6 6 # #2t?r?? # # # # # # # # # # # # # # # # # # #''rrr.s` r emits_warningr1Bs/####Y# Orc2ttj|fi|SN)rrSADeprecationWarningrs rexpect_deprecatedr5Rs F7 H HR H HHrc0tfd}|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. chtgRddi5||i|cdddS#1swxYwYdSr))r&)r,r-rr$rs rr.z"emits_warning_on..decoratebs  =H = = =E = = # #2t?r?? # # # # # # # # # # # # # # # # # #s '++r)r$rr.s`` remits_warning_onr8Vs5#####Y# Orc,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. c`tddi5||i|cdddS#1swxYwYdSr))r5r+s rr.z!uses_deprecated..decoratezs  8% 8 8 # #2t?r?? # # # # # # # # # # # # # # # # # #r/rr0s` ruses_deprecatedr;js/ ####Y# OrTFc# Kr d|Dn|ttjfd}tjd|5dVdddn #1swxYwY|r|rt jsdSdSdSdS)Ncfg|].}tj|tjtjz/S)recompileIS).0msgs r z$_expect_warnings..s,DDDC2:c24"$;//DDDrc:t|r|}t|}n |r |d}nd}|rt|s |g|Ri|SsdSD]9}r||ss||kr |dS:|g|Ri|dS)Nr)r!str issubclassmatchdiscard) rDargr exceptionfilter_exc_clsfilters real_warnregexseens rour_warnz"_expect_warnings..our_warns c7 # # Ii..CC  AIII . 9g > > .9S-3---"-- -  F ' 'G '--,,  %nn W%%% Ic &C & & &2 & & & & &rz warnings.warn)setwarningswarnrpatchrpy3k) rNrrQr*py2konlyrSrOrPrRs ` ` @@@rrrs"  DD8DDD w<rrglobal_cleanup_assertionsr\s&'''''rctjtjrFtdz at dt tjztjtjrRt tj}tjdatj d|zdStdkrdadSdS)Nrz2Encountered a stray connection in test cleanup: %srz8Stray connection refused to leave after gc.collect(): %s ) testutillazy_gcr _refs_STRAY_CONNECTION_FAILURESprintrG gc_collectclearrUrV)errs rr[r[s   z  #a'" @$*oo       z '$*oo %&" IC O      $b ( (%&""" ) (rcdSr3r>abrDs req_regexrkrcdS)z.Assert a == b, with repr messaging on failure.Nr>rhs req_rnrlrcdS)z.Assert a != b, with repr messaging on failure.Nr>rhs rne_rprlrcdS)z.Assert a <= b, with repr messaging on failure.Nr>rhs rle_rrrlrcdSr3r>rhs ris_instance_ofrtrlrc*t|d|dS)NTrDis_rirDs ris_truerzs4Src*t|d|dS)NFrvrwrys ris_falser|s5crcdS)z.Assert a is b, with repr messaging on failure.Nr>rhs rrxrxrlrcdS)z2Assert a is not b, with repr messaging on failure.Nr>rhs ris_notr rlrcdS)z.Assert a in b, with repr messaging on failure.Nr>rhs rin_rrlrcdS)z2Assert a in not b, with repr messaging on failure.Nr>rhs rnot_inrrlrcdS)z>Assert a.startswith(fragment), with repr messaging on failure.Nr>)rifragmentrDs r startswith_r#rlrctjdd|}tjdd|}tjdd|}tjdd|}dS)Nz^\s+?|\nz {2,} )r?subrhs req_ignore_whitespacer+sR {B""A xa  A {B""A xa  AAArcTtjsdS|j|jur |jsdSdSdS)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. N)rrX __context__ __cause____suppress_context__)rLs r _assert_proper_exception_contextr4sC 9 Y%888. 9888888rc.t||||ddSNT) check_context_assert_raises except_cls callable_r-rs r assert_raisesrLs!:y$$GGGGGGrc*t||||dSr3rrs rassert_raises_context_okrPs*  rc*t||||dSrrrs rassert_raises_returnrYs *ir N N NNrc0t|||||ddS)NT)rDrrrrDrr-kwargss rassert_raises_messager]s0ItVDrc.t|||||dS)Nrvrrs r assert_raises_message_context_okrcs#:y$C@@@@@@rcd}|rtjd} ||i|d}n_#|$rW} | }d}||r|st| tt j| dYd} ~ nd} ~ wwxYw|S)NrFTutf-8)sysexc_inforrcr text_typeencode) rrr-rrDrret_errare_we_already_in_a_tracebacksuccessrfs rrrisG:(+ q(9%3 4"6"""  3 3 3 ?  2!> 2 ,S 1 1 1 dnS!!((1122222222 3" Ns *BA BBc(eZdZ ddZdS)AssertsCompiledSQLNFc |rtj}n| rd}n|t|dd}|tjj}n||dkrtj}nb|dkrtj}nHt|tj r.tj | }i} i} | r| | d<|t|| d<| rd| d<dd lm}t||jr(|}d|j_|j}nt||jjret,j|d 5}||jdd d}dddn #1swxYwY| r| | d <Gd dt0Gfddt0}||jdd|i| }t9t|di}tjrd|ddd}tAdtj!|z|zdn:tAdtj!|dz|ztEj#ddtj!|}tI|||d|d||#tI|%|||C|%|tItMfd|j'D||tI|j(|dSdS)N __dialect__rdefault_enhancedschema_translate_map column_keysT literal_bindsr)orm _execute_stmtrcompile_kwargsceZdZdZdS)5AssertsCompiledSQL.assert_compile..DontAccessc td)Nz=compiler accessed .statement; use compiler.current_executable)NotImplementedError)selfkeys r__getattribute__zFAssertsCompiledSQL.assert_compile..DontAccess.__getattribute__s)2rN)__name__ __module__ __qualname__rr>rr DontAccessrs#     rrc2eZdZdZdZdZdZfdZdS)>AssertsCompiledSQL.assert_compile..CheckCompilerAccesscd||_t|dd|_|jr|j|_t |t jt jt jfr |j |_ t |t jt jfr|j |_ |j |_ dSdSdS)Nsupports_executionF) test_statementgetattrr_execution_optionsr!rInsertUpdateDelete _returninginline_return_defaults)rrs r__init__zGAssertsCompiledSQL.assert_compile..CheckCompilerAccess.__init__s&4#*1"$8%++'* P.<.OD+!&SZ(LD+9*C!.3:sz2JKKP&4&; 0>0O--- P PPPrc4|jSr3)r_default_dialectrs rrzOAssertsCompiledSQL.assert_compile..CheckCompilerAccess._default_dialects*;;===rc6|jjj|fd|i|S)Ndialect)rr@__func__rrrs rr@zFAssertsCompiledSQL.assert_compile..CheckCompilerAccess.compiles7;t*2;")-/rc4|jjj||fi|Sr3)r _compilerrrs rrzHAssertsCompiledSQL.assert_compile..CheckCompilerAccess._compilers1=t*4='%'rct|drVtj|d5|jj|fi|cdddS#1swxYwYdS|jj|fi|S)N statement)hasattrrrWobjectr_compiler_dispatch)rcompilerrrs rrzQAssertsCompiledSQL.assert_compile..CheckCompilerAccess._compiler_dispatchs8[11 ** +zz|| Ft2E$  (.  B4.A $*sAA"AN)rrrrrr@rr)rsrCheckCompilerAccessrsm P P P  > > >              rrrparamsrasciiignorez SQL String: z[\n\t]rz != z on dialect c g|] }| Sr>r>)rCxps rrEz5AssertsCompiledSQL.assert_compile..s333qt333rr>))rDefaultDialectrrr$rStrCompileDialectr!rr"rURL get_dialectlist sqlalchemyrQuery_compile_contextr use_labels persistenceBulkUDrrWrexec_ mock_callsr@reprrXrdecodercrr?rrnconstruct_paramstuple positiontupprefetch)rclauseresultr checkparamsrcheckpositionalcheck_prefetchuse_default_dialectallow_dialect_selectrrrrrcontext stmt_mockrc param_strccrrs @@rassert_compilez!AssertsCompiledSQL.assert_compiles2  ;,..GG ! ;GG!$ t<< )+I%%!022...!355GT%677 ;8#''**6688::   >)=B% &   $V B}   3.2N? +"""""" fci ( ( 7--//G+/G  (&FF  6 7 7 7""6?;; 7y "-a03A6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7  2#1B         ) ) ) ) ) ) ) &) ) ) \ 0   ' ' / F F F2 F FHb1122 9 !((1188(KKI "T^A%6%66BJJ     !.##**7334    VIr4>!#4#4 5 5 BBBBHIII  " ""6**K 8 8 8  &""6**A 3333Q]33344o F F F  %  N + + + + + & %s$.FF"%F") NNNNNFFFN)rrrrr>rrrrsK !"!J,J,J,J,J,J,rrceZdZddZdZdS)ComparesTablesFct|j|jD]\}}t|j|jt|j|jt|j|j|rd}n|||t|jtj r$t|jj |jj td|j Dd|j D|j r|jD]}dS)Nz)Type '%s' doesn't correspond to type '%s'c&h|]}|jjSr>columnnamerCfs r z5ComparesTables.assert_tables_equal..*s7771777rc&h|]}|jjSr>r rs rrz5ComparesTables.assert_tables_equal..+sAAA1AAAr)ziprrnr  primary_keynullableassert_types_baser!typesqltypesStringlength foreign_keysserver_default)rtablereflected_table strict_typesr reflected_crDs rassert_tables_equalz"ComparesTables.assert_tables_equals%!%'?+<==  NA{  ( ) ) )  {6 7 7 7  K0 1 1 1 7A &&{A666!&(/22 <AFM;#3#:;;; 77777AA (@AAA     " K KAA K KrcdSr3r>)rc1c2s rrz ComparesTables.assert_types_base6rlrN)F)rrrr rr>rrrrs<KKKKB     rrcleZdZdZdZdZdZd dZdZdZ d Z d Z e j d Zd ZdS)AssertsExecutionResultsct|}tt|||||dSr3)rrcr assert_list)rrclass_objectss r assert_resultz%AssertsExecutionResults.assert_resultAs?f d6ll 11111rc|t|t|kd|jztdt|D]%}||||||&dS)Nz9result list is not the same size as test list, for class r)r*lenrrange assert_row)rrr(list_is rr'z#AssertsExecutionResults.assert_listFs KK3u:: % o    q#e**%% 9 9A OOFF1IuQx 8 8 8 8 9 9rc :||j|udt|z|D]\}}t |t rt |dt r2|t|||d|dg| |dt|||d|t|||kd|dt||d|dS)Nzitem class is not rrz attribute z value z does not match ) r* __class__ritemsr!rrr'rr.)rr(rowobjdescrvalues rr.z"AssertsExecutionResults.assert_rowPs+   &(.immutabledictc t|Sr3)idrs r__hash__zOAssertsExecutionResults.assert_unordered_result..immutabledict.__hash__is $xxrN)rrrr<r>rr immutabledictr9hs#     rr=c&h|] }|Sr>r>)rCer=s rrzBAssertsExecutionResults.assert_unordered_result..ms#777MM!$$777rc$t|Sr3)r!)oclss rzAAssertsExecutionResults.assert_unordered_result..psjC((rzUnexpected type "z ", expected ""zUnexpected object count "c|D]o\}}t|tr= jt |||dg|dRE#t $rYdSwxYwt |||krdSpdS)NrrFT)r3r!rassert_unordered_resultrAssertionError)objr%rr6NOVALUErs r _compare_itemzFAssertsExecutionResults.assert_unordered_result.._compare_items"jjll % % UeU++ %%44#C--uQx:?(*%%%$uuu%sC11U::$uu;4s)A A*)A*z Expected z instance with attributes z not found.T) dictr IdentitySetitertools_filterfalser rrr,rremover) rrrBexpectedfoundwrongrJ expected_item found_itemrIr=s ` ` @@rrFz/AssertsExecutionResults.assert_unordered_resultas     D    ((7777h777/ ( ( ( (%    E D;;'''7     u::X & & Du::::s8}}}}.    ((      &  M#    =];;LL,,,E|||T-%8%8%8%8:trNc:|ddlm}tj|S)Nr)r$)rr$r assert_engine)rr$s rsql_execution_asserterz.AssertsExecutionResults.sql_execution_asserters* : " " " " " "&r***rc||5}|}dddn #1swxYwY|j||Sr3rVr*)rr$rrulesasserterrs rassert_sql_executionz,AssertsExecutionResults.assert_sql_executions  ( ( , , !Y[[F ! ! ! ! ! ! ! ! ! ! ! ! ! ! !%   s -11cg}|D]e}t|tr+tjd|D}ntj|}||f|j||g|RS)Nc>g|]\}}tj||Sr>)r CompiledSQL)rCkvs rrEz6AssertsExecutionResults.assert_sql..s)KKKdai+Aq11KKKr)r!rKrAllOfr3r^appendr[)rr$rrYnewrulesrulenewrules r assert_sqlz"AssertsExecutionResults.assert_sqls % %D$%% 7#/KKdjjllKKK$/6 OOG $ $ $ $(t(YBBBBBrcX|||tj|dSr3)r[rCountStatements)rr$rcounts rassert_sql_countz(AssertsExecutionResults.assert_sql_counts6 !!  94U;;     rc fdt||D}g}|D]-\}}}||. |t||D]G\} \}}}|ddd| t j|HS#t||D]G\} \}}}|ddd| t j|HwxYw)NcFg|]\}}|||fSr>)rV)rCr$rirs rrEzEAssertsExecutionResults.assert_multiple_sql_count..sB   U ( ( , ,b% 8   r)rrb __enter____exit__r*rrh) rdbsrcountsrecs assertersctxr$rirZs ` rassert_multiple_sql_countz1AssertsExecutionResults.assert_multiple_sql_countsL    "3//    " . .NCU   S]]__ - - - - C9;;.1)T.B.B C C**3E T4...  !:5!A!ABBBB Cc)T.B.B C C**3E T4...  !:5!A!ABBBB Cs  B33AD c'K||5}dVdddn #1swxYwY|j|dSr3rX)rr$rYrZs rassert_executionz(AssertsExecutionResults.assert_executions  ( ( , ,  EEE               %    s )--cR||tj|Sr3)rvrrh)rr$ris rassert_statement_countz.AssertsExecutionResults.assert_statement_counts#$$R)B5)I)IJJJrr3)rrrr*r'r.rFrVr[rfrjrt contextlibcontextmanagerrvrxr>rrr%r%@s222 999"666p++++  C C C   C C C!!! KKKKKrr%)TTFr3)NF)@ __future__rryr?rrUrrrrrr_ exclusionsr r r rr rrrrenginerrrrrrzr&r1r5r8r;rr\rbr[rkrnrprrrtrzr|rxris_not_rrnot_in_rrrrrrrrrrrrr%r>rrrsV'&&&&&   > > >         III(0 :?* * * * Z(((''''''T6666.... .... .... KKKK2222 2222 2222 5555 ....   0HHHOOO AAABG:K,K,K,K,K,K,K,K,\) ) ) ) ) V) ) ) XNKNKNKNKNKfNKNKNKNKNKr