Patchwork [077,of,179,tests-refactor] run-tests: move test shuffling and sorting into TestRunner

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <1da4323a9c6cdcf34e7f.1399055914@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4572/
State Accepted
Commit 3a44787e50e2db72b1886f785d4dc1f980db8807
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1398013388 25200
#      Sun Apr 20 10:03:08 2014 -0700
# Branch stable
# Node ID 1da4323a9c6cdcf34e7f15e34fdecb3cf5086910
# Parent  89428680c8a1ced4cdc1f1d816db9d974fa17d10
run-tests: move test shuffling and sorting into TestRunner

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1019,16 +1019,35 @@  class TestRunner(object):
         oldenv = dict(os.environ)
         try:
             return self._run(tests)
         finally:
             os.environ.clear()
             os.environ.update(oldenv)
 
     def _run(self, tests):
+        if self.options.random:
+            random.shuffle(tests)
+        else:
+            # keywords for slow tests
+            slow = 'svn gendoc check-code-hg'.split()
+            def sortkey(f):
+                # run largest tests first, as they tend to take the longest
+                try:
+                    val = -os.stat(f).st_size
+                except OSError, e:
+                    if e.errno != errno.ENOENT:
+                        raise
+                    return -1e9 # file does not exist, tell early
+                for kw in slow:
+                    if kw in f:
+                        val *= 10
+                return val
+            tests.sort(key=sortkey)
+
         self.testdir = os.environ['TESTDIR'] = os.getcwd()
 
         if 'PYTHONHASHSEED' not in os.environ:
             # use a random python hash seed all the time
             # we do the randomness ourself to know what seed is used
             os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
 
         if self.options.tmpdir:
@@ -1444,31 +1463,12 @@  def main(args, runner=None, parser=None)
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)
 
     runner.checktools()
 
     tests = runner.findtests(args)
 
-    if options.random:
-        random.shuffle(tests)
-    else:
-        # keywords for slow tests
-        slow = 'svn gendoc check-code-hg'.split()
-        def sortkey(f):
-            # run largest tests first, as they tend to take the longest
-            try:
-                val = -os.stat(f).st_size
-            except OSError, e:
-                if e.errno != errno.ENOENT:
-                    raise
-                return -1e9 # file does not exist, tell early
-            for kw in slow:
-                if kw in f:
-                    val *= 10
-            return val
-        tests.sort(key=sortkey)
-
     return runner.run(tests)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))