diff Lib/test/test_code.py @ 53930:a171048daf76 legacy-trunk

PyCode_NewEmpty: Most uses of PyCode_New found by http://www.google.com/codesearch?q=PyCode_New are trying to build an empty code object, usually to put it in a dummy frame object. This patch adds a PyCode_NewEmpty wrapper which lets the user specify just the filename, function name, and first line number, instead of also requiring lots of code internals.
author Jeffrey Yasskin <jyasskin@gmail.com>
date Fri, 08 May 2009 21:51:06 +0000
parents 4c5065ddb9bd
children 22f589a8e3ab
line wrap: on
line diff
--- a/Lib/test/test_code.py	Fri May 08 20:58:08 2009 +0000
+++ b/Lib/test/test_code.py	Fri May 08 21:51:06 2009 +0000
@@ -80,6 +80,9 @@
 
 """
 
+import unittest
+import _testcapi
+
 def consts(t):
     """Yield a doctest-safe sequence of object reprs."""
     for elt in t:
@@ -96,10 +99,21 @@
         print "%s: %s" % (attr, getattr(co, "co_" + attr))
     print "consts:", tuple(consts(co.co_consts))
 
+
+class CodeTest(unittest.TestCase):
+
+    def test_newempty(self):
+        co = _testcapi.code_newempty("filename", "funcname", 15)
+        self.assertEquals(co.co_filename, "filename")
+        self.assertEquals(co.co_name, "funcname")
+        self.assertEquals(co.co_firstlineno, 15)
+
+
 def test_main(verbose=None):
-    from test.test_support import run_doctest
+    from test.test_support import run_doctest, run_unittest
     from test import test_code
     run_doctest(test_code, verbose)
+    run_unittest(CodeTest)
 
 
 if __name__ == '__main__':