xref: /aosp_15_r20/external/angle/scripts/angle_presubmit_utils.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/env python3
2# Copyright 2020 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""
6angle_presubmit_utils: Mock depot_tools class for ANGLE presubmit checks's unittests
7"""
8
9
10class Change_mock():
11
12    def __init__(self, description_text):
13        self.description_text = description_text
14
15    def DescriptionText(self):
16        return self.description_text
17
18
19class AffectedFile_mock():
20
21    def __init__(self, diff):
22        self.diff = diff
23
24    def GenerateScmDiff(self):
25        return self.diff
26
27
28class InputAPI_mock():
29
30    def __init__(self, description_text, source_files=[]):
31        self.change = Change_mock(description_text)
32        self.source_files = source_files
33
34    def PresubmitLocalPath(self):
35        return self.cwd
36
37    def AffectedSourceFiles(self, source_filter):
38        return self.source_files
39
40
41class _PresubmitResult(object):
42    """Base class for result objects."""
43    fatal = False
44    should_prompt = False
45
46    def __init__(self, message, long_text=''):
47        self._message = message
48
49    def __eq__(self, other):
50        return self.fatal == other.fatal and self.should_prompt == other.should_prompt \
51            and self._message == other._message
52
53
54# Top level object so multiprocessing can pickle
55# Public access through OutputApi object.
56class _PresubmitError(_PresubmitResult):
57    """A hard presubmit error."""
58    fatal = True
59
60
61# Top level object so multiprocessing can pickle
62# Public access through OutputApi object.
63class _PresubmitPromptWarning(_PresubmitResult):
64    """An warning that prompts the user if they want to continue."""
65    should_prompt = True
66
67
68# Top level object so multiprocessing can pickle
69# Public access through OutputApi object.
70class _PresubmitNotifyResult(_PresubmitResult):
71    """Just print something to the screen -- but it's not even a warning."""
72    pass
73
74
75class OutputAPI_mock():
76    PresubmitResult = _PresubmitResult
77    PresubmitError = _PresubmitError
78    PresubmitPromptWarning = _PresubmitPromptWarning
79    PresubmitNotifyResult = _PresubmitNotifyResult
80