summaryrefslogtreecommitdiff
path: root/Lib/test/test_dis.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-07-16 01:50:38 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-07-16 01:50:38 +0000
commit84be93b2db7e8c351bc5f25991c14a1384b5b523 (patch)
tree5f96b1585c52ccbc422aa01372a51862b326d9bf /Lib/test/test_dis.py
parentec5948aae223e8f4d1ffd86f9eea92aa5ebe7304 (diff)
downloadcpython-git-84be93b2db7e8c351bc5f25991c14a1384b5b523.tar.gz
Bug #1512814, Fix incorrect lineno's when code within a function
had more than 255 blank lines. Byte codes need to go first, line #s second.
Diffstat (limited to 'Lib/test/test_dis.py')
-rw-r--r--Lib/test/test_dis.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 081941dafb..0aaae8feb5 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -81,6 +81,13 @@ dis_bug1333982 = """\
bug1333982.func_code.co_firstlineno + 2,
bug1333982.func_code.co_firstlineno + 3)
+_BIG_LINENO_FORMAT = """\
+%3d 0 LOAD_GLOBAL 0 (spam)
+ 3 POP_TOP
+ 4 LOAD_CONST 0 (None)
+ 7 RETURN_VALUE
+"""
+
class DisTests(unittest.TestCase):
def do_disassembly_test(self, func, expected):
s = StringIO.StringIO()
@@ -124,6 +131,23 @@ class DisTests(unittest.TestCase):
if __debug__:
self.do_disassembly_test(bug1333982, dis_bug1333982)
+ def test_big_linenos(self):
+ def func(count):
+ namespace = {}
+ func = "def foo():\n " + "".join(["\n "] * count + ["spam\n"])
+ exec func in namespace
+ return namespace['foo']
+
+ # Test all small ranges
+ for i in xrange(1, 300):
+ expected = _BIG_LINENO_FORMAT % (i + 2)
+ self.do_disassembly_test(func(i), expected)
+
+ # Test some larger ranges too
+ for i in xrange(300, 5000, 10):
+ expected = _BIG_LINENO_FORMAT % (i + 2)
+ self.do_disassembly_test(func(i), expected)
+
def test_main():
run_unittest(DisTests)