Chromium Code Reviews| 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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | 1271 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) |
| 1272 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], | 1272 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
| 1273 cwd=self.base_path).AndReturn('blah') | 1273 cwd=self.base_path).AndReturn('blah') |
| 1274 # pylint: disable=E1120 | 1274 # pylint: disable=E1120 |
| 1275 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) | 1275 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) |
| 1276 error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr') | 1276 error = subprocess2.CalledProcessError(1, 'cmd', '/cwd', 'stdout', 'stderr') |
| 1277 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], | 1277 gclient_scm.scm.GIT.Capture(['config', '--get', 'svn-remote.svn.fetch'], |
| 1278 cwd=self.base_path).AndRaise(error) | 1278 cwd=self.base_path).AndRaise(error) |
| 1279 gclient_scm.GitWrapper._Fetch(options) | 1279 gclient_scm.GitWrapper._Fetch(options) |
| 1280 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) | 1280 gclient_scm.scm.GIT.Capture(['svn', 'fetch'], cwd=self.base_path) |
| 1281 gclient_scm.GitWrapper._Fetch(options) | |
| 1282 | 1281 |
| 1283 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 1282 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) |
| 1284 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( | 1283 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( |
| 1285 ).AndReturn(True) | 1284 ).AndReturn(True) |
| 1286 | 1285 |
| 1287 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) | 1286 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) |
| 1288 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 | 1287 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 |
| 1289 ).AndReturn(True) | 1288 ).AndReturn(True) |
| 1290 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big | 1289 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big |
| 1291 ).MultipleTimes(2).AndReturn(False) | 1290 ).MultipleTimes(2).AndReturn(False) |
| 1291 # pylint: disable=E1120 | |
| 1292 gclient_scm.GitWrapper._Fetch(options) | |
| 1292 | 1293 |
| 1293 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 1294 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
| 1294 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) | 1295 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) |
| 1295 | 1296 |
| 1296 self.mox.ReplayAll() | 1297 self.mox.ReplayAll() |
| 1297 | 1298 |
| 1298 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 1299 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 1299 relpath=self.relpath) | 1300 relpath=self.relpath) |
| 1300 # Without an existing checkout, this should fail. | 1301 # Without an existing checkout, this should fail. |
| 1301 # TODO(dbeam) Fix this. http://crbug.com/109184 | 1302 # TODO(dbeam) Fix this. http://crbug.com/109184 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1573 relpath=self.relpath) | 1574 relpath=self.relpath) |
| 1574 file_list = [] | 1575 file_list = [] |
| 1575 options.revision = 'unmanaged' | 1576 options.revision = 'unmanaged' |
| 1576 scm.update(options, (), file_list) | 1577 scm.update(options, (), file_list) |
| 1577 self.assertEquals(file_list, expected_file_list) | 1578 self.assertEquals(file_list, expected_file_list) |
| 1578 self.assertEquals(scm.revinfo(options, (), None), | 1579 self.assertEquals(scm.revinfo(options, (), None), |
| 1579 '069c602044c5388d2d15c3f875b057c852003458') | 1580 '069c602044c5388d2d15c3f875b057c852003458') |
| 1580 self.checkstdout('________ unmanaged solution; skipping .\n') | 1581 self.checkstdout('________ unmanaged solution; skipping .\n') |
| 1581 | 1582 |
| 1582 | 1583 |
| 1584 class GitRefishTestCase(unittest.TestCase): | |
| 1585 | |
| 1586 @staticmethod | |
| 1587 def parse(revision, **kwargs): | |
| 1588 kwargs.setdefault('remote', 'origin') | |
| 1589 kwargs.setdefault('other_remotes', ('server', 'backup')) | |
| 1590 return gclient_scm.GitRefish.Parse(revision, **kwargs) | |
| 1591 | |
| 1592 def testParse(self): | |
| 1593 | |
|
M-A Ruel
2014/06/25 20:54:57
remove
dnj
2014/06/25 21:48:31
Done.
| |
| 1594 LONG_HASH = '0c745b5ff533cf50a8731e168908644a9d9be4cf' | |
| 1595 SHORT_HASH = '0c745b5' | |
| 1596 TARGETS = ( | |
| 1597 ( | |
| 1598 'refs/heads/master', | |
| 1599 gclient_scm.GitRefish( | |
| 1600 source='refs/heads/master', | |
| 1601 is_branch=True, | |
| 1602 local_ref='master', | |
| 1603 remote='origin', | |
| 1604 remote_ref='master', | |
| 1605 remote_refspec='origin/master', | |
| 1606 upstream_branch='refs/remotes/origin/master', | |
| 1607 ), | |
| 1608 ), | |
| 1609 | |
|
M-A Ruel
2014/06/25 20:54:57
I don't see value in the whitespaces, it's already
dnj
2014/06/25 21:48:31
The whitespace is useful to me b/c it lets vim tra
| |
| 1610 ( | |
| 1611 'refs/special/magic', | |
| 1612 gclient_scm.GitRefish( | |
| 1613 source='refs/special/magic', | |
| 1614 is_branch=True, | |
| 1615 local_ref='refs/special/magic', | |
| 1616 remote='origin', | |
| 1617 remote_ref='refs/special/magic', | |
| 1618 remote_refspec='origin/refs/special/magic', | |
| 1619 upstream_branch='refs/special/magic', | |
| 1620 ) | |
| 1621 ), | |
| 1622 | |
| 1623 ( | |
| 1624 'origin/foo/bar', | |
| 1625 gclient_scm.GitRefish( | |
| 1626 source='origin/foo/bar', | |
| 1627 is_branch=True, | |
| 1628 local_ref='refs/remotes/origin/foo/bar', | |
| 1629 remote='origin', | |
| 1630 remote_ref='foo/bar', | |
| 1631 remote_refspec='origin/foo/bar', | |
| 1632 upstream_branch='origin/foo/bar', | |
| 1633 ) | |
| 1634 ), | |
| 1635 | |
| 1636 ( | |
| 1637 'server/foo/bar', | |
| 1638 gclient_scm.GitRefish( | |
| 1639 source='server/foo/bar', | |
| 1640 is_branch=True, | |
| 1641 local_ref='refs/remotes/server/foo/bar', | |
| 1642 remote='server', | |
| 1643 remote_ref='foo/bar', | |
| 1644 remote_refspec='server/foo/bar', | |
| 1645 upstream_branch='server/foo/bar', | |
| 1646 ), | |
| 1647 ), | |
| 1648 | |
| 1649 ( | |
| 1650 'refs/remotes/foo/bar/baz', | |
| 1651 gclient_scm.GitRefish( | |
| 1652 source='refs/remotes/foo/bar/baz', | |
| 1653 is_branch=True, | |
| 1654 local_ref='refs/remotes/foo/bar/baz', | |
| 1655 remote='foo', | |
| 1656 remote_ref='bar/baz', | |
| 1657 remote_refspec='foo/bar/baz', | |
| 1658 upstream_branch='refs/remotes/foo/bar/baz', | |
| 1659 ) | |
| 1660 ), | |
| 1661 | |
| 1662 ( | |
| 1663 LONG_HASH, | |
| 1664 gclient_scm.GitRefish( | |
| 1665 source=LONG_HASH, | |
| 1666 is_branch=False, | |
| 1667 local_ref=LONG_HASH, | |
| 1668 remote='origin', | |
| 1669 remote_ref=LONG_HASH, | |
| 1670 remote_refspec=LONG_HASH, | |
| 1671 upstream_branch=None, | |
| 1672 ), | |
| 1673 ), | |
| 1674 | |
| 1675 # Short hash (consider it a hash) | |
| 1676 ( | |
| 1677 SHORT_HASH, | |
| 1678 gclient_scm.GitRefish( | |
| 1679 source=SHORT_HASH, | |
| 1680 is_branch=False, | |
| 1681 local_ref=SHORT_HASH, | |
| 1682 remote='origin', | |
| 1683 remote_ref=SHORT_HASH, | |
| 1684 remote_refspec=SHORT_HASH, | |
| 1685 upstream_branch=None, | |
| 1686 ), | |
| 1687 ), | |
| 1688 | |
| 1689 # Unqualified branches are currently parsed as hash/tag | |
| 1690 ( | |
| 1691 'master', | |
| 1692 gclient_scm.GitRefish( | |
| 1693 source='master', | |
| 1694 is_branch=False, | |
| 1695 local_ref='master', | |
| 1696 remote='origin', | |
| 1697 remote_ref='master', | |
| 1698 remote_refspec='master', | |
| 1699 upstream_branch=None, | |
| 1700 ) | |
| 1701 ), | |
| 1702 ) | |
| 1703 | |
| 1704 for value, refish in TARGETS: | |
| 1705 parsed_refish = self.parse(value) | |
| 1706 self.assertEqual(parsed_refish, refish) | |
| 1707 | |
| 1708 | |
| 1583 if __name__ == '__main__': | 1709 if __name__ == '__main__': |
| 1584 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 1710 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
| 1585 logging.basicConfig( | 1711 logging.basicConfig( |
| 1586 level=level, | 1712 level=level, |
| 1587 format='%(asctime).19s %(levelname)s %(filename)s:' | 1713 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 1588 '%(lineno)s %(message)s') | 1714 '%(lineno)s %(message)s') |
| 1589 unittest.main() | 1715 unittest.main() |
| 1590 | 1716 |
| 1591 # vim: ts=2:sw=2:tw=80:et: | 1717 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |