Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import textwrap | |
|
martiniss
2016/10/03 19:14:19
unused
iannucci
2016/10/06 22:47:11
Done.
| |
| 9 | 10 |
| 10 from cStringIO import StringIO | 11 from cStringIO import StringIO |
| 11 | 12 |
| 12 from .type_definitions import DirSeen, Handler, Failure | 13 from .type_definitions import DirSeen, Handler, Failure |
| 13 from .serialize import GetCurrentData, DiffData, NonExistant | 14 from .serialize import GetCurrentData, DiffData, NonExistant |
| 14 | 15 |
| 15 | 16 |
| 16 Missing = collections.namedtuple('Missing', 'test log_lines') | 17 Missing = collections.namedtuple('Missing', 'test log_lines') |
| 17 Fail = collections.namedtuple('Fail', 'test diff log_lines') | 18 Fail = collections.namedtuple('Fail', 'test diff log_lines') |
| 18 Pass = collections.namedtuple('Pass', 'test') | 19 Pass = collections.namedtuple('Pass', 'test') |
| 19 | 20 |
| 20 | 21 |
| 22 class FailChecks(collections.namedtuple('FailChecks', 'test checks')): | |
|
dnj
2016/10/04 16:42:35
nit: use a tuple of single strings instead of a sp
iannucci
2016/10/06 22:47:11
I usually do the space delimited string because na
| |
| 23 def format(self, indent): | |
| 24 return (' '*indent+'\n').join([c.format(indent+2) for c in self.checks]) | |
| 25 | |
| 26 | |
| 21 class TestHandler(Handler): | 27 class TestHandler(Handler): |
| 22 """Run the tests.""" | 28 """Run the tests.""" |
| 23 | 29 |
| 24 @classmethod | 30 @classmethod |
| 25 def gen_stage_loop(cls, _opts, tests, put_next_stage, put_result_stage): | 31 def gen_stage_loop(cls, _opts, tests, put_next_stage, put_result_stage): |
| 26 dirs_seen = set() | 32 dirs_seen = set() |
| 27 for test in tests: | 33 for test in tests: |
| 28 subtests = test.tests | 34 subtests = test.tests |
| 29 for subtest in subtests: | 35 for subtest in subtests: |
| 30 if subtest.expect_dir not in dirs_seen: | 36 if subtest.expect_dir not in dirs_seen: |
| 31 put_result_stage(DirSeen(subtest.expect_dir)) | 37 put_result_stage(DirSeen(subtest.expect_dir)) |
| 32 dirs_seen.add(subtest.expect_dir) | 38 dirs_seen.add(subtest.expect_dir) |
| 33 put_next_stage(test) | 39 put_next_stage(test) |
| 34 | 40 |
| 35 @classmethod | 41 @classmethod |
| 36 def run_stage_loop(cls, _opts, results, put_next_stage): | 42 def run_stage_loop(cls, _opts, results, put_next_stage): |
| 37 for test, result, log_lines in results: | 43 for test, result, log_lines in results: |
| 38 current, _ = GetCurrentData(test) | 44 current, _ = GetCurrentData(test) |
| 39 if current is NonExistant: | 45 if current is NonExistant: |
| 40 put_next_stage(Missing(test, log_lines)) | 46 put_next_stage(Missing(test, log_lines)) |
| 41 else: | 47 else: |
| 42 diff = DiffData(current, result.data) | 48 diff = DiffData(current, result.data) |
| 43 if not diff: | 49 if not diff: |
| 44 put_next_stage(Pass(test)) | 50 failed_checks = [check for check in result.checks if not check.passed] |
| 51 if failed_checks: | |
| 52 put_next_stage(FailChecks(test, failed_checks)) | |
| 53 else: | |
| 54 put_next_stage(Pass(test)) | |
| 45 else: | 55 else: |
| 46 put_next_stage(Fail(test, diff, log_lines)) | 56 put_next_stage(Fail(test, diff, log_lines)) |
| 47 | 57 |
| 48 class ResultStageHandler(Handler.ResultStageHandler): | 58 class ResultStageHandler(Handler.ResultStageHandler): |
| 49 def __init__(self, *args): | 59 def __init__(self, *args): |
| 50 super(TestHandler.ResultStageHandler, self).__init__(*args) | 60 super(TestHandler.ResultStageHandler, self).__init__(*args) |
| 51 self.dirs_seen = set() | 61 self.dirs_seen = set() |
| 52 self.files_expected = collections.defaultdict(set) | 62 self.files_expected = collections.defaultdict(set) |
| 53 self.err_out = StringIO() | 63 self.err_out = StringIO() |
| 54 self.start = time.time() | 64 self.start = time.time() |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 80 | 90 |
| 81 def handle_DirSeen(self, dirseen): | 91 def handle_DirSeen(self, dirseen): |
| 82 self.dirs_seen.add(dirseen.dir) | 92 self.dirs_seen.add(dirseen.dir) |
| 83 | 93 |
| 84 def _handle_record(self, test): | 94 def _handle_record(self, test): |
| 85 self.num_tests += 1 | 95 self.num_tests += 1 |
| 86 if test.expect_path() is not None: | 96 if test.expect_path() is not None: |
| 87 head, tail = os.path.split(test.expect_path()) | 97 head, tail = os.path.split(test.expect_path()) |
| 88 self.files_expected[head].add(tail) | 98 self.files_expected[head].add(tail) |
| 89 | 99 |
| 100 def handle_FailChecks(self, fc): | |
| 101 self._handle_record(fc.test) | |
| 102 self._emit('C', fc.test, 'womba') | |
|
martiniss
2016/10/03 19:14:19
womba??
iannucci
2016/10/06 22:47:11
er, oops.
| |
| 103 self._add_result(fc.format(2), fc.test, 'FAIL CHECK', 'failed checks') | |
| 104 return Failure() | |
| 105 | |
| 90 def handle_Pass(self, p): | 106 def handle_Pass(self, p): |
| 91 self._handle_record(p.test) | 107 self._handle_record(p.test) |
| 92 if not self.opts.quiet: | 108 if not self.opts.quiet: |
| 93 self._emit('.', p.test, 'ok') | 109 self._emit('.', p.test, 'ok') |
| 94 | 110 |
| 95 def handle_Fail(self, fail): | 111 def handle_Fail(self, fail): |
| 96 self._handle_record(fail.test) | 112 self._handle_record(fail.test) |
| 97 self._emit('F', fail.test, 'FAIL') | 113 self._emit('F', fail.test, 'FAIL') |
| 98 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures', | 114 self._add_result('\n'.join(fail.diff), fail.test, 'FAIL', 'failures', |
| 99 fail.log_lines) | 115 fail.log_lines) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 self.num_tests, time.time() - self.start) | 160 self.num_tests, time.time() - self.start) |
| 145 print | 161 print |
| 146 if aborted: | 162 if aborted: |
| 147 print 'ABORTED' | 163 print 'ABORTED' |
| 148 elif self.errors: | 164 elif self.errors: |
| 149 print 'FAILED (%s)' % (', '.join('%s=%d' % i | 165 print 'FAILED (%s)' % (', '.join('%s=%d' % i |
| 150 for i in self.errors.iteritems())) | 166 for i in self.errors.iteritems())) |
| 151 elif not self.opts.quiet: | 167 elif not self.opts.quiet: |
| 152 print 'OK' | 168 print 'OK' |
| 153 | 169 |
| OLD | NEW |