[PATCH 1 of 3 V2] run-tests: change test identity from a path to a dict

Jun Wu quark at fb.com
Wed May 17 15:23:27 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1493491247 25200
#      Sat Apr 29 11:40:47 2017 -0700
# Node ID 8fb560751eb7e72e87a9c49dee66d2de8bbcfe8e
# Parent  7040f5131454b0ae9117ec10a9f33352a04746a3
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8fb560751eb7
run-tests: change test identity from a path to a dict

Previously, we use path to identify a test. A later patch adds more
information so a path is not enough to identify a test. So we change it to a
dictionary.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1690,5 +1690,5 @@ class TestSuite(unittest.TestSuite):
                 num_tests[0] += 1
                 if getattr(test, 'should_reload', False):
-                    return self._loadtest(test.path, num_tests[0])
+                    return self._loadtest(test, num_tests[0])
                 return test
             if not os.path.exists(test.path):
@@ -1788,5 +1788,5 @@ class TestSuite(unittest.TestSuite):
                             num_tests[0] += 1
                             tests.append(
-                                self._loadtest(test.name, num_tests[0]))
+                                self._loadtest(test, num_tests[0]))
                         else:
                             tests.append(test)
@@ -2101,4 +2101,5 @@ class TestRunner(object):
             def sortkey(f):
                 # run largest tests first, as they tend to take the longest
+                f = f['path']
                 try:
                     return perf[f]
@@ -2268,9 +2269,14 @@ class TestRunner(object):
                 args = os.listdir(b'.')
 
-        return [t for t in args
+        return [{'path': t} for t in args
                 if os.path.basename(t).startswith(b'test-')
                     and (t.endswith(b'.py') or t.endswith(b'.t'))]
 
     def _runtests(self, tests):
+        def _reloadtest(test, i):
+            # convert a test back to its description dict
+            desc = {'path': test.path}
+            return self._gettest(desc, i)
+
         try:
             if self._installdir:
@@ -2286,5 +2292,5 @@ class TestRunner(object):
                 orig = list(tests)
                 while tests:
-                    if os.path.exists(tests[0] + ".err"):
+                    if os.path.exists(tests['path'][0] + ".err"):
                         break
                     tests.pop(0)
@@ -2310,5 +2316,5 @@ class TestRunner(object):
                               runs_per_test=self.options.runs_per_test,
                               showchannels=self.options.showchannels,
-                              tests=tests, loadtest=self._gettest)
+                              tests=tests, loadtest=_reloadtest)
             verbosity = 1
             if self.options.verbose:
@@ -2357,5 +2363,6 @@ class TestRunner(object):
         map to a known type.
         """
-        lctest = test.lower()
+        path = test['path']
+        lctest = path.lower()
         testcls = Test
 
@@ -2365,5 +2372,5 @@ class TestRunner(object):
                 break
 
-        refpath = os.path.join(self._testdir, test)
+        refpath = os.path.join(self._testdir, path)
         tmpdir = os.path.join(self._hgtmp, b'child%d' % count)
 


More information about the Mercurial-devel mailing list