Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1954)

Side by Side Diff: scripts/slave/unittests/expect_tests/handle_test.py

Issue 220353003: Replace recipes_test.py with a new parallel expectation-based test runner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: fix coverage race Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 .type_definitions import Handler, Failure
12 from .serialize import GetCurrentData, DiffData, NonExistant
13
14
15 Missing = collections.namedtuple('Missing', 'test')
16 Fail = collections.namedtuple('Fail', 'test diff')
17 Pass = collections.namedtuple('Pass', 'test')
18
19
20 class TestHandler(Handler):
21 """Run the tests."""
22 @classmethod
23 def run_stage_loop(cls, _opts, results, put_next_stage):
24 for test, result in results:
25 current, _ = GetCurrentData(test)
26 if current is NonExistant:
27 put_next_stage(Missing(test))
28 else:
29 diff = DiffData(current, result.data)
30 if not diff:
31 put_next_stage(Pass(test))
32 else:
33 put_next_stage(Fail(test, diff))
34
35 class ResultStageHandler(Handler.ResultStageHandler):
36 def __init__(self, *args):
37 super(TestHandler.ResultStageHandler, self).__init__(*args)
38 self.err_out = StringIO()
39 self.start = time.time()
40 self.errors = collections.defaultdict(int)
41 self.num_tests = 0
42
43 def _emit(self, short, test, verbose):
44 if self.opts.verbose:
45 print >> sys.stdout, '%s ... %s' % (test.name if test else '????',
46 verbose)
47 else:
48 sys.stdout.write(short)
49 sys.stdout.flush()
50
51 def _add_result(self, msg_lines, test, header, category):
52 print >> self.err_out
53 print >> self.err_out, '=' * 70
54 if test is not None:
55 print >> self.err_out, '%s: %s (%s)' % (
56 header, test.name, test.expect_path())
57 print >> self.err_out, '-' * 70
58 if msg_lines:
59 print >> self.err_out, '\n'.join(msg_lines)
60 self.errors[category] += 1
61 self.num_tests += 1
62
63 def handle_Pass(self, p):
64 if not self.opts.quiet:
65 self._emit('.', p.test, 'ok')
66 self.num_tests += 1
67
68 def handle_Fail(self, fail):
69 self._emit('F', fail.test, 'FAIL')
70 self._add_result(fail.diff, fail.test, 'FAIL', 'failures')
71 return Failure()
72
73 def handle_TestError(self, test_error):
74 self._emit('E', test_error.test, 'ERROR')
75 self._add_result([test_error.message], test_error.test, 'ERROR', 'errors')
76 return Failure()
77
78 def handle_UnknownError(self, error):
79 self._emit('U', None, 'UNKNOWN ERROR')
80 self._add_result([error.message], None, 'UNKNOWN ERROR', 'unknown_errors')
81 return Failure()
82
83 def handle_Missing(self, missing):
84 self._emit('M', missing.test, 'MISSING')
85 self._add_result([], missing.test, 'MISSING', 'missing')
86 return Failure()
87
88 def finalize(self, aborted):
89 # TODO(iannucci): print summary stats (and timing info?)
90 buf = self.err_out.getvalue()
91 if buf:
92 print
93 print buf
94 if not self.opts.quiet:
95 print
96 print '-' * 70
97 print 'Ran %d tests in %0.3fs' % (
98 self.num_tests, time.time() - self.start)
99 print
100 if aborted:
101 print 'ABORTED'
102 elif self.errors:
103 print 'FAILED (%s)' % (', '.join('%s=%d' % i
104 for i in self.errors.iteritems()))
105 elif not self.opts.quiet:
106 print 'OK'
107
OLDNEW
« no previous file with comments | « scripts/slave/unittests/expect_tests/handle_list.py ('k') | scripts/slave/unittests/expect_tests/handle_train.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698