OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Unit tests for gclient_scm.py.""" | 6 """Unit tests for gclient_scm.py.""" |
7 | 7 |
8 # pylint: disable=E1103 | 8 # pylint: disable=E1103 |
9 | 9 |
10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 self.assertRaises(gclient_scm.gclient_utils.Error, | 1290 self.assertRaises(gclient_scm.gclient_utils.Error, |
1291 git_svn_scm.GetUsableRev, too_big, options) | 1291 git_svn_scm.GetUsableRev, too_big, options) |
1292 | 1292 |
1293 def testUpdateNoDotGit(self): | 1293 def testUpdateNoDotGit(self): |
1294 options = self.Options() | 1294 options = self.Options() |
1295 | 1295 |
1296 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 1296 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
1297 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 1297 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
1298 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | 1298 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') |
1299 ).AndReturn(False) | 1299 ).AndReturn(False) |
1300 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
1301 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
1302 ).AndReturn(False) | |
1303 self.mox.StubOutWithMock(gclient_scm.os, 'listdir', True) | |
1304 gclient_scm.os.listdir(self.base_path).AndReturn([]) | |
1305 | 1300 |
1306 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) | 1301 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) |
1307 # pylint: disable=E1120 | 1302 # pylint: disable=E1120 |
1308 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, | 1303 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, |
1309 options) | 1304 options) |
1310 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) | 1305 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) |
1311 gclient_scm.subprocess2.check_output( | 1306 gclient_scm.subprocess2.check_output( |
1312 ['git', 'ls-files'], cwd=self.base_path, | 1307 ['git', 'ls-files'], cwd=self.base_path, |
1313 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('') | 1308 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('') |
1314 gclient_scm.subprocess2.check_output( | 1309 gclient_scm.subprocess2.check_output( |
1315 ['git', 'rev-parse', '--verify', 'HEAD'], | 1310 ['git', 'rev-parse', '--verify', 'HEAD'], |
1316 cwd=self.base_path, | 1311 cwd=self.base_path, |
1317 env=gclient_scm.scm.GIT.ApplyEnvVars({}), | 1312 env=gclient_scm.scm.GIT.ApplyEnvVars({}), |
1318 stderr=-1, | 1313 stderr=-1, |
1319 ).AndReturn('') | 1314 ).AndReturn('') |
1320 | 1315 |
1321 self.mox.ReplayAll() | 1316 self.mox.ReplayAll() |
1322 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 1317 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
1323 relpath=self.relpath) | 1318 relpath=self.relpath) |
1324 scm.update(options, None, []) | 1319 scm.update(options, None, []) |
1325 self.checkstdout('\n') | 1320 self.checkstdout('\n') |
1326 | 1321 |
1327 def testUpdateNoDotGitForce(self): | 1322 def testUpdateConflict(self): |
1328 options = self.Options(force=True) | 1323 options = self.Options() |
1329 | 1324 |
1330 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 1325 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
1331 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 1326 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
1332 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | 1327 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') |
1333 ).AndReturn(False) | 1328 ).AndReturn(False) |
1334 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 1329 |
1335 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
1336 ).AndReturn(False) | |
1337 self.mox.StubOutWithMock(gclient_scm.os, 'listdir', True) | |
1338 gclient_scm.os.listdir(self.base_path).AndReturn([]) | |
1339 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) | 1330 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) |
1340 # pylint: disable=E1120 | 1331 # pylint: disable=E1120 |
| 1332 gclient_scm.GitWrapper._Clone( |
| 1333 'refs/remotes/origin/master', self.url, options |
| 1334 ).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None, |
| 1335 None, None)) |
| 1336 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_DeleteOrMove', True) |
| 1337 gclient_scm.GitWrapper._DeleteOrMove(False) |
1341 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, | 1338 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, |
1342 options) | 1339 options) |
1343 # pylint: disable=E1120 | |
1344 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) | 1340 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) |
1345 gclient_scm.subprocess2.check_output( | 1341 gclient_scm.subprocess2.check_output( |
1346 ['git', 'ls-files'], cwd=self.base_path, | 1342 ['git', 'ls-files'], cwd=self.base_path, |
1347 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('') | 1343 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('') |
1348 gclient_scm.subprocess2.check_output( | 1344 gclient_scm.subprocess2.check_output( |
1349 ['git', 'rev-parse', '--verify', 'HEAD'], | 1345 ['git', 'rev-parse', '--verify', 'HEAD'], |
1350 cwd=self.base_path, | 1346 cwd=self.base_path, |
1351 env=gclient_scm.scm.GIT.ApplyEnvVars({}), | 1347 env=gclient_scm.scm.GIT.ApplyEnvVars({}), |
1352 stderr=-1, | 1348 stderr=-1, |
1353 ).AndReturn('') | 1349 ).AndReturn('') |
(...skipping 24 matching lines...) Expand all Loading... |
1378 | 1374 |
1379 if __name__ == '__main__': | 1375 if __name__ == '__main__': |
1380 if '-v' in sys.argv: | 1376 if '-v' in sys.argv: |
1381 logging.basicConfig( | 1377 logging.basicConfig( |
1382 level=logging.DEBUG, | 1378 level=logging.DEBUG, |
1383 format='%(asctime).19s %(levelname)s %(filename)s:' | 1379 format='%(asctime).19s %(levelname)s %(filename)s:' |
1384 '%(lineno)s %(message)s') | 1380 '%(lineno)s %(message)s') |
1385 unittest.main() | 1381 unittest.main() |
1386 | 1382 |
1387 # vim: ts=2:sw=2:tw=80:et: | 1383 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |