[pypy-svn] r14379 - in pypy/dist/pypy/tool: . test

quest at codespeak.net quest at codespeak.net
Thu Jul 7 15:17:30 CEST 2005


Author: quest
Date: Thu Jul  7 15:17:29 2005
New Revision: 14379

Added:
   pypy/dist/pypy/tool/run_translation.py
   pypy/dist/pypy/tool/test/slowtest_run_translation.py
Log:
Basic tool for testing translation goals. This is an intermediate checkin; checking result from test remains to be done (see pypy/translator/goal/translate_pypy.py:find_someobjects).

Added: pypy/dist/pypy/tool/run_translation.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/run_translation.py	Thu Jul  7 15:17:29 2005
@@ -0,0 +1,62 @@
+import os
+import sys
+from py.path import svnwc
+
+transl_test = """
+import sys
+module = __import__('pypy.translator.goal.%s', None, None, ['target'])
+entry_point, arg_s = module.target()
+
+from pypy.translator.translator import Translator
+from pypy.translator.goal.query import polluted
+
+t = Translator(entry_point)
+a = t.annotate(arg_s)
+a.simplify()
+
+print polluted(t)
+"""
+
+def prepare(repository, wcdir, revision):
+    """
+    Checks out the named revision into wcdir and returns an object
+    with metadata that can be fed to execute and cleanup.
+    """
+    class ExecutionData:
+        def __init__(self, wcdir):
+            self.wcdir = wcdir
+
+    # Make sure the base dir exists
+    if os.path.exists(wcdir):
+        raise RuntimeError("working directory already exists")
+
+    # Checkout revision
+    wc = svnwc(wcdir)
+    wc.checkout(repository, rev=revision)
+    return ExecutionData(wcdir)
+
+def execute(goal, execdata):
+    """
+    Tests annotation of supplied goal. Goal should be a string with an
+    importable name from pypy.translator.goal.
+    """
+    if not os.path.exists(execdata.wcdir):
+        raise RuntimeError("Run prepare to get a working directory")
+    # Make sure imports are from checked out source
+    test_file_name = os.tmpnam()
+    test_file = open(test_file_name, "w")
+    test_file.write(transl_test % (goal,))
+    test_file.close()
+    os.system("PYTHONPATH=%s python %s" % (execdata.wcdir, test_file_name))
+    os.remove(test_file_name)
+
+def cleanup(execdata):
+    """
+    Removes working directory named by execdata.
+    """
+    for root, dirs, files in os.walk(execdata.wcdir, topdown=False):
+        for name in files:
+            os.remove(os.path.join(root, name))
+        for name in dirs:
+            os.rmdir(os.path.join(root, name))
+    os.rmdir(execdata.wcdir)

Added: pypy/dist/pypy/tool/test/slowtest_run_translation.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/test/slowtest_run_translation.py	Thu Jul  7 15:17:29 2005
@@ -0,0 +1,19 @@
+import os
+from pypy.tool.run_translation import *
+
+repository = "http://codespeak.net/svn/pypy/dist"
+tmpdir = os.tmpnam()
+testfile = os.path.join(tmpdir, "pypy", "translator", "gencl.py")
+testrev = 14373
+
+class  TestRunTranslation:
+    def test_prepare_cleanup(self):
+        execdata = prepare(repository, tmpdir, testrev)
+        assert os.path.exists(testfile)
+        cleanup(execdata)
+        assert not os.path.exists(tmpdir)
+
+    def test_execute(self):
+        execdata = prepare(repository, tmpdir, testrev)
+        execute("targetpypymain", execdata)
+



More information about the Pypy-commit mailing list