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 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 self.assertEquals(expected, strip_timestamps(value)) | 1238 self.assertEquals(expected, strip_timestamps(value)) |
1239 | 1239 |
1240 def setUp(self): | 1240 def setUp(self): |
1241 BaseTestCase.setUp(self) | 1241 BaseTestCase.setUp(self) |
1242 self.fake_hash_1 = 't0ta11yf4k3' | 1242 self.fake_hash_1 = 't0ta11yf4k3' |
1243 self.fake_hash_2 = '3v3nf4k3r' | 1243 self.fake_hash_2 = '3v3nf4k3r' |
1244 self.url = 'git://foo' | 1244 self.url = 'git://foo' |
1245 self.root_dir = '/tmp' if sys.platform != 'win32' else 't:\\tmp' | 1245 self.root_dir = '/tmp' if sys.platform != 'win32' else 't:\\tmp' |
1246 self.relpath = 'fake' | 1246 self.relpath = 'fake' |
1247 self.base_path = os.path.join(self.root_dir, self.relpath) | 1247 self.base_path = os.path.join(self.root_dir, self.relpath) |
| 1248 self.backup_base_path = os.path.join(self.root_dir, |
| 1249 'old_%s.git' % self.relpath) |
1248 | 1250 |
1249 def tearDown(self): | 1251 def tearDown(self): |
1250 BaseTestCase.tearDown(self) | 1252 BaseTestCase.tearDown(self) |
1251 | 1253 |
1252 def testGetUsableRevGit(self): | 1254 def testGetUsableRevGit(self): |
1253 # pylint: disable=E1101 | 1255 # pylint: disable=E1101 |
1254 options = self.Options(verbose=True) | 1256 options = self.Options(verbose=True) |
1255 | 1257 |
1256 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) | 1258 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) |
1257 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 | 1259 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1349 # We currently check for seemingly valid SVN revisions by assuming 6 digit |
1348 # numbers, so assure that numeric revs >= 1000000 don't work. | 1350 # numbers, so assure that numeric revs >= 1000000 don't work. |
1349 self.assertRaises(gclient_scm.gclient_utils.Error, | 1351 self.assertRaises(gclient_scm.gclient_utils.Error, |
1350 git_svn_scm.GetUsableRev, too_big, options) | 1352 git_svn_scm.GetUsableRev, too_big, options) |
1351 | 1353 |
1352 def testUpdateNoDotGit(self): | 1354 def testUpdateNoDotGit(self): |
1353 options = self.Options() | 1355 options = self.Options() |
1354 | 1356 |
1355 gclient_scm.os.path.isdir( | 1357 gclient_scm.os.path.isdir( |
1356 os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False) | 1358 os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False) |
| 1359 gclient_scm.os.path.exists(self.backup_base_path).AndReturn(False) |
1357 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 1360 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
1358 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 1361 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
1359 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | 1362 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') |
1360 ).AndReturn(False) | 1363 ).AndReturn(False) |
1361 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) | 1364 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) |
1362 # pylint: disable=E1120 | 1365 # pylint: disable=E1120 |
1363 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, | 1366 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, |
1364 options) | 1367 options) |
1365 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) | 1368 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) |
1366 gclient_scm.subprocess2.check_output( | 1369 gclient_scm.subprocess2.check_output( |
(...skipping 10 matching lines...) Expand all Loading... |
1377 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 1380 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
1378 relpath=self.relpath) | 1381 relpath=self.relpath) |
1379 scm.update(options, None, []) | 1382 scm.update(options, None, []) |
1380 self.checkstdout('\n') | 1383 self.checkstdout('\n') |
1381 | 1384 |
1382 def testUpdateConflict(self): | 1385 def testUpdateConflict(self): |
1383 options = self.Options() | 1386 options = self.Options() |
1384 | 1387 |
1385 gclient_scm.os.path.isdir( | 1388 gclient_scm.os.path.isdir( |
1386 os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False) | 1389 os.path.join(self.base_path, '.git', 'hooks')).AndReturn(False) |
| 1390 gclient_scm.os.path.exists(self.backup_base_path).AndReturn(False) |
1387 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 1391 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
1388 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 1392 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
1389 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | 1393 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') |
1390 ).AndReturn(False) | 1394 ).AndReturn(False) |
1391 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) | 1395 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) |
1392 # pylint: disable=E1120 | 1396 # pylint: disable=E1120 |
1393 gclient_scm.GitWrapper._Clone( | 1397 gclient_scm.GitWrapper._Clone( |
1394 'refs/remotes/origin/master', self.url, options | 1398 'refs/remotes/origin/master', self.url, options |
1395 ).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None, | 1399 ).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None, |
1396 None, None)) | 1400 None, None)) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 | 1622 |
1619 if __name__ == '__main__': | 1623 if __name__ == '__main__': |
1620 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 1624 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
1621 logging.basicConfig( | 1625 logging.basicConfig( |
1622 level=level, | 1626 level=level, |
1623 format='%(asctime).19s %(levelname)s %(filename)s:' | 1627 format='%(asctime).19s %(levelname)s %(filename)s:' |
1624 '%(lineno)s %(message)s') | 1628 '%(lineno)s %(message)s') |
1625 unittest.main() | 1629 unittest.main() |
1626 | 1630 |
1627 # vim: ts=2:sw=2:tw=80:et: | 1631 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |