[Zodb-checkins] CVS: StandaloneZODB - test.py:1.8

Jeremy Hylton jeremy@zope.com
Thu, 25 Oct 2001 10:36:12 -0400


Update of /cvs-repository/StandaloneZODB
In directory cvs.zope.org:/tmp/cvs-serv3722

Modified Files:
	test.py 
Log Message:
Remote DOTSLASH, logic should be a little cleaner on Windows now.
(Key change is to search in the build directory to begin with.)    

Pass filter as None by default, avoiding re.search() in this case.


=== StandaloneZODB/test.py 1.7 => 1.8 ===
 from distutils.util import get_platform
 
-DOTSLASH = "." + os.sep
-
 # setup list of directories to put on the path
 
 def setup_path():
@@ -49,15 +47,11 @@
         self.files = []
 
     def visit(self, rx, dir, files):
-        if dir[:7] == DOTSLASH + "build":
-            return
         if dir[-5:] != "tests":
             return
-        # XXX special case bsddb3Storage
-        if dir[:29] == DOTSLASH + "bsddb3Storage%sbsddb3Storage" % os.sep:
-            dir = "./" + dir[16:]
         # ignore tests that aren't in packages
         if not "__init__.py" in files:
+            print "not a package", dir
             return
         for file in files:
             if file[:4] == "test" and file[-3:] == ".py":
@@ -69,9 +63,12 @@
                     self.files.append(path)
 
 def find_tests(filter):
-    rx = re.compile(filter)
+    if filter is not None:
+        rx = re.compile(filter)
+    else:
+        rx = None
     finder = TestFileFinder()
-    os.path.walk(".", finder.visit, rx)
+    os.path.walk("build", finder.visit, rx)
     return finder.files
 
 def package_import(modname):
@@ -80,6 +77,21 @@
         mod = getattr(mod, part)
     return mod
 
+def module_from_path(path):
+    """Return the Python package name indiciated by the filesystem path.
+
+    The path starts with build/lib or build /lib.mumble..."""
+
+    assert path[-3:] == '.py'
+    path = path[:-3]
+    dirs = []
+    while path:
+        path, end = os.path.split(path)
+        dirs.insert(0, end)
+    assert dirs[0] == "build"
+    assert dirs[1][:3] == "lib"
+    return string.join(dirs[2:], '.')
+
 def main(filter=None):
     setup_path()
     files = find_tests(filter)
@@ -89,10 +101,9 @@
     if LOOP:
         suites = []
         for file in files:
-            assert file[:2] == DOTSLASH
+            assert file[:5] == "build"
             assert file[-3:] == '.py'
-            modname = file[2:-3]
-            modname = string.replace(modname, os.sep, '.')
+            modname = module_from_path(file)
             print modname
             mod = package_import(modname)
             try:
@@ -109,10 +120,9 @@
     else:
         runner = unittest.TextTestRunner(verbosity=VERBOSE)
         for file in files:
-            assert file[:2] == DOTSLASH
+            assert file[:5] == "build"
             assert file[-3:] == '.py'
-            modname = file[2:-3]
-            modname = string.replace(modname, os.sep, '.')
+            modname = module_from_path(file)
             print modname
             mod = package_import(modname)
             try:
@@ -125,7 +135,7 @@
 if __name__ == "__main__":
     import getopt
 
-    filter = '.'
+    filter = None
     VERBOSE = 0
     LOOP = 0