| 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 re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 import PRESUBMIT | 10 import PRESUBMIT |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 859 |
| 860 def tearDown(self): | 860 def tearDown(self): |
| 861 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES | 861 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES |
| 862 | 862 |
| 863 def _RunCheck(self): | 863 def _RunCheck(self): |
| 864 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, | 864 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, |
| 865 self.mock_output_api, | 865 self.mock_output_api, |
| 866 checker_for_tests=self.checker) | 866 checker_for_tests=self.checker) |
| 867 | 867 |
| 868 def testAddedPydep(self): | 868 def testAddedPydep(self): |
| 869 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 870 if self.mock_input_api.platform != 'linux2': |
| 871 return [] |
| 872 |
| 869 self.mock_input_api.files = [ | 873 self.mock_input_api.files = [ |
| 870 MockAffectedFile('new.pydeps', [], action='A'), | 874 MockAffectedFile('new.pydeps', [], action='A'), |
| 871 ] | 875 ] |
| 872 | 876 |
| 873 results = self._RunCheck() | 877 results = self._RunCheck() |
| 874 self.assertEqual(1, len(results)) | 878 self.assertEqual(1, len(results)) |
| 875 self.assertTrue('PYDEPS_FILES' in str(results[0])) | 879 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 876 | 880 |
| 877 def testRemovedPydep(self): | 881 def testRemovedPydep(self): |
| 882 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 883 if self.mock_input_api.platform != 'linux2': |
| 884 return [] |
| 885 |
| 878 self.mock_input_api.files = [ | 886 self.mock_input_api.files = [ |
| 879 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), | 887 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), |
| 880 ] | 888 ] |
| 881 | 889 |
| 882 results = self._RunCheck() | 890 results = self._RunCheck() |
| 883 self.assertEqual(1, len(results)) | 891 self.assertEqual(1, len(results)) |
| 884 self.assertTrue('PYDEPS_FILES' in str(results[0])) | 892 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 885 | 893 |
| 886 def testRandomPyIgnored(self): | 894 def testRandomPyIgnored(self): |
| 895 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 896 if self.mock_input_api.platform != 'linux2': |
| 897 return [] |
| 898 |
| 887 self.mock_input_api.files = [ | 899 self.mock_input_api.files = [ |
| 888 MockAffectedFile('random.py', []), | 900 MockAffectedFile('random.py', []), |
| 889 ] | 901 ] |
| 890 | 902 |
| 891 results = self._RunCheck() | 903 results = self._RunCheck() |
| 892 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) | 904 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 893 | 905 |
| 894 def testRelevantPyNoChange(self): | 906 def testRelevantPyNoChange(self): |
| 907 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 908 if self.mock_input_api.platform != 'linux2': |
| 909 return [] |
| 910 |
| 895 self.mock_input_api.files = [ | 911 self.mock_input_api.files = [ |
| 896 MockAffectedFile('A.py', []), | 912 MockAffectedFile('A.py', []), |
| 897 ] | 913 ] |
| 898 | 914 |
| 899 def mock_check_output(cmd, shell=False): | 915 def mock_check_output(cmd, shell=False): |
| 900 self.assertEqual('CMD A --output ""', cmd) | 916 self.assertEqual('CMD A --output ""', cmd) |
| 901 return self.checker._file_cache['A.pydeps'] | 917 return self.checker._file_cache['A.pydeps'] |
| 902 | 918 |
| 903 self.mock_input_api.subprocess.check_output = mock_check_output | 919 self.mock_input_api.subprocess.check_output = mock_check_output |
| 904 | 920 |
| 905 results = self._RunCheck() | 921 results = self._RunCheck() |
| 906 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) | 922 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 907 | 923 |
| 908 def testRelevantPyOneChange(self): | 924 def testRelevantPyOneChange(self): |
| 925 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 926 if self.mock_input_api.platform != 'linux2': |
| 927 return [] |
| 928 |
| 909 self.mock_input_api.files = [ | 929 self.mock_input_api.files = [ |
| 910 MockAffectedFile('A.py', []), | 930 MockAffectedFile('A.py', []), |
| 911 ] | 931 ] |
| 912 | 932 |
| 913 def mock_check_output(cmd, shell=False): | 933 def mock_check_output(cmd, shell=False): |
| 914 self.assertEqual('CMD A --output ""', cmd) | 934 self.assertEqual('CMD A --output ""', cmd) |
| 915 return 'changed data' | 935 return 'changed data' |
| 916 | 936 |
| 917 self.mock_input_api.subprocess.check_output = mock_check_output | 937 self.mock_input_api.subprocess.check_output = mock_check_output |
| 918 | 938 |
| 919 results = self._RunCheck() | 939 results = self._RunCheck() |
| 920 self.assertEqual(1, len(results)) | 940 self.assertEqual(1, len(results)) |
| 921 self.assertTrue('File is stale' in str(results[0])) | 941 self.assertTrue('File is stale' in str(results[0])) |
| 922 | 942 |
| 923 def testRelevantPyTwoChanges(self): | 943 def testRelevantPyTwoChanges(self): |
| 944 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 945 if self.mock_input_api.platform != 'linux2': |
| 946 return [] |
| 947 |
| 924 self.mock_input_api.files = [ | 948 self.mock_input_api.files = [ |
| 925 MockAffectedFile('C.py', []), | 949 MockAffectedFile('C.py', []), |
| 926 ] | 950 ] |
| 927 | 951 |
| 928 def mock_check_output(cmd, shell=False): | 952 def mock_check_output(cmd, shell=False): |
| 929 return 'changed data' | 953 return 'changed data' |
| 930 | 954 |
| 931 self.mock_input_api.subprocess.check_output = mock_check_output | 955 self.mock_input_api.subprocess.check_output = mock_check_output |
| 932 | 956 |
| 933 results = self._RunCheck() | 957 results = self._RunCheck() |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 ['char* host = "https://www.aol.com"; // google.com']) | 1110 ['char* host = "https://www.aol.com"; // google.com']) |
| 1087 ] | 1111 ] |
| 1088 | 1112 |
| 1089 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 1113 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
| 1090 input_api, MockOutputApi()) | 1114 input_api, MockOutputApi()) |
| 1091 self.assertEqual(0, len(warnings)) | 1115 self.assertEqual(0, len(warnings)) |
| 1092 | 1116 |
| 1093 | 1117 |
| 1094 if __name__ == '__main__': | 1118 if __name__ == '__main__': |
| 1095 unittest.main() | 1119 unittest.main() |
| OLD | NEW |