From 1c6af67b450348458ac1292e14de6b27f34207ad Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 14 Jul 2022 09:19:48 -0400 Subject: [PATCH 1/2] gh-94814: Improve coverage of _PyCode_CreateLineArray The case where there are more than (1 << 15) lines was not covered --- Lib/test/test_sys_settrace.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index f03b03e19a2528..f75289a11e4d19 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -1571,6 +1571,31 @@ def func(): self.run_and_compare(func, EXPECTED_EVENTS) + def test_very_large_function(self): + # There is a separate code path when the number of lines > (1 << 15). + d = {} + exec("""def f(): # line 0 + x = 0 # line 1 + y = 1 # line 2 + ''' # line 3 + %s # lines 4 through (1 << 16) + ''' # + x += 1 # + return""" % ('\n' * (1 << 16),), d) + f = d['f'] + + EXPECTED_EVENTS = [ + (0, 'call'), + (1, 'line'), + (2, 'line'), + (3, 'line'), + (65542, 'line'), + (65543, 'line'), + (65543, 'return'), + ] + + self.run_and_compare(f, EXPECTED_EVENTS) + EVENT_NAMES = [ 'call', From 0bfea394f5993fedb89214896988a077dba093b6 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 14 Jul 2022 15:19:56 -0400 Subject: [PATCH 2/2] Simplify test --- Lib/test/test_sys_settrace.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index f75289a11e4d19..4f2dd4f9eade37 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -1577,9 +1577,7 @@ def test_very_large_function(self): exec("""def f(): # line 0 x = 0 # line 1 y = 1 # line 2 - ''' # line 3 - %s # lines 4 through (1 << 16) - ''' # + %s # lines 3 through (1 << 16) x += 1 # return""" % ('\n' * (1 << 16),), d) f = d['f'] @@ -1588,10 +1586,9 @@ def test_very_large_function(self): (0, 'call'), (1, 'line'), (2, 'line'), - (3, 'line'), - (65542, 'line'), - (65543, 'line'), - (65543, 'return'), + (65540, 'line'), + (65541, 'line'), + (65541, 'return'), ] self.run_and_compare(f, EXPECTED_EVENTS)