annotate Lib/test/test_dis.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents ef8fe9088696
children 17891566a478
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)
51920
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
57 3 POP_JUMP_IF_TRUE 38
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
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
70 35 RAISE_VARARGS 2
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
71
51920
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
72 %-4d >> 38 LOAD_CONST 0 (None)
ef8fe9088696 Backport r69961 to trunk, replacing JUMP_IF_{TRUE,FALSE} with
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 50204
diff changeset
73 41 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
74 """%(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
75 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
76 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
77
39094
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
78 _BIG_LINENO_FORMAT = """\
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
79 %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
80 3 POP_TOP
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
81 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
82 7 RETURN_VALUE
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
83 """
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
84
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
85 class DisTests(unittest.TestCase):
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
86 def do_disassembly_test(self, func, expected):
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
87 s = StringIO.StringIO()
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
88 save_stdout = sys.stdout
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
89 sys.stdout = s
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
90 dis.dis(func)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
91 sys.stdout = save_stdout
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
92 got = s.getvalue()
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
93 # Trim trailing blanks (if any).
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
94 lines = got.split('\n')
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
95 lines = [line.rstrip() for line in lines]
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
96 expected = expected.split("\n")
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
97 import difflib
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
98 if expected != lines:
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
99 self.fail(
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
100 "events did not match expectation:\n" +
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
101 "\n".join(difflib.ndiff(expected,
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
102 lines)))
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
103
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
104 def test_opmap(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
105 self.assertEqual(dis.opmap["STOP_CODE"], 0)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
106 self.assertEqual(dis.opmap["LOAD_CONST"] in dis.hasconst, True)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
107 self.assertEqual(dis.opmap["STORE_NAME"] in dis.hasname, True)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
108
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
109 def test_opname(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
110 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
111
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
112 def test_boundaries(self):
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
113 self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
114 self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
115
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
116 def test_dis(self):
28887
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
117 self.do_disassembly_test(_f, dis_f)
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
118
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
119 def test_bug_708901(self):
e4eabe5b3da1 Use Tim's suggestion to fix
Michael W. Hudson <mwh@python.net>
parents: 28229
diff changeset
120 self.do_disassembly_test(bug708901, dis_bug708901)
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
121
36081
19d96c2d7df5 Fix Armin's bug 1333982. He found it, he didn't created it :-)
Neal Norwitz <nnorwitz@gmail.com>
parents: 33248
diff changeset
122 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
123 # 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
124 # 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
125 if __debug__:
43bc7ca2d9df test_bug_1333982(): This one must fail under -O.
Tim Peters <tim.peters@gmail.com>
parents: 36081
diff changeset
126 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
127
39094
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
128 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
129 def func(count):
39117
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
130 namespace = {}
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
131 func = "def foo():\n " + "".join(["\n "] * count + ["spam\n"])
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
132 exec func in namespace
acff1c34cca3 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39094
diff changeset
133 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
134
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
135 # 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
136 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
137 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
138 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
139
756d57acda85 Bug #1512814, Fix incorrect lineno's when code within a function
Neal Norwitz <nnorwitz@gmail.com>
parents: 36824
diff changeset
140 # 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
141 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
142 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
143 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
144
28090
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
145 def test_main():
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
146 run_unittest(DisTests)
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
147
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 if __name__ == "__main__":
3c5a8814470c simple test case for dis module
Skip Montanaro <skip@pobox.com>
parents:
diff changeset
150 test_main()