1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
U
¸ý°d6ã@s¬ddlmZddlZddlZddlZddlmZddlmZddlmZddlZddl    Z    ddl
m Z ddl m Z dd    l mZd
d l
mZd
d l
mZd
d l mZd
dlmZejrÖd
dlmZd
dlmZd
dlmZGdd„dƒZeƒZe dd„ƒZe dd„ƒZe dd„ƒZe dd„ƒZ d6dd„Z!Gdd„dƒZ"d7d d!„Z#ej$d8d#d$d%d&d'd(œd)d*„ƒZ%ej$d9d#d$d,d&d-d(œd.d*„ƒZ%d:d/d*„Z%d;d0d1„Z&Gd2d3„d3ƒZ'Gd4d5„d5ƒZ(dS)<é)Ú annotationsN)ÚAny)ÚDict)ÚOptionalé)Úconfig)Ú    decorator)Ú
gc_collecté)Úevent)Úpool)Ú
await_only)ÚLiteral)ÚEngine)ÚURL)Ú AsyncEnginec@s”eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd d„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#S)$ÚConnectionKillercCs"t ¡|_t t¡|_tƒ|_dS©N)ÚweakrefÚWeakKeyDictionaryÚ
proxy_refsÚ collectionsÚ defaultdictÚsetÚtesting_enginesÚdbapi_connections©Úself©rúQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/testing/engines.pyÚ__init__%s
 zConnectionKiller.__init__cCsDt |d|j¡t |d|j¡t |d|j¡t |d|j¡dS)NÚcheckoutZcheckinÚcloseZclose_detached)r ÚlistenÚ    _add_connÚ _remove_conn)rr rrrÚadd_pool*szConnectionKiller.add_poolcCs|j |¡d|j|<dS)NT)rÚaddr)rZ    dbapi_conZ
con_recordZ    con_proxyrrrr$2s zConnectionKiller._add_conncGs|j |¡dSr)rÚdiscard)rZ
dbapi_connÚargrrrr%6szConnectionKiller._remove_conncCs,| |j¡|dkst‚|j| |¡dS)N)ÚclassÚglobalÚfunctionZfixture)r&r ÚAssertionErrorrr')rÚengineÚscoperrrÚ
add_engine9s  zConnectionKiller.add_enginec
Cs@z
|ƒWn0tk
r:}zt d|¡W5d}~XYnXdS)Nz5testing_reaper couldn't rollback/close connection: %s©Ú    ExceptionÚwarningsÚwarn©rÚfnÚerrrÚ_safe?s 
ÿzConnectionKiller._safecCs.t|jƒD]}|dk    r
|jr
| |j¡q
dSr)ÚlistrÚis_validr8Úrollback©rÚrecrrrÚ rollback_allGszConnectionKiller.rollback_allcCs^t|jƒD],}|dk    r
|jr
|j |j¡| |j¡q
|jD]}| |j¡q>|j     ¡dSr)
r9rr:rr(Údbapi_connectionr8Ú_checkinr;Úclear)rr=ÚconrrrÚ checkin_allLs
zConnectionKiller.checkin_allcCs | ¡dSr)rCrrrrÚ    close_all[szConnectionKiller.close_allcCs*tjs
dSddlm}| |jj|¡dS©Nr)Ú    provision)rÚbootstrapped_as_sqlalchemyÚrFÚprepare_for_drop_tablesr.Úurl)rÚ
connectionrFrrrrI^s z(ConnectionKiller.prepare_for_drop_tablescCs„|j|}t|ƒD]d}t|jƒD]4}|dk    r |jr |jdk    r |j|jkr | |j¡q t|dƒrnt    | 
¡ƒq| 
¡q|  ¡dS)NÚ sync_engine) rr9rr:Ú_poolr r8r@Úhasattrr ÚdisposerA)rr/Zengr=Z    proxy_refrrrÚ_drop_testing_enginesgs
 ÿ
þ
 
