[pypy-svn] rev 1495 - in pypy/trunk/src/pypy: objspace/flow objspace/flow/test tool translator translator/test

hpk at codespeak.net hpk at codespeak.net
Wed Oct 1 09:45:50 CEST 2003


Author: hpk
Date: Wed Oct  1 09:45:49 2003
New Revision: 1495

Added:
   pypy/trunk/src/pypy/tool/udir.py
   pypy/trunk/src/pypy/translator/flowmodel.py   (contents, props changed)
      - copied, changed from rev 1489, pypy/trunk/src/pypy/translator/controlflow.py
Removed:
   pypy/trunk/src/pypy/translator/controlflow.py
Modified:
   pypy/trunk/src/pypy/objspace/flow/flowcontext.py
   pypy/trunk/src/pypy/objspace/flow/objspace.py
   pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
   pypy/trunk/src/pypy/objspace/flow/wrapper.py
   pypy/trunk/src/pypy/translator/genpyrex.py
   pypy/trunk/src/pypy/translator/test/buildpyxmodule.py
   pypy/trunk/src/pypy/translator/test/make_dot.py
   pypy/trunk/src/pypy/translator/test/test_pyrextrans.py
   pypy/trunk/src/pypy/translator/test/test_sourcegen.py
Log:
- renamed controlflow to flowmodel because it fits better

- enhanced generation of files
  now all files are put into a unqiue directory per 
  process (so all unittests will essentially put files
  into some directory). Also the filenames are now 
  formed semantically.

- improved dot-output a bit here and there 

- lots of small enhancements
 


Modified: pypy/trunk/src/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/flowcontext.py	Wed Oct  1 09:45:49 2003
@@ -3,7 +3,7 @@
 from pypy.interpreter.pyframe \
      import ControlFlowException, ExitFrame, PyFrame
 from pypy.objspace.flow.wrapper import W_Variable, W_Constant, UnwrapException
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 
 class SpamBlock(BasicBlock):
     dead = False

Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py	Wed Oct  1 09:45:49 2003
@@ -5,7 +5,7 @@
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.error import OperationError
 from pypy.objspace.flow.wrapper import *
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 from pypy.objspace.flow import flowcontext
 
 # ______________________________________________________________________

Modified: pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py	Wed Oct  1 09:45:49 2003
@@ -2,122 +2,139 @@
 from pypy.tool import test
 
 from pypy.objspace.flow.wrapper import *
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 
 class TestFlowOjSpace(test.TestCase):
     def setUp(self):
         self.space = test.objspace('flow')
 
-    def codetest(self, source, functionname):
-        glob = {}
-        exec source in glob
-        func = glob[functionname]
-        return self.space.build_flow(func)
+    def codetest(self, func):
+        import inspect
+        try:
+            func = func.im_func
+        except AttributeError:
+            pass
+        #name = func.func_name
+        graph = self.space.build_flow(func)
+        graph.source = inspect.getsource(func)
+        return graph
 
     def reallyshow(self, x):
         import os
-        from pypy.translator.test.make_dot import make_png
-        make_png(x)
-        #os.system('xv -nolimits /tmp/testgraph.png')
-        os.system('gv /tmp/testgraph.ps')
+        from pypy.translator.test.make_dot import make_dot
+        from pypy.tool.udir import udir
+        dest = make_dot(x, udir, 'ps')
+        os.system('gv %s' % str(dest))
 
     def show(self, x):
         pass   # or   self.reallyshow(x)
 
+    #__________________________________________________________
+    def nothing():
+        pass
+
     def test_nothing(self):
-        x = self.codetest("def nothing():\n"
-                          "    pass\n",
-                          'nothing')
-        #self.assertEquals(x.functionname, 'f')
+        x = self.codetest(self.nothing)
         self.assertEquals(x.startblock.branch.__class__, EndBranch)
         self.show(x)
 
+    #__________________________________________________________
+    def simplebranch(i, j):
+        if i < 0:
+            return i
+        return j
+
     def test_simplebranch(self):
-        x = self.codetest("def simplebranch(i, j):\n"
-                          "    if i < 0:\n"
-                          "        return i\n"
-                          "    return j\n",
-                          'simplebranch')
+        x = self.codetest(self.simplebranch)
         self.show(x)
 
+    #__________________________________________________________
+    def ifthenelse(i, j):
+        if i < 0:
+            i = j
+        return g(i) + 1
+    
     def test_ifthenelse(self):
