[Zodb-checkins] CVS: ZODB4 - setup.py:1.3 test.py:1.4

Jeremy Hylton jeremy@zope.com
Thu, 5 Dec 2002 11:58:07 -0500


Update of /cvs-repository/ZODB4
In directory cvs.zope.org:/tmp/cvs-serv29740

Modified Files:
	setup.py test.py 
Log Message:
Make BDBStorage part of the default build/install.
Extend test.py with a way to skip tests when external dependencies
aren't satisfied.



=== ZODB4/setup.py 1.2 => 1.3 ===
--- ZODB4/setup.py:1.2	Thu Dec  5 11:54:13 2002
+++ ZODB4/setup.py	Thu Dec  5 11:58:07 2002
@@ -120,27 +120,21 @@
                          "Persistence/cPersistenceAPI.h",]),
     Extension("ZODB._TimeStamp", ["ZODB/TimeStamp.c"]),
     Extension("ZODB.winlock", ["ZODB/winlock.c"]),
+    Extension("BDBStorage._helper", ["BDBStorage/_helper.c"]),
     ]
 
 packages = [
+    "BDBStorage",
     "Interface", "Interface.Common", "Interface.Registry",
     "Persistence", "Persistence.BTrees",
     "ThreadedAsync",
     "Transaction",
     "ZConfig",
     "ZEO", "ZEO.zrpc",
-    "ZODB", "zLOG",
+    "zLOG",
+    "ZODB",
     ]
 
-try:
-    import bsddb3
-except ImportError:
-    pass
-else:
-    packages += ["BDBStorage"]
-    ext_modules += [Extension("BDBStorage._helper",
-                              ["BDBStorage/_helper.c"])]
-
 def hastests(p):
     path = "/".join(p.split(".")) + "/tests"
     return os.path.isdir(path)
@@ -156,7 +150,7 @@
       url = "http://www.zope.org/Wikis/ZODB/FrontPage",
       packages = packages,
       ext_modules = ext_modules,
-      headers = ['ZODB/cPersistence.h'],
+      headers = ["ZODB/cPersistence.h", "ZODB/cPersistenceAPI.h"],
       license = "http://www.zope.org/Resources/ZPL",
       platforms = ["any"],
       description = doclines[0],


=== ZODB4/test.py 1.3 => 1.4 ===
--- ZODB4/test.py:1.3	Wed Dec  4 19:01:34 2002
+++ ZODB4/test.py	Thu Dec  5 11:58:07 2002
@@ -194,17 +194,53 @@
         return re.search(rx, s) is not None
 
 class TestFileFinder:
+
+    # In certain cases, it is okay to skip a test when dependencies
+    # can't be supported.  Only example so far is that BDBStorage
+    # won't work without the external bsddb3 package.
+
+    # depends maps directory names to a list of module dependencies
+    depends = {}
+    depends["BDBStorage"] = ["bsddb3"]
+    
     def __init__(self):
         self.files = []
 
+    def check_depends(self, dir):
+        # dir is the path of a tests directory
+        dirs = []
+        rest = dir
+        while rest:
+            rest, tl = os.path.split(rest)
+            dirs.append(tl)
+        for dir in dirs:
+            if not self._check_depends_component(dir):
+                return False
+        return True
+
+    def _check_depends_component(self, dir):
+        # dir is a component of a test path
+        depends = self.depends.get(dir)
+        if depends is None:
+            return True
+        for mod in depends:
+            try:
+                __import__(mod)
+            except ImportError, err:
+                print "Skipping %s.  Can't import %s." % (dir, mod)
+                return False
+        return True
+
     def visit(self, rx, dir, files):
-        if dir[-5:] != "tests":
+        if not dir.endswith("tests"):
+            return
+        if not self.check_depends(dir):
             return
         # Since we're running from the build directory, every dir
         # should be a file.
         assert "__init__.py" in files
         for file in files:
-            if file[:4] == "test" and file[-3:] == ".py":
+            if file.startswith("test") and file.endswith(".py"):
                 path = os.path.join(dir, file)
                 if not hasgooddir(path):
                     # built for a different version