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 gcl.py.""" | 6 """Unit tests for gcl.py.""" |
7 | 7 |
8 # pylint is too confused. | 8 # pylint is too confused. |
9 # pylint: disable=E1101,E1103,E1120,W0212,W0403 | 9 # pylint: disable=E1101,E1103,E1120,W0212,W0403 |
10 | 10 |
11 # Fixes include path. | 11 # Fixes include path. |
12 from super_mox import mox, SuperMoxTestBase | 12 from super_mox import mox, SuperMoxTestBase |
13 | 13 |
14 import gcl | 14 import gcl |
15 import presubmit_support | 15 import presubmit_support |
16 | 16 |
17 | 17 |
18 class GclTestsBase(SuperMoxTestBase): | 18 class GclTestsBase(SuperMoxTestBase): |
19 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 19 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
20 def setUp(self): | 20 def setUp(self): |
21 SuperMoxTestBase.setUp(self) | 21 SuperMoxTestBase.setUp(self) |
22 self.fake_root_dir = self.RootDir() | 22 self.fake_root_dir = self.RootDir() |
23 self.mox.StubOutWithMock(gcl, 'RunShell') | 23 self.mox.StubOutWithMock(gcl.subprocess2, 'call') |
| 24 self.mox.StubOutWithMock(gcl.subprocess2, 'check_output') |
24 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') | 25 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') |
25 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') | 26 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') |
26 self.mox.StubOutWithMock(gcl, 'tempfile') | 27 self.mox.StubOutWithMock(gcl, 'tempfile') |
27 self.mox.StubOutWithMock(gcl.upload, 'RealMain') | 28 self.mox.StubOutWithMock(gcl.upload, 'RealMain') |
28 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') | 29 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') |
29 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') | 30 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') |
30 gcl.REPOSITORY_ROOT = None | 31 gcl.REPOSITORY_ROOT = None |
31 self.old_review_settings = gcl.CODEREVIEW_SETTINGS | 32 self.old_review_settings = gcl.CODEREVIEW_SETTINGS |
32 self.assertEquals(gcl.CODEREVIEW_SETTINGS, {}) | 33 self.assertEquals(gcl.CODEREVIEW_SETTINGS, {}) |
33 | 34 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 'CMDstatus', 'CMDtry', 'CMDupload', | 82 'CMDstatus', 'CMDtry', 'CMDupload', |
82 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', | 83 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', |
83 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', | 84 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', |
84 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', | 85 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', |
85 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', | 86 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', |
86 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', | 87 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', |
87 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', | 88 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', |
88 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', | 89 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles', |
89 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', | 90 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', |
90 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', | 91 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 'REVIEWERS_REGEX', |
91 'RunShell', 'RunShellWithReturnCode', 'SVN', | 92 'SVN', 'TryChange', 'UnknownFiles', 'Warn', |
92 'TryChange', 'UnknownFiles', 'Warn', | |
93 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', | 93 'attrs', 'breakpad', 'defer_attributes', 'fix_encoding', |
94 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args', | 94 'gclient_utils', 'json', 'main', 'need_change', 'need_change_and_args', |
95 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're', | 95 'no_args', 'optparse', 'os', 'presubmit_support', 'random', 're', |
96 'rietveld', | 96 'rietveld', |
97 'string', 'subprocess2', 'sys', 'tempfile', 'time', | 97 'string', 'subprocess2', 'sys', 'tempfile', 'time', |
98 'upload', 'urllib2', | 98 'upload', 'urllib2', |
99 ] | 99 ] |
100 # If this test fails, you should add the relevant test. | 100 # If this test fails, you should add the relevant test. |
101 self.compareMembers(gcl, members) | 101 self.compareMembers(gcl, members) |
102 | 102 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 def mockCommit(self, change_info, commit_message, shell_output): | 520 def mockCommit(self, change_info, commit_message, shell_output): |
521 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'commit')) | 521 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'commit')) |
522 gcl.os.write(42, commit_message) | 522 gcl.os.write(42, commit_message) |
523 gcl.os.close(42) | 523 gcl.os.close(42) |
524 gcl.tempfile.mkstemp(text=True).AndReturn((43, 'files')) | 524 gcl.tempfile.mkstemp(text=True).AndReturn((43, 'files')) |
525 gcl.os.write(43, '\n'.join(change_info.GetFileNames())) | 525 gcl.os.write(43, '\n'.join(change_info.GetFileNames())) |
526 gcl.os.close(43) | 526 gcl.os.close(43) |
527 | 527 |
528 gcl.os.getcwd().AndReturn('prev') | 528 gcl.os.getcwd().AndReturn('prev') |
529 gcl.os.chdir(change_info.GetLocalRoot()) | 529 gcl.os.chdir(change_info.GetLocalRoot()) |
530 gcl.RunShell(['svn', 'commit', '--file=commit', '--targets=files'], | 530 gcl.subprocess2.check_output( |
531 True).AndReturn(shell_output) | 531 ['svn', 'commit', '--file=commit', '--targets=files'] |
| 532 ).AndReturn(shell_output) |
532 if 'Committed' in shell_output: | 533 if 'Committed' in shell_output: |
533 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') | 534 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') |
534 gcl.GetCodeReviewSetting('VIEW_VC').AndReturn('http://view/') | 535 gcl.GetCodeReviewSetting('VIEW_VC').AndReturn('http://view/') |
535 | 536 |
536 gcl.os.remove('commit') | 537 gcl.os.remove('commit') |
537 gcl.os.remove('files') | 538 gcl.os.remove('files') |
538 gcl.os.chdir('prev') | 539 gcl.os.chdir('prev') |
539 | 540 |
540 def testPresubmitEmpty(self): | 541 def testPresubmitEmpty(self): |
541 self.mockLoad(files=[]) | 542 self.mockLoad(files=[]) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 self.assertEquals(retval, 0) | 582 self.assertEquals(retval, 0) |
582 self.assertEquals(change_info.description, | 583 self.assertEquals(change_info.description, |
583 'deescription\n\nCommitted: http://view/12345') | 584 'deescription\n\nCommitted: http://view/12345') |
584 self.assertTrue(change_info._deleted) | 585 self.assertTrue(change_info._deleted) |
585 self.assertTrue(change_info._closed) | 586 self.assertTrue(change_info._closed) |
586 | 587 |
587 | 588 |
588 if __name__ == '__main__': | 589 if __name__ == '__main__': |
589 import unittest | 590 import unittest |
590 unittest.main() | 591 unittest.main() |
OLD | NEW |