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

Python code coverage for Lib/test/test_cprofile.py

#countcontent
1n/a"""Test suite for the cProfile module."""
2n/a
3n/aimport sys
4n/afrom test.support import run_unittest, TESTFN, unlink
5n/a
6n/a# rip off all interesting stuff from test_profile
7n/aimport cProfile
8n/afrom test.test_profile import ProfileTest, regenerate_expected_output
9n/a
10n/a
11n/aclass CProfileTest(ProfileTest):
12n/a profilerclass = cProfile.Profile
13n/a profilermodule = cProfile
14n/a expected_max_output = "{built-in method builtins.max}"
15n/a
16n/a def get_expected_output(self):
17n/a return _ProfileOutput
18n/a
19n/a # Issue 3895.
20n/a def test_bad_counter_during_dealloc(self):
21n/a import _lsprof
22n/a # Must use a file as StringIO doesn't trigger the bug.
23n/a orig_stderr = sys.stderr
24n/a try:
25n/a with open(TESTFN, 'w') as file:
26n/a sys.stderr = file
27n/a try:
28n/a obj = _lsprof.Profiler(lambda: int)
29n/a obj.enable()
30n/a obj = _lsprof.Profiler(1)
31n/a obj.disable()
32n/a obj.clear()
33n/a finally:
34n/a sys.stderr = orig_stderr
35n/a finally:
36n/a unlink(TESTFN)
37n/a
38n/a
39n/adef test_main():
40n/a run_unittest(CProfileTest)
41n/a
42n/adef main():
43n/a if '-r' not in sys.argv:
44n/a test_main()
45n/a else:
46n/a regenerate_expected_output(__file__, CProfileTest)
47n/a
48n/a
49n/a# Don't remove this comment. Everything below it is auto-generated.
50n/a#--cut--------------------------------------------------------------------------
51n/a_ProfileOutput = {}
52n/a_ProfileOutput['print_stats'] = """\
53n/a 28 0.028 0.001 0.028 0.001 profilee.py:110(__getattr__)
54n/a 1 0.270 0.270 1.000 1.000 profilee.py:25(testfunc)
55n/a 23/3 0.150 0.007 0.170 0.057 profilee.py:35(factorial)
56n/a 20 0.020 0.001 0.020 0.001 profilee.py:48(mul)
57n/a 2 0.040 0.020 0.600 0.300 profilee.py:55(helper)
58n/a 4 0.116 0.029 0.120 0.030 profilee.py:73(helper1)
59n/a 2 0.000 0.000 0.140 0.070 profilee.py:84(helper2_indirect)
60n/a 8 0.312 0.039 0.400 0.050 profilee.py:88(helper2)
61n/a 8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)"""
62n/a_ProfileOutput['print_callers'] = """\
63n/aprofilee.py:110(__getattr__) <- 16 0.016 0.016 profilee.py:98(subhelper)
64n/aprofilee.py:25(testfunc) <- 1 0.270 1.000 <string>:1(<module>)
65n/aprofilee.py:35(factorial) <- 1 0.014 0.130 profilee.py:25(testfunc)
66n/a 20/3 0.130 0.147 profilee.py:35(factorial)
67n/a 2 0.006 0.040 profilee.py:84(helper2_indirect)
68n/aprofilee.py:48(mul) <- 20 0.020 0.020 profilee.py:35(factorial)
69n/aprofilee.py:55(helper) <- 2 0.040 0.600 profilee.py:25(testfunc)
70n/aprofilee.py:73(helper1) <- 4 0.116 0.120 profilee.py:55(helper)
71n/aprofilee.py:84(helper2_indirect) <- 2 0.000 0.140 profilee.py:55(helper)
72n/aprofilee.py:88(helper2) <- 6 0.234 0.300 profilee.py:55(helper)
73n/a 2 0.078 0.100 profilee.py:84(helper2_indirect)
74n/aprofilee.py:98(subhelper) <- 8 0.064 0.080 profilee.py:88(helper2)
75n/a{built-in method builtins.hasattr} <- 4 0.000 0.004 profilee.py:73(helper1)
76n/a 8 0.000 0.008 profilee.py:88(helper2)
77n/a{built-in method sys.exc_info} <- 4 0.000 0.000 profilee.py:73(helper1)
78n/a{method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)"""
79n/a_ProfileOutput['print_callees'] = """\
80n/a<string>:1(<module>) -> 1 0.270 1.000 profilee.py:25(testfunc)
81n/aprofilee.py:110(__getattr__) ->
82n/aprofilee.py:25(testfunc) -> 1 0.014 0.130 profilee.py:35(factorial)
83n/a 2 0.040 0.600 profilee.py:55(helper)
84n/aprofilee.py:35(factorial) -> 20/3 0.130 0.147 profilee.py:35(factorial)
85n/a 20 0.020 0.020 profilee.py:48(mul)
86n/aprofilee.py:48(mul) ->
87n/aprofilee.py:55(helper) -> 4 0.116 0.120 profilee.py:73(helper1)
88n/a 2 0.000 0.140 profilee.py:84(helper2_indirect)
89n/a 6 0.234 0.300 profilee.py:88(helper2)
90n/aprofilee.py:73(helper1) -> 4 0.000 0.004 {built-in method builtins.hasattr}
91n/aprofilee.py:84(helper2_indirect) -> 2 0.006 0.040 profilee.py:35(factorial)
92n/a 2 0.078 0.100 profilee.py:88(helper2)
93n/aprofilee.py:88(helper2) -> 8 0.064 0.080 profilee.py:98(subhelper)
94n/aprofilee.py:98(subhelper) -> 16 0.016 0.016 profilee.py:110(__getattr__)
95n/a{built-in method builtins.hasattr} -> 12 0.012 0.012 profilee.py:110(__getattr__)"""
96n/a
97n/aif __name__ == "__main__":
98n/a main()