[Zope-Checkins] CVS: Zope - test.py:1.2.2.4

Chris Withers chris at simplistix.co.uk
Tue Jul 27 12:18:18 EDT 2004


Update of /cvs-repository/Zope
In directory cvs.zope.org:/tmp/cvs-serv2782

Modified Files:
      Tag: Zope-2_7-branch
	test.py 
Log Message:
Added Stefan Holek's changes to test.py that allow for tests to be run from an instance


=== Zope/test.py 1.2.2.3 => 1.2.2.4 ===
--- Zope/test.py:1.2.2.3	Thu Mar 25 17:27:17 2004
+++ Zope/test.py	Tue Jul 27 12:17:47 2004
@@ -46,7 +46,11 @@
     In Python < 2.3 the -q flag is added to the setup.py command
     line.)
 
--c  use pychecker
+-c  
+    use pychecker
+
+--config-file filename
+    Configure Zope by loading the specified configuration file (zope.conf).
 
 -d
     Instead of the normal test harness, run a debug version which
@@ -79,6 +83,10 @@
     of the DEBUG_ flags defined bythe Python gc module.  Multiple options
     can be specified by using "-G OPTION1 -G OPTION2."
 
+--import-testing
+    Import the Testing module to setup the test ZODB.  Useful for running
+    tests that forgot to "import Testing".
+
 --libdir test_root
     Search for tests starting in the specified start directory
     (useful for testing components being developed outside the main
@@ -349,23 +357,25 @@
 # setup list of directories to put on the path
 class PathInit:
     def __init__(self, build, libdir=None):
-        # Calculate which directories we're going to add to sys.path, and cd
-        # to the appropriate working directory
-        org_cwd = os.getcwd()
+        # Calculate which directories we're going to add to sys.path.
         self.libdir = "lib/python"
         # Hack sys.path
-        self.cwd = os.getcwd()
-        sys.path.insert(0, os.path.join(self.cwd, self.libdir))
+        self.home = os.path.dirname(os.path.realpath(sys.argv[0]))
+        # test.py lives in bin directory when installed ...
+        dir, file = os.path.split(self.home)
+        if file == 'bin': self.home = dir
+        sys.path.insert(0, os.path.join(self.home, self.libdir))
+        self.cwd = os.path.realpath(os.getcwd())
         # Hack again for external products.
         global functional
         kind = functional and "functional" or "unit"
         if libdir:
-            extra = os.path.join(org_cwd, libdir)
-            print "Running %s tests from %s" % (kind, extra)
-            self.libdir = extra
-            sys.path.insert(0, extra)
+            self.libdir = os.path.realpath(os.path.join(self.cwd, libdir))
         else:
-            print "Running %s tests from %s" % (kind, self.cwd)
+            self.libdir = os.path.realpath(os.path.join(self.cwd, self.libdir))
+        if self.libdir not in sys.path:
+            sys.path.insert(0, self.libdir)
+        print "Running %s tests from %s" % (kind, self.libdir)
         # Make sure functional tests find ftesting.zcml
         if functional:
             config_file = 'ftesting.zcml'
@@ -456,7 +466,10 @@
 def find_tests(rx):
     global finder
     finder = TestFileFinder(pathinit.libdir)
-    walkdir = test_dir or pathinit.libdir
+    if test_dir:
+        walkdir = os.path.realpath(os.path.join(pathinit.cwd, test_dir))
+    else:
+        walkdir = pathinit.libdir
     os.path.walk(walkdir, finder.visit, rx)
     return finder.files
 
@@ -602,20 +615,32 @@
                 os.unlink(fullname)
 
 def main(module_filter, test_filter, libdir):
-    if not keepStaleBytecode:
-        os.path.walk(os.curdir, remove_stale_bytecode, None)
-
     global pathinit
+    global config_file
+
+    # Initialize the path and cwd
+    pathinit = PathInit(build, libdir)
+
+    if not keepStaleBytecode:
+        os.path.walk(pathinit.home, remove_stale_bytecode, None)
     
+    # Load configuration
+    if config_file:
+        config_file = os.path.realpath(config_file)
+        print "Parsing %s" % config_file
+        import Zope
+        Zope.configure(config_file)
+
+    # Import Testing module to setup the test ZODB
+    if import_testing:
+        import Testing
+
     # Get the log.ini file from the current directory instead of possibly
     # buried in the build directory.  XXX This isn't perfect because if
     # log.ini specifies a log file, it'll be relative to the build directory.
     # Hmm...
     logini = os.path.abspath('log.ini')
 
-    # Initialize the path and cwd
-    pathinit = PathInit(build, libdir)
-
     # Initialize the logging module.
     import logging.config
     logging.basicConfig()
@@ -670,6 +695,8 @@
     global keepStaleBytecode
     global functional
     global test_dir
+    global config_file
+    global import_testing
 
     if argv is None:
         argv = sys.argv
@@ -695,11 +722,14 @@
     keepStaleBytecode = 0
     functional = False
     test_dir = None
+    config_file = None
+    import_testing = False
 
     try:
         opts, args = getopt.getopt(argv[1:], "a:bcdDfg:G:hLmprtTuv",
                                    ["all", "help", "libdir=", "times=",
-                                    "keepbytecode", "dir="])
+                                    "keepbytecode", "dir=", 
+                                    "config-file=", "import-testing"])
     except getopt.error, msg:
         print msg
         print "Try `python %s -h' for more information." % argv[0]
@@ -766,6 +796,10 @@
                 timesfn = v
         elif k == '--dir':
             test_dir = v
+        elif k == '--config-file':
+            config_file = v
+        elif k == '--import-testing':
+            import_testing = True
 
     if gcthresh is not None:
         if gcthresh == 0:



More information about the Zope-Checkins mailing list