z&ConnectionKiller._drop_testing_enginescCs| d¡dS)Nr,)rPrrrrÚ
after_testxszConnectionKiller.after_testc    CsTtjs
dS|jjrdS| ¡ddlm}tj ¡}|     |j
j |¡W5QRXdSrE) rrGÚ    __class__Z"__leave_connections_for_teardown__rCrHrFÚdbÚconnectrIr.rJ)rÚtestrFÚconnrrrÚafter_test_outside_fixtures{s  z,ConnectionKiller.after_test_outside_fixturescCs | ¡| d¡| d¡dS)Nr,r*)rCrPrrrrÚstop_test_class_inside_fixturess
z0ConnectionKiller.stop_test_class_inside_fixturescCsBtjjr>tƒtjjr>ttjjƒ}tjj ¡ds>td|ƒ‚dS)NFz/%d connection recs not cleared after test suite)r ÚbaseZ_strong_ref_connection_recordsr    ÚlenrAr-)rÚlnrrrÚ stop_test_class_outside_fixtures’s  ÿþz1ConnectionKiller.stop_test_class_outside_fixturescCs"| ¡|jD]}| |¡qdSr)rCrrP)rr/rrrÚ final_cleanupŸs
zConnectionKiller.final_cleanupcCs|jD]}|jrdst‚qdS©NF)rr:r-r<rrrÚassert_all_closed¤s
z"ConnectionKiller.assert_all_closedN)Ú__name__Ú
__module__Ú __qualname__r r&r$r%r0r8r>rCrDrIrPrQrWrXr\r]r_rrrrr$s"     rcOsz|||ŽW5t ¡XdSr)Útesting_reaperr_©r6ÚargsÚkwrrrÚassert_conns_closed­srgcOsz|||ŽW5t ¡XdS)zBDecorator that rolls back all open connections after fn execution.N)rcr>rdrrrÚrollback_open_connectionsµsrhcOst ¡|||ŽdS)z:Decorator that closes all connections before fn execution.N©rcrCrdrrrÚ close_first¿srjcOsz|||ŽW5t ¡XdS)z9Decorator that closes all connections after fn execution.NrirdrrrÚclose_open_connectionsÇsrkccsXddlm}|jD]@}|r$||kr$qt||dƒ}|sHttd|ƒj|ƒ}| ¡VqdS)Nrzsqlalchemy.dialects.%s)Zsqlalchemy.dialectsZdialectsÚ__all__ÚgetattrÚ
__import__Údialect)ÚexcludeÚdÚnameÚmodrrrÚ all_dialectsÐs 
   ÿrtc@s>eZdZdd„Zdd„Zdd„Zdd„Zdd
d „Zd d „ZdS)ÚReconnectFixturecCs||_g|_d|_dSr^)ÚdbapiÚ connectionsÚ
is_stopped)rrvrrrr àszReconnectFixture.__init__cCs t|j|ƒSr)rmrv©rÚkeyrrrÚ __getattr__åszReconnectFixture.__getattr__cOsT|jj||Ž}|jr@| |j¡| ¡}| d¡dsPtdƒ‚n|j     |¡|SdS)Nzselect 1Fz%simulated connect failure didn't work)
rvrTrxr8r"ÚcursorÚexecuter-rwÚappend)rreÚkwargsrVZcursrrrrTès 
 zReconnectFixture.connectc
