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

Side by Side Diff: tests/bot_update_coverage_test.py

Issue 2382653005: Remove git lockfile flakiness on win (bot_update) (Closed)
Patch Set: Remove git lockfile flakiness on win (bot_update) Created 4 years, 2 months 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2015 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 import codecs 6 import codecs
7 import copy 7 import copy
8 import json 8 import json
9 import os 9 import os
10 import subprocess
10 import sys 11 import sys
11 import unittest 12 import unittest
12 13
13 #import test_env # pylint: disable=W0403,W0611 14 #import test_env # pylint: disable=W0403,W0611
14 15
15 sys.path.insert(0, os.path.join( 16 sys.path.insert(0, os.path.join(
16 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 17 os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
17 'recipe_modules', 'bot_update', 'resources')) 18 'recipe_modules', 'bot_update', 'resources'))
18 sys.platform = 'linux2' # For consistency, ya know? 19 sys.platform = 'linux2' # For consistency, ya know?
19 import bot_update 20 import bot_update
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if 'w' in mode: 156 if 'w' in mode:
156 self.files[target] = FakeFile() 157 self.files[target] = FakeFile()
157 return self.files[target] 158 return self.files[target]
158 return self.files[target] 159 return self.files[target]
159 160
160 161
161 def fake_git(*args, **kwargs): 162 def fake_git(*args, **kwargs):
162 return bot_update.call('git', *args, **kwargs) 163 return bot_update.call('git', *args, **kwargs)
163 164
164 165
166 class MockSubprocess():
167 def __init__(self):
168 self.calls = []
169
170 def call(self, command):
171 self.calls.append(command)
172 return 0
173
174
165 class BotUpdateUnittests(unittest.TestCase): 175 class BotUpdateUnittests(unittest.TestCase):
166 def setUp(self): 176 def setUp(self):
167 self.filesystem = FakeFilesystem() 177 self.filesystem = FakeFilesystem()
168 self.call = MockedCall(self.filesystem) 178 self.call = MockedCall(self.filesystem)
169 self.gclient = MockedGclientSync(self.filesystem) 179 self.gclient = MockedGclientSync(self.filesystem)
170 self.call.expect(('gclient', 'sync')).returns(self.gclient) 180 self.call.expect(('gclient', 'sync')).returns(self.gclient)
171 self.old_call = getattr(bot_update, 'call') 181 self.old_call = getattr(bot_update, 'call')
172 self.params = copy.deepcopy(DEFAULT_PARAMS) 182 self.params = copy.deepcopy(DEFAULT_PARAMS)
173 setattr(bot_update, 'call', self.call) 183 setattr(bot_update, 'call', self.call)
174 setattr(bot_update, 'git', fake_git) 184 setattr(bot_update, 'git', fake_git)
175 185
176 self.old_os_cwd = os.getcwd 186 self.old_os_cwd = os.getcwd
177 setattr(os, 'getcwd', lambda: '/b/build/slave/foo/build') 187 setattr(os, 'getcwd', lambda: '/b/build/slave/foo/build')
178 188
179 setattr(bot_update, 'open', self.filesystem.open) 189 setattr(bot_update, 'open', self.filesystem.open)
180 self.old_codecs_open = codecs.open 190 self.old_codecs_open = codecs.open
181 setattr(codecs, 'open', self.filesystem.open) 191 setattr(codecs, 'open', self.filesystem.open)
182 192
193 self.subprocess = MockSubprocess()
194 self.old_sp_call = subprocess.call
195 setattr(subprocess, 'call', self.subprocess.call)
196
183 def tearDown(self): 197 def tearDown(self):
184 setattr(bot_update, 'call', self.old_call) 198 setattr(bot_update, 'call', self.old_call)
185 setattr(os, 'getcwd', self.old_os_cwd) 199 setattr(os, 'getcwd', self.old_os_cwd)
186 delattr(bot_update, 'open') 200 delattr(bot_update, 'open')
187 setattr(codecs, 'open', self.old_codecs_open) 201 setattr(codecs, 'open', self.old_codecs_open)
202 delattr(subprocess, 'call')
203 setattr(subprocess, 'call', self.old_sp_call)
188 204
189 def testBasic(self): 205 def testBasic(self):
190 bot_update.ensure_checkout(**self.params) 206 bot_update.ensure_checkout(**self.params)
191 return self.call.records 207 return self.call.records
192 208
193 def testBasicShallow(self): 209 def testBasicShallow(self):
194 self.params['shallow'] = True 210 self.params['shallow'] = True
195 bot_update.ensure_checkout(**self.params) 211 bot_update.ensure_checkout(**self.params)
196 return self.call.records 212 return self.call.records
197 213
214 def testMaybeRemoveWinLockfile(self):
215 git_lockfile_err = '''
216 fatal: Unable to create 'E:/b/c/b/win/src/.git/index.lock': File exists.
217 '''
218 bot_update.maybe_remove_win_lockfile('win32', git_lockfile_err)
219 self.assertEqual(
220 self.subprocess.calls,
221 [['cmd.exe', '/c', 'del', '/f',
222 '/q', 'E:/b/c/b/win/src/.git/index.lock']])
223
198 224
199 if __name__ == '__main__': 225 if __name__ == '__main__':
200 unittest.main() 226 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698