File: result.py

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (124 lines) | stat: -rw-r--r-- 3,033 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright 2018 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


class ResultBase(object):
  @property
  def is_skipped(self):
    return False

  @property
  def is_grouped(self):
    return False

  @property
  def is_rerun(self):
    return False

  @property
  def as_list(self):
    return [self]


class Result(ResultBase):
  """Result created by the output processor."""

  def __init__(self,
               has_unexpected_output,
               output,
               cmd=None,
               error_details=None):
    self.has_unexpected_output = has_unexpected_output
    self.output = output
    self.cmd = cmd
    self.error_details = error_details

  def status(self):
    if self.has_unexpected_output:
      if not hasattr(self.output, "HasCrashed"):
        raise Exception(type(self))
      if self.output.HasCrashed():
        return 'CRASH'
      else:
        return 'FAIL'
    else:
      return 'PASS'


class GroupedResult(ResultBase):
  """Result consisting of multiple results. It can be used by processors that
  create multiple subtests for each test and want to pass all results back.
  """

  @staticmethod
  def create(results):
    """Create grouped result from the list of results. It filters out skipped
    results. If all results are skipped results it returns skipped result.

    Args:
      results: list of pairs (test, result)
    """
    results = [(t, r) for (t, r) in results if not r.is_skipped]
    if not results:
      return SKIPPED
    return GroupedResult(results)

  def __init__(self, results):
    self.results = results

  @property
  def is_grouped(self):
    return True


class SkippedResult(ResultBase):
  """Result without any meaningful value. Used primarily to inform the test
  processor that it's test wasn't executed.
  """

  @property
  def is_skipped(self):
    return True


SKIPPED = SkippedResult()


class RerunResult(Result):
  """Result generated from several reruns of the same test. It's a subclass of
  Result since the result of rerun is result of the last run. In addition to
  normal result it contains results of all reruns.
  """
  @staticmethod
  def create(results):
    """Create RerunResult based on list of results. List cannot be empty. If it
    has only one element it's returned as a result.
    """
    assert results

    if len(results) == 1:
      return results[0]
    return RerunResult(results)

  def __init__(self, results):
    """Has unexpected output and the output itself of the RerunResult equals to
    the last result in the passed list.
    """
    assert results

    last = results[-1]
    super(RerunResult, self).__init__(last.has_unexpected_output, last.output,
                                      last.cmd)
    self.results = results

  @property
  def is_rerun(self):
    return True

  @property
  def as_list(self):
    return self.results

  def status(self):
    return ' '.join(r.status() for r in self.results)