Cs@z
|ƒWn0tk
r:}zt d|¡W5d}~XYnXdS)Nz.ReconnectFixture couldn't close connection: %sr1r5rrrr8ös
zReconnectFixture._safeFcCs,||_t|jƒD]}| |j¡qg|_dSr)rxr9rwr8r")rÚstopÚcrrrÚshutdownüszReconnectFixture.shutdowncCs
d|_dSr^)rxrrrrÚrestartszReconnectFixture.restartN)F)    r`rarbr r{rTr8r‚rƒrrrrrußs 
rucsj|p
tjj}tjjj}|si}t|ƒ|d<t||ƒ‰ˆj‰‡‡fdd„}ˆjjjˆ_    ˆjjj
ˆ_ |ˆ_ˆS)NÚmodulecs ˆjj ¡dˆjj_ˆƒdSr^)rorvr‚rxr©Z_disposer.rrrOs 
z$reconnecting_engine.<locals>.dispose) rrSrJrorvruÚtesting_enginerOr‚Z test_shutdownrƒZ test_restart)rJÚoptionsrvrOrr…rÚreconnecting_engine s 
 
  rˆFz Optional[URL]zOptional[Dict[str, Any]]zLiteral[False]Úboolr)rJr‡ÚasyncioÚtransfer_staticpoolÚreturncCsdSrr©rJr‡rŠr‹rrrr†sr†Tz Literal[True]rcCsdSrrrrrrr†)scCsÊ|r|r t‚ddlm}n ddlm}ddlm}|sDd}d}    d}
n$| dd¡}| d    d¡}    | d
d¡}
|prtj    j
}||ƒ}|dkr¬tj    dksž|j tj    j
j kr¦tj }qÚi}n.tj    dk    rÚ|j tj    j
j krÚtj   ¡} |  |¡||f|Ž} |
r | jd kr t | d ¡d d„ƒ} t | d¡dd„ƒ}|rdddlm}tj    dk    rtttj    j|ƒrtd}| j tj    j¡n|rttj    j| _|    dkr”|rŽd| j_nd| _t| jtjƒr´d| j_d| j_|rÆt | |    ¡| S)Nr)Úcreate_async_engine)Ú create_engine)Úmake_urlTr,FÚ
use_reaperr/Úsqlite_savepointZsqliterTcSs
d|_dSr)Zisolation_level)r?Zconnection_recordrrrÚ
do_connect]sz"testing_engine.<locals>.do_connectÚbegincSs| d¡dS)NZBEGIN)Zexec_driver_sql)rVrrrÚdo_beginasz testing_engine.<locals>.do_begin)Ú
StaticPoolr+)r-Zsqlalchemy.ext.asynciorŽÚ
sqlalchemyrZsqlalchemy.engine.urlrÚpoprrSrJZ
drivernameZdb_optsÚcopyÚupdaterrr Z listens_forZsqlalchemy.poolr–Ú
isinstancer Z_transfer_fromrLZ _has_eventsZ    QueuePoolÚ_timeoutZ _max_overflowrcr0)rJr‡rŠr‹Z
share_poolZ_sqlite_savepointrrr‘r/r’Z default_optr.r“r•r–rrrr†3sZ      
 
 
 
 
 
 
 
 
ÿ csrddlm}|stjj}g‰‡fdd„}‡fdd„}‡fdd„}||d    |ƒ‰tˆd
ƒr\t‚ˆˆ_|ˆ_|ˆ_    ˆS) a'Provides a mocking engine based on the current testing.db.
 
    This is normally used to test DDL generation flow as emitted
    by an Engine.
 
    It should not be used in other cases, as assert_compile() and
    assert_sql_execution() are much better choices with fewer
    moving parts.
 
    r)Úcreate_mock_enginecsˆ |¡dSr)r~)ZsqlÚarf©ÚbufferrrÚexecutor’szmock_engine.<locals>.executorcs"dd„ˆDƒ}||kst|ƒ‚dS)NcSsg|]}t ddt|ƒ¡‘qS)z[\n\t]rH)ÚreÚsubÚstr©Ú.0ÚsrrrÚ
<listcomp>–sz3mock_engine.<locals>.assert_sql.<locals>.<listcomp>)r-)ZstmtsÚrecvrŸrrÚ
assert_sql•szmock_engine.<locals>.assert_sqlcs ˆj‰d ‡fdd„ˆjDƒ¡S)NÚ
c3s|]}t|jˆdƒVqdS))roN)r¤Úcompiler¥©rqrrÚ    <genexpr>›sz1mock_engine.<locals>.print_sql.<locals>.<genexpr>)roÚjoinÚmockr)r.r­rÚ    print_sql™szmock_engine.<locals>.print_sqlz://r°)
r—rrrSrrrNr-r°rªr±)Z dialect_namerr¡rªr±r)r r.rÚ mock_engines    r²c@s:eZdZdZdd„Zd dd„Zdd„Zd    d
„Zd d „ZdS)ÚDBAPIProxyCursorzuProxy a DBAPI cursor.
 
    Tests can provide subclasses of this to intercept
    DBAPI-level cursor operations.
 
    cOs||_||_|j||Ž|_dSr)r.rKr|)rr.rVrerrrrr ­szDBAPIProxyCursor.__init__NcKs*|r|jj||f|ŽS|jj|f|ŽSdSr)r|r})rÚstmtÚ
parametersrfrrrr}²szDBAPIProxyCursor.executecKs|jj||f|ŽSr)r|Ú executemany)rr´Úparamsrfrrrr¶¸szDBAPIProxyCursor.executemanycCs
t|jƒSr)Úiterr|rrrrÚ__iter__»szDBAPIProxyCursor.__iter__cCs t|j|ƒSr)rmr|ryrrrr{¾szDBAPIProxyCursor.__getattr__)N)    r`rarbÚ__doc__r r}r¶r¹r{rrrrr³¥s 
r³c@s0eZdZdZdd„Zdd„Zdd„Zdd    „Zd
S) ÚDBAPIProxyConnectionz}Proxy a DBAPI connection.
 
    Tests can provide subclasses of this to intercept
    DBAPI-level connection operations.
 
    cCs||_||_||_dSr)rVr.Ú
cursor_cls)rr.rVr¼rrrr ÊszDBAPIProxyConnection.__init__cOs|j|j|jf|ž|ŽSr)r¼r.rV)rrerrrrr|ÏszDBAPIProxyConnection.cursorcCs|j ¡dSr)rVr"rrrrr"ÒszDBAPIProxyConnection.closecCs t|j|ƒSr)rmrVryrrrr{Õsz DBAPIProxyConnection.__getattr__N)r`rarbrºr r|r"r{rrrrr»Âs
r»)N)NN)NNFF)NNTF)NNFFFF)N))Ú
__future__rrr¢Útypingrrrr3rrHrÚutilrr    r r r Z util.typingrÚ TYPE_CHECKINGr.rZ
engine.urlrZ ext.asynciorrrcrgrhrjrkrtrurˆÚoverloadr†r²r³r»rrrrÚ<module>
sn              
 
    
 
 
,
ü    ü
ú
L
&