-        x = self.codetest("def g(i):\n"
-                          "    pass\n"
-                          "def ifthenelse(i, j):\n"
-                          "    if i < 0:\n"
-                          "        i = j\n"
-                          "    return g(i) + 1\n",
-                          'ifthenelse')
+        x = self.codetest(self.simplebranch)
         self.show(x)
 
+    #__________________________________________________________
+    def print_(i):
+        print i
+    
     def test_print(self):
-        x = self.codetest("def test_print(i):\n"
-                          "    print i\n",
-                          'test_print')
+        x = self.codetest(self.print_)
         self.show(x)
 
+    #__________________________________________________________
+    def while_(i):
+        while i > 0:
+            i = i - 1
+
     def test_while(self):
-        #import sys; print >> sys.stderr, "--- starting! ---"
-        x = self.codetest("def test_while(i):\n"
-                          "    while i > 0:\n"
-                          "        i = i - 1\n"
-                          "        #print i\n",
-                          'test_while')
-        #import sys; print >> sys.stderr, "--- done! ---"
+        x = self.codetest(self.while_)
         self.show(x)
 
+    #__________________________________________________________
+    def union_easy(i):
+        if i:
+            pass
+        else:
+            i = 5
+        return i
+
     def test_union_easy(self):
-        x = self.codetest("def union_easy(i):\n"
-                          "    if i:\n"
-                          "        pass\n"
-                          "    else:\n"
-                          "        i = 5\n"
-                          "    return i\n",
-                          'union_easy')
+        x = self.codetest(self.union_easy)
         self.show(x)
 
+    #__________________________________________________________
+    def union_hard(i):
+        if i:
+            i = 5
+        return i
+    
     def test_union_hard(self):
-        x = self.codetest("def union_hard(i):\n"
-                          "    if i:\n"
-                          "        i = 5\n"
-                          "    return i\n",
-                          'union_hard')
+        x = self.codetest(self.union_hard)
         self.show(x)
 
+    #__________________________________________________________
+    def while_union(i):
+        total = 0
+        while i > 0:
+            total += i
+            i = i - 1
+        return total
+    
     def test_while_union(self):
-        x = self.codetest("def while_union(i):\n"
-                          "    total = 0\n"
-                          "    while i > 0:\n"
-                          "        total += i\n"
-                          "        i = i - 1\n"
-                          "    return total\n",
-                          'while_union')
+        x = self.codetest(self.while_union)
         self.show(x)
 
+    #__________________________________________________________
+    def simple_for(lst):
+        total = 0
+        for i in lst:
+            total += i
+        return total
+    
     def test_simple_for(self):
-        x = self.codetest("def simple_for(lst):\n"
-                          "    total = 0\n"
-                          "    for i in lst:\n"
-                          "        total += i\n"
-                          "    return total\n",
-                          'simple_for')
+        x = self.codetest(self.simple_for)
         self.show(x)
 
+    #__________________________________________________________
+    def nested_whiles(i, j):
+        s = ''
+        z = 5
+        while z > 0:
+            z = z - 1
+            u = i
+            while u < j:
+                u = u + 1
+                s = s + '.'
+            s = s + '!'
+        return s
+
     def test_nested_whiles(self):
-        src = """
-def nested_whiles(i, j):
-    s = ''
-    z = 5
-    while z > 0:
-        z = z - 1
-        u = i
-        while u < j:
-            u = u + 1
-            s = s + '.'
-        s = s + '!'
-    return s
-"""
-        x = self.codetest(src, 'nested_whiles')
+        x = self.codetest(self.nested_whiles)
         self.reallyshow(x)
 
 if __name__ == '__main__':

Modified: pypy/trunk/src/pypy/objspace/flow/wrapper.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/wrapper.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/wrapper.py	Wed Oct  1 09:45:49 2003
@@ -5,7 +5,7 @@
 # This is kinda a hack, but at the same time, I don't see why this was defined
 # in the object space module in the annotation object space.
 
-from pypy.translator.controlflow import Variable, Constant
+from pypy.translator.flowmodel import Variable, Constant
 
 class UnwrapException(Exception):
     pass

