| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit.py and presubmit_canned_checks.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import StringIO | 9 import StringIO |
| 10 import unittest | 10 import unittest |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 elif path.count('binary'): | 46 elif path.count('binary'): |
| 47 return 'application/octet-stream' | 47 return 'application/octet-stream' |
| 48 else: | 48 else: |
| 49 if len(path) % 2: | 49 if len(path) % 2: |
| 50 return 'text/plain' | 50 return 'text/plain' |
| 51 else: | 51 else: |
| 52 return '' | 52 return '' |
| 53 gcl.GetSVNFileProperty = MockGetSVNFileProperty | 53 gcl.GetSVNFileProperty = MockGetSVNFileProperty |
| 54 | 54 |
| 55 self.original_ReadFile = gcl.ReadFile | 55 self.original_ReadFile = gcl.ReadFile |
| 56 def MockReadFile(path): | 56 def MockReadFile(path, dummy='r'): |
| 57 if path.count('nosuchfile'): | 57 if path.count('nosuchfile'): |
| 58 return None | 58 return None |
| 59 elif path.endswith('isdir'): | 59 elif path.endswith('isdir'): |
| 60 self.fail('Should not attempt to read file that is directory.') | 60 self.fail('Should not attempt to read file that is directory.') |
| 61 elif path.endswith('PRESUBMIT.py'): | 61 elif path.endswith('PRESUBMIT.py'): |
| 62 # used in testDoPresubmitChecks | 62 # used in testDoPresubmitChecks |
| 63 return ('def CheckChangeOnUpload(input_api, output_api):\n' | 63 return ('def CheckChangeOnUpload(input_api, output_api):\n' |
| 64 ' if not input_api.change.NOSUCHKEY:\n' | 64 ' if not input_api.change.NOSUCHKEY:\n' |
| 65 ' return [output_api.PresubmitError("!!")]\n' | 65 ' return [output_api.PresubmitError("!!")]\n' |
| 66 ' elif not input_api.change.REALLYNOSUCHKEY:\n' | 66 ' elif not input_api.change.REALLYNOSUCHKEY:\n' |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 self.failIf(presubmit_canned_checks.CheckTreeIsOpen( | 657 self.failIf(presubmit_canned_checks.CheckTreeIsOpen( |
| 658 self.MockInputApi(), presubmit.OutputApi, url='url_to_open', closed='0' | 658 self.MockInputApi(), presubmit.OutputApi, url='url_to_open', closed='0' |
| 659 )) | 659 )) |
| 660 self.failUnless(presubmit_canned_checks.CheckTreeIsOpen( | 660 self.failUnless(presubmit_canned_checks.CheckTreeIsOpen( |
| 661 self.MockInputApi(), presubmit.OutputApi, url='url_to_closed', closed='0' | 661 self.MockInputApi(), presubmit.OutputApi, url='url_to_closed', closed='0' |
| 662 )) | 662 )) |
| 663 | 663 |
| 664 | 664 |
| 665 if __name__ == '__main__': | 665 if __name__ == '__main__': |
| 666 unittest.main() | 666 unittest.main() |
| OLD | NEW |