OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 # pylint is too confused. | 8 # pylint is too confused. |
9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 | 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 |
10 | 10 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 members = [ | 147 members = [ |
148 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 148 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', |
149 'GetTrySlavesExecuter', 'GitAffectedFile', | 149 'GetTrySlavesExecuter', 'GitAffectedFile', |
150 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 150 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
151 'OutputApi', 'ParseFiles', 'PresubmitFailure', | 151 'OutputApi', 'ParseFiles', 'PresubmitFailure', |
152 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', | 152 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', |
153 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', | 153 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', |
154 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'json', | 154 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'json', |
155 'load_files', | 155 'load_files', |
156 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 156 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', |
157 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', | 157 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', |
| 158 'subprocess', |
158 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 159 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', |
159 'warn', | 160 'warn', |
160 ] | 161 ] |
161 # If this test fails, you should add the relevant test. | 162 # If this test fails, you should add the relevant test. |
162 self.compareMembers(presubmit, members) | 163 self.compareMembers(presubmit, members) |
163 | 164 |
164 def testListRelevantPresubmitFiles(self): | 165 def testListRelevantPresubmitFiles(self): |
165 join = presubmit.os.path.join | 166 join = presubmit.os.path.join |
166 files = [ | 167 files = [ |
167 'blat.cc', | 168 'blat.cc', |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 path = presubmit.InputApi( | 832 path = presubmit.InputApi( |
832 self.fake_change, './p', False, False, None, False).LocalToDepotPath( | 833 self.fake_change, './p', False, False, None, False).LocalToDepotPath( |
833 'notfound-food') | 834 'notfound-food') |
834 self.assertEquals(path, None) | 835 self.assertEquals(path, None) |
835 | 836 |
836 def testInputApiConstruction(self): | 837 def testInputApiConstruction(self): |
837 self.mox.ReplayAll() | 838 self.mox.ReplayAll() |
838 api = presubmit.InputApi( | 839 api = presubmit.InputApi( |
839 self.fake_change, | 840 self.fake_change, |
840 presubmit_path='foo/path/PRESUBMIT.py', | 841 presubmit_path='foo/path/PRESUBMIT.py', |
841 is_committing=False, tbr=False, rietveld=None, verbose=False) | 842 is_committing=False, tbr=False, rietveld_obj=None, verbose=False) |
842 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') | 843 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') |
843 self.assertEquals(api.change, self.fake_change) | 844 self.assertEquals(api.change, self.fake_change) |
844 self.assertEquals(api.host_url, 'http://codereview.chromium.org') | 845 self.assertEquals(api.host_url, 'http://codereview.chromium.org') |
845 | 846 |
846 def testInputApiPresubmitScriptFiltering(self): | 847 def testInputApiPresubmitScriptFiltering(self): |
847 join = presubmit.os.path.join | 848 join = presubmit.os.path.join |
848 description_lines = ('Hello there', | 849 description_lines = ('Hello there', |
849 'this is a change', | 850 'this is a change', |
850 'BUG=123', | 851 'BUG=123', |
851 ' STORY =http://foo/ \t', | 852 ' STORY =http://foo/ \t', |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 normpath(join(self.fake_root_dir, 'isdir'))) | 1076 normpath(join(self.fake_root_dir, 'isdir'))) |
1076 self.assertEquals(affected_files[1].AbsoluteLocalPath(), | 1077 self.assertEquals(affected_files[1].AbsoluteLocalPath(), |
1077 normpath(join(self.fake_root_dir, 'isdir/blat.cc'))) | 1078 normpath(join(self.fake_root_dir, 'isdir/blat.cc'))) |
1078 | 1079 |
1079 # New helper functions need to work | 1080 # New helper functions need to work |
1080 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True) | 1081 paths_from_change = change.AbsoluteLocalPaths(include_dirs=True) |
1081 self.assertEqual(len(paths_from_change), 3) | 1082 self.assertEqual(len(paths_from_change), 3) |
1082 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py') | 1083 presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py') |
1083 api = presubmit.InputApi( | 1084 api = presubmit.InputApi( |
1084 change=change, presubmit_path=presubmit_path, | 1085 change=change, presubmit_path=presubmit_path, |
1085 is_committing=True, tbr=False, rietveld=None, verbose=False) | 1086 is_committing=True, tbr=False, rietveld_obj=None, verbose=False) |
1086 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) | 1087 paths_from_api = api.AbsoluteLocalPaths(include_dirs=True) |
1087 self.assertEqual(len(paths_from_api), 2) | 1088 self.assertEqual(len(paths_from_api), 2) |
1088 for absolute_paths in [paths_from_change, paths_from_api]: | 1089 for absolute_paths in [paths_from_change, paths_from_api]: |
1089 self.assertEqual(absolute_paths[0], | 1090 self.assertEqual(absolute_paths[0], |
1090 normpath(join(self.fake_root_dir, 'isdir'))) | 1091 normpath(join(self.fake_root_dir, 'isdir'))) |
1091 self.assertEqual(absolute_paths[1], | 1092 self.assertEqual(absolute_paths[1], |
1092 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) | 1093 normpath(join(self.fake_root_dir, 'isdir', 'blat.cc'))) |
1093 | 1094 |
1094 def testDeprecated(self): | 1095 def testDeprecated(self): |
1095 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2) | 1096 presubmit.warn(mox.IgnoreArg(), category=mox.IgnoreArg(), stacklevel=2) |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 whitelist=['^a$', '^b$'], | 2154 whitelist=['^a$', '^b$'], |
2154 blacklist=['a']) | 2155 blacklist=['a']) |
2155 self.assertEqual(results, []) | 2156 self.assertEqual(results, []) |
2156 self.checkstdout( | 2157 self.checkstdout( |
2157 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) | 2158 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) |
2158 | 2159 |
2159 | 2160 |
2160 if __name__ == '__main__': | 2161 if __name__ == '__main__': |
2161 import unittest | 2162 import unittest |
2162 unittest.main() | 2163 unittest.main() |
OLD | NEW |