##// END OF EJS Templates
run-tests: extract sorting of tests to own function...
Gregory Szorc -
r35505:212a6e9a default
parent child Browse files
Show More
@@ -2268,6 +2268,50 b' class TextTestRunner(unittest.TextTestRu'
2268 separators=(',', ': '))
2268 separators=(',', ': '))
2269 outf.writelines(("testreport =", jsonout))
2269 outf.writelines(("testreport =", jsonout))
2270
2270
2271 def sorttests(testdescs, shuffle=False):
2272 """Do an in-place sort of tests."""
2273 if shuffle:
2274 random.shuffle(testdescs)
2275 return
2276
2277 # keywords for slow tests
2278 slow = {b'svn': 10,
2279 b'cvs': 10,
2280 b'hghave': 10,
2281 b'largefiles-update': 10,
2282 b'run-tests': 10,
2283 b'corruption': 10,
2284 b'race': 10,
2285 b'i18n': 10,
2286 b'check': 100,
2287 b'gendoc': 100,
2288 b'contrib-perf': 200,
2289 }
2290 perf = {}
2291
2292 def sortkey(f):
2293 # run largest tests first, as they tend to take the longest
2294 f = f['path']
2295 try:
2296 return perf[f]
2297 except KeyError:
2298 try:
2299 val = -os.stat(f).st_size
2300 except OSError as e:
2301 if e.errno != errno.ENOENT:
2302 raise
2303 perf[f] = -1e9 # file does not exist, tell early
2304 return -1e9
2305 for kw, mul in slow.items():
2306 if kw in f:
2307 val *= mul
2308 if f.endswith(b'.py'):
2309 val /= 10.0
2310 perf[f] = val / 1000.0
2311 return perf[f]
2312
2313 testdescs.sort(key=sortkey)
2314
2271 class TestRunner(object):
2315 class TestRunner(object):
2272 """Holds context for executing tests.
2316 """Holds context for executing tests.
2273
2317
@@ -2335,44 +2379,7 b' class TestRunner(object):'
2335 os.umask(oldmask)
2379 os.umask(oldmask)
2336
2380
2337 def _run(self, testdescs):
2381 def _run(self, testdescs):
2338 if self.options.random:
2382 sorttests(testdescs, shuffle=self.options.random)
2339 random.shuffle(testdescs)
2340 else:
2341 # keywords for slow tests
2342 slow = {b'svn': 10,
2343 b'cvs': 10,
2344 b'hghave': 10,
2345 b'largefiles-update': 10,
2346 b'run-tests': 10,
2347 b'corruption': 10,
2348 b'race': 10,
2349 b'i18n': 10,
2350 b'check': 100,
2351 b'gendoc': 100,
2352 b'contrib-perf': 200,
2353 }
2354 perf = {}
2355 def sortkey(f):
2356 # run largest tests first, as they tend to take the longest
2357 f = f['path']
2358 try:
2359 return perf[f]
2360 except KeyError:
2361 try:
2362 val = -os.stat(f).st_size
2363 except OSError as e:
2364 if e.errno != errno.ENOENT:
2365 raise
2366 perf[f] = -1e9 # file does not exist, tell early
2367 return -1e9
2368 for kw, mul in slow.items():
2369 if kw in f:
2370 val *= mul
2371 if f.endswith(b'.py'):
2372 val /= 10.0
2373 perf[f] = val / 1000.0
2374 return perf[f]
2375 testdescs.sort(key=sortkey)
2376
2383
2377 self._testdir = osenvironb[b'TESTDIR'] = getattr(
2384 self._testdir = osenvironb[b'TESTDIR'] = getattr(
2378 os, 'getcwdb', os.getcwd)()
2385 os, 'getcwdb', os.getcwd)()
General Comments 0
You need to be logged in to leave comments. Login now