[pypy-svn] r58365 - in pypy/build/testrunner: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Sep 23 11:26:44 CEST 2008


Author: pedronis
Date: Tue Sep 23 11:26:42 2008
New Revision: 58365

Modified:
   pypy/build/testrunner/runner.py
   pypy/build/testrunner/test/test_runner.py
Log:
(iko, pedronis)

--dry-run option for debugging setups



Modified: pypy/build/testrunner/runner.py
==============================================================================
--- pypy/build/testrunner/runner.py	(original)
+++ pypy/build/testrunner/runner.py	Tue Sep 23 11:26:42 2008
@@ -10,6 +10,13 @@
     finally:
         f.close()
 
+def dry_run(args, cwd, out):
+    f = out.open('w')
+    try:
+        f.write("run %s with cwd='%s'\n" % (args, cwd))
+    finally:
+        f.close()
+    return 0
 
 def getsignalname(n):
     for name, value in signal.__dict__.items():
@@ -17,13 +24,19 @@
             return name
     return 'signal %d' % (n,)
 
-def execute_test(cwd, test, out, logfname, interp, test_driver):
+def execute_test(cwd, test, out, logfname, interp, test_driver,
+                 do_dry_run=False):
     args = interp+test_driver
     args += ['--resultlog=%s' % logfname, test]
 
     args = map(str, args)
-
-    exitcode = run(args, cwd, out)
+    if do_dry_run:
+        runfunc = dry_run
+    else:
+        runfunc = run
+    
+    exitcode = runfunc(args, cwd, out)
+    
     return exitcode
 
 def interpret_exitcode(exitcode, test):
@@ -45,6 +58,7 @@
     root = run_param.root
     test_driver = run_param.test_driver
     interp = run_param.interp
+    dry_run = run_param.dry_run
     # xxx cfg thread start
     while 1:
         try:
@@ -58,7 +72,7 @@
         num += n
 
         exitcode = execute_test(root, test, one_output, logfname,
-                                interp, test_driver)
+                                interp, test_driver, do_dry_run=dry_run)
 
         # xxx cfg cleanup after testdir
         
@@ -74,13 +88,14 @@
             logdata += extralog
 
         result_queue.put((failure, logdata, output))
-        
+
+invoke_in_thread = thread.start_new_thread
 
 def start_workers(n, run_param, testdirs):
     result_queue = Queue.Queue()
     for i in range(n):
-        thread.start_new_thread(worker, (i, n, run_param, testdirs,
-                                         result_queue))
+        invoke_in_thread(worker, (i, n, run_param, testdirs,
+                                  result_queue))
     return result_queue
 
 
@@ -120,6 +135,7 @@
 
 
 class RunParam(object):
+    dry_run = False
     interp = [os.path.abspath(sys.executable)]
     test_driver = [os.path.abspath(os.path.join('py', 'bin', 'py.test'))]
     parallel_runs = 1
@@ -170,8 +186,11 @@
                       help="root directory for the run")
     parser.add_option("--parallel-runs", dest="parallel_runs", default=0,
                       type="int",
-                      help="number of parallel test runs")    
-    
+                      help="number of parallel test runs")
+    parser.add_option("--dry-run", dest="dry_run", default=False,
+                      action="store_true",
+                      help="dry run")    
+        
     opts, args = parser.parse_args(args)
 
     if opts.logfile is None:
@@ -200,6 +219,10 @@
 
     if opts.parallel_runs:
         run_param.parallel_runs = opts.parallel_runs
+    run_param.dry_run = opts.dry_run
+
+    if run_param.dry_run:
+        print >>out, run_param.__dict__
     
     res = execute_tests(run_param, testdirs, logfile, out)
 

Modified: pypy/build/testrunner/test/test_runner.py
==============================================================================
--- pypy/build/testrunner/test/test_runner.py	(original)
+++ pypy/build/testrunner/test/test_runner.py	Tue Sep 23 11:26:42 2008
@@ -70,10 +70,14 @@
 """        
 
 
-class TestRunner(object):
-
+class RunnerTests(object):
+    with_thread = True
 
     def setup_class(cls):
+        cls.real_invoke_in_thread = (runner.invoke_in_thread,)
+        if not cls.with_thread:
+            runner.invoke_in_thread = lambda func, args: func(*args)
+        
         cls.udir = py.path.local.make_numbered_dir(prefix='usession-runner-',
                                               keep=3)
 
@@ -99,7 +103,7 @@
         
 
     def teardown_class(cls):
-        pass
+        runner.invoke_in_thread = cls.real_invoke_in_thread[0]
 
     def test_collect_testdirs(self):
         res = []
@@ -146,6 +150,29 @@
         assert noutcomes == 107
         assert nfailures == 6
 
+    def test_one_dir_dry_run(self):
+        test_driver = [py.path.local(py.__file__).dirpath('bin', 'py.test')]
+
+        log = cStringIO.StringIO()
+        out = cStringIO.StringIO()
+
+        run_param = runner.RunParam(self.one_test_dir)
+        run_param.test_driver = test_driver
+        run_param.parallel_runs = 3
+        run_param.dry_run = True
+        
+        res = runner.execute_tests(run_param, ['test_normal'], log, out)
+
+        assert not res
+
+        assert log.getvalue() == ""
+
+        out_lines = out.getvalue().splitlines()
+
+        assert len(out_lines) == 1
+
+        assert out_lines[0].startswith("run [")
+        assert "test_normal" in out_lines[0]
 
     def test_many_dirs(self):
         test_driver = [py.path.local(py.__file__).dirpath('bin', 'py.test')]
@@ -180,5 +207,10 @@
         assert nfailures == 3*6
 
 
-        
+class TestRunnerNoThreads(RunnerTests):
+    with_thread = False
+
+
+class TestRunner(RunnerTests):
+    pass
 



More information about the Pypy-commit mailing list