1# Copyright 2018 the V8 project 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 6class ResultBase(object): 7 @property 8 def is_skipped(self): 9 return False 10 11 @property 12 def is_grouped(self): 13 return False 14 15 @property 16 def is_rerun(self): 17 return False 18 19 20class Result(ResultBase): 21 """Result created by the output processor.""" 22 23 def __init__(self, has_unexpected_output, output, cmd=None): 24 self.has_unexpected_output = has_unexpected_output 25 self.output = output 26 self.cmd = cmd 27 28 29class GroupedResult(ResultBase): 30 """Result consisting of multiple results. It can be used by processors that 31 create multiple subtests for each test and want to pass all results back. 32 """ 33 34 @staticmethod 35 def create(results): 36 """Create grouped result from the list of results. It filters out skipped 37 results. If all results are skipped results it returns skipped result. 38 39 Args: 40 results: list of pairs (test, result) 41 """ 42 results = [(t, r) for (t, r) in results if not r.is_skipped] 43 if not results: 44 return SKIPPED 45 return GroupedResult(results) 46 47 def __init__(self, results): 48 self.results = results 49 50 @property 51 def is_grouped(self): 52 return True 53 54 55class SkippedResult(ResultBase): 56 """Result without any meaningful value. Used primarily to inform the test 57 processor that it's test wasn't executed. 58 """ 59 60 @property 61 def is_skipped(self): 62 return True 63 64 65SKIPPED = SkippedResult() 66 67 68class RerunResult(Result): 69 """Result generated from several reruns of the same test. It's a subclass of 70 Result since the result of rerun is result of the last run. In addition to 71 normal result it contains results of all reruns. 72 """ 73 @staticmethod 74 def create(results): 75 """Create RerunResult based on list of results. List cannot be empty. If it 76 has only one element it's returned as a result. 77 """ 78 assert results 79 80 if len(results) == 1: 81 return results[0] 82 return RerunResult(results) 83 84 def __init__(self, results): 85 """Has unexpected output and the output itself of the RerunResult equals to 86 the last result in the passed list. 87 """ 88 assert results 89 90 last = results[-1] 91 super(RerunResult, self).__init__(last.has_unexpected_output, last.output, 92 last.cmd) 93 self.results = results 94 95 @property 96 def is_rerun(self): 97 return True 98