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

Side by Side Diff: third_party/recipe_engine/expect_tests/handle_test.py

Issue 1347263002: Revert of Cross-repo recipe package system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 years, 3 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 collections
6 import os
7 import sys
8 import time
9
10 from cStringIO import StringIO
11
12 from .type_definitions import DirSeen, Handler, Failure
13 from .serialize import GetCurrentData, DiffData, NonExistant
14
15
16 Missing = collections.namedtuple('Missing', 'test log_lines')
17 Fail = collections.namedtuple('Fail', 'test diff log_lines')
18 Pass = collections.namedtuple('Pass', 'test')
19
20
21 class TestHandler(Handler):
22 """Run the tests."""
23
24 @classmethod
25 def gen_stage_loop(cls, _opts, tests, put_next_stage, put_result_stage):
26 dirs_seen = set()
27 for test in tests:
28 subtests = test.tests
29 for subtest in subtests:
30 if subtest.expect_dir not in dirs_seen:
31 put_result_stage(DirSeen(subtest.expect_dir))
32 dirs_seen.add(subtest.expect_dir)
33 put_next_stage(test)
34
35 @classmethod
36 def run_stage_loop(cls, _opts, results, put_next_stage):
37 for test, result, log_lines in results:
38 current, _ = GetCurrentData(test)
39 if current is NonExistant:
40 put_next_stage(Missing(test, log_lines))
41 else:
42 diff = DiffData(current, result.data)
43 if not diff:
44 put_next_stage(Pass(test))
45 else:
46 put_next_stage(Fail(test, diff, log_lines))
47
48 class ResultStageHandler(Handler.ResultStageHandler):
49 def __init__(self, *args):
50 super(TestHandler.ResultStageHandler, self).__init__(*args)
51 self.dirs_seen = set()
52 self.files_expected = collections.defaultdict(set)
53 self.err_out = StringIO()
54 self.start = time.time()
55 self.errors = collections.defaultdict(int)
56 self.num_tests = 0
57
58 def _emit(self, short, test, verbose):
59 if self.opts.verbose:
60 print >> sys.stdout, '%s ... %s' % (test.name if test else '????',
61 verbose)
62 else:
63 sys.stdout.write(short)
64 sys.stdout.flush()
65
66 def _add_result(self, msg, test, header, category, log_lines=()):
67 print >> self.err_out
68 print >> self.err_out, '=' * 70
69 if test is not None:
70 print >> self.err_out, '%s: %s (%s)' % (
71 header, test.name, test.expect_path())
72 print >> self.err_out, '-' * 70
73 if msg:
74 print >> self.err_out, msg
75 if log_lines:
76 print >> self.err_out, '==== captured logging output ===='
77 print >> self.err_out, '\n'.join(log_lines)
78 self.errors[category] += 1
79 self.num_tests += 1
80
81 def handle_DirSeen(self, dirseen):
82 self.dirs_seen.add(dirseen.dir)
83
84 def _handle_record(self, test):
85 self.num_tests += 1
86 if test.expect_path() is not None:
87 head, tail = os.path.split(test.expect_path())
88 self.files_expected[head].add(tail)
89
90 def handle_Pass(self, p):
91 self._handle_record(p.test)
92 if not self.opts.quiet:
93 self._emit('.', p.test, 'ok')
94
95 def handle_Fail(self, fail):
96 self._handle_record(fail.test)
97 self._emit('F', fail.test, 'FAIL')
98 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures',
99 fail.log_lines)
100 return Failure()
101
102 def handle_TestError(self, test_error):
103 self._handle_record(test_error.test)
104 self._emit('E', test_error.test, 'ERROR')
105 self._add_result(test_error.message, test_error.test, 'ERROR', 'errors',
106 test_error.log_lines)
107 return Failure()
108
109 def handle_UnknownError(self, error):
110 self._handle_record(error.test)
111 self._emit('U', None, 'UNKNOWN ERROR')
112 self._add_result(error.message, None, 'UNKNOWN ERROR', 'unknown_errors')
113 return Failure()
114
115 def handle_Missing(self, missing):
116 self._handle_record(missing.test)
117 self._emit('M', missing.test, 'MISSING')
118 self._add_result('', missing.test, 'MISSING', 'missing',
119 missing.log_lines)
120 return Failure()
121
122 def finalize(self, aborted):
123 # TODO(iannucci): print summary stats (and timing info?)
124 if not aborted and not self.opts.test_glob:
125 for d in self.dirs_seen:
126 expected = self.files_expected[d]
127 for f in os.listdir(d):
128 # Skip OWNERS files and files beginning with a '.' (like '.svn')
129 if f == 'OWNERS' or f[0] == '.':
130 continue
131 if f not in expected:
132 path = os.path.join(d, f)
133 self._add_result('Unexpected file %s' % path, None, 'UNEXPECTED',
134 'unexpected_file')
135
136 buf = self.err_out.getvalue()
137 if buf:
138 print
139 print buf
140 if not self.opts.quiet:
141 print
142 print '-' * 70
143 print 'Ran %d tests in %0.3fs' % (
144 self.num_tests, time.time() - self.start)
145 print
146 if aborted:
147 print 'ABORTED'
148 elif self.errors:
149 print 'FAILED (%s)' % (', '.join('%s=%d' % i
150 for i in self.errors.iteritems()))
151 elif not self.opts.quiet:
152 print 'OK'
153
OLDNEW
« no previous file with comments | « third_party/recipe_engine/expect_tests/handle_list.py ('k') | third_party/recipe_engine/expect_tests/handle_train.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698