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

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 sys 10 import sys
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 self.call = MockedCall(self.filesystem) 168 self.call = MockedCall(self.filesystem)
169 self.gclient = MockedGclientSync(self.filesystem) 169 self.gclient = MockedGclientSync(self.filesystem)
170 self.call.expect(('gclient', 'sync')).returns(self.gclient) 170 self.call.expect(('gclient', 'sync')).returns(self.gclient)
171 self.old_call = getattr(bot_update, 'call') 171 self.old_call = getattr(bot_update, 'call')
172 self.params = copy.deepcopy(DEFAULT_PARAMS) 172 self.params = copy.deepcopy(DEFAULT_PARAMS)
173 setattr(bot_update, 'call', self.call) 173 setattr(bot_update, 'call', self.call)
174 setattr(bot_update, 'git', fake_git) 174 setattr(bot_update, 'git', fake_git)
175 175
176 self.old_os_cwd = os.getcwd 176 self.old_os_cwd = os.getcwd
177 setattr(os, 'getcwd', lambda: '/b/build/slave/foo/build') 177 setattr(os, 'getcwd', lambda: '/b/build/slave/foo/build')
178 self.old_os_listdir = os.listdir
179 setattr(os, 'listdir', lambda _: ['a.lock', 'b.lock', 'c.txt'])
178 180
179 setattr(bot_update, 'open', self.filesystem.open) 181 setattr(bot_update, 'open', self.filesystem.open)
180 self.old_codecs_open = codecs.open 182 self.old_codecs_open = codecs.open
181 setattr(codecs, 'open', self.filesystem.open) 183 setattr(codecs, 'open', self.filesystem.open)
182 184
183 def tearDown(self): 185 def tearDown(self):
184 setattr(bot_update, 'call', self.old_call) 186 setattr(bot_update, 'call', self.old_call)
185 setattr(os, 'getcwd', self.old_os_cwd) 187 setattr(os, 'getcwd', self.old_os_cwd)
188 setattr(os, 'listdir', self.old_os_listdir)
186 delattr(bot_update, 'open') 189 delattr(bot_update, 'open')
187 setattr(codecs, 'open', self.old_codecs_open) 190 setattr(codecs, 'open', self.old_codecs_open)
188 191
189 def testBasic(self): 192 def testBasic(self):
190 bot_update.ensure_checkout(**self.params) 193 bot_update.ensure_checkout(**self.params)
191 return self.call.records 194 return self.call.records
192 195
193 def testBasicShallow(self): 196 def testBasicShallow(self):
194 self.params['shallow'] = True 197 self.params['shallow'] = True
195 bot_update.ensure_checkout(**self.params) 198 bot_update.ensure_checkout(**self.params)
196 return self.call.records 199 return self.call.records
197 200
201 def testRemoveGitLockfiles(self):
202 bot_update.remove_git_lockfiles('win32', 'E:/b/c/b/win/src',1)
203 self.assertTrue((('cmd.exe', '/c', 'del', '/f', '/q',
204 'E:/b/c/b/win/src/.git/a.lock'), {}) in self.call.records)
205 self.assertTrue((('cmd.exe', '/c', 'del', '/f', '/q',
206 'E:/b/c/b/win/src/.git/b.lock'), {}) in self.call.records)
207 self.assertFalse((('cmd.exe', '/c', 'del', '/f', '/q',
208 'E:/b/c/b/win/src/.git/c.txt'), {}) in self.call.records)
209
210 def testRemoveGitLockfilesInBadDirectory(self):
211 setattr(os, 'listdir', self.old_os_listdir)
212 # If a directory doesn't exist, we don't want this method to raise an
213 # Exception
214 self.assertEqual(bot_update.remove_git_lockfiles(
215 'win32', 'this/dir/does/not/exist'), None)
198 216
199 if __name__ == '__main__': 217 if __name__ == '__main__':
200 unittest.main() 218 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698