Added: pypy/trunk/src/pypy/tool/udir.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/tool/udir.py	Wed Oct  1 09:45:49 2003
@@ -0,0 +1,41 @@
+import autopath
+
+#__________________________________________________________
+# udir (a unique human-readable directory path where unittests can store
+#       files to their likening)
+
+def make_udir():
+    from vpath.local import Path, mkdtemp
+
+    _newtmpdir = mkdtemp()
+    _tmpdir = _newtmpdir.dirname()
+    _newtmpdir.rmdir()
+
+    name, num = 'usession', 0
+    items = []
+    for item in _tmpdir.listdir():
+        if item.basename().startswith(name):
+            xb = item.basename().split('-')
+            try:
+                name, num = xb[0], int(xb[1])
+                items.append((name, num))
+            except (TypeError,ValueError):
+                continue
+           
+    if items:
+        items.sort() 
+        name, num = items[-1]
+        num += 1
+
+    udir = _tmpdir.join('-'.join([name, str(num)]))
+    udir.mkdir()
+    return udir
+
+udir = make_udir()
+
+#__________________________________________________________
+
+
+if __name__ == '__main__':
+    # test all of pypy
+    print udir

Deleted: /pypy/trunk/src/pypy/translator/controlflow.py
==============================================================================
--- /pypy/trunk/src/pypy/translator/controlflow.py	Wed Oct  1 09:45:49 2003
+++ (empty file)
@@ -1,67 +0,0 @@
-
-import autopath
-
-
-class BasicBlock:
-    def __init__(self, input_args, locals, operations, branch=None):
-        self.input_args = input_args
-        self.locals = locals
-        self.operations = operations
-        self.branch = branch
-    def closeblock(self, branch):
-        self.operations = tuple(self.operations)  # should no longer change
-        self.branch = branch
-
-class Variable:
-    def __init__(self, pseudoname):
-        self.pseudoname = pseudoname
-    def __repr__(self):
-        return "<%s>" % self.pseudoname
-
-class Constant:
-    def __init__(self, value):
-        self.value = value
-    
-    def __repr__(self):
-        return str(self.value)
-
-class SpaceOperation:
-    def __init__(self, opname, args, result):
-        self.opname = opname
-        self.args = args # list of variables
-        self.result = result # <Variable/Constant instance>
-    def __eq__(self, other):
-        return (self.__class__ is other.__class__ and
-                self.opname == other.opname and
-                self.args == other.args and
-                self.result == other.result)
-
-    def __repr__(self):
-        return "%s(%s) -> %s" % (self.opname, ", ".join(map(str, self.args)), self.result)
-
-class Branch:
-    def __init__(self, args=None, target=None):
-        self.set(args, target)
-
-    def set(self, args, target):
-        self.args = args     # list of variables
-        self.target = target # basic block instance
-
-class ConditionalBranch:
-    def __init__(self, condition=None, ifbranch=None, elsebranch=None):
-        self.set(condition, ifbranch, elsebranch)
-
-    def set(self, condition, ifbranch, elsebranch):
-        self.condition = condition
-        self.ifbranch = ifbranch
-        self.elsebranch = elsebranch
-
-class EndBranch:
-    def __init__(self, returnvalue):
-        self.returnvalue = returnvalue
-
-class FunctionGraph:
-    def __init__(self, startblock, functionname):
-        self.startblock = startblock
-        self.functionname = functionname
-

Copied: pypy/trunk/src/pypy/translator/flowmodel.py (from rev 1489, pypy/trunk/src/pypy/translator/controlflow.py)
==============================================================================
--- pypy/trunk/src/pypy/translator/controlflow.py	(original)
+++ pypy/trunk/src/pypy/translator/flowmodel.py	Wed Oct  1 09:45:49 2003
@@ -1,13 +1,16 @@
-
-import autopath
-
-
+"""
+the objectmodel on which the FlowObjSpace and the translator 
+interoperate. While the FlowObjSpace may (and does) use subclasses
+of the classes in this module the translator parts will only look 
+into the attributes defined here. 
+"""
 class BasicBlock:
     def __init__(self, input_args, locals, operations, branch=None):
         self.input_args = input_args
         self.locals = locals
         self.operations = operations
         self.branch = branch
+
     def closeblock(self, branch):
         self.operations = tuple(self.operations)  # should no longer change
         self.branch = branch
@@ -15,6 +18,7 @@
 class Variable:
     def __init__(self, pseudoname):
         self.pseudoname = pseudoname
+
     def __repr__(self):
         return "<%s>" % self.pseudoname
 
