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 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 scm.update(options, (), file_list) | 1554 scm.update(options, (), file_list) |
1555 | 1555 |
1556 self.assertEquals(file_list, expected_file_list) | 1556 self.assertEquals(file_list, expected_file_list) |
1557 self.assertEquals(scm.revinfo(options, (), None), | 1557 self.assertEquals(scm.revinfo(options, (), None), |
1558 '9a51244740b25fa2ded5252ca00a3178d3f665a9') | 1558 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1559 self.assertEquals(self.getCurrentBranch(), 'feature') | 1559 self.assertEquals(self.getCurrentBranch(), 'feature') |
1560 self.checkNotInStdout('Checked out feature to a detached HEAD') | 1560 self.checkNotInStdout('Checked out feature to a detached HEAD') |
1561 | 1561 |
1562 rmtree(origin_root_dir) | 1562 rmtree(origin_root_dir) |
1563 | 1563 |
1564 def testUpdateCloneOnDetachedBranch(self): | 1564 def testUpdateCloneOnFetchedRemoteBranch(self): |
1565 if not self.enabled: | 1565 if not self.enabled: |
1566 return | 1566 return |
1567 options = self.Options() | 1567 options = self.Options() |
1568 | 1568 |
1569 origin_root_dir = self.root_dir | 1569 origin_root_dir = self.root_dir |
1570 self.root_dir = tempfile.mkdtemp() | 1570 self.root_dir = tempfile.mkdtemp() |
1571 self.relpath = '.' | 1571 self.relpath = '.' |
1572 self.base_path = join(self.root_dir, self.relpath) | 1572 self.base_path = join(self.root_dir, self.relpath) |
1573 url_with_branch_ref = origin_root_dir + '@refs/remotes/origin/feature' | 1573 url_with_branch_ref = origin_root_dir + '@refs/remotes/origin/feature' |
1574 | 1574 |
(...skipping 11 matching lines...) Expand all Loading... |
1586 self.assertEquals(file_list, expected_file_list) | 1586 self.assertEquals(file_list, expected_file_list) |
1587 self.assertEquals(scm.revinfo(options, (), None), | 1587 self.assertEquals(scm.revinfo(options, (), None), |
1588 '9a51244740b25fa2ded5252ca00a3178d3f665a9') | 1588 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1589 # indicates detached HEAD | 1589 # indicates detached HEAD |
1590 self.assertEquals(self.getCurrentBranch(), None) | 1590 self.assertEquals(self.getCurrentBranch(), None) |
1591 self.checkInStdout( | 1591 self.checkInStdout( |
1592 'Checked out refs/remotes/origin/feature to a detached HEAD') | 1592 'Checked out refs/remotes/origin/feature to a detached HEAD') |
1593 | 1593 |
1594 rmtree(origin_root_dir) | 1594 rmtree(origin_root_dir) |
1595 | 1595 |
1596 def testUpdateCloneOnBranchHead(self): | 1596 def testUpdateCloneOnTrueRemoteBranch(self): |
1597 if not self.enabled: | 1597 if not self.enabled: |
1598 return | 1598 return |
1599 options = self.Options() | 1599 options = self.Options() |
1600 | 1600 |
1601 origin_root_dir = self.root_dir | 1601 origin_root_dir = self.root_dir |
1602 self.root_dir = tempfile.mkdtemp() | 1602 self.root_dir = tempfile.mkdtemp() |
1603 self.relpath = '.' | 1603 self.relpath = '.' |
1604 self.base_path = join(self.root_dir, self.relpath) | 1604 self.base_path = join(self.root_dir, self.relpath) |
1605 url_with_branch_ref = origin_root_dir + '@refs/heads/feature' | 1605 url_with_branch_ref = origin_root_dir + '@refs/heads/feature' |
1606 | 1606 |
1607 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, | 1607 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, |
1608 root_dir=self.root_dir, | 1608 root_dir=self.root_dir, |
1609 relpath=self.relpath) | 1609 relpath=self.relpath) |
1610 | 1610 |
1611 expected_file_list = [join(self.base_path, "a"), | 1611 expected_file_list = [join(self.base_path, "a"), |
1612 join(self.base_path, "b"), | 1612 join(self.base_path, "b"), |
1613 join(self.base_path, "c")] | 1613 join(self.base_path, "c")] |
1614 file_list = [] | 1614 file_list = [] |
1615 options.revision = 'unmanaged' | 1615 options.revision = 'unmanaged' |
1616 scm.update(options, (), file_list) | 1616 scm.update(options, (), file_list) |
1617 | 1617 |
1618 self.assertEquals(file_list, expected_file_list) | 1618 self.assertEquals(file_list, expected_file_list) |
1619 self.assertEquals(scm.revinfo(options, (), None), | 1619 self.assertEquals(scm.revinfo(options, (), None), |
1620 '9a51244740b25fa2ded5252ca00a3178d3f665a9') | 1620 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1621 self.assertEquals(self.getCurrentBranch(), 'feature') | 1621 # @refs/heads/feature is AKA @refs/remotes/origin/feature in the clone, so |
1622 self.checkNotInStdout( | 1622 # should be treated as such by gclient. |
1623 'Checked out refs/heads/feature to a detached HEAD') | 1623 # TODO(mmoss): Though really, we should only allow DEPS to specify branches |
| 1624 # as they are known in the upstream repo, since the mapping into the local |
| 1625 # repo can be modified by users (or we might even want to change the gclient |
| 1626 # defaults at some point). But that will take more work to stop using |
| 1627 # refs/remotes/ everywhere that we do (and to stop assuming a DEPS ref will |
| 1628 # always resolve locally, like when passing them to show-ref or rev-list). |
| 1629 self.assertEquals(self.getCurrentBranch(), None) |
| 1630 self.checkInStdout( |
| 1631 'Checked out refs/remotes/origin/feature to a detached HEAD') |
1624 | 1632 |
1625 rmtree(origin_root_dir) | 1633 rmtree(origin_root_dir) |
1626 | 1634 |
1627 def testUpdateUpdate(self): | 1635 def testUpdateUpdate(self): |
1628 if not self.enabled: | 1636 if not self.enabled: |
1629 return | 1637 return |
1630 options = self.Options() | 1638 options = self.Options() |
1631 expected_file_list = [] | 1639 expected_file_list = [] |
1632 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1640 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
1633 relpath=self.relpath) | 1641 relpath=self.relpath) |
1634 file_list = [] | 1642 file_list = [] |
1635 options.revision = 'unmanaged' | 1643 options.revision = 'unmanaged' |
1636 scm.update(options, (), file_list) | 1644 scm.update(options, (), file_list) |
1637 self.assertEquals(file_list, expected_file_list) | 1645 self.assertEquals(file_list, expected_file_list) |
1638 self.assertEquals(scm.revinfo(options, (), None), | 1646 self.assertEquals(scm.revinfo(options, (), None), |
1639 '069c602044c5388d2d15c3f875b057c852003458') | 1647 '069c602044c5388d2d15c3f875b057c852003458') |
1640 self.checkstdout('________ unmanaged solution; skipping .\n') | 1648 self.checkstdout('________ unmanaged solution; skipping .\n') |
1641 | 1649 |
1642 | 1650 |
1643 if __name__ == '__main__': | 1651 if __name__ == '__main__': |
1644 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL | 1652 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL |
1645 logging.basicConfig( | 1653 logging.basicConfig( |
1646 level=level, | 1654 level=level, |
1647 format='%(asctime).19s %(levelname)s %(filename)s:' | 1655 format='%(asctime).19s %(levelname)s %(filename)s:' |
1648 '%(lineno)s %(message)s') | 1656 '%(lineno)s %(message)s') |
1649 unittest.main() | 1657 unittest.main() |
1650 | 1658 |
1651 # vim: ts=2:sw=2:tw=80:et: | 1659 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |