Chris Mumford | 0e8fd7b | 2023-04-24 14:04:54 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Chris Mumford | c1aab42 | 2023-04-27 12:01:55 -0700 | [diff] [blame] | 2 | # Copyright 2023 Google Inc. |
Chris Mumford | 0e8fd7b | 2023-04-24 14:04:54 -0700 | [diff] [blame] | 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 io |
| 7 | import os.path |
| 8 | import subprocess |
| 9 | import textwrap |
| 10 | import unittest |
| 11 | |
| 12 | import PRESUBMIT |
| 13 | |
| 14 | from PRESUBMIT_test_mocks import MockFile, MockAffectedFile |
| 15 | from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
| 16 | |
| 17 | |
| 18 | class ReleaseNotesTest(unittest.TestCase): |
| 19 | def testNoEditTopReleaseNotesNoWarning(self): |
| 20 | mock_input_api = MockInputApi() |
| 21 | mock_input_api.files = [ |
| 22 | MockFile('README.chromium', ''), |
| 23 | ] |
| 24 | |
| 25 | mock_output_api = MockOutputApi() |
| 26 | results = PRESUBMIT._CheckTopReleaseNotesChanged( |
| 27 | mock_input_api, mock_output_api) |
| 28 | |
| 29 | self.assertEqual(0, len(results)) |
| 30 | |
| 31 | def testUpdateTopReleaseNotesIssuesWarning(self): |
| 32 | mock_input_api = MockInputApi() |
| 33 | mock_input_api.files = [ |
| 34 | MockFile('RELEASE_NOTES.md', ''), |
| 35 | ] |
| 36 | |
| 37 | mock_output_api = MockOutputApi() |
| 38 | results = PRESUBMIT._CheckTopReleaseNotesChanged( |
| 39 | mock_input_api, mock_output_api) |
| 40 | |
| 41 | self.assertEqual(1, len(results)) |
| 42 | self.assertIsInstance( |
| 43 | results[0], mock_output_api.PresubmitPromptWarning, 'Not a warning') |
| 44 | self.assertTrue(results[0].message.startswith( |
| 45 | 'Do not edit RELEASE_NOTES.md')) |
| 46 | |
| 47 | def testUpdateTopReleaseNotesNoWarning(self): |
| 48 | mock_input_api = MockInputApi() |
| 49 | mock_input_api.files = [ |
| 50 | MockFile('RELEASE_NOTES.md', ''), |
| 51 | MockFile('relnotes/deleted_note.md', ''), |
| 52 | ] |
| 53 | |
| 54 | mock_output_api = MockOutputApi() |
| 55 | results = PRESUBMIT._CheckTopReleaseNotesChanged( |
| 56 | mock_input_api, mock_output_api) |
| 57 | |
| 58 | self.assertEqual(0, len(results)) |
| 59 | |
| 60 | def testUpdatePublicHeaderAndNoReleaseNoteGeneratesWarning(self): |
| 61 | mock_input_api = MockInputApi() |
| 62 | mock_input_api.files = [ |
| 63 | MockFile('include/core/SkDrawable.h', ''), |
| 64 | ] |
| 65 | |
| 66 | mock_output_api = MockOutputApi() |
| 67 | results = PRESUBMIT._CheckReleaseNotesForPublicAPI( |
| 68 | mock_input_api, mock_output_api) |
| 69 | |
| 70 | self.assertEqual(1, len(results)) |
| 71 | self.assertIsInstance( |
| 72 | results[0], mock_output_api.PresubmitPromptWarning, 'Not a warning') |
| 73 | |
| 74 | def testUpdatePublicHeaderAndReleaseNoteGeneratesNoWarning(self): |
| 75 | mock_input_api = MockInputApi() |
| 76 | mock_input_api.files = [ |
| 77 | MockFile('include/core/SkDrawable.h', ''), |
| 78 | MockFile('relnotes/new_note.md', ''), |
| 79 | ] |
| 80 | |
| 81 | mock_output_api = MockOutputApi() |
| 82 | results = PRESUBMIT._CheckReleaseNotesForPublicAPI( |
| 83 | mock_input_api, mock_output_api) |
| 84 | |
| 85 | self.assertEqual(0, len(results)) |
| 86 | |
| 87 | |
| 88 | if __name__ == '__main__': |
| 89 | unittest.main() |