OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import sys |
| 6 import time |
| 7 import collections |
| 8 |
| 9 from cStringIO import StringIO |
| 10 |
| 11 from .types import Handler |
| 12 from .serialize import GetCurrentData, DiffData, NonExistant |
| 13 |
| 14 Missing = collections.namedtuple('Missing', 'test') |
| 15 Fail = collections.namedtuple('Fail', 'test diff') |
| 16 Pass = collections.namedtuple('Pass', 'test') |
| 17 |
| 18 class TestHandler(Handler): |
| 19 """Run the tests.""" |
| 20 @classmethod |
| 21 def run_stage_loop(cls, _opts, results, put_next_stage): |
| 22 for test, result in results: |
| 23 current, _ = GetCurrentData(test) |
| 24 if current is NonExistant: |
| 25 put_next_stage(Missing(test)) |
| 26 else: |
| 27 diff = DiffData(current, result.data) |
| 28 if not diff: |
| 29 put_next_stage(Pass(test)) |
| 30 else: |
| 31 put_next_stage(Fail(test, diff)) |
| 32 |
| 33 class ResultStageHandler(Handler.ResultStageHandler): |
| 34 def __init__(self, *args): |
| 35 super(TestHandler.ResultStageHandler, self).__init__(*args) |
| 36 self.err_out = StringIO() |
| 37 self.start = time.time() |
| 38 self.errors = collections.defaultdict(int) |
| 39 self.num_tests = 0 |
| 40 |
| 41 def _emit(self, short, test, verbose): |
| 42 if self.opts.verbose: |
| 43 print >> sys.stdout, '%s ... %s' % (test.name if test else '????', |
| 44 verbose) |
| 45 else: |
| 46 sys.stdout.write(short) |
| 47 sys.stdout.flush() |
| 48 |
| 49 def _add_result(self, msg_lines, test, header, category): |
| 50 print >> self.err_out |
| 51 print >> self.err_out, '=' * 70 |
| 52 if test is not None: |
| 53 print >> self.err_out, '%s: %s (%s)' % ( |
| 54 header, test.name, test.expect_path()) |
| 55 print >> self.err_out, '-' * 70 |
| 56 if msg_lines: |
| 57 print >> self.err_out, '\n'.join(msg_lines) |
| 58 self.errors[category] += 1 |
| 59 self.num_tests += 1 |
| 60 |
| 61 # Handlers |
| 62 def Pass(self, p): |
| 63 if not self.opts.quiet: |
| 64 self._emit('.', p.test, 'ok') |
| 65 self.num_tests += 1 |
| 66 |
| 67 def Fail(self, fail): |
| 68 self._emit('F', fail.test, 'FAIL') |
| 69 self._add_result(fail.diff, fail.test, 'FAIL', 'failures') |
| 70 return False |
| 71 |
| 72 def TestError(self, test_error): |
| 73 self._emit('E', test_error.test, 'ERROR') |
| 74 self._add_result([test_error.message], test_error.test, 'ERROR', 'errors') |
| 75 return False |
| 76 |
| 77 def UnknownError(self, error): |
| 78 self._emit('U', None, 'UNKNOWN ERROR') |
| 79 self._add_result([error.message], None, 'UNKNOWN ERROR', 'unknown_errors') |
| 80 return False |
| 81 |
| 82 def Missing(self, missing): |
| 83 self._emit('M', missing.test, 'MISSING') |
| 84 self._add_result([], missing.test, 'MISSING', 'missing') |
| 85 return False |
| 86 |
| 87 def finalize(self, aborted): |
| 88 # TODO(iannucci): print summary stats (and timing info?) |
| 89 buf = self.err_out.getvalue() |
| 90 if buf: |
| 91 print |
| 92 print buf |
| 93 if not self.opts.quiet: |
| 94 print |
| 95 print '-' * 70 |
| 96 print 'Ran %d tests in %0.3fs' % ( |
| 97 self.num_tests, time.time() - self.start) |
| 98 print |
| 99 if aborted: |
| 100 print 'ABORTED' |
| 101 elif self.errors: |
| 102 print 'FAILED (%s)' % (', '.join('%s=%d' % i |
| 103 for i in self.errors.iteritems())) |
| 104 elif not self.opts.quiet: |
| 105 print 'OK' |
| 106 |
OLD | NEW |