ยปCore Development>Code coverage>Lib/test/profilee.py

Python code coverage for Lib/test/profilee.py

#countcontent
1n/a"""
2n/aInput for test_profile.py and test_cprofile.py.
3n/a
4n/aIMPORTANT: This stuff is touchy. If you modify anything above the
5n/atest class you'll have to regenerate the stats by running the two
6n/atest files.
7n/a
8n/a*ALL* NUMBERS in the expected output are relevant. If you change
9n/athe formatting of pstats, please don't just regenerate the expected
10n/aoutput without checking very carefully that not a single number has
11n/achanged.
12n/a"""
13n/a
14n/aimport sys
15n/a
16n/a# In order to have reproducible time, we simulate a timer in the global
17n/a# variable 'TICKS', which represents simulated time in milliseconds.
18n/a# (We can't use a helper function increment the timer since it would be
19n/a# included in the profile and would appear to consume all the time.)
20n/aTICKS = 42000
21n/a
23n/a return TICKS
24n/a
26n/a # 1 call
27n/a # 1000 ticks total: 270 ticks local, 730 ticks in subfunctions
28n/a global TICKS
29n/a TICKS += 99
30n/a helper() # 300
31n/a helper() # 300
32n/a TICKS += 171
33n/a factorial(14) # 130
34n/a
36n/a # 23 calls total
37n/a # 170 ticks total, 150 ticks local
38n/a # 3 primitive calls, 130, 20 and 20 ticks total
39n/a # including 116, 17, 17 ticks local
40n/a global TICKS
41n/a if n > 0:
42n/a TICKS += n
43n/a return mul(n, factorial(n-1))
44n/a else:
45n/a TICKS += 11
46n/a return 1
47n/a
49n/a # 20 calls
50n/a # 1 tick, local
51n/a global TICKS
52n/a TICKS += 1
53n/a return a * b
54n/a
56n/a # 2 calls
57n/a # 300 ticks total: 20 ticks local, 260 ticks in subfunctions
58n/a global TICKS
59n/a TICKS += 1
60n/a helper1() # 30
61n/a TICKS += 2
62n/a helper1() # 30
63n/a TICKS += 6
64n/a helper2() # 50
65n/a TICKS += 3
66n/a helper2() # 50
67n/a TICKS += 2
68n/a helper2() # 50
69n/a TICKS += 5
70n/a helper2_indirect() # 70
71n/a TICKS += 1
72n/a
74n/a # 4 calls
75n/a # 30 ticks total: 29 ticks local, 1 tick in subfunctions
76n/a global TICKS
77n/a TICKS += 10
78n/a hasattr(C(), "foo") # 1
79n/a TICKS += 19
80n/a lst = []
81n/a lst.append(42) # 0
82n/a sys.exc_info() # 0
83n/a
85n/a helper2() # 50
86n/a factorial(3) # 20
87n/a
89n/a # 8 calls
90n/a # 50 ticks local: 39 ticks local, 11 ticks in subfunctions
91n/a global TICKS
92n/a TICKS += 11
93n/a hasattr(C(), "bar") # 1
94n/a TICKS += 13
95n/a subhelper() # 10
96n/a TICKS += 15
97n/a
99n/a # 8 calls
100n/a # 10 ticks total: 8 ticks local, 2 ticks in subfunctions
101n/a global TICKS
102n/a TICKS += 2
103n/a for i in range(2): # 0
104n/a try:
105n/a C().foo # 1 x 2
106n/a except AttributeError:
107n/a TICKS += 3 # 3 x 2
108n/a
109n/aclass C:
110n/a def __getattr__(self, name):
111n/a # 28 calls
112n/a # 1 tick, local
113n/a global TICKS
114n/a TICKS += 1
115n/a raise AttributeError