[pypy-svn] pypy default: add the possibility to pass an entire source file as string
antocuni
commits-noreply at bitbucket.org
Wed Mar 9 14:58:06 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42483:3ccc4ac27684
Date: 2011-03-07 14:02 +0100
http://bitbucket.org/pypy/pypy/changeset/3ccc4ac27684/
Log: add the possibility to pass an entire source file as string
diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -1,4 +1,5 @@
import sys
+import types
import subprocess
import py
from lib_pypy import disassembler
@@ -19,12 +20,17 @@
def setup_method(self, meth):
self.filepath = self.tmpdir.join(meth.im_func.func_name + '.py')
- def run(self, func, args=[], **jitopts):
+ def run(self, func_or_src, args=[], **jitopts):
+ src = py.code.Source(func_or_src)
+ if isinstance(func_or_src, types.FunctionType):
+ funcname = func_or_src.func_name
+ else:
+ funcname = 'main'
# write the snippet
arglist = ', '.join(map(repr, args))
with self.filepath.open("w") as f:
- f.write(str(py.code.Source(func)) + "\n")
- f.write("print %s(%s)\n" % (func.func_name, arglist))
+ f.write(str(src) + "\n")
+ f.write("print %s(%s)\n" % (funcname, arglist))
#
# run a child pypy-c with logging enabled
logfile = self.filepath.new(ext='.log')
@@ -222,6 +228,16 @@
log = self.run(f, [30, 12])
assert log.result == 42
+ def test_run_src(self):
+ src = """
+ def f(a, b):
+ return a+b
+ def main(a, b):
+ return f(a, b)
+ """
+ log = self.run(src, [30, 12])
+ assert log.result == 42
+
def test_parse_jitlog(self):
def f():
i = 0
More information about the Pypy-commit
mailing list