[Zope-CVS] CVS: Packages/JobBoardEx/tests - __init__.py:1.2

Fred L. Drake, Jr. fdrake@acm.org
Wed, 20 Mar 2002 10:01:42 -0500


Update of /cvs-repository/Packages/JobBoardEx/tests
In directory cvs.zope.org:/tmp/cvs-serv16206/tests

Modified Files:
	__init__.py 
Log Message:
Add a function that returns a combined test suite for the JobBoardEx product.

=== Packages/JobBoardEx/tests/__init__.py 1.1 => 1.2 ===
+
+import glob
+import os.path
+import sys
+import unittest
+
+def alltests():
+    """Return a suite containing all the tests defined for this package.
+
+    This is useful with the unittestgui.py script (at least).
+    """
+    mydir = os.path.dirname(__file__)
+    files = glob.glob(os.path.join(mydir, "*.py"))
+    suites = []
+    for file in files:
+        base = os.path.splitext(os.path.basename(file))[0]
+        if not base.startswith("test"):
+            continue
+        modname = "%s.%s" % (__name__, base)
+        __import__(modname)
+        module = sys.modules[modname]
+        try:
+            tsfunc = module.test_suite
+        except AttributeError:
+            pass
+        else:
+            suites.append(tsfunc())
+    if len(suites) == 1:
+        return suites[0]
+    elif len(suites) == 0:
+        return
+    else:
+        return unittest.TestSuite(suites)