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
133
134
135
136
137
138
139
140
U
¸ý°d`9ã@s ddlmZddlmZddlZddlZddlmZddlZddl    Z    ddl    m
Z
ddl Z ddl m Z ddl mZd    d
l mZd    d lmZd    d lmZd    d lmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlmZd    dlm Z es0dd„Z!e!Z"Z#nej$Z"dd„Z#dd„Z%dJdd„Z&d d!„Z'Gd"d#„d#e(ƒZ)d$d%„Z*d&d'„Z+d(d)„Z,d*d+„Z-d,d-„Z.d.d/„Z/ed0d1„ƒZ0d2d3„Z1d4d5„Z2d6d7„Z3dKd9d:„Z4d;d<„Z5Gd=d>„d>e6ƒZ7d?d@„Z8dLdBdC„Z9dDdE„Z:dFdG„Z;dHdI„Z<dS)Mé)Ú annotations)ÚdequeN)Úchain)Ú    getsizeofé)Úconfig)Úmocké)Úinspect)Ú
Connection)ÚColumn)ÚDropConstraint)Ú    DropTable)ÚForeignKeyConstraint)ÚMetaData)ÚTable©Úschema)ÚInteger©Ú    decorator)Ú defaultdict)Úhas_refcount_gc)Úinspect_getfullargspeccGst ¡t ¡dS©N)ÚgcÚcollect)Úargs©rúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/testing/util.pyÚnon_refcount_gc_collect)sr cCsdSrrrrrrÚlazy_gc2sr!c#sRtƒ}ddl}| |¡|D]0‰td|jdƒD]‰ˆj‡‡fdd„fVq0qdS)Nréþÿÿÿrcs ˆ |ˆ¡Sr)Údumps©Úd©Zpickle_ÚprotocolrrÚ<lambda>?ózpicklers.<locals>.<lambda>)ÚsetÚpickleÚaddÚrangeÚHIGHEST_PROTOCOLÚloads)Úpicklersr+rr&rr06s 
r0cCstj||dS)N)Úk)ÚrandomÚchoices)Ú
populationr1rrrÚrandom_choicesBsr5cCs<t|tƒrt||ƒS|t dd|¡ tj¡td|ƒS)NÚ1Ú0é
)Ú
isinstanceÚfloatÚroundÚdecimalÚDecimalÚ to_integralÚ ROUND_FLOORÚpow)ÚvalueÚprecrrrÚ round_decimalFs
 
ÿþrCc@s<eZdZdd„Zdd„Zdd„Zdd„Zd    d
„Zd d „Zd S)Ú    RandomSetcCs tt |¡ƒ}t |¡t|ƒSr)Úlistr*Ú__iter__r2ÚshuffleÚiter)ÚselfÚlrrrrFQs
zRandomSet.__iter__cCs4t dt|ƒd¡}tt |¡ƒ|}| |¡|S)Nrr)r2ÚrandintÚlenrEr*rFÚremove)rIÚindexÚitemrrrÚpopVs
z RandomSet.popcCstt ||¡ƒSr)rDr*Úunion©rIÚotherrrrrQ\szRandomSet.unioncCstt ||¡ƒSr)rDr*Ú
differencerRrrrrT_szRandomSet.differencecCstt ||¡ƒSr)rDr*Ú intersectionrRrrrrUbszRandomSet.intersectioncCst|ƒSr)rD©rIrrrÚcopyeszRandomSet.copyN)    Ú__name__Ú
__module__Ú __qualname__rFrPrQrTrUrWrrrrrDPs rDcCs`ttƒ}|D]\}}|| |¡q t|ƒD].\}}||d…D]}|||kr@dSq@q,dS)zATrue if the given sorting conforms to the given partial ordering.NFT)rr*r,Ú    enumerate)ÚtuplesZsorted_elementsÚdepsÚparentÚchildÚiÚnodeÚnrrrÚconforms_partial_orderingis   rccs>ttƒ‰|D]\}}ˆ| |¡q ‡‡fdd„‰tˆ|ƒƒS)Nc3s^t|ƒdkrt|ƒVnB|D]<}t|ƒ |g¡}| ˆ|¡sˆ|ƒD]}|g|VqFqdS)Nr)rLrEr*rTrU)ÚelementsÚelemZsubsetZ sub_ordering©Ú_all_orderingsÚedgesrrrg|s   z-all_partial_orderings.<locals>._all_orderings)rr*r,rH)r\rdr^r_rrfrÚall_partial_orderingsws
  ric
Cs>z
||_Wn.tk
r8t |j|j||j|j¡}YnX|S)acReturn a function with a given __name__.
 
    Will assign to __name__ and return the original function if possible on
    the Python implementation, otherwise a new function will be constructed.
 
    This function should be phased out as much as possible
    in favor of @decorator.   Tests that "generate" many named tests
    should be modernized.
 
    )rXÚ    TypeErrorÚtypesÚ FunctionTypeÚ__code__Ú __globals__Ú __defaults__Ú __closure__)ÚfnÚnamerrrÚfunction_namedŠs 
