annotate Lib/test/test_trace.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents cd8d3c2d3bce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
1 import os
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
2 import sys
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
3 from test.test_support import (run_unittest, TESTFN, rmtree, unlink,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
4 captured_stdout)
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
5 import unittest
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
6
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
7 import trace
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
8 from trace import CoverageResults, Trace
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
9
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
10 from test.tracedmodules import testmod
37468
04afb3650847 Generate line number table entries for except handlers.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35738
diff changeset
11
04afb3650847 Generate line number table entries for except handlers.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35738
diff changeset
12
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
13 #------------------------------- Utilities -----------------------------------#
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
14
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
15 def fix_ext_py(filename):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
16 """Given a .pyc/.pyo filename converts it to the appropriate .py"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
17 if filename.endswith(('.pyc', '.pyo')):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
18 filename = filename[:-1]
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
19 return filename
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
20
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
21 def my_file_and_modname():
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
22 """The .py file and module name of this file (__file__)"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
23 modname = os.path.splitext(os.path.basename(__file__))[0]
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
24 return fix_ext_py(__file__), modname
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
25
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
26 def get_firstlineno(func):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
27 return func.__code__.co_firstlineno
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
28
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
29 #-------------------- Target functions for tracing ---------------------------#
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
30 #
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
31 # The relative line numbers of lines in these functions matter for verifying
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
32 # tracing. Please modify the appropriate tests if you change one of the
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
33 # functions. Absolute line numbers don't matter.
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
34 #
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
35
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
36 def traced_func_linear(x, y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
37 a = x
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
38 b = y
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
39 c = a + b
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
40 return c
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
41
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
42 def traced_func_loop(x, y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
43 c = x
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
44 for i in range(5):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
45 c += y
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
46 return c
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
47
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
48 def traced_func_importing(x, y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
49 return x + y + testmod.func(1)
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
50
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
51 def traced_func_simple_caller(x):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
52 c = traced_func_linear(x, x)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
53 return c + x
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
54
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
55 def traced_func_importing_caller(x):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
56 k = traced_func_simple_caller(x)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
57 k += traced_func_importing(k, x)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
58 return k
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
59
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
60 def traced_func_generator(num):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
61 c = 5 # executed once
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
62 for i in range(num):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
63 yield i + c
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
64
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
65 def traced_func_calling_generator():
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
66 k = 0
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
67 for i in traced_func_generator(10):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
68 k += i
31765
24e070e95bf8 Test for lack of implicit return line event
Nicholas Bastin <nick.bastin@gmail.com>
parents: 28917
diff changeset
69
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
70 def traced_doubler(num):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
71 return num * 2
31765
24e070e95bf8 Test for lack of implicit return line event
Nicholas Bastin <nick.bastin@gmail.com>
parents: 28917
diff changeset
72
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
73 def traced_caller_list_comprehension():
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
74 k = 10
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
75 mylist = [traced_doubler(i) for i in range(k)]
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
76 return mylist
31766
75a91fd8b50c Test for tight loop line event fix, SF bug #765624
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31765
diff changeset
77
75a91fd8b50c Test for tight loop line event fix, SF bug #765624
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31765
diff changeset
78
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
79 class TracedClass(object):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
80 def __init__(self, x):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
81 self.a = x
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
82
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
83 def inst_method_linear(self, y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
84 return self.a + y
31769
7f464dd680aa The fix in ceval.c 2.386 allows iteration-by-iteration line tracing even in
Armin Rigo <arigo@tunes.org>
parents: 31767
diff changeset
85
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
86 def inst_method_calling(self, x):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
87 c = self.inst_method_linear(x)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
88 return c + traced_func_linear(x, c)
31769
7f464dd680aa The fix in ceval.c 2.386 allows iteration-by-iteration line tracing even in
Armin Rigo <arigo@tunes.org>
parents: 31767
diff changeset
89
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
90 @classmethod
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
91 def class_method_linear(cls, y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
92 return y * 2
43846
d5fc6e96091f Backport for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39363
diff changeset
93
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
94 @staticmethod
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
95 def static_method_linear(y):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
96 return y * 2
43846
d5fc6e96091f Backport for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39363
diff changeset
97
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
98
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
99 #------------------------------ Test cases -----------------------------------#
43846
d5fc6e96091f Backport for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39363
diff changeset
100
d5fc6e96091f Backport for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39363
diff changeset
101
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
102 class TestLineCounts(unittest.TestCase):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
103 """White-box testing of line-counting, via runfunc"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
104 def setUp(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
105 self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
106 self.my_py_filename = fix_ext_py(__file__)
46550
95947fdf40ae Disable gc when running test_trace, or we may record the __del__ of collected objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 45160
diff changeset
107
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
108 def test_traced_func_linear(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
109 result = self.tracer.runfunc(traced_func_linear, 2, 5)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
110 self.assertEqual(result, 7)
46550
95947fdf40ae Disable gc when running test_trace, or we may record the __del__ of collected objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 45160
diff changeset
111
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
112 # all lines are executed once
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
113 expected = {}
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
114 firstlineno = get_firstlineno(traced_func_linear)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
115 for i in range(1, 5):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
116 expected[(self.my_py_filename, firstlineno + i)] = 1
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
117
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
118 self.assertEqual(self.tracer.results().counts, expected)
45155
86602b603462 backport of r60575 (issue #1750076): Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43846
diff changeset
119
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
120 def test_traced_func_loop(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
121 self.tracer.runfunc(traced_func_loop, 2, 3)
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
122
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
123 firstlineno = get_firstlineno(traced_func_loop)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
124 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
125 (self.my_py_filename, firstlineno + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
126 (self.my_py_filename, firstlineno + 2): 6,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
127 (self.my_py_filename, firstlineno + 3): 5,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
128 (self.my_py_filename, firstlineno + 4): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
129 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
130 self.assertEqual(self.tracer.results().counts, expected)
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
131
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
132 def test_traced_func_importing(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
133 self.tracer.runfunc(traced_func_importing, 2, 5)
44822
424cccfd2baa #1648: add sys.gettrace() and sys.getprofile().
Georg Brandl <georg@python.org>
parents: 43845
diff changeset
134
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
135 firstlineno = get_firstlineno(traced_func_importing)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
136 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
137 (self.my_py_filename, firstlineno + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
138 (fix_ext_py(testmod.__file__), 2): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
139 (fix_ext_py(testmod.__file__), 3): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
140 }
25206
bf75f3a45927 Bunch more tests.
Michael W. Hudson <mwh@python.net>
parents: 25078
diff changeset
141
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
142 self.assertEqual(self.tracer.results().counts, expected)
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
143
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
144 def test_trace_func_generator(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
145 self.tracer.runfunc(traced_func_calling_generator)
43846
d5fc6e96091f Backport for issue1265 (pdb bug with "with" statement).
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 39363
diff changeset
146
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
147 firstlineno_calling = get_firstlineno(traced_func_calling_generator)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
148 firstlineno_gen = get_firstlineno(traced_func_generator)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
149 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
150 (self.my_py_filename, firstlineno_calling + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
151 (self.my_py_filename, firstlineno_calling + 2): 11,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
152 (self.my_py_filename, firstlineno_calling + 3): 10,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
153 (self.my_py_filename, firstlineno_gen + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
154 (self.my_py_filename, firstlineno_gen + 2): 11,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
155 (self.my_py_filename, firstlineno_gen + 3): 10,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
156 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
157 self.assertEqual(self.tracer.results().counts, expected)
45155
86602b603462 backport of r60575 (issue #1750076): Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43846
diff changeset
158
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
159 def test_trace_list_comprehension(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
160 self.tracer.runfunc(traced_caller_list_comprehension)
45155
86602b603462 backport of r60575 (issue #1750076): Debugger did not step on every iteration of a while statement.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 43846
diff changeset
161
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
162 firstlineno_calling = get_firstlineno(traced_caller_list_comprehension)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
163 firstlineno_called = get_firstlineno(traced_doubler)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
164 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
165 (self.my_py_filename, firstlineno_calling + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
166 (self.my_py_filename, firstlineno_calling + 2): 11,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
167 (self.my_py_filename, firstlineno_calling + 3): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
168 (self.my_py_filename, firstlineno_called + 1): 10,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
169 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
170 self.assertEqual(self.tracer.results().counts, expected)
45158
0dfaa92bd534 No need to emit co_lnotab item when both offsets are zeros.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 45155
diff changeset
171
0dfaa92bd534 No need to emit co_lnotab item when both offsets are zeros.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 45155
diff changeset
172
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
173 def test_linear_methods(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
174 # XXX todo: later add 'static_method_linear' and 'class_method_linear'
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
175 # here, once issue1764286 is resolved
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
176 #
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
177 for methname in ['inst_method_linear',]:
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
178 tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
179 traced_obj = TracedClass(25)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
180 method = getattr(traced_obj, methname)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
181 tracer.runfunc(method, 20)
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
182
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
183 firstlineno = get_firstlineno(method)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
184 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
185 (self.my_py_filename, firstlineno + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
186 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
187 self.assertEqual(tracer.results().counts, expected)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
188
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
189 class TestRunExecCounts(unittest.TestCase):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
190 """A simple sanity test of line-counting, via runctx (exec)"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
191 def setUp(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
192 self.my_py_filename = fix_ext_py(__file__)
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
193
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
194 def test_exec_counts(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
195 self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
196 code = r'''traced_func_loop(2, 5)'''
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
197 code = compile(code, __file__, 'exec')
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
198 self.tracer.runctx(code, globals(), vars())
26128
23ef7c163a12 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26110
diff changeset
199
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
200 firstlineno = get_firstlineno(traced_func_loop)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
201 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
202 (self.my_py_filename, firstlineno + 1): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
203 (self.my_py_filename, firstlineno + 2): 6,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
204 (self.my_py_filename, firstlineno + 3): 5,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
205 (self.my_py_filename, firstlineno + 4): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
206 }
28886
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 26686
diff changeset
207
68588
cd8d3c2d3bce #11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 68256
diff changeset
208 # When used through 'run', some other spurious counts are produced, like
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
209 # the settrace of threading, which we ignore, just making sure that the
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
210 # counts fo traced_func_loop were right.
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
211 #
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
212 for k in expected.keys():
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
213 self.assertEqual(self.tracer.results().counts[k], expected[k])
28886
af53729d3cdd Armin Rigo's fix & test for
Michael W. Hudson <mwh@python.net>
parents: 26686
diff changeset
214
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
215
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
216 class TestFuncs(unittest.TestCase):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
217 """White-box testing of funcs tracing"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
218 def setUp(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
219 self.tracer = Trace(count=0, trace=0, countfuncs=1)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
220 self.filemod = my_file_and_modname()
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
221
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
222 def test_simple_caller(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
223 self.tracer.runfunc(traced_func_simple_caller, 1)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
224
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
225 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
226 self.filemod + ('traced_func_simple_caller',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
227 self.filemod + ('traced_func_linear',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
228 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
229 self.assertEqual(self.tracer.results().calledfuncs, expected)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
230
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
231 def test_loop_caller_importing(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
232 self.tracer.runfunc(traced_func_importing_caller, 1)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
233
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
234 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
235 self.filemod + ('traced_func_simple_caller',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
236 self.filemod + ('traced_func_linear',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
237 self.filemod + ('traced_func_importing_caller',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
238 self.filemod + ('traced_func_importing',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
239 (fix_ext_py(testmod.__file__), 'testmod', 'func'): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
240 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
241 self.assertEqual(self.tracer.results().calledfuncs, expected)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
242
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
243 def test_inst_method_calling(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
244 obj = TracedClass(20)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
245 self.tracer.runfunc(obj.inst_method_calling, 1)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
246
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
247 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
248 self.filemod + ('TracedClass.inst_method_calling',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
249 self.filemod + ('TracedClass.inst_method_linear',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
250 self.filemod + ('traced_func_linear',): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
251 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
252 self.assertEqual(self.tracer.results().calledfuncs, expected)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
253
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
254
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
255 class TestCallers(unittest.TestCase):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
256 """White-box testing of callers tracing"""
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
257 def setUp(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
258 self.tracer = Trace(count=0, trace=0, countcallers=1)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
259 self.filemod = my_file_and_modname()
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
260
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
261 def test_loop_caller_importing(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
262 self.tracer.runfunc(traced_func_importing_caller, 1)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
263
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
264 expected = {
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
265 ((os.path.splitext(trace.__file__)[0] + '.py', 'trace', 'Trace.runfunc'),
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
266 (self.filemod + ('traced_func_importing_caller',))): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
267 ((self.filemod + ('traced_func_simple_caller',)),
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
268 (self.filemod + ('traced_func_linear',))): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
269 ((self.filemod + ('traced_func_importing_caller',)),
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
270 (self.filemod + ('traced_func_simple_caller',))): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
271 ((self.filemod + ('traced_func_importing_caller',)),
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
272 (self.filemod + ('traced_func_importing',))): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
273 ((self.filemod + ('traced_func_importing',)),
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
274 (fix_ext_py(testmod.__file__), 'testmod', 'func')): 1,
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
275 }
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
276 self.assertEqual(self.tracer.results().callers, expected)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
277
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
278
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
279 # Created separately for issue #3821
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
280 class TestCoverage(unittest.TestCase):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
281 def tearDown(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
282 rmtree(TESTFN)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
283 unlink(TESTFN)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
284
64926
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
285 def _coverage(self, tracer,
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
286 cmd='from test import test_pprint; test_pprint.test_main()'):
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
287 tracer.run(cmd)
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
288 r = tracer.results()
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
289 r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
290
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
291 def test_coverage(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
292 tracer = trace.Trace(trace=0, count=1)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
293 with captured_stdout() as stdout:
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
294 self._coverage(tracer)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
295 stdout = stdout.getvalue()
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
296 self.assertTrue("pprint.py" in stdout)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
297 self.assertTrue("case.py" in stdout) # from unittest
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
298 files = os.listdir(TESTFN)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
299 self.assertTrue("pprint.cover" in files)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
300 self.assertTrue("unittest.case.cover" in files)
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
301
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
302 def test_coverage_ignore(self):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
303 # Ignore all files, nothing should be traced nor printed
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
304 libpath = os.path.normpath(os.path.dirname(os.__file__))
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
305 # sys.prefix does not work when running from a checkout
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
306 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, libpath],
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
307 trace=0, count=1)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
308 with captured_stdout() as stdout:
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
309 self._coverage(tracer)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
310 if os.path.exists(TESTFN):
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
311 files = os.listdir(TESTFN)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 64950
diff changeset
312 self.assertEqual(files, [])
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26128
diff changeset
313
64926
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
314 def test_issue9936(self):
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
315 tracer = trace.Trace(trace=0, count=1)
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
316 modname = 'test.tracedmodules.testmod'
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
317 # Ensure that the module is executed in import
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
318 if modname in sys.modules:
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
319 del sys.modules[modname]
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
320 cmd = ("import test.tracedmodules.testmod as t;"
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
321 "t.func(0); t.func2();")
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
322 with captured_stdout() as stdout:
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
323 self._coverage(tracer, cmd)
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
324 stdout.seek(0)
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
325 stdout.readline()
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
326 coverage = {}
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
327 for line in stdout:
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
328 lines, cov, module = line.split()[:3]
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
329 coverage[module] = (int(lines), int(cov[:-1]))
64950
05c58b3d6d39 Merged revisions 85000 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64926
diff changeset
330 # XXX This is needed to run regrtest.py as a script
05c58b3d6d39 Merged revisions 85000 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64926
diff changeset
331 modname = trace.fullmodname(sys.modules[modname].__file__)
64926
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
332 self.assertIn(modname, coverage)
12e0dffef7bd Merged revisions 84994 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64716
diff changeset
333 self.assertEqual(coverage[modname], (5, 100))
54494
52295ebcca31 Merged revisions 73114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46550
diff changeset
334
52295ebcca31 Merged revisions 73114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 46550
diff changeset
335
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
336 def test_main():
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
337 run_unittest(__name__)
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
338
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
339
64711
0f3b8f928ec1 Issue #9315: Fix for the trace module to record correct class name
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
340 if __name__ == '__main__':
25078
be2868a63ed5 Further SET_LINENO reomval fixes. See comments in patch #587933.
Michael W. Hudson <mwh@python.net>
parents:
diff changeset
341 test_main()