| OLD | NEW |
| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 setattr(bot_update, 'open', self.filesystem.open) | 179 setattr(bot_update, 'open', self.filesystem.open) |
| 180 self.old_codecs_open = codecs.open | 180 self.old_codecs_open = codecs.open |
| 181 setattr(codecs, 'open', self.filesystem.open) | 181 setattr(codecs, 'open', self.filesystem.open) |
| 182 | 182 |
| 183 def tearDown(self): | 183 def tearDown(self): |
| 184 setattr(bot_update, 'call', self.old_call) | 184 setattr(bot_update, 'call', self.old_call) |
| 185 setattr(os, 'getcwd', self.old_os_cwd) | 185 setattr(os, 'getcwd', self.old_os_cwd) |
| 186 delattr(bot_update, 'open') | 186 delattr(bot_update, 'open') |
| 187 setattr(codecs, 'open', self.old_codecs_open) | 187 setattr(codecs, 'open', self.old_codecs_open) |
| 188 | 188 |
| 189 def overrideSetupForWindows(self): |
| 190 sys.platform = 'win' |
| 191 self.call.expect(('gclient.bat', 'sync')).returns(self.gclient) |
| 192 |
| 189 def testBasic(self): | 193 def testBasic(self): |
| 190 bot_update.ensure_checkout(**self.params) | 194 bot_update.ensure_checkout(**self.params) |
| 191 return self.call.records | 195 return self.call.records |
| 192 | 196 |
| 193 def testBasicShallow(self): | 197 def testBasicShallow(self): |
| 194 self.params['shallow'] = True | 198 self.params['shallow'] = True |
| 195 bot_update.ensure_checkout(**self.params) | 199 bot_update.ensure_checkout(**self.params) |
| 196 return self.call.records | 200 return self.call.records |
| 197 | 201 |
| 198 def testBreakLocks(self): | 202 def testBreakLocks(self): |
| 199 sys.platform = 'win' | 203 self.overrideSetupForWindows() |
| 200 self.call.expect(('gclient.bat', 'sync')).returns(self.gclient) | |
| 201 bot_update.ensure_checkout(**self.params) | 204 bot_update.ensure_checkout(**self.params) |
| 202 gclient_sync_cmd = None | 205 gclient_sync_cmd = None |
| 203 for record in self.call.records: | 206 for record in self.call.records: |
| 204 args = record[0] | 207 args = record[0] |
| 205 if args[0] == 'gclient.bat' and args[1] == 'sync': | 208 if args[0] == 'gclient.bat' and args[1] == 'sync': |
| 206 gclient_sync_cmd = args | 209 gclient_sync_cmd = args |
| 207 self.assertTrue('--break_repo_locks' in gclient_sync_cmd) | 210 self.assertTrue('--break_repo_locks' in gclient_sync_cmd) |
| 208 | 211 |
| 212 def testGitCheckoutBreaksLocks(self): |
| 213 self.overrideSetupForWindows() |
| 214 path = '/b/build/slave/foo/build/.git' |
| 215 lockfile = 'index.lock' |
| 216 removed = [] |
| 217 old_os_walk = os.walk |
| 218 old_os_remove = os.remove |
| 219 setattr(os, 'walk', lambda _: [(path, None, [lockfile])]) |
| 220 setattr(os, 'remove', removed.append) |
| 221 bot_update.ensure_checkout(**self.params) |
| 222 setattr(os, 'walk', old_os_walk) |
| 223 setattr(os, 'remove', old_os_remove) |
| 224 self.assertTrue(os.path.join(path, lockfile) in removed) |
| 225 |
| 209 | 226 |
| 210 if __name__ == '__main__': | 227 if __name__ == '__main__': |
| 211 unittest.main() | 228 unittest.main() |
| OLD | NEW |