Mercurial > hg
changeset 21362:ff4ce72cc8d6
run-tests: move scheduletests() into TestRunner
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 00:12:26 -0700 |
parents | 0fdf92500012 |
children | 00e5f5b9fc90 |
files | tests/run-tests.py |
diffstat | 1 files changed, 41 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Sun Apr 20 00:10:06 2014 -0700 +++ b/tests/run-tests.py Sun Apr 20 00:12:26 2014 -0700 @@ -995,45 +995,6 @@ iolock = threading.Lock() -def scheduletests(runner, tests): - jobs = runner.options.jobs - done = queue.Queue() - running = 0 - count = 0 - - def job(test, count): - try: - t = runner.gettest(test, count) - done.put(t.run()) - t.cleanup() - except KeyboardInterrupt: - pass - except: # re-raises - done.put(('!', test, 'run-test raised an error, see traceback')) - raise - - try: - while tests or running: - if not done.empty() or running == jobs or not tests: - try: - code, test, msg = done.get(True, 1) - runner.results[code].append((test, msg)) - if runner.options.first and code not in '.si': - break - except queue.Empty: - continue - running -= 1 - if tests and not running == jobs: - test = tests.pop(0) - if runner.options.loop: - tests.append(test) - t = threading.Thread(target=job, name=test, args=(test, count)) - t.start() - running += 1 - count += 1 - except KeyboardInterrupt: - runner.abort[0] = True - class TestRunner(object): """Holds context for executing tests. @@ -1083,7 +1044,7 @@ print "running all tests" tests = orig - scheduletests(self, tests) + self._executetests(tests) failed = len(self.results['!']) warned = len(self.results['~']) @@ -1311,6 +1272,46 @@ os.mkdir(adir) covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit) + def _executetests(self, tests): + jobs = self.options.jobs + done = queue.Queue() + running = 0 + count = 0 + + def job(test, count): + try: + t = self.gettest(test, count) + done.put(t.run()) + t.cleanup() + except KeyboardInterrupt: + pass + except: # re-raises + done.put(('!', test, 'run-test raised an error, see traceback')) + raise + + try: + while tests or running: + if not done.empty() or running == jobs or not tests: + try: + code, test, msg = done.get(True, 1) + self.results[code].append((test, msg)) + if self.options.first and code not in '.si': + break + except queue.Empty: + continue + running -= 1 + if tests and not running == jobs: + test = tests.pop(0) + if self.options.loop: + tests.append(test) + t = threading.Thread(target=job, name=test, + args=(test, count)) + t.start() + running += 1 + count += 1 + except KeyboardInterrupt: + self.abort[0] = True + def main(args, parser=None): runner = TestRunner()