@@ -28,8 +32,9 @@
 class SpaceOperation:
     def __init__(self, opname, args, result):
         self.opname = opname
-        self.args = args # list of variables
+        self.args = args     # list of variables
         self.result = result # <Variable/Constant instance>
+
     def __eq__(self, other):
         return (self.__class__ is other.__class__ and
                 self.opname == other.opname and

Modified: pypy/trunk/src/pypy/translator/genpyrex.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genpyrex.py	(original)
+++ pypy/trunk/src/pypy/translator/genpyrex.py	Wed Oct  1 09:45:49 2003
@@ -1,8 +1,11 @@
+"""
+generate Pyrex files from the flowmodel. 
 
+"""
 import autopath
 from pypy.tool import test
 from pypy.interpreter.baseobjspace import ObjSpace
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 
 class GenPyrex:
     def __init__(self, functiongraph):
@@ -19,19 +22,19 @@
         self.blockids = {}
         self.lines = []
         self.indent = 0
-        self.createCodeFromGraph()
+        self.gen_Graph()
         return "\n".join(self.lines)
 
     def putline(self, line):
         self.lines.append("  " * self.indent + line)
 
-    def createCodeFromGraph(self):
+    def gen_Graph(self):
         fun = self.functiongraph
         inputargnames = [ var.pseudoname for var in fun.startblock.input_args ]
         params = ", ".join(inputargnames)
         self.putline("def %s(%s):" % (fun.functionname, params))
         self.indent += 1 
-        self.createCodeFromBasicBlock(fun.startblock)
+        self.gen_BasicBlock(fun.startblock)
         self.indent -= 1
 
     def _str(self, obj):
@@ -42,13 +45,14 @@
         else:
             raise ValueError("Unknow class: %s" % obj.__class__)
 
-    def createCodeFromBasicBlock(self, block):
+    def gen_BasicBlock(self, block):
         if self.blockids.has_key(block):
             self.putline('cinline "goto Label%s;"' % self.blockids[block])
             return 
 
         blockids = self.blockids
         blockids.setdefault(block, len(blockids))
+
         
         self.putline('cinline "Label%s:"' % blockids[block])
         for op in block.operations:
@@ -65,10 +69,10 @@
         self.dispatchBranch(block.branch)
 
     def dispatchBranch(self, branch):
-        method = getattr(self, "createCodeFrom" + branch.__class__.__name__)
+        method = getattr(self, "gen_" + branch.__class__.__name__)
         method(branch)
 
-    def createCodeFromBranch(self, branch):
+    def gen_Branch(self, branch):
         _str = self._str
         block = branch.target
         sourceargs = [_str(arg) for arg in branch.args]       
@@ -77,13 +81,12 @@
         if sourceargs and sourceargs != targetargs: 
             self.putline("%s = %s" % (", ".join(targetargs), ", ".join(sourceargs)))
 
-        self.createCodeFromBasicBlock(block)    
+        self.gen_BasicBlock(block)    
 
-    def createCodeFromEndBranch(self, branch):
+    def gen_EndBranch(self, branch):
         self.putline("return %s" % self._str(branch.returnvalue))
-   
  
-    def createCodeFromConditionalBranch(self, branch):
+    def gen_ConditionalBranch(self, branch):
         self.putline("if %s:" % self._str(branch.condition))
         self.indent += 1
         self.dispatchBranch(branch.ifbranch)

Modified: pypy/trunk/src/pypy/translator/test/buildpyxmodule.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/buildpyxmodule.py	(original)
+++ pypy/trunk/src/pypy/translator/test/buildpyxmodule.py	Wed Oct  1 09:45:49 2003
@@ -2,15 +2,13 @@
 import autopath
 from pypy.tool import test
 
-from vpath.local import Path, mkdtemp
+from vpath.local import Path
 import os, sys
 
-debug = 1
+debug = 0
 
-def make_module_from_pyxstring(string, num=[0]):
-    tmpdir = mkdtemp()
-    n = num[0] = num[0]+1
-    pyxfile = tmpdir.join('test%d.pyx' %n) 
+def make_module_from_pyxstring(name, dirpath, string):
+    pyxfile = dirpath.join('%s.pyx' % name) 
     pyxfile.write(string)
     if debug: print "made pyxfile", pyxfile
     make_c_from_pyxfile(pyxfile)
@@ -53,8 +51,8 @@
         sys.path.pop(0)
     finally:
         os.chdir(str(lastdir))
-        if not debug:
-            dirpath.rmtree()
+        #if not debug:
+        #dirpath.rmtree()
     return testmodule
 
 def make_c_from_pyxfile(pyxfile):

Modified: pypy/trunk/src/pypy/translator/test/make_dot.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/make_dot.py	(original)
+++ pypy/trunk/src/pypy/translator/test/make_dot.py	Wed Oct  1 09:45:49 2003
@@ -4,9 +4,11 @@
 """
 
 import autopath
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 import os
 
+debug = 0
+
 
 counters = {}
 class Node:
@@ -115,8 +117,12 @@
         self.traverse(fun)
         l = []
         for node in self.nodes.values():
-            l.append(node.descr_node())
-            l.append(node.descr_edges())
+            if hasattr(node, 'source'):
+                l.insert(0, node.descr_node())
+                l.insert(0, node.descr_edges())
+            else:
+                l.append(node.descr_node())
+                l.append(node.descr_edges())
 
         content = "\n".join(l)
 
@@ -167,24 +173,30 @@
                 if trynode:
                     node.addedge(trynode, name)
                 else:
-                    node.data.append("%s=%r" % (name, attr))
+                    if name == 'source' and type(attr) is str:
+                        attr = "\\l".join(attr.split('\n'))
+                        node.data.append('\\l%s' % attr.replace('"', '\\"'))
+                    else:
+                        node.data.append("%s=%s" % (name, repr(attr).replace('"', '\\"')))
                     #print "unknown attribute", name, item
             return node
-        else:
+        elif debug:
             print "unknown obj", obj
 
-def make_png(fun):
+def make_dot(fun, udir, target='ps'):
     dotgen = DotGen()
+
+    name = fun.functionname
    
     from vpath.local import Path
     from vpath.adapter.process import exec_cmd
-    dest = Path('/tmp/testgraph.dot')
-    #print dotgen.get_source(fun)
+    dest = udir.join('%s.dot' % name)
     dest.write(dotgen.get_source(fun))
-    psdest = dest.newsuffix('.ps')
-    out = exec_cmd('dot -Tps %s' % str(dest))
+    psdest = dest.newsuffix(target)
+    out = exec_cmd('dot -T%s %s' % (target, str(dest)))
     psdest.write(out)
     print "wrote", psdest
+    return psdest
 
 if __name__ == '__main__':
         i = Variable("i")

Modified: pypy/trunk/src/pypy/translator/test/test_pyrextrans.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_pyrextrans.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_pyrextrans.py	Wed Oct  1 09:45:49 2003
@@ -1,79 +1,87 @@
 
 import autopath
 from pypy.tool import test
-
+from pypy.tool.udir import udir
 from pypy.translator.genpyrex import GenPyrex
-from pypy.translator.controlflow import *
-
+from pypy.translator.flowmodel import *
 from pypy.translator.test.buildpyxmodule import make_module_from_pyxstring
-#from pypy.translator.test.make_dot import make_ps
+
+make_dot = 1
+
+if make_dot: 
+    from pypy.translator.test.make_dot import make_dot
+else:
+    def make_dot(*args): pass
 
 class TestCase(test.IntTestCase):
     def setUp(self):
         self.space = test.objspace('flow')
 
-    def makemod(self, source, fname):
-        fun = self.codetest(source, fname)
-        fun.source = source
-        result = GenPyrex(fun).emitcode()
-        return make_module_from_pyxstring(result)
-
-    def codetest(self, source, functionname):
-        glob = {}
-        exec source in glob
-        func = glob[functionname]
-        return self.space.build_flow(func)
+    def make_cfunc(self, func):
+        """ make a pyrex-generated cfunction from the given func """
+        import inspect
+        try:
+            func = func.im_func
+        except AttributeError:
+            pass
+        name = func.func_name
+        funcgraph = self.space.build_flow(func)
+        funcgraph.source = inspect.getsource(func)
+        result = GenPyrex(funcgraph).emitcode()
+        make_dot(funcgraph, udir, 'ps')
+        mod = make_module_from_pyxstring(name, udir, result)
+        return getattr(mod, name)
+
+    #____________________________________________________
+    def simple_func(i):
+        return i+1
 
     def test_simple_func(self):
-        src = """
-def simple_func(i):
-    return i+1
-"""
-        mod = self.makemod(src, 'simple_func')
-        self.assertEquals(mod.simple_func(1), 2)
-
-    def test_while(self):
-        src = """
-def while_func(i):
-    total = 0
-    while i > 0:
-        total = total + i
-        i = i - 1
-    return total
-"""
-        mod = self.makemod(src, 'while_func')
-        self.assertEquals(mod.while_func(10), 55)
+        cfunc = self.make_cfunc(self.simple_func)
+        self.assertEquals(cfunc(1), 2)
+
+    #____________________________________________________
+    def while_func(i):
+        total = 0
+        while i > 0:
+            total = total + i
+            i = i - 1
+        return total
+
+    def test_while_func(self):
+        while_func = self.make_cfunc(self.while_func)
+        self.assertEquals(while_func(10), 55)
+
+    #____________________________________________________
+    def nested_whiles(i, j):
+        s = ''
+        z = 5
+        while z > 0:
+            z = z - 1
+            u = i
+            while u < j:
+                u = u + 1
+                s = s + '.'
+            s = s + '!'
+        return s
 
     def test_nested_whiles(self):
-        src = """
-def nested_whiles(i, j):
-    s = ''
-    z = 5
-    while z > 0:
-        z = z - 1
-        u = i
-        while u < j:
-            u = u + 1
-            s = s + '.'
-        s = s + '!'
-    return s
-"""
-        mod = self.makemod(src, 'nested_whiles')
-        self.assertEquals(mod.nested_whiles(111, 114),
+        nested_whiles = self.make_cfunc(self.nested_whiles)
+        self.assertEquals(nested_whiles(111, 114),
                           '...!...!...!...!...!')
 
+    #____________________________________________________
+    def poor_man_range(i):
+        lst = []
+        while i > 0:
+            i = i - 1
+            lst.append(i)
+        lst.reverse()
+        return lst
+
     def dont_yet_test_poor_man_range(self):
-        src = """
-def poor_man_range(i):
-    lst = []
-    while i > 0:
-        i = i - 1
-        lst.append(i)
-    lst.reverse()
-    return lst
-"""
-        mod = self.makemod(src, 'poor_man_range')
-        self.assertEquals(mod.poor_man_range(10), range(10))
+        poor_man_range = self.make_cfunc(self.poor_man_range)
+        self.assertEquals(poor_man_range(10), range(10))
 
 if __name__ == '__main__':
     test.main()

Modified: pypy/trunk/src/pypy/translator/test/test_sourcegen.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_sourcegen.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_sourcegen.py	Wed Oct  1 09:45:49 2003
@@ -1,9 +1,10 @@
 
 import autopath
 from pypy.tool import test
+from pypy.tool.udir import udir
 
 from pypy.translator.genpyrex import GenPyrex
-from pypy.translator.controlflow import *
+from pypy.translator.flowmodel import *
 
 from pypy.translator.test.buildpyxmodule import make_module_from_pyxstring
 #from pypy.translator.test.make_dot import make_ps
@@ -24,7 +25,7 @@
                            endbranch)
         fun = FunctionGraph(block, "f")
         result = GenPyrex(fun).emitcode()
-        mod = make_module_from_pyxstring(result)
+        mod = make_module_from_pyxstring('test_source1', udir, result)
         self.assertEquals(mod.f(1), 2)
 
     def test_if(self):
@@ -51,7 +52,7 @@
                            conditionalbranch)
         fun = FunctionGraph(startblock, "f")
         result = GenPyrex(fun).emitcode()
-        mod = make_module_from_pyxstring(result)
+        mod = make_module_from_pyxstring('test_source2', udir, result)
         self.assertEquals(mod.f(-1, 42), 42)
         self.assertEquals(mod.f(3, 5), 3)
 
@@ -87,7 +88,7 @@
         #make_ps(fun)
         
         result = GenPyrex(fun).emitcode()
-        mod = make_module_from_pyxstring(result)
+        mod = make_module_from_pyxstring('test_source3', udir, result)
         self.assertEquals(mod.f(42), 0)
         self.assertEquals(mod.f(-3), -3)
 
@@ -128,7 +129,7 @@
 
         fun = FunctionGraph(startblock, "f")
         result = GenPyrex(fun).emitcode()
-        mod = make_module_from_pyxstring(result)
+        mod = make_module_from_pyxstring('test_source4', udir, result)
         self.assertEquals(mod.f(3), 6)
         self.assertEquals(mod.f(-3), 0)
 


More information about the Pypy-commit mailing list