Hui Yingst | 2aa0a4a | 2020-04-09 19:04:21 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 | |
| 6 | import unittest |
| 7 | |
| 8 | import PRESUBMIT |
| 9 | from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi, MockFile |
| 10 | |
| 11 | |
| 12 | class CheckChangeOnUploadTest(unittest.TestCase): |
| 13 | |
| 14 | def testCheckPNGFormat(self): |
| 15 | correct_paths = [ |
| 16 | 'test_expected.pdf.0.png', |
| 17 | 'test_expected_win.pdf.1.png', |
| 18 | 'test_expected_skia.pdf.2.png', |
| 19 | 'test_expected_skiapaths.pdf.3.png', |
| 20 | 'test_expected_skia_mac.pdf.4.png', |
| 21 | 'test_expected_skiapaths_win.pdf.5.png', |
| 22 | 'notpng.cc', # Check will be skipped for non-PNG files |
| 23 | ] |
| 24 | wrong_paths = [ |
| 25 | 'expected.pdf.0.png', # Missing '_expected' |
| 26 | 'test1_expected.0.png', # Missing '.pdf' |
| 27 | 'test2_expected.pdf.png', # Missing page number |
| 28 | 'test3_expected.pdf.x.png', # Wrong character for page number |
| 29 | 'test4_expected_mac_skia.pdf.0.png', # Wrong order of keywords |
| 30 | 'test5_expected_useskia.pdf.0.png', # Wrong keyword |
| 31 | ] |
| 32 | mock_input_api = MockInputApi() |
| 33 | mock_output_api = MockOutputApi() |
| 34 | mock_input_api.files = map(MockFile, correct_paths + wrong_paths) |
| 35 | errors = map(str, PRESUBMIT._CheckPNGFormat(mock_input_api, |
| 36 | mock_output_api)) |
| 37 | |
| 38 | self.assertEqual(len(wrong_paths), len(errors)) |
| 39 | self.assertFalse('notpng.cc' in errors[0]) |
| 40 | for path, error in zip(wrong_paths, errors): |
| 41 | self.assertIn(path, error) |
| 42 | |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | unittest.main() |