| 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 """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: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 | 
| 9 | 9 | 
| 10 import logging | 10 import logging | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 152   """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 152   """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 
| 153 | 153 | 
| 154   _INHERIT_SETTINGS = 'inherit-review-settings-ok' | 154   _INHERIT_SETTINGS = 'inherit-review-settings-ok' | 
| 155 | 155 | 
| 156   def testMembersChanged(self): | 156   def testMembersChanged(self): | 
| 157     self.mox.ReplayAll() | 157     self.mox.ReplayAll() | 
| 158     members = [ | 158     members = [ | 
| 159       'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 159       'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 
| 160       'GetTrySlavesExecuter', 'GitAffectedFile', | 160       'GetTrySlavesExecuter', 'GitAffectedFile', | 
| 161       'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 161       'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 
| 162       'OutputApi', 'ParseFiles', 'PresubmitFailure', | 162       'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles', | 
| 163       'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', | 163       'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', | 
| 164       'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', | 164       'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 'contextlib', | 
| 165       'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'inspect', 'json', | 165       'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', | 
| 166       'load_files', | 166       'inspect', 'json', 'load_files', | 
| 167       'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 167       'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 
| 168       'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', | 168       'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', | 
| 169       'subprocess', | 169       'subprocess', | 
| 170       'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 170       'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 
| 171       'warn', | 171       'warn', | 
| 172     ] | 172     ] | 
| 173     # If this test fails, you should add the relevant test. | 173     # If this test fails, you should add the relevant test. | 
| 174     self.compareMembers(presubmit, members) | 174     self.compareMembers(presubmit, members) | 
| 175 | 175 | 
|  | 176   def testCannedCheckFilter(self): | 
|  | 177     canned = presubmit.presubmit_canned_checks | 
|  | 178     orig = canned.CheckOwners | 
|  | 179     with presubmit.canned_check_filter(['CheckOwners']): | 
|  | 180       self.assertNotEqual(canned.CheckOwners, orig) | 
|  | 181       self.assertEqual(canned.CheckOwners(None, None), []) | 
|  | 182     self.assertEqual(canned.CheckOwners, orig) | 
|  | 183 | 
|  | 184   def testCannedCheckFilterFail(self): | 
|  | 185     canned = presubmit.presubmit_canned_checks | 
|  | 186     orig = canned.CheckOwners | 
|  | 187     def failAttempt(): | 
|  | 188       with presubmit.canned_check_filter(['CheckOwners', 'Spazfleem']): | 
|  | 189         pass | 
|  | 190     self.assertRaises(presubmit.NonexistantCannedCheckFilter, failAttempt) | 
|  | 191     self.assertEqual(canned.CheckOwners, orig) | 
|  | 192 | 
| 176   def testListRelevantPresubmitFiles(self): | 193   def testListRelevantPresubmitFiles(self): | 
| 177     join = presubmit.os.path.join | 194     join = presubmit.os.path.join | 
| 178     files = [ | 195     files = [ | 
| 179       'blat.cc', | 196       'blat.cc', | 
| 180       join('foo', 'haspresubmit', 'yodle', 'smart.h'), | 197       join('foo', 'haspresubmit', 'yodle', 'smart.h'), | 
| 181       join('moo', 'mat', 'gat', 'yo.h'), | 198       join('moo', 'mat', 'gat', 'yo.h'), | 
| 182       join('foo', 'luck.h'), | 199       join('foo', 'luck.h'), | 
| 183     ] | 200     ] | 
| 184     inherit_path = presubmit.os.path.join(self.fake_root_dir, | 201     inherit_path = presubmit.os.path.join(self.fake_root_dir, | 
| 185                                           self._INHERIT_SETTINGS) | 202                                           self._INHERIT_SETTINGS) | 
| (...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2504         owners_check=False) | 2521         owners_check=False) | 
| 2505     self.assertEqual(1, len(results)) | 2522     self.assertEqual(1, len(results)) | 
| 2506     self.assertEqual( | 2523     self.assertEqual( | 
| 2507         'Found line ending with white spaces in:', results[0]._message) | 2524         'Found line ending with white spaces in:', results[0]._message) | 
| 2508     self.checkstdout('') | 2525     self.checkstdout('') | 
| 2509 | 2526 | 
| 2510 | 2527 | 
| 2511 if __name__ == '__main__': | 2528 if __name__ == '__main__': | 
| 2512   import unittest | 2529   import unittest | 
| 2513   unittest.main() | 2530   unittest.main() | 
| OLD | NEW | 
|---|