tests/run-tests.py
changeset 32310 b96be0098624
parent 32303 dc131b9772f2
child 32311 a77a75a428f7
equal deleted inserted replaced
32309:16a5cb4eedb7 32310:b96be0098624
  1682         num_tests = [0]
  1682         num_tests = [0]
  1683         for test in self._tests:
  1683         for test in self._tests:
  1684             def get():
  1684             def get():
  1685                 num_tests[0] += 1
  1685                 num_tests[0] += 1
  1686                 if getattr(test, 'should_reload', False):
  1686                 if getattr(test, 'should_reload', False):
  1687                     return self._loadtest(test.path, num_tests[0])
  1687                     return self._loadtest(test, num_tests[0])
  1688                 return test
  1688                 return test
  1689             if not os.path.exists(test.path):
  1689             if not os.path.exists(test.path):
  1690                 result.addSkip(test, "Doesn't exist")
  1690                 result.addSkip(test, "Doesn't exist")
  1691                 continue
  1691                 continue
  1692 
  1692 
  1780                     test = tests.pop(0)
  1780                     test = tests.pop(0)
  1781                     if self._loop:
  1781                     if self._loop:
  1782                         if getattr(test, 'should_reload', False):
  1782                         if getattr(test, 'should_reload', False):
  1783                             num_tests[0] += 1
  1783                             num_tests[0] += 1
  1784                             tests.append(
  1784                             tests.append(
  1785                                 self._loadtest(test.name, num_tests[0]))
  1785                                 self._loadtest(test, num_tests[0]))
  1786                         else:
  1786                         else:
  1787                             tests.append(test)
  1787                             tests.append(test)
  1788                     if self._jobs == 1:
  1788                     if self._jobs == 1:
  1789                         job(test, result)
  1789                         job(test, result)
  1790                     else:
  1790                     else:
  2093                     b'contrib-perf': 200,
  2093                     b'contrib-perf': 200,
  2094                    }
  2094                    }
  2095             perf = {}
  2095             perf = {}
  2096             def sortkey(f):
  2096             def sortkey(f):
  2097                 # run largest tests first, as they tend to take the longest
  2097                 # run largest tests first, as they tend to take the longest
       
  2098                 f = f['path']
  2098                 try:
  2099                 try:
  2099                     return perf[f]
  2100                     return perf[f]
  2100                 except KeyError:
  2101                 except KeyError:
  2101                     try:
  2102                     try:
  2102                         val = -os.stat(f).st_size
  2103                         val = -os.stat(f).st_size
  2260                 stdout, stderr = proc.communicate()
  2261                 stdout, stderr = proc.communicate()
  2261                 args = stdout.strip(b'\0').split(b'\0')
  2262                 args = stdout.strip(b'\0').split(b'\0')
  2262             else:
  2263             else:
  2263                 args = os.listdir(b'.')
  2264                 args = os.listdir(b'.')
  2264 
  2265 
  2265         return [t for t in args
  2266         return [{'path': t} for t in args
  2266                 if os.path.basename(t).startswith(b'test-')
  2267                 if os.path.basename(t).startswith(b'test-')
  2267                     and (t.endswith(b'.py') or t.endswith(b'.t'))]
  2268                     and (t.endswith(b'.py') or t.endswith(b'.t'))]
  2268 
  2269 
  2269     def _runtests(self, tests):
  2270     def _runtests(self, tests):
       
  2271         def _reloadtest(test, i):
       
  2272             # convert a test back to its description dict
       
  2273             desc = {'path': test.path}
       
  2274             return self._gettest(desc, i)
       
  2275 
  2270         try:
  2276         try:
  2271             if self._installdir:
  2277             if self._installdir:
  2272                 self._installhg()
  2278                 self._installhg()
  2273                 self._checkhglib("Testing")
  2279                 self._checkhglib("Testing")
  2274             else:
  2280             else:
  2278                 self._installchg()
  2284                 self._installchg()
  2279 
  2285 
  2280             if self.options.restart:
  2286             if self.options.restart:
  2281                 orig = list(tests)
  2287                 orig = list(tests)
  2282                 while tests:
  2288                 while tests:
  2283                     if os.path.exists(tests[0] + ".err"):
  2289                     if os.path.exists(tests[0]['path'] + ".err"):
  2284                         break
  2290                         break
  2285                     tests.pop(0)
  2291                     tests.pop(0)
  2286                 if not tests:
  2292                 if not tests:
  2287                     print("running all tests")
  2293                     print("running all tests")
  2288                     tests = orig
  2294                     tests = orig
  2302                               retest=self.options.retest,
  2308                               retest=self.options.retest,
  2303                               keywords=kws,
  2309                               keywords=kws,
  2304                               loop=self.options.loop,
  2310                               loop=self.options.loop,
  2305                               runs_per_test=self.options.runs_per_test,
  2311                               runs_per_test=self.options.runs_per_test,
  2306                               showchannels=self.options.showchannels,
  2312                               showchannels=self.options.showchannels,
  2307                               tests=tests, loadtest=self._gettest)
  2313                               tests=tests, loadtest=_reloadtest)
  2308             verbosity = 1
  2314             verbosity = 1
  2309             if self.options.verbose:
  2315             if self.options.verbose:
  2310                 verbosity = 2
  2316                 verbosity = 2
  2311             runner = TextTestRunner(self, verbosity=verbosity)
  2317             runner = TextTestRunner(self, verbosity=verbosity)
  2312             result = runner.run(suite)
  2318             result = runner.run(suite)
  2349         """Obtain a Test by looking at its filename.
  2355         """Obtain a Test by looking at its filename.
  2350 
  2356 
  2351         Returns a Test instance. The Test may not be runnable if it doesn't
  2357         Returns a Test instance. The Test may not be runnable if it doesn't
  2352         map to a known type.
  2358         map to a known type.
  2353         """
  2359         """
  2354         lctest = test.lower()
  2360         path = test['path']
       
  2361         lctest = path.lower()
  2355         testcls = Test
  2362         testcls = Test
  2356 
  2363 
  2357         for ext, cls in self.TESTTYPES:
  2364         for ext, cls in self.TESTTYPES:
  2358             if lctest.endswith(ext):
  2365             if lctest.endswith(ext):
  2359                 testcls = cls
  2366                 testcls = cls
  2360                 break
  2367                 break
  2361 
  2368 
  2362         refpath = os.path.join(self._testdir, test)
  2369         refpath = os.path.join(self._testdir, path)
  2363         tmpdir = os.path.join(self._hgtmp, b'child%d' % count)
  2370         tmpdir = os.path.join(self._hgtmp, b'child%d' % count)
  2364 
  2371 
  2365         t = testcls(refpath, tmpdir,
  2372         t = testcls(refpath, tmpdir,
  2366                     keeptmpdir=self.options.keep_tmpdir,
  2373                     keeptmpdir=self.options.keep_tmpdir,
  2367                     debug=self.options.debug,
  2374                     debug=self.options.debug,