Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / tools / mb / PRESUBMIT_test.py
1 #!/usr/bin/env python3
2 # Copyright 2021 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import time
7 import unittest
8
9 import PRESUBMIT
10
11
12 class PresubmitError:
13   def __init__(self, message):
14     self.message = message
15
16   def __eq__(self, other):
17     return isinstance(other, PresubmitError) and self.message == other.message
18
19   def __repr__(self):
20     return 'PresubmitError({!r})'.format(self.message)
21
22
23 class TestCheckFreeze(unittest.TestCase):
24   def get_input_api(self, current_time, footers=None):
25     """Get an input API to use for tests.
26
27     Args:
28       current_time - Current time expressed as seconds since the epoch.
29     """
30
31     class FakeTime:
32
33       localtime = time.localtime
34       strftime = time.strftime
35
36       def time(self):
37         return float(current_time)
38
39     class FakeChange:
40       def GitFootersFromDescription(self):
41         return footers or []
42
43     class FakeInputApi:
44
45       time = FakeTime()
46       change = FakeChange()
47       no_diffs = False
48
49     return FakeInputApi()
50
51   def get_output_api(self):
52     class FakeOutputApi:
53
54       PresubmitError = PresubmitError
55
56     return FakeOutputApi
57
58   def test_before_freeze(self):
59     input_api = self.get_input_api(PRESUBMIT._FREEZE_START - 1)
60     output_api = self.get_output_api()
61
62     errors = PRESUBMIT.CheckFreeze(input_api, output_api)
63
64     self.assertEqual(errors, [])
65
66   def test_start_of_freeze(self):
67     input_api = self.get_input_api(PRESUBMIT._FREEZE_START + 1)
68     output_api = self.get_output_api()
69
70     errors = PRESUBMIT.CheckFreeze(input_api, output_api)
71
72     self.assertEqual(len(errors), 1)
73     self.assertTrue(
74         errors[0].message.startswith('There is a prod freeze in effect'))
75
76   def test_end_of_freeze(self):
77     input_api = self.get_input_api(PRESUBMIT._FREEZE_END - 1)
78     output_api = self.get_output_api()
79
80     errors = PRESUBMIT.CheckFreeze(input_api, output_api)
81
82     self.assertEqual(len(errors), 1)
83     self.assertTrue(
84         errors[0].message.startswith('There is a prod freeze in effect'))
85
86   def test_after_freeze(self):
87     input_api = self.get_input_api(PRESUBMIT._FREEZE_END + 1)
88     output_api = self.get_output_api()
89
90     errors = PRESUBMIT.CheckFreeze(input_api, output_api)
91
92     self.assertEqual(errors, [])
93
94   def test_ignore_freeze(self):
95     input_api = self.get_input_api(PRESUBMIT._FREEZE_START + 1,
96                                    footers={'Ignore-Freeze': 'testing'})
97     output_api = self.get_output_api()
98
99     errors = PRESUBMIT.CheckFreeze(input_api, output_api)
100
101     self.assertEqual(errors, [])
102
103
104 if __name__ == '__main__':
105   unittest.main()