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

pedronis at codespeak.net pedronis at codespeak.net
Mon Sep 22 16:20:55 CEST 2008


Author: pedronis
Date: Mon Sep 22 16:20:52 2008
New Revision: 58321

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

added first incarnation of testdirs collecting code



Modified: pypy/build/testrunner/runner.py
==============================================================================
--- pypy/build/testrunner/runner.py	(original)
+++ pypy/build/testrunner/runner.py	Mon Sep 22 16:20:52 2008
@@ -1,6 +1,6 @@
 import sys, os, signal
 import py
-from py.compat import subprocess
+from py.compat import subprocess, optparse
 
 
 def run(args, cwd, out):
@@ -59,6 +59,63 @@
 
     return failure
 
-        
-        
-        
+
+def is_test_py_file(p):
+    name = p.basename
+    return name.startswith('test_') and name.endswith('.py')
+
+def collect_one_testdir(testdirs, root, reldir, tests):
+    testdirs.append(reldir)
+    return
+
+def collect_testdirs(testdirs, p, root=None):
+    if root is None:
+        root = p
+
+    reldir = p.relto(root)
+    entries = [p1 for p1 in p.listdir() if p1.check(dotfile=0)]
+
+    if p != root:
+        for p1 in entries:
+            if is_test_py_file(p1):
+                collect_one_testdir(testdirs, root, reldir,
+                                   [t for t in entries if is_test_py_file(t)])
+                return
+
+    for p1 in entries:
+        if p1.check(dir=1, link=0):
+            collect_testdirs(testdirs, p1, root=root)
+
+
+if __name__ == '__main__':
+    parser = optparse.OptionParser()
+    parser.add_option("--logfile", dest="logfile", default=None,
+                      help="accumulated machine-readable logfile")
+    parser.add_option("--output", dest="output", default='-',
+                      help="plain test output (default: stdout)")
+    parser.add_option("--config", dest="config", default=None,
+                      help="configuration python file (optional)")
+    parser.add_option("--root", dest="root", default=".",
+                      help="root directory for the run")
+    opts, args = parser.parse_args()
+
+    if opts.logfile is None:
+        print "no logfile specified"
+        sys.exit(2)
+
+    logfile = open(opts.logfile, "w")
+    if opts.output == '-':
+        out = sys.stdout
+    else:
+        out = open(opts.output, "w")
+
+    root = py.path.local(opts.root)
+
+    testdirs = []
+    
+    collect_testdirs(testdirs, root)
+
+    res = execute_tests(root, testdirs, logfile, out)
+
+    if res:
+        sys.exit(1)

Modified: pypy/build/testrunner/test/test_runner.py
==============================================================================
--- pypy/build/testrunner/test/test_runner.py	(original)
+++ pypy/build/testrunner/test/test_runner.py	Mon Sep 22 16:20:52 2008
@@ -69,6 +69,13 @@
     def teardown_class(cls):
         pass
 
+    def test_collect_testdirs_simple(self):
+        res = []
+        runner.collect_testdirs(res, self.udir)
+
+        assert res == ['test_normal']
+        
+
     def test_one_dir(self):
         test_driver = [py.path.local(py.__file__).dirpath('bin', 'py.test')]
 



More information about the Pypy-commit mailing list