Tests of an entire source tree build invocation.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 12 Sep 2010 08:37:13 +0000 (01:37 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 12 Sep 2010 08:37:13 +0000 (01:37 -0700)
Cython/TestUtils.py
runtests.py

index 094bc1a23cec2b5acd239e8e487b00ba56655733..0cdcbbf0a300760ddc0330e3e404eb2f68826593 100644 (file)
@@ -168,18 +168,20 @@ class TreeAssertVisitor(VisitorTransform):
 
     visit_Node = VisitorTransform.recurse_to_children
 
-def unpack_source_tree(tree_file):
-    dir = tempfile.mkdtemp()
+def unpack_source_tree(tree_file, dir=None):
+    if dir is None:
+        dir = tempfile.mkdtemp()
+    header = []
     cur_file = None
     for line in open(tree_file).readlines():
         if line[:5] == '#####':
-            filename = line.strip().strip('#').strip()
+            filename = line.strip().strip('#').strip().replace('/', os.path.sep)
             path = os.path.join(dir, filename)
-            print os.path.dirname(path)
             if not os.path.exists(os.path.dirname(path)):
-                print "    ...creating"
                 os.makedirs(os.path.dirname(path))
             cur_file = open(path, 'w')
         elif cur_file is not None:
             cur_file.write(line)
-    return dir
+        else:
+            header.append(line)
+    return dir, ''.join(header)
index d4d7d323bb297b6d29f091833c06efd63f8e1ddf..0db8fb6ccc137dbb95fbba310b6403083eed19ff 100644 (file)
@@ -28,7 +28,7 @@ from distutils.core import Extension
 from distutils.command.build_ext import build_ext as _build_ext
 distutils_distro = Distribution()
 
-TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr']
+TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr', 'build']
 TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr']
 
 # Lists external modules, and a matcher matching tests
@@ -162,6 +162,9 @@ class TestBuilder(object):
         filenames = os.listdir(path)
         filenames.sort()
         for filename in filenames:
+            if context == "build" and filename.endswith(".srctree"):
+                suite.addTest(EndToEndTest(filename, workdir, self.cleanup_workdir))
+                continue
             if not (filename.endswith(".pyx") or filename.endswith(".py")):
                 continue
             if filename.startswith('.'): continue # certain emacs backup files
@@ -623,6 +626,47 @@ def collect_doctests(path, module_prefix, suite, selectors):
                         except ValueError: # no tests
                             pass
 
+
+class EndToEndTest(unittest.TestCase):
+    """
+    This is a test of build/*.srctree files, where srctree defines a full
+    directory structure and its header gives a list of commands to run.
+    """
+    def __init__(self, treefile, workdir, cleanup_workdir=True):
+        self.treefile = treefile
+        self.workdir = os.path.join(workdir, os.path.splitext(treefile)[0])
+        self.cleanup_workdir = cleanup_workdir
+        unittest.TestCase.__init__(self)
+
+    def shortDescription(self):
+        return "End-to-end %s" % self.treefile
+
+    def setUp(self):
+        from Cython.TestUtils import unpack_source_tree
+        _, self.commands = unpack_source_tree(os.path.join('tests', 'build', self.treefile), self.workdir)
+        self.old_dir = os.getcwd()
+        if not os.path.exists(self.workdir):
+            os.makedirs(self.workdir)
+        os.chdir(self.workdir)
+        if self.workdir not in sys.path:
+            sys.path.insert(0, self.workdir)
+
+    def tearDown(self):
+        try:
+            sys.path.remove(self.workdir)
+        except ValueError:
+            pass
+        if self.cleanup_workdir:
+            shutil.rmtree(self.workdir)
+        os.chdir(self.old_dir)
+    
+    def runTest(self):
+        commands = (self.commands
+            .replace("CYTHON", "PYTHON %s" % os.path.join(self.old_dir, 'cython.py'))
+            .replace("PYTHON", sys.executable))
+        self.assertEqual(0, os.system(commands))
+
+
 # TODO: Support cython_freeze needed here as well.
 # TODO: Windows support.