[pypy-svn] r45017 - pypy/dist/pypy/objspace/flow/test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 13 14:45:58 CEST 2007


Author: antocuni
Date: Fri Jul 13 14:45:57 2007
New Revision: 45017

Modified:
   pypy/dist/pypy/objspace/flow/test/test_objspace.py
Log:
factor out the monkey-patching



Modified: pypy/dist/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/test/test_objspace.py	Fri Jul 13 14:45:57 2007
@@ -1,3 +1,4 @@
+import new
 import py
 from pypy.objspace.flow.model import Constant, Block, Link, Variable, traverse
 from pypy.objspace.flow.model import flatten
@@ -795,6 +796,13 @@
         simplify_graph(graph)
         assert self.all_operations(graph) == {'getitem': 1}
 
+    def monkey_patch_code(self, code, stacksize, flags, codestring, names, varnames):
+        c = code
+        return new.code(c.co_argcount, c.co_nlocals, stacksize, flags,
+                        codestring, c.co_consts, names, varnames,
+                        c.co_filename, c.co_name, c.co_firstlineno,
+                        c.co_lnotab)
+
     def test_callmethod_opcode(self):
         """ Tests code generated by pypy-c compiled with CALL_METHOD
         bytecode
@@ -807,15 +815,9 @@
             x = X()
             return x.m()
 
-        # monkey patch code
-        import new
-        c = f.func_code
         # this code is generated by pypy-c when compiling above f
         pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\x91\x02\x00\x92\x00\x00Sd\x00\x00S'
-        new_c = new.code(c.co_argcount, c.co_nlocals, 3,
-                         3, pypy_code, c.co_consts, ('X', 'x', 'm'),
-                         ('x',), c.co_filename,
-                         'f', c.co_firstlineno, c.co_lnotab)
+        new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
         f2 = new.function(new_c, locals(), 'f')
         
         graph = self.codetest(f2)
@@ -823,6 +825,7 @@
         assert all_ops['simple_call'] == 2
         assert all_ops['getattr'] == 1
 
+
 class TestFlowObjSpaceDelay(Base):
     def setup_class(cls):
         cls.space = FlowObjSpace()



More information about the Pypy-commit mailing list