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) |
1281 | 1282 |
1282 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | 1283 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) |
1283 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( | 1284 gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( |
1284 ).AndReturn(True) | 1285 ).AndReturn(True) |
1285 | 1286 |
1286 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) | 1287 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) |
1287 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 | 1288 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 |
1288 ).AndReturn(True) | 1289 ).AndReturn(True) |
1289 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big | 1290 gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=too_big |
1290 ).MultipleTimes(2).AndReturn(False) | 1291 ).MultipleTimes(2).AndReturn(False) |
1291 # pylint: disable=E1120 | |
1292 gclient_scm.GitWrapper._Fetch(options) | |
1293 | 1292 |
1294 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 1293 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
1295 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) | 1294 gclient_scm.os.path.isdir(self.base_path).MultipleTimes().AndReturn(True) |
1296 | 1295 |
1297 self.mox.ReplayAll() | 1296 self.mox.ReplayAll() |
1298 | 1297 |
1299 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 1298 git_svn_scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
1300 relpath=self.relpath) | 1299 relpath=self.relpath) |
1301 # Without an existing checkout, this should fail. | 1300 # Without an existing checkout, this should fail. |
1302 # TODO(dbeam) Fix this. http://crbug.com/109184 | 1301 # TODO(dbeam) Fix this. http://crbug.com/109184 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 relpath=self.relpath) | 1573 relpath=self.relpath) |
1575 file_list = [] | 1574 file_list = [] |
1576 options.revision = 'unmanaged' | 1575 options.revision = 'unmanaged' |
1577 scm.update(options, (), file_list) | 1576 scm.update(options, (), file_list) |
1578 self.assertEquals(file_list, expected_file_list) | 1577 self.assertEquals(file_list, expected_file_list) |
1579 self.assertEquals(scm.revinfo(options, (), None), | 1578 self.assertEquals(scm.revinfo(options, (), None), |
1580 '069c602044c5388d2d15c3f875b057c852003458') | 1579 '069c602044c5388d2d15c3f875b057c852003458') |
1581 self.checkstdout('________ unmanaged solution; skipping .\n') | 1580 self.checkstdout('________ unmanaged solution; skipping .\n') |
1582 | 1581 |
1583 | 1582 |
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 LONG_HASH = '0c745b5ff533cf50a8731e168908644a9d9be4cf' | |
1594 SHORT_HASH = '0c745b5' | |
1595 TARGETS = ( | |
1596 ( | |
1597 'refs/heads/master', | |
1598 gclient_scm.GitRefish( | |
1599 source='refs/heads/master', | |
1600 is_branch=True, | |
1601 local_ref='master', | |
1602 remote='origin', | |
1603 remote_ref='master', | |
1604 remote_refspec='origin/master', | |
1605 upstream_branch='refs/remotes/origin/master', | |
1606 ), | |
1607 ), | |
1608 | |
1609 ( | |
1610 'refs/special/magic', | |
1611 gclient_scm.GitRefish( | |
1612 source='refs/special/magic', | |
1613 is_branch=True, | |
1614 local_ref='refs/special/magic', | |
1615 remote='origin', | |
1616 remote_ref='refs/special/magic', | |
1617 remote_refspec='origin/refs/special/magic', | |
1618 upstream_branch='refs/special/magic', | |
1619 ) | |
1620 ), | |
1621 | |
1622 ( | |
1623 'origin/foo/bar', | |
1624 gclient_scm.GitRefish( | |
1625 source='origin/foo/bar', | |
1626 is_branch=True, | |
1627 local_ref='refs/remotes/origin/foo/bar', | |
1628 remote='origin', | |
1629 remote_ref='foo/bar', | |
1630 remote_refspec='origin/foo/bar', | |
1631 upstream_branch='origin/foo/bar', | |
1632 ) | |
1633 ), | |
1634 | |
1635 ( | |
1636 'server/foo/bar', | |
1637 gclient_scm.GitRefish( | |
1638 source='server/foo/bar', | |
1639 is_branch=True, | |
1640 local_ref='refs/remotes/server/foo/bar', | |
1641 remote='server', | |
1642 remote_ref='foo/bar', | |
1643 remote_refspec='server/foo/bar', | |
1644 upstream_branch='server/foo/bar', | |
1645 ), | |
1646 ), | |
1647 | |
1648 ( | |
1649 'refs/remotes/foo/bar/baz', | |
1650 gclient_scm.GitRefish( | |
1651 source='refs/remotes/foo/bar/baz', | |
1652 is_branch=True, | |
1653 local_ref='refs/remotes/foo/bar/baz', | |
1654 remote='foo', | |
1655 remote_ref='bar/baz', | |
1656 remote_refspec='foo/bar/baz', | |
1657 upstream_branch='refs/remotes/foo/bar/baz', | |
1658 ) | |
1659 ), | |
1660 | |
1661 ( | |
1662 'foo/bar', | |
1663 gclient_scm.GitRefish( | |
1664 source='foo/bar', | |
1665 is_branch=True, | |
1666 local_ref='foo/bar', | |
1667 remote='origin', | |
1668 remote_ref='foo/bar', | |
1669 remote_refspec='origin/foo/bar', | |
1670 upstream_branch='foo/bar', | |
1671 ), | |
1672 ), | |
1673 | |
1674 ( | |
1675 LONG_HASH, | |
1676 gclient_scm.GitRefish( | |
1677 source=LONG_HASH, | |
1678 is_branch=False, | |
1679 local_ref=LONG_HASH, | |
1680 remote='origin', | |
1681 remote_ref=LONG_HASH, | |
1682 remote_refspec=LONG_HASH, | |
1683 upstream_branch=None, | |
1684 ), | |
1685 ), | |
1686 | |
1687 # Short hash (consider it a hash) | |
1688 ( | |
1689 SHORT_HASH, | |
1690 gclient_scm.GitRefish( | |
1691 source=SHORT_HASH, | |
1692 is_branch=False, | |
1693 local_ref=SHORT_HASH, | |
1694 remote='origin', | |
1695 remote_ref=SHORT_HASH, | |
1696 remote_refspec=SHORT_HASH, | |
1697 upstream_branch=None, | |
1698 ), | |
1699 ), | |
1700 | |
1701 # Unqualified branches are currently parsed as hash/tag | |
1702 ( | |
1703 'master', | |
1704 gclient_scm.GitRefish( | |
1705 source='master', | |
1706 is_branch=False, | |
1707 local_ref='master', | |
1708 remote='origin', | |
1709 remote_ref='master', | |
1710 remote_refspec='master', | |
1711 upstream_branch=None, | |
1712 ) | |
1713 ), | |
1714 ) | |
1715 | |
1716 for value, refish in TARGETS: | |
1717 parsed_refish = self.parse(value) | |
1718 self.assertEqual(parsed_refish, refish) | |
1719 | |
1720 | |
1721 if __name__ == '__main__': | 1583 if __name__ == '__main__': |
1722 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 1584 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
1723 logging.basicConfig( | 1585 logging.basicConfig( |
1724 level=level, | 1586 level=level, |
1725 format='%(asctime).19s %(levelname)s %(filename)s:' | 1587 format='%(asctime).19s %(levelname)s %(filename)s:' |
1726 '%(lineno)s %(message)s') | 1588 '%(lineno)s %(message)s') |
1727 unittest.main() | 1589 unittest.main() |
1728 | 1590 |
1729 # vim: ts=2:sw=2:tw=80:et: | 1591 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |