[Zope3-checkins] SVN: zope.testing/trunk/ Avoid to hardcode sys.argv[0] as script;

Godefroid Chapelle gotcha at bubblenet.be
Mon Aug 10 09:44:36 EDT 2009


Log message for revision 102626:
  Avoid to hardcode sys.argv[0] as script; 
  allow for instance Zope 2 `bin/instance test` (LP#407916).
  
  

Changed:
  U   zope.testing/trunk/CHANGES.txt
  U   zope.testing/trunk/src/zope/testing/testrunner/__init__.py
  U   zope.testing/trunk/src/zope/testing/testrunner/runner.py

-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt	2009-08-10 11:59:08 UTC (rev 102625)
+++ zope.testing/trunk/CHANGES.txt	2009-08-10 13:44:36 UTC (rev 102626)
@@ -4,6 +4,9 @@
 3.8.1 (unreleased)
 ==================
 
+- Avoid to hardcode sys.argv[0] as script; 
+  allow for instance Zope 2 `bin/instance test` (LP#407916).
+
 - Produce a clear error message when subprocess doesn't follow the
   zope.testing.testrunner protocol (LP#407916).
 

Modified: zope.testing/trunk/src/zope/testing/testrunner/__init__.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/__init__.py	2009-08-10 11:59:08 UTC (rev 102625)
+++ zope.testing/trunk/src/zope/testing/testrunner/__init__.py	2009-08-10 13:44:36 UTC (rev 102626)
@@ -23,17 +23,17 @@
 import zope.testing.testrunner.interfaces
 
 
-def run(defaults=None, args=None):
+def run(defaults=None, args=None, script_parts=None):
     """Main runner function which can be and is being used from main programs.
 
     Will execute the tests and exit the process according to the test result.
 
     """
-    failed = run_internal(defaults, args)
+    failed = run_internal(defaults, args, script_parts=script_parts)
     sys.exit(int(failed))
 
 
-def run_internal(defaults=None, args=None):
+def run_internal(defaults=None, args=None, script_parts=None):
     """Execute tests.
 
     Returns whether errors or failures occured during testing.
@@ -41,7 +41,7 @@
     """
     # XXX Bah. Lazy import to avoid circular/early import problems
     from zope.testing.testrunner.runner import Runner
-    runner = Runner(defaults, args)
+    runner = Runner(defaults, args, script_parts=script_parts)
     runner.run()
     return runner.failed
 

Modified: zope.testing/trunk/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/runner.py	2009-08-10 11:59:08 UTC (rev 102625)
+++ zope.testing/trunk/src/zope/testing/testrunner/runner.py	2009-08-10 13:44:36 UTC (rev 102626)
@@ -77,11 +77,12 @@
     """
 
     def __init__(self, defaults=None, args=None, found_suites=None,
-                 options=None):
+                 options=None, script_parts=None):
         self.defaults = defaults
         self.args = args
         self.found_suites = found_suites
         self.options = options
+        self.script_parts = script_parts
         self.failed = True
 
         self.ran = 0
@@ -147,7 +148,6 @@
     def configure(self):
         if self.args is None:
             self.args = sys.argv[:]
-
         # Check to see if we are being run as a subprocess. If we are,
         # then use the resume-layer and defaults passed in.
         if len(self.args) > 1 and self.args[1] == '--resume-layer':
@@ -229,7 +229,7 @@
         if should_resume:
             setup_layers = None
             if layers_to_run:
-                self.ran += resume_tests(self.options, self.features,
+                self.ran += resume_tests(self.script_parts, self.options, self.features,
                     layers_to_run, self.failures, self.errors)
 
         if setup_layers:
@@ -378,13 +378,15 @@
         "Layer set up failure."
 
 
-def spawn_layer_in_subprocess(result, options, features, layer_name, layer,
+def spawn_layer_in_subprocess(result, script_parts, options, features, layer_name, layer,
         failures, errors, resume_number):
     try:
-        args = [sys.executable,
-                sys.argv[0],
-                '--resume-layer', layer_name, str(resume_number),
-                ]
+        # BBB
+        if script_parts is None:
+            script_parts = sys.argv[0:1]
+        args = [sys.executable]
+        args.extend(script_parts)
+        args.extend(['--resume-layer', layer_name, str(resume_number)])
         for d in options.testrunner_defaults:
             args.extend(['--default', d])
 
@@ -443,7 +445,7 @@
         self.done = False
 
 
-def resume_tests(options, features, layers, failures, errors):
+def resume_tests(script_parts, options, features, layers, failures, errors):
     results = []
     resume_number = int(options.processes > 1)
     ready_threads = []
@@ -452,7 +454,7 @@
         results.append(result)
         ready_threads.append(threading.Thread(
             target=spawn_layer_in_subprocess,
-            args=(result, options, features, layer_name, layer, failures,
+            args=(result, script_parts, options, features, layer_name, layer, failures,
                 errors, resume_number)))
         resume_number += 1
 



More information about the Zope3-Checkins mailing list