?PKzVddlmZddlZddlZddlZddlZddlmZddlmZddlm 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 /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/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#dKr d|Dn|ttjfd}tjd|5dVdddn #1swxYwY|r<|r t js2r.JddfdDzdSdSdS)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.warnzWarnings were not seen: %sz, c34K|]}dr|jn|zVdS)z%rN)pattern)rCsrQs r z#_expect_warnings..sLB B 34D-AIIA .B B B B B B r)setwarningswarnrpatchrpy3kjoin) rNrrQr*py2konlyrSrOrPrRs ` ` @@@rrrsv  DD8DDD w<rrglobal_cleanup_assertionsras&'''''rctjtjrFtdz at dt tjztjtjrRt tj}tjdatj d|zdStdkr JddS)Nrz2Encountered a stray connection in test cleanup: %srz8Stray connection refused to leave after gc.collect(): %s Fz*Encountered more than 10 stray connections) testutillazy_gcr _refs_STRAY_CONNECTION_FAILURESprintrG gc_collectclearrYrZ)errs rr`r`s   z  #a'" @$*oo       z '$*oo %&" IC O      $b ( (BBBBu ) (rcRtj||sJ|p|d|dS)N !~ )r?rIabrDs req_regexrqs5 8Aq>>553511"555>55rc4||ksJ|p|d|dS)z.Assert a == b, with repr messaging on failure. != Nr>rns req_rt) 6663-11-66666rc4||ksJ|p|d|dS)z.Assert a != b, with repr messaging on failure.z == Nr>rns rne_rwrurc4||ksJ|p|d|dS)z.Assert a <= b, with repr messaging on failure.rsNr>rns rle_ryrurcHt||sJ|p|d|dS)Nz is not an instance of r!rns ris_instance_ofr|s6 a  JJSJQQQ$JJJ JJrc*t|d|dS)NTrDis_rorDs ris_truers4Src*t|d|dS)NFr~rrs ris_falsers5crc0||usJ|p|d|dS)z.Assert a is b, with repr messaging on failure.z is not Nr>rns rrr) 66631AAAqq166666rc0||usJ|p|d|dS)z2Assert a is not b, with repr messaging on failure.z is Nr>rns ris_notr s) A:::s1AAAqq1:::::rc0||vsJ|p|d|dS)z.Assert a in b, with repr messaging on failure.z not in Nr>rns rin_rrrc0||vsJ|p|d|dS)z2Assert a in not b, with repr messaging on failure.z is in Nr>rns rnot_inrs) A:::s4qqq!!4:::::rcR||sJ|p|d|dS)z>Assert a.startswith(fragment), with repr messaging on failure.z does not start with N) startswith)rofragmentrDs r startswith_r#sJ << ! !3$ + !rctjdd|}tjdd|}tjdd|}tjdd|}||ksJ|p|d|dS)Nz^\s+?|\nz {2,} rs)r?subrns req_ignore_whitespacer+su {B""A xa  A {B""A xa  A 6663-11-66666rc|tjsdS|j|jur|jsJd|d|jddSdS)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. NFz Exception z> was correctly raised but did not set a cause, within context z as its cause.)rr\ __context__ __cause____suppress_context__)rLs r _assert_proper_exception_contextr4sn 9 Y%888. 9  yy)/// 1  u 9888rc.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)Nr~rrs r assert_raises_message_context_okrcs#:y$C@@@@@@rcd}|rtjd} ||i|d}n#|$r} | }d}|Atj|t j| tjsJ|d| |r|st| tt j|  dYd} ~ nd} ~ wwxYw|s Jd|S)NrFTrmutf-8z#Callable did not raise an exception) sysexc_infor?searchr text_typeUNICODErrhencode) rrr-rrDrret_errare_we_already_in_a_tracebacksuccessrks rrris/G:(+ q(9%3 4"6"""  3 3 3 ?9T^C(("*      2!> 2 ,S 1 1 1 dnS!!((1122222222 3 999997 Ns *CBCCc(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)hasattrrr[objectr_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]rrsz on dialect c g|] }| Sr>r>)rCxps rrEz5AssertsCompiledSQL.assert_compile..s333qt333rr>))rDefaultDialectrrr$rStrCompileDialectr!rr"rURL get_dialectlist sqlalchemyrQuery_compile_contextr use_labels persistenceBulkUDrr[rexec_ mock_callsr@reprr\rdecoderhrr?rrtconstruct_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|jt|jksJt|j|jD]^\}}t|j|j||j|jusJt|j|jt|j|j|rCd}t|jt|jsJ||j|jfzn| ||t|jtj r$t|jj |jj td|j Dd|j D|jr!t|jtjsJ`t|jt|jksJ|jD]}|jj|jJdS)Nz)Type '%s' doesn't correspond to type '%s'c&h|]}|jjSr>columnnamerCfs r z5ComparesTables.assert_tables_equal..*s7771777rc&h|]}|jjSr>rrs rrz5ComparesTables.assert_tables_equal..+sAAA1AAAr)lenrziprtr primary_keynullabler!typeassert_types_basesqltypesStringlength foreign_keysserver_defaultr FetchedValuecolumns)rtablereflected_table strict_typesr reflected_crDs rassert_tables_equalz"ComparesTables.assert_tables_equals57||s?#4555555!%'?+<==  NA{  ( ) ) )/"3AF";;;;;  {6 7 7 7  K0 1 1 1 7A!+"2DLLAA3$FJDA &&{A666!&(/22 <AFM;#3#:;;; 77777AA (@AAA    !.0C5$%%_-H)I)IIIII" K KA".6qv>JJJJ K Krc|j|js#Jd|jd|jd|jddS)Nz On column z, type 'z' doesn't correspond to type '')r"_compare_type_affinityr)rc1c2s rr#z ComparesTables.assert_types_base6sfw-- G      GGG GGG GGG      rN)F)rrrr/r#r>rrrrs<KKKKB     rrcleZdZdZdZdZdZd dZdZdZ d Z d Z e j d Zd ZdS)AssertsExecutionResultsct|}tt|||||dSr3)rrhr 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*rrrange assert_row)rrr9list_is rr8z#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!rrr8rr>)rr9rowobjdescrvalues rr>z"AssertsExecutionResults.assert_rowPs+   &(.immutabledictc t|Sr3)idrs r__hash__zOAssertsExecutionResults.assert_unordered_result..immutabledict.__hash__is $xxrN)rrrrLr>rr immutabledictrIhs#     rrMc&h|] }|Sr>r>)rCerMs rrzBAssertsExecutionResults.assert_unordered_result..ms#777MM!$$777rc$t|Sr3r{)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)rCr!rassert_unordered_resultrAssertionError)objr%rrFNOVALUErs 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 r"rrrremover) rrrRexpectedfoundwrongrZ expected_item found_itemrYrMs ` ` @@rrVz/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||Sr3rfr*)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!r[rAllOfrCrnappendrk)rr$rrinewrulesrulenewrules r assert_sqlz"AssertsExecutionResults.assert_sqls % %D$%% 7#/KKdjjllKKK$/6 OOG $ $ $ $(t(YBBBBBrcX|||tj|dSr3)rkrCountStatements)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>)rf)rCr$ryrs rrEzEAssertsExecutionResults.assert_multiple_sql_count..sB   U ( ( , ,b% 8   r)rrr __enter____exit__r*rrx) rdbsrcountsrecs assertersctxr$ryrjs ` 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|dSr3rh)rr$rirjs rassert_executionz(AssertsExecutionResults.assert_executions  ( ( , ,  EEE               %    s )--cR||tj|Sr3)rrrx)rr$rys rassert_statement_countz.AssertsExecutionResults.assert_statement_counts#$$R)B5)I)IJJJrr3)rrrr;r8r>rVrfrkrvrzr contextlibcontextmanagerrrr>rrr6r6@s222 999"666p++++  C C C   C C C!!! KKKKKrr6)TTFr3)NF)@ __future__rrr?rrYrrrrrrd exclusionsr r r rr rrrr$enginerrrrrrr&r1r5r8r;rrargr`rqrtrwryr|rrrris_not_rrnot_in_rrrrrrrrrrrrr6r>rrrsV'&&&&&   > > >         III(0 :?* * * * Z(((''''''T6666.... .... .... KKKK2222 2222 2222 5555 ....   0HHHOOO AAABG:K,K,K,K,K,K,K,K,\) ) ) ) ) V) ) ) XNKNKNKNKNKfNKNKNKNKNKr