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
U
¸ý°dî(ã@sÎdZddlmZddlZddlZddlZddlZddlZddlZddl    Z    ddl
m Z ddl m Z ddl mZz ddlZWnek
rdZYnXdZdad    d
„ZGd d „d ƒZddd„Zejddd„ƒZdS)z§Profiling support for unit and performance tests.
 
These are special purpose profiling methods which operate
in a more fine-grained way than nose's profiling plugin.
 
é)Ú annotationsNé)Úconfig)Ú
gc_collecté)Úhas_compiled_extcCs|atjrt ¡dS©N)Ú _current_testÚ_profile_statsÚ force_writeÚ reset_count)Zid_©r úSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/testing/profiling.pyÚ_start_current_test6src@s^eZdZdZddd„Zedd„ƒZdd    „Zd
d „Zd d „Z    dd„Z
dd„Z dd„Z dd„Z dS)ÚProfileStatsFilezøStore per-platform/fn profiling results in a file.
 
    There was no json module available when this was written, but now
    the file format which is very deterministically line oriented is kind of
    handy in any case for diffs and merges.
 
    Ú
cumulativeNcCs†tjdk    otjj|_|jp*tjdk    o*tjj|_tj |¡|_    tj 
|j    ¡d|_ t   dd„¡|_||_||_| ¡|jr‚| ¡dS)NéÿÿÿÿcSs
t t¡Sr)Ú collectionsÚ defaultdictÚdictr r r rÚ<lambda>Qóz+ProfileStatsFile.__init__.<locals>.<lambda>)rÚoptionsZforce_write_profilesr Zwrite_profilesÚwriteÚosÚpathÚabspathÚfnameÚsplitÚ short_fnamerrÚdataÚdumpÚsortÚ_readÚ_write)ÚselfÚfilenamer"r!r r rÚ__init__GsÿÿÿzProfileStatsFile.__init__cCs¦tjjdtjj}tjjdkr:tjj tjj¡r:|d7}d dd„tj    dd…Dƒ¡}t
  ¡t
  ¡  ¡t
 ¡  ¡||g}| d    ¡tƒ}| |r–d
p˜d ¡d |¡S) NÚ_ZsqliteÚ_fileÚ.cSsg|] }t|ƒ‘qSr ©Ústr)Ú.0Úvr r rÚ
<listcomp>fsz1ProfileStatsFile.platform_key.<locals>.<listcomp>rrZ dbapiunicodeZ cextensionsZ nocextensions)rÚdbÚnameZdriverÚdialectZ_is_url_file_dbÚurlÚjoinÚsysÚ version_infoÚplatformÚmachineÚsystemÚlowerÚpython_implementationÚappendr)r%Z    dbapi_keyÚ
py_versionZplatform_tokensZ    _has_cextr r rÚ platform_key[s ÿ
 
û
zProfileStatsFile.platform_keycCst}||jko|j|j|kSr©r    r r>)r%Útest_keyr r rÚ    has_statsusÿzProfileStatsFile.has_statsc    Cs¦t}|j|}||j}d|kr.g|d<}n|d}d|krLd|d<}n|d}t|ƒ|k}|s‚| |¡|jr|| ¡d}n|d||f}|dd7<|S)NÚcountsÚ current_countrÚlinenor)r    r r>Úlenr<rr$)    r%Ú    callcountr@Úper_fnÚ per_platformrBrCZ    has_countÚresultr r rrI{s$
 
 
zProfileStatsFile.resultcCsPt}||jkrdS|j|}|j|kr*dS||j}d|krLg|ddd…<dS)NrBr?)r%r@rGrHr r rr –s
 
 
 
zProfileStatsFile.reset_countcCs\t}|j|}||j}|d}|d}|t|ƒkrB|||d<n||d<|jrX| ¡dS)NrBrCrr)r    r r>rErr$)r%rFr@rGrHrBrCr r rÚreplace£s
 
 zProfileStatsFile.replacecCs
