Chromium Code Reviews| 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 git_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import StringIO | 9 import StringIO |
| 10 import stat | 10 import stat |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) | 94 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) |
| 95 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) | 95 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) |
| 96 self.mock(git_cl.upload, 'RealMain', self.fail) | 96 self.mock(git_cl.upload, 'RealMain', self.fail) |
| 97 self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock) | 97 self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock) |
| 98 self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock) | 98 self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock) |
| 99 self.mock(git_cl.auth, '_should_use_oauth2', lambda: False) | 99 self.mock(git_cl.auth, '_should_use_oauth2', lambda: False) |
| 100 # It's important to reset settings to not have inter-tests interference. | 100 # It's important to reset settings to not have inter-tests interference. |
| 101 git_cl.settings = None | 101 git_cl.settings = None |
| 102 | 102 |
| 103 def tearDown(self): | 103 def tearDown(self): |
| 104 super(TestGitCl, self).tearDown() | |
| 104 if not self.has_failed(): | 105 if not self.has_failed(): |
|
M-A Ruel
2015/04/19 19:32:28
In general; I do:
try:
<cleanup>
finally:
sup
wychen
2015/04/20 17:44:43
This does look more readable. Modified to your sty
| |
| 105 self.assertEquals([], self.calls) | 106 self.assertEquals([], self.calls) |
| 106 super(TestGitCl, self).tearDown() | |
| 107 | 107 |
| 108 def _mocked_call(self, *args, **_kwargs): | 108 def _mocked_call(self, *args, **_kwargs): |
| 109 self.assertTrue( | 109 self.assertTrue( |
| 110 self.calls, | 110 self.calls, |
| 111 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) | 111 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) |
| 112 expected_args, result = self.calls.pop(0) | 112 expected_args, result = self.calls.pop(0) |
| 113 # Also logs otherwise it could get caught in a try/finally and be hard to | 113 # Also logs otherwise it could get caught in a try/finally and be hard to |
| 114 # diagnose. | 114 # diagnose. |
| 115 if expected_args != args: | 115 if expected_args != args: |
| 116 msg = '@%d Expected: %r Actual: %r' % ( | 116 msg = '@%d Expected: %r Actual: %r' % ( |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 # Check target refs for pending prefix. | 851 # Check target refs for pending prefix. |
| 852 self.assertEqual('prefix/heads/master', | 852 self.assertEqual('prefix/heads/master', |
| 853 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', | 853 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
| 854 None, 'prefix/')) | 854 None, 'prefix/')) |
| 855 | 855 |
| 856 | 856 |
| 857 if __name__ == '__main__': | 857 if __name__ == '__main__': |
| 858 git_cl.logging.basicConfig( | 858 git_cl.logging.basicConfig( |
| 859 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 859 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 860 unittest.main() | 860 unittest.main() |
| OLD | NEW |