[pypy-svn] r55696 - in pypy/dist/pypy/interpreter: . test

fijal at codespeak.net fijal at codespeak.net
Mon Jun 9 18:59:04 CEST 2008


Author: fijal
Date: Mon Jun  9 18:59:03 2008
New Revision: 55696

Modified:
   pypy/dist/pypy/interpreter/pycode.py
   pypy/dist/pypy/interpreter/test/test_code.py
   pypy/dist/pypy/interpreter/typedef.py
Log:
Pycode.__repr__


Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Mon Jun  9 18:59:03 2008
@@ -393,3 +393,8 @@
             #hidden_applevel=False, magic = 62061 | 0x0a0d0000
         ]
         return space.newtuple([new_inst, space.newtuple(tup)])
+
+    def repr(self, space):
+        return space.wrap("<code object %s, file '%s', line %d>" % (
+            self.co_name, self.co_filename, self.co_firstlineno))
+    repr.unwrap_spec = ['self', ObjSpace]

Modified: pypy/dist/pypy/interpreter/test/test_code.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_code.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_code.py	Mon Jun  9 18:59:03 2008
@@ -1,6 +1,16 @@
 
+from pypy.conftest import gettestobjspace
+from pypy.interpreter import gateway
+import py
 
 class AppTestCodeIntrospection:
+    def setup_class(cls):
+        space = gettestobjspace()
+        cls.space = space
+        if py.test.config.option.runappdirect:
+            cls.w_file = space.wrap(__file__[:-1])
+        else:
+            cls.w_file = space.wrap("None<%s" % gateway.__file__[:-1])
 
     def test_attributes(self):
         def f(): pass
@@ -135,3 +145,14 @@
         assert args == ['obj']
         assert varargs is None
         assert varkw is None
+
+    def test_repr(self):
+        def f():
+            xxx
+        res = repr(f.func_code)
+        expected = ["<code object f",
+                    self.file,
+                    'line']
+        for i in expected:
+            assert i in res
+

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Mon Jun  9 18:59:03 2008
@@ -666,6 +666,7 @@
     __hash__ = interp2app(PyCode.descr_code__hash__),
     __reduce__   = interp2app(PyCode.descr__reduce__,
                               unwrap_spec=['self', ObjSpace]),
+    __repr__ = interp2app(PyCode.repr),
     co_argcount = interp_attrproperty('co_argcount', cls=PyCode),
     co_nlocals = interp_attrproperty('co_nlocals', cls=PyCode),
     co_stacksize = interp_attrproperty('co_stacksize', cls=PyCode),



More information about the Pypy-commit mailing list