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

Side by Side Diff: expect_tests/handle_test.py

Issue 412773002: Copy expect_tests from build (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests@master
Patch Set: Fancy ast walker Created 6 years, 4 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
« no previous file with comments | « expect_tests/handle_list.py ('k') | expect_tests/handle_train.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 expect_tests.type_definitions import Handler, Failure
12 from expect_tests.serialize import GetCurrentData, DiffData, NonExistant
13
14
15 Missing = collections.namedtuple('Missing', 'test log_lines')
16 Fail = collections.namedtuple('Fail', 'test diff log_lines')
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, log_lines in results:
25 current, _ = GetCurrentData(test)
26 if current is NonExistant:
27 put_next_stage(Missing(test, log_lines))
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, log_lines))
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, test, header, category, log_lines=()):
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:
59 print >> self.err_out, msg
60 if log_lines:
61 print >> self.err_out, '==== captured logging output ===='
62 print >> self.err_out, '\n'.join(log_lines)
63 self.errors[category] += 1
64 self.num_tests += 1
65
66 def handle_Pass(self, p):
67 if not self.opts.quiet:
68 self._emit('.', p.test, 'ok')
69 self.num_tests += 1
70
71 def handle_Fail(self, fail):
72 self._emit('F', fail.test, 'FAIL')
73 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures',
74 fail.log_lines)
75 return Failure()
76
77 def handle_TestError(self, test_error):
78 self._emit('E', test_error.test, 'ERROR')
79 self._add_result(test_error.message, test_error.test, 'ERROR', 'errors',
80 test_error.log_lines)
81 return Failure()
82
83 def handle_UnknownError(self, error):
84 self._emit('U', None, 'UNKNOWN ERROR')
85 self._add_result(error.message, None, 'UNKNOWN ERROR', 'unknown_errors')
86 return Failure()
87
88 def handle_Missing(self, missing):
89 self._emit('M', missing.test, 'MISSING')
90 self._add_result('', missing.test, 'MISSING', 'missing',
91 missing.log_lines)
92 return Failure()
93
94 def finalize(self, aborted):
95 # TODO(iannucci): print summary stats (and timing info?)
96 buf = self.err_out.getvalue()
97 if buf:
98 print
99 print buf
100 if not self.opts.quiet:
101 print
102 print '-' * 70
103 print 'Ran %d tests in %0.3fs' % (
104 self.num_tests, time.time() - self.start)
105 print
106 if aborted:
107 print 'ABORTED'
108 elif self.errors:
109 print 'FAILED (%s)' % (', '.join('%s=%d' % i
110 for i in self.errors.iteritems()))
111 elif not self.opts.quiet:
112 print 'OK'
113
OLDNEW
« no previous file with comments | « expect_tests/handle_list.py ('k') | expect_tests/handle_train.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698