summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_trace.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-10-30 11:16:02 (GMT)
committerGitHub <noreply@github.com>2018-10-30 11:16:02 (GMT)
commit95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9 (patch)
tree8f6c2e5a36ae932599e81ba3a226360ca59b19d7 /Lib/test/test_trace.py
parentb83d917fafd87e4130f9c7d5209ad2debc7219cd (diff)
downloadcpython-95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9.zip
cpython-95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9.tar.gz
cpython-95b6acf951fa7f503a3cc5ce7d969d7bcf2f95c9.tar.bz2
bpo-34876: Change the lineno of the AST for decorated function and class. (GH-9731)
It was overridden by the lineno of the first decorator. Now it is the lineno of 'def' or 'class'.
Diffstat (limited to 'Lib/test/test_trace.py')
-rw-r--r--Lib/test/test_trace.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 63f4741..5c333b7 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -75,6 +75,19 @@ def traced_caller_list_comprehension():
mylist = [traced_doubler(i) for i in range(k)]
return mylist
+def traced_decorated_function():
+ def decorator1(f):
+ return f
+ def decorator_fabric():
+ def decorator2(f):
+ return f
+ return decorator2
+ @decorator1
+ @decorator_fabric()
+ def func():
+ pass
+ func()
+
class TracedClass(object):
def __init__(self, x):
@@ -172,6 +185,24 @@ class TestLineCounts(unittest.TestCase):
}
self.assertEqual(self.tracer.results().counts, expected)
+ def test_traced_decorated_function(self):
+ self.tracer.runfunc(traced_decorated_function)
+
+ firstlineno = get_firstlineno(traced_decorated_function)
+ expected = {
+ (self.my_py_filename, firstlineno + 1): 1,
+ (self.my_py_filename, firstlineno + 2): 1,
+ (self.my_py_filename, firstlineno + 3): 1,
+ (self.my_py_filename, firstlineno + 4): 1,
+ (self.my_py_filename, firstlineno + 5): 1,
+ (self.my_py_filename, firstlineno + 6): 1,
+ (self.my_py_filename, firstlineno + 7): 1,
+ (self.my_py_filename, firstlineno + 8): 1,
+ (self.my_py_filename, firstlineno + 9): 1,
+ (self.my_py_filename, firstlineno + 10): 1,
+ (self.my_py_filename, firstlineno + 11): 1,
+ }
+ self.assertEqual(self.tracer.results().counts, expected)
def test_linear_methods(self):
# XXX todo: later add 'static_method_linear' and 'class_method_linear'
@@ -189,6 +220,7 @@ class TestLineCounts(unittest.TestCase):
}
self.assertEqual(tracer.results().counts, expected)
+
class TestRunExecCounts(unittest.TestCase):
"""A simple sanity test of line-counting, via runctx (exec)"""
def setUp(self):
@@ -263,6 +295,18 @@ class TestFuncs(unittest.TestCase):
}
self.assertEqual(self.tracer.results().calledfuncs, expected)
+ def test_traced_decorated_function(self):
+ self.tracer.runfunc(traced_decorated_function)
+
+ expected = {
+ self.filemod + ('traced_decorated_function',): 1,
+ self.filemod + ('decorator_fabric',): 1,
+ self.filemod + ('decorator2',): 1,
+ self.filemod + ('decorator1',): 1,
+ self.filemod + ('func',): 1,
+ }
+ self.assertEqual(self.tracer.results().calledfuncs, expected)
+
class TestCallers(unittest.TestCase):
"""White-box testing of callers tracing"""