| 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 |
| 6 import re | 9 import re |
| 7 import subprocess | 10 import subprocess |
| 11 import sys |
| 8 import unittest | 12 import unittest |
| 9 | 13 |
| 10 import PRESUBMIT | 14 import PRESUBMIT |
| 11 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile | 15 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile |
| 12 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi | 16 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
| 13 | 17 |
| 14 _TEST_DATA_DIR = 'base/test/data/presubmit' | 18 _TEST_DATA_DIR = 'base/test/data/presubmit' |
| 15 | 19 |
| 16 class IncludeOrderTest(unittest.TestCase): | 20 class IncludeOrderTest(unittest.TestCase): |
| 17 def testSystemHeaderOrder(self): | 21 def testSystemHeaderOrder(self): |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 829 |
| 826 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) | 830 output = PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()) |
| 827 self.assertEqual( | 831 self.assertEqual( |
| 828 ('File %s line %d: %s is missing in ' | 832 ('File %s line %d: %s is missing in ' |
| 829 'tools/metrics/actions/actions.xml. Please run ' | 833 'tools/metrics/actions/actions.xml. Please run ' |
| 830 'tools/metrics/actions/extract_actions.py to update.' | 834 'tools/metrics/actions/extract_actions.py to update.' |
| 831 % (file_with_user_action, 1, 'NotInActionsXml')), | 835 % (file_with_user_action, 1, 'NotInActionsXml')), |
| 832 output[0].message) | 836 output[0].message) |
| 833 | 837 |
| 834 | 838 |
| 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 | |
| 932 class LogUsageTest(unittest.TestCase): | 839 class LogUsageTest(unittest.TestCase): |
| 933 | 840 |
| 934 def testCheckAndroidCrLogUsage(self): | 841 def testCheckAndroidCrLogUsage(self): |
| 935 mock_input_api = MockInputApi() | 842 mock_input_api = MockInputApi() |
| 936 mock_output_api = MockOutputApi() | 843 mock_output_api = MockOutputApi() |
| 937 | 844 |
| 938 mock_input_api.files = [ | 845 mock_input_api.files = [ |
| 939 MockAffectedFile('RandomStuff.java', [ | 846 MockAffectedFile('RandomStuff.java', [ |
| 940 'random stuff' | 847 'random stuff' |
| 941 ]), | 848 ]), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 ['char* host = "https://www.aol.com"; // google.com']) | 986 ['char* host = "https://www.aol.com"; // google.com']) |
| 1080 ] | 987 ] |
| 1081 | 988 |
| 1082 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 989 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
| 1083 input_api, MockOutputApi()) | 990 input_api, MockOutputApi()) |
| 1084 self.assertEqual(0, len(warnings)) | 991 self.assertEqual(0, len(warnings)) |
| 1085 | 992 |
| 1086 | 993 |
| 1087 if __name__ == '__main__': | 994 if __name__ == '__main__': |
| 1088 unittest.main() | 995 unittest.main() |
| OLD | NEW |