ÿ
rscOs`| ¡}z$||f|ž|Ž}| ddd¡|WSt ¡}|j|Ž}|sN‚n|YSYnXdS)aRun the given function under the given contextmanager,
    simulating the behavior of 'with' to support older
    Python versions.
 
    This is not necessary anymore as we have placed 2.6
    as minimum Python version, however some tests are still using
    this structure.
 
    N)Ú    __enter__Ú__exit__ÚsysÚexc_info)ÚctxrqÚargÚkwÚobjÚresultrwZraise_rrrÚrun_as_contextmanageržs 
r}cCsdd„|DƒS)zŠConverts the results of sql execution into a plain set of column tuples.
 
    Useful for asserting the results of an unordered query.
    cSsh|] }t|ƒ’qSr©Útuple)Ú.0ÚrowrrrÚ    <setcomp>½szrowset.<locals>.<setcomp>r)ÚresultsrrrÚrowset·sr„cCsds t|ƒ‚dS)NF)ÚAssertionError)ÚmsgrrrÚfailÀsr‡c    Os€ddlm}t ¡}|d}t|ddƒ}||_z|||ŽW¢S| ¡|jrht||jƒ|j     ¡ 
¡n t|t j ƒ||_XdS)ztProvide bound MetaData for a single test, dropping afterwards.
 
    Legacy; use the "metadata" pytest fixture.
 
    r)ÚfixturesrÚmetadataN) ÚrˆrrÚgetattrr‰Z_close_all_sessionsZ_connection_fixture_connectionÚdrop_all_tables_from_metadataZget_transactionÚcommitrÚdb)rqrrzrˆr‰rIZ    prev_metarrrÚprovide_metadataÄs       ÿ rcsTtƒ‰|D]}ˆ |¡q
tˆƒ‰tj‡fdd„|Dƒddtˆƒd ˆ¡dœŽS)a A facade around @testing.combinations() oriented towards boolean
    keyword-based arguments.
 
    Basically generates a nice looking identifier based on the keywords
    and also sets up the argument names.
 
    E.g.::
 
        @testing.flag_combinations(
            dict(lazy=False, passive=False),
            dict(lazy=True, passive=False),
            dict(lazy=False, passive=True),
            dict(lazy=False, passive=True, raiseload=True),
        )
 
 
    would result in::
 
        @testing.combinations(
            ('', False, False, False),
            ('lazy', True, False, False),
            ('lazy_passive', True, True, False),
            ('lazy_passive', True, True, True),
            id_='iaaa',
            argnames='lazy,passive,raiseload'
        )
 
    cs<g|]4‰d ‡fdd„ˆDƒ¡ft‡fdd„ˆDƒƒ‘qS)Ú_c3s|]}ˆ |d¡r|VqdS©FN©Úget©r€r1r$rrÚ    <genexpr>s z/flag_combinations.<locals>.<listcomp>.<genexpr>c3s|]}ˆ |d¡VqdSr‘r’r”r$rrr•s)Újoinr)r€©Úkeysr$rÚ
<listcomp>sþÿz%flag_combinations.<locals>.<listcomp>r`Úaú,)Zid_Úargnames)r*ÚupdateÚsortedrÚ combinationsrLr–)rŸr%rr—rÚflag_combinationsñs 
ýùr c sLtˆƒ}ˆdd„|dDƒŽ}‡fdd„‰tj‡fdd„tt|ƒƒDƒ|ŽS)NcSsg|] }t ¡‘qSr)rZMock©r€ryrrrr™$sz'lambda_combinations.<locals>.<listcomp>rcs‡‡fdd„}dˆ|_|S)Ncsˆf|ŽˆSrr©rz)Úlambda_arg_setsÚposrrÚfixture'sz<lambda_combinations.<locals>.create_fixture.<locals>.fixturez fixture_%3.3d)rX)r¤r¥)r£)r¤rÚcreate_fixture&s
z+lambda_combinations.<locals>.create_fixturecsg|]}ˆ|ƒf‘qSrr)r€r`)r¦rrr™.s)rrrŸr-rL)r£rzrZarg_setsr)r¦r£rÚlambda_combinations!s ÿr§c sJt|ƒd}‡fdd„|Dƒ}t|jƒ}| ˆ¡t |j|¡}|f|ŽS)zÝGiven a no-arg lambda and a namespace, return a new lambda that
    has all the values filled in.
 
    This is used so that we can have module-level fixtures that
    refer to instance-level variables using lambdas.
 
    rcsi|]}|ˆ |¡“qSr)rPr¡r¢rrÚ
<dictcomp><sz"resolve_lambda.<locals>.<dictcomp>)rÚdictrnrrkrlrm)Z__fnrzZpos_argsZ pass_pos_argsZglbZnew_fnrr¢rÚresolve_lambda2s      
 
rªÚfunctioncs‡fdd„}|S)z&Provide MetaData for a pytest fixture.cs‡fdd„}tjˆd|ƒS)Nc    3sBt ¡}|_z ˆ||ƒ}| tj¡|VW5| tj¡XdSr)rrr‰Údrop_allrrŽZ
create_all)rIr‰r|©rqrrÚrun_ddlGs 
 
z3metadata_fixture.<locals>.decorate.<locals>.run_ddl)Zscope)rr¥)rqr®©Úddlr­rÚdecorateFs z"metadata_fixture.<locals>.decorater)r°r±rr¯rÚmetadata_fixtureCs r²cst‡fdd„ƒ}|S)ziForce the given table names to be dropped after test complete,
    isolating for foreign key cycles
 
    c s,z|||ŽW¢SttjttjƒˆdXdS)N)Ú include_names)Údrop_all_tablesrrŽr
)rqrrz©ÚnamesrrÚgo^szforce_drop_names.<locals>.gor)r¶r·rrµrÚforce_drop_namesXsr¸c@s$eZdZdZdd„Zdd„ZeZdS)Úadictz,Dict keys available as attributes.  Shadows.cCs0z
||WStk
r*t ||¡YSXdSr)ÚKeyErrorr©Ú__getattribute__)rIÚkeyrrrr»ls
zadict.__getattribute__cst‡fdd„|DƒƒS)Ncsg|] }ˆ|‘qSrr)r€r¼rVrrr™ssz"adict.__call__.<locals>.<listcomp>r~)rIr˜rrVrÚ__call__rszadict.__call__N)rXrYrZÚ__doc__r»r½Úget_allrrrrr¹isr¹c    sNddlm‰‡‡fdd„}t|tƒsB| ¡}||ƒW5QRXn||ƒdS)Nr)Úenginesc    sTˆj |¡|jjsFddlm}|jdddˆ |¡W5QRXn
ˆ |¡dS)Nr)Ú
assertionszCan't sort tablesF)Zassert_)Ztesting_reaperZprepare_for_drop_tablesÚdialectÚsupports_alterrŠrÁZexpect_warningsr¬)Ú
connectionrÁ©rÀr‰rrr·{s  ÿz)drop_all_tables_from_metadata.<locals>.go)rŠrÀr9r Úbegin)r‰Zengine_or_connectionr·rÄrrÅrrŒxs  
 
rŒrc Cs|dk    rt|ƒ}|dk    r.|dks(tdƒ‚|f}| ¡Ü}t|j|dƒD]Ä\}}|rŽ|dk    rj|d|krjqH| tt|dtƒ|ddƒ¡qH|rH|j    j
sœqH|D]j\}}    |dk    r¾|d|kr¾q t|dtƒt dt ƒt dt ƒ|dd}
| t t|
jjg|
jjg|    d    ƒ¡q qHW5QRXdS)
Nrz2consider_schemas and schema are mutually exclusive)Úconsider_schemasrrrÚxÚy)rr)r*r…rÆÚreversedZ%sort_tables_on_foreign_key_dependencyÚexecuterrrrÂrÃr rr rÚcrÈrÉ) ÚengineZ    inspectorrrÇr³ÚconnZ    table_keyZfkcsZt_keyZfkcÚtbrrrr´sZ
þ
ÿÿ ÿ
þÿÿ ÿ
þûÿÿr´cst‡fdd„ƒ}|S)Ncsz|||ŽW¢Sˆ ¡XdSr)Ú_clear)rqryrz©Ú    event_clsrrr±Ész!teardown_events.<locals>.decorater)rÒr±rrÑrÚteardown_eventsÈsrÓc sLdd„}ttttttt|tttti‰tƒ‰tdƒ‰‡‡‡‡fdd„‰ˆ|ƒS)zReturns the approximate memory footprint an object and all of its
    contents.
 
    source: https://code.activestate.com/recipes/577504/
 
 
    cSst | ¡¡Sr)rÚ from_iterableÚitemsr$rrrÚ dict_handlerÜsz total_size.<locals>.dict_handlerrcsbt|ƒˆkrdSˆ t|ƒ¡t|ˆƒ}ˆ ¡D],\}}t||ƒr0|ttˆ||ƒƒƒ7}q^q0|S)Nr)Úidr,rrÕr9ÚsumÚmap)ÚoÚsÚtypÚhandler©Z all_handlersZ default_sizeÚseenÚsizeofrrràês 
 
ztotal_size.<locals>.sizeof)rrHrErr©r*Ú    frozensetr)rÚrÖrrÞrÚ
total_sizeÓs$    ú râcCsV|g}tƒ}d}|rR| d¡}||kr0|d7}qt|tƒr|rt|ƒ|g|}q|S)zgiven a cache key tuple, counts how many instances of actual
    tuples are found.
 
    used to alert large jumps in cache key complexity.
 
    rr)ÚobjectrPr9rrE)ÚtupÚstackÚsentinelZ num_elementsrerrrÚcount_cache_key_tuplesùs
 
 
rç)r)r«)NrN)=Ú
__future__rÚ collectionsrr<rÚ    itertoolsrr2rvrrkrŠrrr
rÍr rr r rrrrZsqlZ sql.sqltypesrÚutilrrrrr Z
gc_collectr!rr0r5rCr*rDrcrirsr}r„r‡rr r§rªr²r¸r©r¹rŒr´rÓrârçrrrrÚ<module>
sn                    
 
 
    
,0
û
9 &