forked from google/skia
-
Notifications
You must be signed in to change notification settings - Fork 55
/
PRESUBMIT_test.py
executable file
·89 lines (68 loc) · 2.74 KB
/
PRESUBMIT_test.py
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
#!/usr/bin/env python3
# Copyright 2023 Google Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import io
import os.path
import subprocess
import textwrap
import unittest
import PRESUBMIT
from PRESUBMIT_test_mocks import MockFile, MockAffectedFile
from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi
class ReleaseNotesTest(unittest.TestCase):
def testNoEditTopReleaseNotesNoWarning(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('README.chromium', ''),
]
mock_output_api = MockOutputApi()
results = PRESUBMIT._CheckTopReleaseNotesChanged(
mock_input_api, mock_output_api)
self.assertEqual(0, len(results))
def testUpdateTopReleaseNotesIssuesWarning(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('RELEASE_NOTES.md', ''),
]
mock_output_api = MockOutputApi()
results = PRESUBMIT._CheckTopReleaseNotesChanged(
mock_input_api, mock_output_api)
self.assertEqual(1, len(results))
self.assertIsInstance(
results[0], mock_output_api.PresubmitPromptWarning, 'Not a warning')
self.assertTrue(results[0].message.startswith(
'Do not edit RELEASE_NOTES.md'))
def testUpdateTopReleaseNotesNoWarning(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('RELEASE_NOTES.md', ''),
MockFile('relnotes/deleted_note.md', ''),
]
mock_output_api = MockOutputApi()
results = PRESUBMIT._CheckTopReleaseNotesChanged(
mock_input_api, mock_output_api)
self.assertEqual(0, len(results))
def testUpdatePublicHeaderAndNoReleaseNoteGeneratesWarning(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('include/core/SkDrawable.h', ''),
]
mock_output_api = MockOutputApi()
results = PRESUBMIT._CheckReleaseNotesForPublicAPI(
mock_input_api, mock_output_api)
self.assertEqual(1, len(results))
self.assertIsInstance(
results[0], mock_output_api.PresubmitPromptWarning, 'Not a warning')
def testUpdatePublicHeaderAndReleaseNoteGeneratesNoWarning(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile('include/core/SkDrawable.h', ''),
MockFile('relnotes/new_note.md', ''),
]
mock_output_api = MockOutputApi()
results = PRESUBMIT._CheckReleaseNotesForPublicAPI(
mock_input_api, mock_output_api)
self.assertEqual(0, len(results))
if __name__ == '__main__':
unittest.main()