diff options
| author | Jeffrey Yasskin <jyasskin@gmail.com> | 2009-05-08 21:51:06 (GMT) |
|---|---|---|
| committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2009-05-08 21:51:06 (GMT) |
| commit | 1aa4700234aa0657ee8cb12cfd9b615fef9e0300 (patch) | |
| tree | 6a480c31e4b83218ae9412f7ab2e9d41b34f8fd0 /Lib/test/test_code.py | |
| parent | 083d1f9f9a26486cf9f0d85fb0e76e6cf9474b0c (diff) | |
| download | cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.zip cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.tar.gz cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.tar.bz2 | |
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.
Diffstat (limited to 'Lib/test/test_code.py')
| -rw-r--r-- | Lib/test/test_code.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index b69223d..4a88e60 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -80,6 +80,9 @@ consts: ("'doc string'", 'None') """ +import unittest +import _testcapi + def consts(t): """Yield a doctest-safe sequence of object reprs.""" for elt in t: @@ -96,10 +99,21 @@ def dump(co): 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__': |
