OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import glob | |
7 import json | |
8 import os | |
9 import re | 6 import re |
10 import subprocess | 7 import subprocess |
11 import sys | |
12 import unittest | 8 import unittest |
13 | 9 |
14 import PRESUBMIT | 10 import PRESUBMIT |
15 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile | 11 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile |
16 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi | 12 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
17 | 13 |
18 _TEST_DATA_DIR = 'base/test/data/presubmit' | 14 _TEST_DATA_DIR = 'base/test/data/presubmit' |
19 | 15 |
20 class IncludeOrderTest(unittest.TestCase): | 16 class IncludeOrderTest(unittest.TestCase): |
21 def testSystemHeaderOrder(self): | 17 def testSystemHeaderOrder(self): |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 824 |
829 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) | 825 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) |
830 self.assertEqual( | 826 self.assertEqual( |
831 ('File %s line %d: %s is missing in ' | 827 ('File %s line %d: %s is missing in ' |
832 'tools/metrics/actions/actions.xml. Please run ' | 828 'tools/metrics/actions/actions.xml. Please run ' |
833 'tools/metrics/actions/extract_actions.py to update.' | 829 'tools/metrics/actions/extract_actions.py to update.' |
834 % (file_with_user_action, 1, 'NotInActionsXml')), | 830 % (file_with_user_action, 1, 'NotInActionsXml')), |
835 output[0].message) | 831 output[0].message) |
836 | 832 |
837 | 833 |
| 834 class PydepsNeedsUpdatingTest(unittest.TestCase): |
| 835 |
| 836 class MockSubprocess(object): |
| 837 CalledProcessError = subprocess.CalledProcessError |
| 838 |
| 839 def setUp(self): |
| 840 mock_all_pydeps = ['A.pydeps', 'B.pydeps'] |
| 841 self.old_ALL_PYDEPS_FILES = PRESUBMIT._ALL_PYDEPS_FILES |
| 842 PRESUBMIT._ALL_PYDEPS_FILES = mock_all_pydeps |
| 843 self.mock_input_api = MockInputApi() |
| 844 self.mock_output_api = MockOutputApi() |
| 845 self.mock_input_api.subprocess = PydepsNeedsUpdatingTest.MockSubprocess() |
| 846 self.checker = PRESUBMIT.PydepsChecker(self.mock_input_api, mock_all_pydeps) |
| 847 self.checker._file_cache = { |
| 848 'A.pydeps': '# Generated by:\n# CMD A\nA.py\nC.py\n', |
| 849 'B.pydeps': '# Generated by:\n# CMD B\nB.py\nC.py\n', |
| 850 } |
| 851 |
| 852 def tearDown(self): |
| 853 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES |
| 854 |
| 855 def _RunCheck(self): |
| 856 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, |
| 857 self.mock_output_api, |
| 858 checker_for_tests=self.checker) |
| 859 |
| 860 def testAddedPydep(self): |
| 861 self.mock_input_api.files = [ |
| 862 MockAffectedFile('new.pydeps', [], action='A'), |
| 863 ] |
| 864 |
| 865 results = self._RunCheck() |
| 866 self.assertEqual(1, len(results)) |
| 867 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 868 |
| 869 def testRemovedPydep(self): |
| 870 self.mock_input_api.files = [ |
| 871 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), |
| 872 ] |
| 873 |
| 874 results = self._RunCheck() |
| 875 self.assertEqual(1, len(results)) |
| 876 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 877 |
| 878 def testRandomPyIgnored(self): |
| 879 self.mock_input_api.files = [ |
| 880 MockAffectedFile('random.py', []), |
| 881 ] |
| 882 |
| 883 results = self._RunCheck() |
| 884 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 885 |
| 886 def testRelevantPyNoChange(self): |
| 887 self.mock_input_api.files = [ |
| 888 MockAffectedFile('A.py', []), |
| 889 ] |
| 890 |
| 891 def mock_check_output(cmd, shell=False): |
| 892 self.assertEqual('CMD A --output ""', cmd) |
| 893 return self.checker._file_cache['A.pydeps'] |
| 894 |
| 895 self.mock_input_api.subprocess.check_output = mock_check_output |
| 896 |
| 897 results = self._RunCheck() |
| 898 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 899 |
| 900 def testRelevantPyOneChange(self): |
| 901 self.mock_input_api.files = [ |
| 902 MockAffectedFile('A.py', []), |
| 903 ] |
| 904 |
| 905 def mock_check_output(cmd, shell=False): |
| 906 self.assertEqual('CMD A --output ""', cmd) |
| 907 return 'changed data' |
| 908 |
| 909 self.mock_input_api.subprocess.check_output = mock_check_output |
| 910 |
| 911 results = self._RunCheck() |
| 912 self.assertEqual(1, len(results)) |
| 913 self.assertTrue('File is stale' in str(results[0])) |
| 914 |
| 915 def testRelevantPyTwoChanges(self): |
| 916 self.mock_input_api.files = [ |
| 917 MockAffectedFile('C.py', []), |
| 918 ] |
| 919 |
| 920 def mock_check_output(cmd, shell=False): |
| 921 return 'changed data' |
| 922 |
| 923 self.mock_input_api.subprocess.check_output = mock_check_output |
| 924 |
| 925 results = self._RunCheck() |
| 926 self.assertEqual(2, len(results)) |
| 927 self.assertTrue('File is stale' in str(results[0])) |
| 928 self.assertTrue('File is stale' in str(results[1])) |
| 929 |
| 930 |
838 class LogUsageTest(unittest.TestCase): | 931 class LogUsageTest(unittest.TestCase): |
839 | 932 |
840 def testCheckAndroidCrLogUsage(self): | 933 def testCheckAndroidCrLogUsage(self): |
841 mock_input_api = MockInputApi() | 934 mock_input_api = MockInputApi() |
842 mock_output_api = MockOutputApi() | 935 mock_output_api = MockOutputApi() |
843 | 936 |
844 mock_input_api.files = [ | 937 mock_input_api.files = [ |
845 MockAffectedFile('RandomStuff.java', [ | 938 MockAffectedFile('RandomStuff.java', [ |
846 'random stuff' | 939 'random stuff' |
847 ]), | 940 ]), |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 ['char* host = "https://www.aol.com"; // google.com']) | 1078 ['char* host = "https://www.aol.com"; // google.com']) |
986 ] | 1079 ] |
987 | 1080 |
988 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 1081 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
989 input_api, MockOutputApi()) | 1082 input_api, MockOutputApi()) |
990 self.assertEqual(0, len(warnings)) | 1083 self.assertEqual(0, len(warnings)) |
991 | 1084 |
992 | 1085 |
993 if __name__ == '__main__': | 1086 if __name__ == '__main__': |
994 unittest.main() | 1087 unittest.main() |
OLD | NEW |