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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 825 |
830 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) | 826 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) |
831 self.assertEqual( | 827 self.assertEqual( |
832 ('File %s line %d: %s is missing in ' | 828 ('File %s line %d: %s is missing in ' |
833 'tools/metrics/actions/actions.xml. Please run ' | 829 'tools/metrics/actions/actions.xml. Please run ' |
834 'tools/metrics/actions/extract_actions.py to update.' | 830 'tools/metrics/actions/extract_actions.py to update.' |
835 % (file_with_user_action, 1, 'NotInActionsXml')), | 831 % (file_with_user_action, 1, 'NotInActionsXml')), |
836 output[0].message) | 832 output[0].message) |
837 | 833 |
838 | 834 |
| 835 class PydepsNeedsUpdatingTest(unittest.TestCase): |
| 836 |
| 837 class MockSubprocess(object): |
| 838 CalledProcessError = subprocess.CalledProcessError |
| 839 |
| 840 def setUp(self): |
| 841 mock_all_pydeps = ['A.pydeps', 'B.pydeps'] |
| 842 self.old_ALL_PYDEPS_FILES = PRESUBMIT._ALL_PYDEPS_FILES |
| 843 PRESUBMIT._ALL_PYDEPS_FILES = mock_all_pydeps |
| 844 self.mock_input_api = MockInputApi() |
| 845 self.mock_output_api = MockOutputApi() |
| 846 self.mock_input_api.subprocess = PydepsNeedsUpdatingTest.MockSubprocess() |
| 847 self.checker = PRESUBMIT.PydepsChecker(self.mock_input_api, mock_all_pydeps) |
| 848 self.checker._file_cache = { |
| 849 'A.pydeps': '# target: //A.py\n# root: //\nA.py\nC.py\n', |
| 850 'B.pydeps': '# target: //B.py\n# root: //\nB.py\nC.py\n', |
| 851 } |
| 852 |
| 853 def tearDown(self): |
| 854 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES |
| 855 |
| 856 def _RunCheck(self): |
| 857 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, |
| 858 self.mock_output_api, |
| 859 checker_for_tests=self.checker) |
| 860 |
| 861 def testAddedPydep(self): |
| 862 self.mock_input_api.files = [ |
| 863 MockAffectedFile('new.pydeps', [], action='A'), |
| 864 ] |
| 865 |
| 866 results = self._RunCheck() |
| 867 self.assertEqual(1, len(results)) |
| 868 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 869 |
| 870 def testRemovedPydep(self): |
| 871 self.mock_input_api.files = [ |
| 872 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), |
| 873 ] |
| 874 |
| 875 results = self._RunCheck() |
| 876 self.assertEqual(1, len(results)) |
| 877 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 878 |
| 879 def testRandomPyIgnored(self): |
| 880 self.mock_input_api.files = [ |
| 881 MockAffectedFile('random.py', []), |
| 882 ] |
| 883 |
| 884 results = self._RunCheck() |
| 885 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 886 |
| 887 def testRelevantPyNoChange(self): |
| 888 self.mock_input_api.files = [ |
| 889 MockAffectedFile('A.py', []), |
| 890 ] |
| 891 |
| 892 def mock_check_output(cmd): |
| 893 self.assertEqual('A.py', cmd[3]) |
| 894 return self.checker._file_cache['A.pydeps'] |
| 895 |
| 896 self.mock_input_api.subprocess.check_output = mock_check_output |
| 897 |
| 898 results = self._RunCheck() |
| 899 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 900 |
| 901 def testRelevantPyOneChange(self): |
| 902 self.mock_input_api.files = [ |
| 903 MockAffectedFile('A.py', []), |
| 904 ] |
| 905 |
| 906 def mock_check_output(cmd): |
| 907 self.assertEqual('A.py', cmd[3]) |
| 908 return 'changed data' |
| 909 |
| 910 self.mock_input_api.subprocess.check_output = mock_check_output |
| 911 |
| 912 results = self._RunCheck() |
| 913 self.assertEqual(1, len(results)) |
| 914 self.assertTrue('File is stale' in str(results[0])) |
| 915 |
| 916 def testRelevantPyTwoChanges(self): |
| 917 self.mock_input_api.files = [ |
| 918 MockAffectedFile('C.py', []), |
| 919 ] |
| 920 |
| 921 def mock_check_output(cmd): |
| 922 return 'changed data' |
| 923 |
| 924 self.mock_input_api.subprocess.check_output = mock_check_output |
| 925 |
| 926 results = self._RunCheck() |
| 927 self.assertEqual(2, len(results)) |
| 928 self.assertTrue('File is stale' in str(results[0])) |
| 929 self.assertTrue('File is stale' in str(results[1])) |
| 930 |
| 931 |
839 class LogUsageTest(unittest.TestCase): | 932 class LogUsageTest(unittest.TestCase): |
840 | 933 |
841 def testCheckAndroidCrLogUsage(self): | 934 def testCheckAndroidCrLogUsage(self): |
842 mock_input_api = MockInputApi() | 935 mock_input_api = MockInputApi() |
843 mock_output_api = MockOutputApi() | 936 mock_output_api = MockOutputApi() |
844 | 937 |
845 mock_input_api.files = [ | 938 mock_input_api.files = [ |
846 MockAffectedFile('RandomStuff.java', [ | 939 MockAffectedFile('RandomStuff.java', [ |
847 'random stuff' | 940 'random stuff' |
848 ]), | 941 ]), |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 ['char* host = "https://www.aol.com"; // google.com']) | 1079 ['char* host = "https://www.aol.com"; // google.com']) |
987 ] | 1080 ] |
988 | 1081 |
989 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 1082 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
990 input_api, MockOutputApi()) | 1083 input_api, MockOutputApi()) |
991 self.assertEqual(0, len(warnings)) | 1084 self.assertEqual(0, len(warnings)) |
992 | 1085 |
993 | 1086 |
994 if __name__ == '__main__': | 1087 if __name__ == '__main__': |
995 unittest.main() | 1088 unittest.main() |
OLD | NEW |