| 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 850 |
| 851 def tearDown(self): | 851 def tearDown(self): |
| 852 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES | 852 PRESUBMIT._ALL_PYDEPS_FILES = self.old_ALL_PYDEPS_FILES |
| 853 | 853 |
| 854 def _RunCheck(self): | 854 def _RunCheck(self): |
| 855 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, | 855 return PRESUBMIT._CheckPydepsNeedsUpdating(self.mock_input_api, |
| 856 self.mock_output_api, | 856 self.mock_output_api, |
| 857 checker_for_tests=self.checker) | 857 checker_for_tests=self.checker) |
| 858 | 858 |
| 859 def testAddedPydep(self): | 859 def testAddedPydep(self): |
| 860 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 861 if self.mock_input_api.platform != 'linux2': |
| 862 return [] |
| 863 |
| 860 self.mock_input_api.files = [ | 864 self.mock_input_api.files = [ |
| 861 MockAffectedFile('new.pydeps', [], action='A'), | 865 MockAffectedFile('new.pydeps', [], action='A'), |
| 862 ] | 866 ] |
| 863 | 867 |
| 864 results = self._RunCheck() | 868 results = self._RunCheck() |
| 865 self.assertEqual(1, len(results)) | 869 self.assertEqual(1, len(results)) |
| 866 self.assertTrue('PYDEPS_FILES' in str(results[0])) | 870 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 867 | 871 |
| 868 def testRemovedPydep(self): | 872 def testRemovedPydep(self): |
| 873 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 874 if self.mock_input_api.platform != 'linux2': |
| 875 return [] |
| 876 |
| 869 self.mock_input_api.files = [ | 877 self.mock_input_api.files = [ |
| 870 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), | 878 MockAffectedFile(PRESUBMIT._ALL_PYDEPS_FILES[0], [], action='D'), |
| 871 ] | 879 ] |
| 872 | 880 |
| 873 results = self._RunCheck() | 881 results = self._RunCheck() |
| 874 self.assertEqual(1, len(results)) | 882 self.assertEqual(1, len(results)) |
| 875 self.assertTrue('PYDEPS_FILES' in str(results[0])) | 883 self.assertTrue('PYDEPS_FILES' in str(results[0])) |
| 876 | 884 |
| 877 def testRandomPyIgnored(self): | 885 def testRandomPyIgnored(self): |
| 886 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 887 if self.mock_input_api.platform != 'linux2': |
| 888 return [] |
| 889 |
| 878 self.mock_input_api.files = [ | 890 self.mock_input_api.files = [ |
| 879 MockAffectedFile('random.py', []), | 891 MockAffectedFile('random.py', []), |
| 880 ] | 892 ] |
| 881 | 893 |
| 882 results = self._RunCheck() | 894 results = self._RunCheck() |
| 883 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) | 895 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 884 | 896 |
| 885 def testRelevantPyNoChange(self): | 897 def testRelevantPyNoChange(self): |
| 898 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 899 if self.mock_input_api.platform != 'linux2': |
| 900 return [] |
| 901 |
| 886 self.mock_input_api.files = [ | 902 self.mock_input_api.files = [ |
| 887 MockAffectedFile('A.py', []), | 903 MockAffectedFile('A.py', []), |
| 888 ] | 904 ] |
| 889 | 905 |
| 890 def mock_check_output(cmd, shell=False): | 906 def mock_check_output(cmd, shell=False): |
| 891 self.assertEqual('CMD A --output ""', cmd) | 907 self.assertEqual('CMD A --output ""', cmd) |
| 892 return self.checker._file_cache['A.pydeps'] | 908 return self.checker._file_cache['A.pydeps'] |
| 893 | 909 |
| 894 self.mock_input_api.subprocess.check_output = mock_check_output | 910 self.mock_input_api.subprocess.check_output = mock_check_output |
| 895 | 911 |
| 896 results = self._RunCheck() | 912 results = self._RunCheck() |
| 897 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) | 913 self.assertEqual(0, len(results), 'Unexpected results: %r' % results) |
| 898 | 914 |
| 899 def testRelevantPyOneChange(self): | 915 def testRelevantPyOneChange(self): |
| 916 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 917 if self.mock_input_api.platform != 'linux2': |
| 918 return [] |
| 919 |
| 900 self.mock_input_api.files = [ | 920 self.mock_input_api.files = [ |
| 901 MockAffectedFile('A.py', []), | 921 MockAffectedFile('A.py', []), |
| 902 ] | 922 ] |
| 903 | 923 |
| 904 def mock_check_output(cmd, shell=False): | 924 def mock_check_output(cmd, shell=False): |
| 905 self.assertEqual('CMD A --output ""', cmd) | 925 self.assertEqual('CMD A --output ""', cmd) |
| 906 return 'changed data' | 926 return 'changed data' |
| 907 | 927 |
| 908 self.mock_input_api.subprocess.check_output = mock_check_output | 928 self.mock_input_api.subprocess.check_output = mock_check_output |
| 909 | 929 |
| 910 results = self._RunCheck() | 930 results = self._RunCheck() |
| 911 self.assertEqual(1, len(results)) | 931 self.assertEqual(1, len(results)) |
| 912 self.assertTrue('File is stale' in str(results[0])) | 932 self.assertTrue('File is stale' in str(results[0])) |
| 913 | 933 |
| 914 def testRelevantPyTwoChanges(self): | 934 def testRelevantPyTwoChanges(self): |
| 935 # PRESUBMIT._CheckPydepsNeedsUpdating is only implemented for Android. |
| 936 if self.mock_input_api.platform != 'linux2': |
| 937 return [] |
| 938 |
| 915 self.mock_input_api.files = [ | 939 self.mock_input_api.files = [ |
| 916 MockAffectedFile('C.py', []), | 940 MockAffectedFile('C.py', []), |
| 917 ] | 941 ] |
| 918 | 942 |
| 919 def mock_check_output(cmd, shell=False): | 943 def mock_check_output(cmd, shell=False): |
| 920 return 'changed data' | 944 return 'changed data' |
| 921 | 945 |
| 922 self.mock_input_api.subprocess.check_output = mock_check_output | 946 self.mock_input_api.subprocess.check_output = mock_check_output |
| 923 | 947 |
| 924 results = self._RunCheck() | 948 results = self._RunCheck() |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 ['char* host = "https://www.aol.com"; // google.com']) | 1101 ['char* host = "https://www.aol.com"; // google.com']) |
| 1078 ] | 1102 ] |
| 1079 | 1103 |
| 1080 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 1104 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
| 1081 input_api, MockOutputApi()) | 1105 input_api, MockOutputApi()) |
| 1082 self.assertEqual(0, len(warnings)) | 1106 self.assertEqual(0, len(warnings)) |
| 1083 | 1107 |
| 1084 | 1108 |
| 1085 if __name__ == '__main__': | 1109 if __name__ == '__main__': |
| 1086 unittest.main() | 1110 unittest.main() |
| OLD | NEW |