Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: appengine/findit/lib/gitiles/test/repo_util_test.py

Issue 2432203003: [Predator] Run predator. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698