Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import StringIO | 6 import StringIO |
| 7 import subprocess | 7 import subprocess |
| 8 from testing_utils import testing | 8 from testing_utils import testing |
| 9 import textwrap | 9 import textwrap |
| 10 import urllib2 | 10 import urllib2 |
| 11 | 11 |
| 12 from lib.gitiles import repo_util | 12 from lib.gitiles import repo_util |
| 13 from lib.cache_decorator import LocalCacher | |
| 13 | 14 |
| 14 | 15 |
| 15 class RepoUtilTest(testing.AppengineTestCase): | 16 class RepoUtilTest(testing.AppengineTestCase): |
| 16 | 17 |
| 17 def testExtractCommitPositionAndCodeReviewUrl(self): | 18 def testExtractCommitPositionAndCodeReviewUrl(self): |
| 18 testcases = [ | 19 testcases = [ |
| 19 { | 20 { |
| 20 'message': | 21 'message': |
| 21 'balabala...\n' | 22 'balabala...\n' |
| 22 '\n' | 23 '\n' |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 135 |
| 135 reverted_revision = repo_util.GetRevertedRevision(message) | 136 reverted_revision = repo_util.GetRevertedRevision(message) |
| 136 self.assertIsNone(reverted_revision) | 137 self.assertIsNone(reverted_revision) |
| 137 | 138 |
| 138 def testGetLocalGitCommandOutput(self): | 139 def testGetLocalGitCommandOutput(self): |
| 139 class _MockProcess(object): | 140 class _MockProcess(object): |
| 140 def __init__(self, command, *_): | 141 def __init__(self, command, *_): |
| 141 self.command = command | 142 self.command = command |
| 142 | 143 |
| 143 def communicate(self, *_): | 144 def communicate(self, *_): |
| 144 return self.command, 'dummy' | 145 return self.command, 'error' |
| 145 | 146 |
| 146 @property | 147 @property |
| 147 def returncode(self): | 148 def returncode(self): |
| 148 if self.command == 'dummy': | 149 if self.command == 'dummy': |
|
wrengr
2016/11/01 22:07:52
nit: would be cleaner to ``return 1 if ... else 0`
Sharu Jiang
2016/11/11 23:10:26
Done.
| |
| 149 return 1 | 150 return 1 |
| 150 | 151 |
| 151 return 0 | 152 return 0 |
| 152 | 153 |
| 153 def _MockPopen(command, **_): | 154 def _MockPopen(command, **_): |
|
wrengr
2016/11/01 22:07:52
nit: would be cleaner to inline this as a lambda.
Sharu Jiang
2016/11/11 23:10:26
Done.
| |
| 154 return _MockProcess(command) | 155 return _MockProcess(command) |
| 155 | 156 |
| 156 self.mock(subprocess, 'Popen', _MockPopen) | 157 self.mock(subprocess, 'Popen', _MockPopen) |
| 158 self.mock(LocalCacher, 'Get', lambda *_: None) | |
| 157 output = repo_util.GetCommandOutput('command') | 159 output = repo_util.GetCommandOutput('command') |
| 158 self.assertEqual(output, 'command') | 160 self.assertEqual(output, 'command') |
| 159 | 161 |
| 160 output = repo_util.GetCommandOutput('dummy') | 162 output = repo_util.GetCommandOutput('dummy') |
| 161 self.assertEqual(output, None) | 163 self.assertEqual(output, None) |
| OLD | NEW |