d|jS)Na # %s
# This file is written out on a per-environment basis.
# For each test in aaa_profiling, the corresponding function and 
# environment is located within this file.  If it doesn't exist,
# the test is skipped.
# If a callcount does exist, it is compared to what we received. 
# assertions are raised if the counts do not match.
# To add a new callcount test, apply the function_call_count 
# decorator and re-run the tests using the --write-profiles 
# option - this file will be rewritten including the new count.
)r)r%r r rÚ_header°sðzProfileStatsFile._headerc
Cs¬zt|jƒ}Wntk
r$YdSXt|ƒD]p\}}| ¡}|r.| d¡rNq.| ¡\}}}|j|}||}dd„| d¡Dƒ}    |    |d<|d|d<d|d    <q.| ¡dS)
Nú#cSsg|] }t|ƒ‘qSr )Úint©r-Úcountr r rr/Ðsz*ProfileStatsFile._read.<locals>.<listcomp>ú,rBrrDrrC)    ÚopenrÚOSErrorÚ    enumerateÚstripÚ
startswithrr Úclose)
r%Ú    profile_frDÚliner@r>rBrGrHÚcr r rr#Ãs 
 
zProfileStatsFile._readcCsžtd|jƒt|jdƒ}| | ¡¡t|jƒD]^}|j|}| d|¡t|ƒD]8}||}d dd„|dDƒ¡}| d|||f¡qVq2| ¡dS)    NzWriting profile file %sÚwz
# TEST: %s
 
rPcss|]}t|ƒVqdSrr+rNr r rÚ    <genexpr>àsz*ProfileStatsFile._write.<locals>.<genexpr>rBz    %s %s %s
)    ÚprintrrQrrKÚsortedr r4rV)r%rWr@rGr>rHrYr r rr$Ös 
 zProfileStatsFile._write)rN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r'Úpropertyr>rArIr rJrKr#r$r r r rr>s
 
  r皙™™™™©?cs$ddlm}|‡‡‡fdd„ƒ}|S)a©Assert a target for a test case's function call count.
 
    The main purpose of this assertion is to detect changes in
    callcounts for various functions - the actual number is not as important.
    Callcounts are stored in a file keyed to Python version and OS platform
    information.  This file is generated automatically for new tests,
    and versioned so that unexpected changes in callcounts will be detected.
 
    r)Ú    decoratorc
sZtˆƒD]}|||Žqtˆƒ}tˆd&|D]}|||Ž}q0|W5QR£SQRXdS)N)Úvariance)ÚrangeÚcount_functions)ÚfnÚargsÚkwZwarmZ    timerangeÚtimeÚrv©ÚtimesreÚwarmupr rÚwrapös    z!function_call_count.<locals>.wrap)Zsqlalchemy.utilrd)rernrordrpr rmrÚfunction_call_countås  rqc csttdkrt d¡‚t ¡s0tjs0t dtj¡tƒt     ¡}| 
¡dV|  ¡t j |tjd}|j}t |¡}|dkr‚d}n|\}}td||fƒ|jt dtj¡Ž| ¡tjrtj tj¡\}}t d¡d}    d||    |pêd    f}
| |
¡td
|
ƒtjrt |¡nV|rpt ||ƒ} t!||ƒ| k} | rptjrVt |¡nt"d ||d |tj#fƒ‚dS) NzcProfile is not installedzŒNo profiling stats available on this platform for this function.  Run tests with --write-profiles to add statistics to %s for this platform.)ÚstreamzPstats calls: %d Expected %sz[, ]r*rz%s_%s%sz.profilezDumped stats to file %sz†Adjusted function call count %s not within %s%% of expected %s, platform %s. Rerun with --write-profiles to regenerate this callcount.éd)$ÚcProfilerZ_skip_test_exceptionr
rArZ    skip_testrrZProfileÚenableÚdisableÚpstatsZStatsr5ÚstdoutZ total_callsrIr\Z
sort_statsÚrerr"Z print_statsr!rrÚsplitextr    Z
dump_statsr rJrMÚabsÚAssertionErrorr>) reÚprÚstatsrFÚexpectedZexpected_countÚline_noÚbaseÚextZ    test_nameZdumpfileZdevianceÚfailedr r rrgsZ
ýÿ
 
    üüÿrg)rcrr)rc)raÚ
__future__rrÚ
contextlibrr7rwryr5ÚrÚutilrrrtÚ ImportErrorr
r    rrrqÚcontextmanagerrgr r r rÚ<module>
s.     
    (