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

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

Issue 2387763003: Add initial postprocess unit test thingy. (Closed)
Patch Set: rewrite parser code Created 4 years, 2 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections 5 import collections
6 import os 6 import os
7 import sys 7 import sys
8 import time 8 import time
9 9
10 from cStringIO import StringIO 10 from cStringIO import StringIO
11 11
12 from .type_definitions import DirSeen, Handler, Failure 12 from .type_definitions import DirSeen, Handler, Failure
13 from .serialize import GetCurrentData, DiffData, NonExistant 13 from .serialize import GetCurrentData, DiffData, NonExistant
14 14
15 15
16 Missing = collections.namedtuple('Missing', 'test log_lines') 16 Missing = collections.namedtuple('Missing', 'test log_lines')
17 Fail = collections.namedtuple('Fail', 'test diff log_lines') 17 Fail = collections.namedtuple('Fail', 'test diff log_lines')
18 Pass = collections.namedtuple('Pass', 'test') 18 Pass = collections.namedtuple('Pass', 'test')
19 19
20 20
21 class FailChecks(collections.namedtuple('FailChecks', 'test checks')):
22 def format(self, indent):
23 return (' '*indent+'\n').join([c.format(indent+2) for c in self.checks])
24
25
21 class TestHandler(Handler): 26 class TestHandler(Handler):
22 """Run the tests.""" 27 """Run the tests."""
23 28
24 @classmethod 29 @classmethod
25 def gen_stage_loop(cls, _opts, tests, put_next_stage, put_result_stage): 30 def gen_stage_loop(cls, _opts, tests, put_next_stage, put_result_stage):
26 dirs_seen = set() 31 dirs_seen = set()
27 for test in tests: 32 for test in tests:
28 subtests = test.tests 33 subtests = test.tests
29 for subtest in subtests: 34 for subtest in subtests:
30 if subtest.expect_dir not in dirs_seen: 35 if subtest.expect_dir not in dirs_seen:
31 put_result_stage(DirSeen(subtest.expect_dir)) 36 put_result_stage(DirSeen(subtest.expect_dir))
32 dirs_seen.add(subtest.expect_dir) 37 dirs_seen.add(subtest.expect_dir)
33 put_next_stage(test) 38 put_next_stage(test)
34 39
35 @classmethod 40 @classmethod
36 def run_stage_loop(cls, _opts, results, put_next_stage): 41 def run_stage_loop(cls, _opts, results, put_next_stage):
37 for test, result, log_lines in results: 42 for test, result, log_lines in results:
38 current, _ = GetCurrentData(test) 43 current, _ = GetCurrentData(test)
39 if current is NonExistant: 44 if current is NonExistant:
40 put_next_stage(Missing(test, log_lines)) 45 put_next_stage(Missing(test, log_lines))
41 else: 46 else:
42 diff = DiffData(current, result.data) 47 diff = DiffData(current, result.data)
43 if not diff: 48 if not diff:
44 put_next_stage(Pass(test)) 49 failed_checks = [check for check in result.checks if not check.passed]
50 if failed_checks:
51 put_next_stage(FailChecks(test, failed_checks))
52 else:
53 put_next_stage(Pass(test))
45 else: 54 else:
46 put_next_stage(Fail(test, diff, log_lines)) 55 put_next_stage(Fail(test, diff, log_lines))
47 56
48 class ResultStageHandler(Handler.ResultStageHandler): 57 class ResultStageHandler(Handler.ResultStageHandler):
49 def __init__(self, *args): 58 def __init__(self, *args):
50 super(TestHandler.ResultStageHandler, self).__init__(*args) 59 super(TestHandler.ResultStageHandler, self).__init__(*args)
51 self.dirs_seen = set() 60 self.dirs_seen = set()
52 self.files_expected = collections.defaultdict(set) 61 self.files_expected = collections.defaultdict(set)
53 self.err_out = StringIO() 62 self.err_out = StringIO()
54 self.start = time.time() 63 self.start = time.time()
(...skipping 25 matching lines...) Expand all
80 89
81 def handle_DirSeen(self, dirseen): 90 def handle_DirSeen(self, dirseen):
82 self.dirs_seen.add(dirseen.dir) 91 self.dirs_seen.add(dirseen.dir)
83 92
84 def _handle_record(self, test): 93 def _handle_record(self, test):
85 self.num_tests += 1 94 self.num_tests += 1
86 if test.expect_path() is not None: 95 if test.expect_path() is not None:
87 head, tail = os.path.split(test.expect_path()) 96 head, tail = os.path.split(test.expect_path())
88 self.files_expected[head].add(tail) 97 self.files_expected[head].add(tail)
89 98
99 def handle_FailChecks(self, fc):
100 self._handle_record(fc.test)
101 self._emit('C', fc.test, 'FAIL CHECK')
102 self._add_result(fc.format(2), fc.test, 'FAIL CHECK', 'failed checks')
103 return Failure()
104
90 def handle_Pass(self, p): 105 def handle_Pass(self, p):
91 self._handle_record(p.test) 106 self._handle_record(p.test)
92 if not self.opts.quiet: 107 if not self.opts.quiet:
93 self._emit('.', p.test, 'ok') 108 self._emit('.', p.test, 'ok')
94 109
95 def handle_Fail(self, fail): 110 def handle_Fail(self, fail):
96 self._handle_record(fail.test) 111 self._handle_record(fail.test)
97 self._emit('F', fail.test, 'FAIL') 112 self._emit('F', fail.test, 'FAIL')
98 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures', 113 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures',
99 fail.log_lines) 114 fail.log_lines)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 self.num_tests, time.time() - self.start) 159 self.num_tests, time.time() - self.start)
145 print 160 print
146 if aborted: 161 if aborted:
147 print 'ABORTED' 162 print 'ABORTED'
148 elif self.errors: 163 elif self.errors:
149 print 'FAILED (%s)' % (', '.join('%s=%d' % i 164 print 'FAILED (%s)' % (', '.join('%s=%d' % i
150 for i in self.errors.iteritems())) 165 for i in self.errors.iteritems()))
151 elif not self.opts.quiet: 166 elif not self.opts.quiet:
152 print 'OK' 167 print 'OK'
153 168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698