[Zope3-checkins] CVS: Zope3 - test.py:1.62

Marius Gedminas mgedmin@codeworks.lt
Tue, 17 Jun 2003 10:20:13 -0400


Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv5492

Modified Files:
	test.py 
Log Message:
The test runner now follows symlinks.  This enables you to run unit and
functional tests for products that are checked out in a different CVS
sandbox and just symlinked from $ZOPE_3_SANDBOX_ROOT/src/zopeproducts.


=== Zope3/test.py 1.61 => 1.62 ===
--- Zope3/test.py:1.61	Wed Jun 11 04:14:29 2003
+++ Zope3/test.py	Tue Jun 17 10:20:12 2003
@@ -423,11 +423,29 @@
         mod = path.replace(os.sep, ".")
         return mod
 
+def walk_with_symlinks(top, func, arg):
+    """Like os.path.walk, but follows symlinks on POSIX systems.
+
+    This could theoreticaly result in an infinite loop, if you create symlink
+    cycles in your Zope sandbox, so don't do that.
+    """
+    try:
+        names = os.listdir(top)
+    except os.error:
+        return
+    func(arg, top, names)
+    exceptions = ('.', '..')
+    for name in names:
+        if name not in exceptions:
+            name = os.path.join(top, name)
+            if os.path.isdir(name):
+                walk_with_symlinks(name, func, arg)
+
 def find_tests(rx):
     global finder
     finder = TestFileFinder(pathinit.libdir)
     walkdir = test_dir or pathinit.libdir
-    os.path.walk(walkdir, finder.visit, rx)
+    walk_with_symlinks(walkdir, finder.visit, rx)
     return finder.files
 
 def package_import(modname):