[Checkins] SVN: z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner. Changed to work on windows:

Jim Fulton jim at zope.com
Mon Aug 17 08:39:48 EDT 2009


Log message for revision 102882:
  Changed to work on windows:
  
  - Can't use the subprocess close_fds option on windows.
  
  - Can't use select with pipes on windows.  The select was pretty
    pointless anyway, snce it was followed by a read that could block
    anyway.
  
  - Invoke tests scripts using the runner's Python. This means we can't
    run any old executable, but we don't need to.
  
  - Adjust script path for windows.
  
  - fixed a long line.
  

Changed:
  U   z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py
  U   z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.txt

-=-
Modified: z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py
===================================================================
--- z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py	2009-08-17 12:26:34 UTC (rev 102881)
+++ z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.py	2009-08-17 12:39:48 UTC (rev 102882)
@@ -15,10 +15,14 @@
 options you can use, refer to the test runner documentation.
 """ % sys.argv[0]
 
+windoze = sys.platform.startswith('win')
+
 class Job(object):
 
     def __init__(self, script, args):
         self.script = script
+        if windoze:
+            self.script += '-script.py'
         self.args = args
         self.name = os.path.basename(script)
         self.output = StringIO.StringIO()
@@ -27,18 +31,23 @@
     def start(self):
         self.start = time.time()
         self.process = subprocess.Popen(
-            [self.script, '--exit-with-status'] + self.args,
+            [sys.executable, self.script, '--exit-with-status'] + self.args,
             stdin=subprocess.PIPE,
             stdout=subprocess.PIPE,
-            close_fds=True)
+            stderr=subprocess.STDOUT,
+            close_fds = not windoze,
+            )
 
     def poll(self):
         self.exitcode = self.process.poll()
         if self.exitcode is not None:
             self.end = time.time()
-        read, _, _ = select.select([self.process.stdout], [], [], 0.01)
-        if read:
-            self.output.write(read[0].read())
+            # We're done, get it all
+            data = self.process.stdout.read()
+        else:
+            # We're not done, so just get some
+            data = self.process.stdout.readline()
+        self.output.write(data.replace('\r\n', '\n'))
 
 
 def main(max_jobs, *scripts):
@@ -65,7 +74,9 @@
         default_time = sum(stats.values()) / float(len(stats))
     else:
         default_time = 0
-    scripts.sort(key=lambda package:-stats.get(os.path.basename(package), default_time))
+    scripts.sort(
+        key=lambda package:-stats.get(os.path.basename(package), default_time)
+        )
 
     # Main loop for controlling test runs
     while scripts or running:

Modified: z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.txt
===================================================================
--- z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.txt	2009-08-17 12:26:34 UTC (rev 102881)
+++ z3c.recipe.compattest/trunk/src/z3c/recipe/compattest/runner.txt	2009-08-17 12:39:48 UTC (rev 102882)
@@ -9,37 +9,42 @@
 It monitors the stdout of those processes and reports back packages with
 failures.
 
->>> import os
->>> ok_script = os.path.join(sample_buildout, 'test-ok')
->>> write(ok_script, '#!/bin/bash\n sleep 1; exit')
->>> os.chmod(ok_script, 0755)
+    >>> import os, sys
 
->>> failure_script = os.path.join(sample_buildout, 'test-failure')
->>> write(failure_script, '#!/bin/bash\n sleep 1; echo ouch; exit 1')
->>> os.chmod(failure_script, 0755)
+    >>> ok_script = ok_path = os.path.join(sample_buildout, 'test-ok')
+    >>> failure_script = failure_path = os.path.join(sample_buildout, 'test-failure')
+    >>> if sys.platform.startswith('win'):
+    ...     ok_path += '-script.py'
+    ...     failure_path += '-script.py'
 
->>> import os.path
->>> from z3c.recipe.compattest.runner import main
->>> main(1, ok_script, failure_script)
-Running test-ok
-Running test-failure
-test-failure failed with:
-ouch
-<BLANKLINE>
-1 failure(s).
-- test-failure
+    >>> write(ok_path, """
+    ... import time
+    ... time.sleep(1)
+    ... print 'ok'
+    ... """)
+    >>> write(failure_path, """
+    ... import time
+    ... time.sleep(1)
+    ... raise SystemError('Fail!')
+    ... """)
 
->>> main(2, failure_script, ok_script, failure_script, ok_script)
-Running test-failure
-Running test-ok
-test-failure failed with:
-ouch
-<BLANKLINE>
-Running test-failure
-Running test-ok
-test-failure failed with:
-ouch
-<BLANKLINE>
-2 failure(s).
-- test-failure
-- test-failure
+    >>> from z3c.recipe.compattest.runner import main
+    >>> main(1, ok_script, failure_script)
+    Running test-ok
+    Running test-failure
+    test-failure failed with:
+    Traceback (most recent call last):
+    ...
+    SystemError: Fail!
+    <BLANKLINE>
+    1 failure(s).
+    - test-failure
+
+Note that when we pass a number greater than 1 as the first argument,
+tests are run in parallel, so the order of output varies.
+
+    >>> main(2, failure_script, ok_script, failure_script, ok_script)
+    Running ...
+    2 failure(s).
+    - test-failure
+    - test-failure



More information about the Checkins mailing list