| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 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 top-level Chromium presubmit script. | 6 """Unit tests for top-level Chromium presubmit script. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 self.msg = msg | 47 self.msg = msg |
| 48 self.items = items | 48 self.items = items |
| 49 | 49 |
| 50 | 50 |
| 51 class PresubmitUnittest(unittest.TestCase): | 51 class PresubmitUnittest(unittest.TestCase): |
| 52 def setUp(self): | 52 def setUp(self): |
| 53 self.file_contents = '' | 53 self.file_contents = '' |
| 54 def MockReadFile(path): | 54 def MockReadFile(path): |
| 55 self.failIf(path.endswith('notsource')) | 55 self.failIf(path.endswith('notsource')) |
| 56 return self.file_contents | 56 return self.file_contents |
| 57 PRESUBMIT._ReadFile = MockReadFile | 57 self._ReadFile = PRESUBMIT.ReadFile |
| 58 PRESUBMIT.ReadFile = MockReadFile |
| 58 | 59 |
| 59 def tearDown(self): | 60 def tearDown(self): |
| 60 PRESUBMIT._ReadFile = PRESUBMIT.ReadFile | 61 PRESUBMIT.ReadFile = self._ReadFile |
| 61 | 62 |
| 62 def testLocalChecks(self): | 63 def testLocalChecks(self): |
| 63 api = MockInputApi() | 64 api = MockInputApi() |
| 64 api.affected_files = [ | 65 api.affected_files = [ |
| 65 MockAffectedFile('foo/blat/yoo.notsource'), | 66 MockAffectedFile('foo/blat/yoo.notsource'), |
| 66 MockAffectedFile('third_party/blat/source.cc'), | 67 MockAffectedFile('third_party/blat/source.cc'), |
| 67 MockAffectedFile('foo/blat/source.h'), | 68 MockAffectedFile('foo/blat/source.h'), |
| 68 MockAffectedFile('foo/blat/source.mm'), | 69 MockAffectedFile('foo/blat/source.mm'), |
| 69 MockAffectedFile('foo/blat/source.py'), | 70 MockAffectedFile('foo/blat/source.py'), |
| 70 ] | 71 ] |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 api = MockInputApi() | 94 api = MockInputApi() |
| 94 api.affected_files = [ | 95 api.affected_files = [ |
| 95 MockAffectedFile('foo/blat/source.py', 'D'), | 96 MockAffectedFile('foo/blat/source.py', 'D'), |
| 96 ] | 97 ] |
| 97 self.file_contents = 'file with \n\terror\nhere\r\nyes there' | 98 self.file_contents = 'file with \n\terror\nhere\r\nyes there' |
| 98 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0) | 99 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0) |
| 99 | 100 |
| 100 | 101 |
| 101 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 102 unittest.main() | 103 unittest.main() |
| OLD | NEW |