summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2003-02-27 21:27:07 (GMT)
committerSkip Montanaro <skip@pobox.com>2003-02-27 21:27:07 (GMT)
commitadd0ccc251e2dd5eb6e2267a9fcd661dd29fa4c2 (patch)
tree5e203f7906518067020159d801ab7490ce5aab5f /Lib/test
parent68468eba635570400f607e140425a222018e56f9 (diff)
downloadcpython-add0ccc251e2dd5eb6e2267a9fcd661dd29fa4c2.zip
cpython-add0ccc251e2dd5eb6e2267a9fcd661dd29fa4c2.tar.gz
cpython-add0ccc251e2dd5eb6e2267a9fcd661dd29fa4c2.tar.bz2
simple test case for dis module
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_dis.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
new file mode 100644
index 0000000..78ff1c2
--- /dev/null
+++ b/Lib/test/test_dis.py
@@ -0,0 +1,53 @@
+from test.test_support import verify, verbose, TestFailed, run_unittest
+import sys
+import dis
+import StringIO
+
+# Minimal tests for dis module
+
+import unittest
+
+# placement is crucial!!! move the start of _f and you have to adjust the
+# line numbers in dis_f
+def _f(a):
+ print a
+ return 1
+
+dis_f = """\
+ 13 0 LOAD_FAST 0 (a)
+ 3 PRINT_ITEM
+ 4 PRINT_NEWLINE
+
+ 14 5 LOAD_CONST 1 (1)
+ 8 RETURN_VALUE
+ 9 LOAD_CONST 0 (None)
+ 12 RETURN_VALUE
+"""
+
+class DisTests(unittest.TestCase):
+ def test_opmap(self):
+ self.assertEqual(dis.opmap["STOP_CODE"], 0)
+ self.assertEqual(dis.opmap["LOAD_CONST"] in dis.hasconst, True)
+ self.assertEqual(dis.opmap["STORE_NAME"] in dis.hasname, True)
+
+ def test_opname(self):
+ self.assertEqual(dis.opname[dis.opmap["LOAD_FAST"]], "LOAD_FAST")
+
+ def test_boundaries(self):
+ self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG)
+ self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT)
+
+ def test_dis(self):
+ s = StringIO.StringIO()
+ save_stdout = sys.stdout
+ sys.stdout = s
+ dis.dis(_f)
+ sys.stdout = save_stdout
+ self.assertEqual(dis_f, s.getvalue())
+
+def test_main():
+ run_unittest(DisTests)
+
+
+if __name__ == "__main__":
+ test_main()