U kfA @sXddlmZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z Gdd d ZGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddZGd d!d!ed!d"d#d$d%gZGd&d'd'Zejd(d)ZdS)*) annotationsN)event)url)DefaultDialect)BaseDDLElementc@s(eZdZdZdZdZddZddZdS) AssertRuleFNTcCsdSNselfexecute_observedr r L/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/testing/assertsql.pyprocess_statementszAssertRule.process_statementcCsds tddS)NFz?All statements are complete, but pending assertion rules remain)AssertionErrorr r r rno_more_statementsszAssertRule.no_more_statements)__name__ __module__ __qualname__ is_consumed errormessageconsume_statementrrr r r rrs rc@s eZdZdS) SQLMatchRuleNrrrr r r rr&src@seZdZdddZddZdS) CursorSQLNTcCs||_||_||_dSr ) statementparamsr)r rrrr r r__init__+szCursorSQL.__init__cCsp|jd}|j|jks,|jdk rN|j|jkrNd|_d|j|j|j|jf|_n|jdd|_|jsld|_dS)NrTz5Testing for exact SQL %s parameters %s received %s %s) statementsrr parametersrrpopr)r r stmtr r rr0s&    zCursorSQL.process_statement)NTrrrrrr r r rr*s rc@sFeZdZdddZddZdd Zd d Zd d ZddZddZ dS) CompiledSQLNdefaultTcCs||_||_||_||_dSr )rrdialectenable_returning)r rrr&r'r r rrGszCompiledSQL.__init__cCstdd|j}||kSN[\n\t])resubrr r received_statementr"r r r _compare_sqlOszCompiledSQL._compare_sqlcCsl|jdkrTt}d|_|jrPd|_|_|_d|_d|_d|_ d|_ |j sPt |St j|jSdS)Nr%T)r&rZsupports_default_metavaluer'Zinsert_returningZupdate_returningZdelete_returningZuse_insertmanyvaluesZsupports_multivalues_insertZupdate_returning_multifromZdelete_returning_multifromZinsert_executemany_returningrrURLcreate get_dialect)r r r&r r r_compile_dialectSs   zCompiledSQL._compile_dialectc s|j}||}d}dd|jkr.|jd}nd}t|jtrP|jj||dn|jj|||jj|jj |dt ddt }|j }|sjdg}nfdd |D}||fS) zxreconstruct the statement and params in terms of a target dialect, which for CompiledSQL is just DefaultDialect.Nschema_translate_map)r&r4) cache_keyr& column_keysfor_executemanyr4r)r*extracted_parameterscsg|]}j|dqS)r8)construct_params).0mcompiledr9r r s z3CompiledSQL._received_statement..)contextr3execution_options isinstance clauseelementrcompiler>r6r7r+r,strr r:) r r r@Zcompare_dialectr5Zmap__received_statementr _received_parametersr r=rrFms>     zCompiledSQL._received_statementc Cs|j}||\}}||}|||}|r|dk rt|}t|}|r|rt|d} tt|D]8\} } | D] } | | ks| | | | krtqhqt|| =qFqhd}qqF|s|rd}|rd|_d|_ n| ||||d|_ dS)NrFT)r.Zreceived_parameters) r@rF _all_paramsr/listdictr! enumeraterr_failure_message) r r r@rFrGrZ equivalent all_paramsZ all_receivedparamidxZreceivedZ param_keyr r rrsH  zCompiledSQL.process_statementcCs>|jr6t|jr||}n|j}t|ts2|g}|SdSdSr )rcallablerBrI)r r@rr r rrHs   zCompiledSQL._all_paramscCs"d|jddt|ddfSNzzTesting for compiled statement %r partial params %s, received %%(received_statement)r with params %%(received_parameters)r%%%)rreplacereprr r Zexpected_paramsr r rrLs  zCompiledSQL._failure_message)Nr%T) rrrrr/r3rFrrHrLr r r rr$Fs 53 r$c@s&eZdZd ddZddZdd ZdS) RegexSQLNr%FcCs2t|t||_||_||_||_||_dSr ) rrr+rDregex orig_regexrr&r')r rXrr&r'r r rrs   zRegexSQL.__init__cCs"d|jddt|ddfS)Nz{Testing for compiled statement ~%r partial params %s, received %%(received_statement)r with params %%(received_parameters)rrRrS)rYrTrUrVr r rrLs  zRegexSQL._failure_messagecCst|j|Sr )boolrXmatch)r r r.r r rr/szRegexSQL._compare_sql)Nr%F)rrrrrLr/r r r rrWs   rWcsDeZdZddZddZfddZddZd d Zd d ZZ S) DialectSQLcCs|jjSr )r@r&r r r rr3szDialectSQL._compile_dialectcCstdd|}||kSr()r+r,)r real_stmt received_stmtr"r r r_compare_no_space szDialectSQL._compare_no_spacecsFt|\}}|jD]}||j|rq:qtd|||jjfS)NzICan't locate compiled statement %r in list of statements actually invoked)superrFrr_rrr@Zcompiled_parameters)r r r^Zreceived_paramsr] __class__r rrFs zDialectSQL._received_statementcs|j}tdd|j}|dd}|dkr:tdd|}n`d}|dkrLd }n@|d krZd }n2|d rtd |dkrzdndfdd}td||}|dd}|S)Nr)r*z::z!!Zpyformatz :([\w_]+)z%(\1)sZqmark?formatz%snumericZnumeric_dollar$:cstSr )next)r<counterZnum_identifierr rrepl5sz4DialectSQL._dialect_adjusted_statement..repl) paramstyler+r,rrT startswith itertoolscount)r r&rmr"rlr rjr_dialect_adjusted_statement s"    z&DialectSQL._dialect_adjusted_statementcCs||jj}||kSr )rqr@r&r-r r rr/?szDialectSQL._compare_sqlcCs*d||jjddt|ddfSrQ)rqr@r&rTrUrVr r rrLEszDialectSQL._failure_message) rrrr3r_rFrqr/rL __classcell__r r rarr\s  r\c@s$eZdZddZddZddZdS)CountStatementscCs||_d|_dSNr)rp_statement_count)r rpr r rrTszCountStatements.__init__cCs|jd7_dS)Nrf)rur r r rrXsz!CountStatements.process_statementcCs(|j|jkr$ds$td|j|jfdS)NFz,desired statement count %d does not match %d)rprurrr r rr[s  z"CountStatements.no_more_statementsN)rrrrrrr r r rrsSsrsc@seZdZddZddZdS)AllOfcGst||_dSr )setrulesr rxr r rrdszAllOf.__init__cCsjt|jD]H}d|_|||jrB|j||js.connection_executeZafter_cursor_executecsj|sdSjr*jdj|kr*jd}n&t|ddd}j||jt||||dS)Nrrfr)rr@rappendrr)rcursorrr r@rZobsZasserterrr rcursor_executes"  z%assert_engine..cursor_execute)rrZ listens_forremover)enginerrr rr assert_engines   r) __future__r collections contextlibror+r*rrrZengine.defaultrZschemarrrrr$rWr\rsrvr~rrr namedtuplerrcontextmanagerrr r r r s<     (L