annotate Lib/test/test_dis.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 595ad43fdd94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41379
b7e378e9d02d Clean up imports.
Collin Winter <collinw@gmail.com>
parents: 39117
diff changeset
1 # Minimal tests for dis module
b7e378e9d02d Clean up imports.
Collin Winter <collinw@gmail.com>
parents: 39117
diff changeset
2
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 41379
diff changeset
3 from test.test_support import run_unittest
41379
b7e378e9d02d Clean up imports.
Collin Winter <collinw@gmail.com>
parents: 39117
diff changeset
4 import unittest
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
5 import sys
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
6 import dis
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
7 import StringIO
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
8
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
9
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
10 def _f(a):
28229
6e49ba3f60be This test relied on significant trailing whitespace in a string literal.
Tim Peters <tim.peters@gmail.com>
parents: 28090
diff changeset
11 print a
6e49ba3f60be This test relied on significant trailing whitespace in a string literal.
Tim Peters <tim.peters@gmail.com>
parents: 28090
diff changeset
12 return 1
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
13
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
14 dis_f = """\
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
15 %-4d 0 LOAD_FAST 0 (a)
28229
6e49ba3f60be This test relied on significant trailing whitespace in a string literal.
Tim Peters <tim.peters@gmail.com>
parents: 28090
diff changeset
16 3 PRINT_ITEM
6e49ba3f60be This test relied on significant trailing whitespace in a string literal.
Tim Peters <tim.peters@gmail.com>
parents: 28090
diff changeset
17 4 PRINT_NEWLINE
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
18
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
19 %-4d 5 LOAD_CONST 1 (1)
28229
6e49ba3f60be This test relied on significant trailing whitespace in a string literal.
Tim Peters <tim.peters@gmail.com>
parents: 28090
diff changeset
20 8 RETURN_VALUE
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
21 """%(_f.func_code.co_firstlineno + 1,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
22 _f.func_code.co_firstlineno + 2)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
23
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
24
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
25 def bug708901():
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
26 for res in range(1,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
27 10):
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
28 pass
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
29
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
30 dis_bug708901 = """\
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
31 %-4d 0 SETUP_LOOP 23 (to 26)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
32 3 LOAD_GLOBAL 0 (range)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
33 6 LOAD_CONST 1 (1)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
34
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
35 %-4d 9 LOAD_CONST 2 (10)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
36 12 CALL_FUNCTION 2
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
37 15 GET_ITER
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
38 >> 16 FOR_ITER 6 (to 25)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
39 19 STORE_FAST 0 (res)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
40
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
41 %-4d 22 JUMP_ABSOLUTE 16
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
42 >> 25 POP_BLOCK
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
43 >> 26 LOAD_CONST 0 (None)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
44 29 RETURN_VALUE
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
45 """%(bug708901.func_code.co_firstlineno + 1,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
46 bug708901.func_code.co_firstlineno + 2,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
47 bug708901.func_code.co_firstlineno + 3)
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
48
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
49
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
50 def bug1333982(x=[]):
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
51 assert 0, ([s for s in x] +
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
52 1)
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
53 pass
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
54
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
55 dis_bug1333982 = """\
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
56 %-4d 0 LOAD_CONST 1 (0)
73146
595ad43fdd94 adjust for change in assert bytecode
Benjamin Peterson <benjamin@python.org>
parents: 58460
diff changeset
57 3 POP_JUMP_IF_TRUE 41
51920
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
58 6 LOAD_GLOBAL 0 (AssertionError)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
59 9 BUILD_LIST 0
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
60 12 LOAD_FAST 0 (x)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
61 15 GET_ITER
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
62 >> 16 FOR_ITER 12 (to 31)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
63 19 STORE_FAST 1 (s)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
64 22 LOAD_FAST 1 (s)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
65 25 LIST_APPEND 2
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
66 28 JUMP_ABSOLUTE 16
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
67
51920
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
68 %-4d >> 31 LOAD_CONST 2 (1)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
69 34 BINARY_ADD
73146
595ad43fdd94 adjust for change in assert bytecode
Benjamin Peterson <benjamin@python.org>
parents: 58460
diff changeset
70 35 CALL_FUNCTION 1
595ad43fdd94 adjust for change in assert bytecode
Benjamin Peterson <benjamin@python.org>
parents: 58460
diff changeset
71 38 RAISE_VARARGS 1
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
72
73146
595ad43fdd94 adjust for change in assert bytecode
Benjamin Peterson <benjamin@python.org>
parents: 58460
diff changeset
73 %-4d >> 41 LOAD_CONST 0 (None)
595ad43fdd94 adjust for change in assert bytecode
Benjamin Peterson <benjamin@python.org>
parents: 58460
diff changeset
74 44 RETURN_VALUE
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
75 """%(bug1333982.func_code.co_firstlineno + 1,
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
76 bug1333982.func_code.co_firstlineno + 2,
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
77 bug1333982.func_code.co_firstlineno + 3)
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
78
39094
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
79 _BIG_LINENO_FORMAT = """\
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
80 %3d 0 LOAD_GLOBAL 0 (spam)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
81 3 POP_TOP
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
82 4 LOAD_CONST 0 (None)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
83 7 RETURN_VALUE
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
84 """
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
85
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
86 class DisTests(unittest.TestCase):
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
87 def do_disassembly_test(self, func, expected):
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
88 s = StringIO.StringIO()
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
89 save_stdout = sys.stdout
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
90 sys.stdout = s
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
91 dis.dis(func)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
92 sys.stdout = save_stdout
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
93 got = s.getvalue()
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
94 # Trim trailing blanks (if any).
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
95 lines = got.split('\n')
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
96 lines = [line.rstrip() for line in lines]
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
97 expected = expected.split("\n")
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
98 import difflib
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
99 if expected != lines:
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
100 self.fail(
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
101 "events did not match expectation:\n" +
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
102 "\n".join(difflib.ndiff(expected,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
103 lines)))
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
104
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
105 def test_opmap(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
106 self.assertEqual(dis.opmap["STOP_CODE"], 0)
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 51920
diff changeset
107 self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst)
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 51920
diff changeset
108 self.assertIn(dis.opmap["STORE_NAME"], dis.hasname)
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
109
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
110 def test_opname(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
111 self.assertEqual(dis.opname[dis.opmap["LOAD_FAST"]], "LOAD_FAST")
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
112
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
113 def test_boundaries(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
114 self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
115 self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
116
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
117 def test_dis(self):
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
118 self.do_disassembly_test(_f, dis_f)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
119
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
120 def test_bug_708901(self):
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
121 self.do_disassembly_test(bug708901, dis_bug708901)
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
122
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
123 def test_bug_1333982(self):
36120
43bc7ca2d9df test_bug_1333982(): This one must fail under -O.
Tim Peters <tim.peters@gmail.com>
parents: 36081
diff changeset
124 # This one is checking bytecodes generated for an `assert` statement,
43bc7ca2d9df test_bug_1333982(): This one must fail under -O.
Tim Peters <tim.peters@gmail.com>
parents: 36081
diff changeset
125 # so fails if the tests are run with -O. Skip this test then.
43bc7ca2d9df test_bug_1333982(): This one must fail under -O.
Tim Peters <tim.peters@gmail.com>
parents: 36081
diff changeset
126 if __debug__:
43bc7ca2d9df test_bug_1333982(): This one must fail under -O.
Tim Peters <tim.peters@gmail.com>
parents: 36081
diff changeset
127 self.do_disassembly_test(bug1333982, dis_bug1333982)
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
128
39094
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
129 def test_big_linenos(self):
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
130 def func(count):
39117
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
131 namespace = {}
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
132 func = "def foo():\n " + "".join(["\n "] * count + ["spam\n"])
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
133 exec func in namespace
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
134 return namespace['foo']
39094
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
135
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
136 # Test all small ranges
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
137 for i in xrange(1, 300):
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
138 expected = _BIG_LINENO_FORMAT % (i + 2)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
139 self.do_disassembly_test(func(i), expected)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
140
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
141 # Test some larger ranges too
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
142 for i in xrange(300, 5000, 10):
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
143 expected = _BIG_LINENO_FORMAT % (i + 2)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
144 self.do_disassembly_test(func(i), expected)
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
145
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
146 def test_main():
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
147 run_unittest(DisTests)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
148
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
149
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
150 if __name__ == "__main__":
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
151 test_main()