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