~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-14 06:47:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5155.
  • Revision ID: andrew.bennetts@canonical.com-20100414064718-130ptdug4opfjj6b
Link to Python bug in comment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    errors,
23
22
    log,
24
23
    registry,
1542
1541
 
1543
1542
    def test_bugs_handler_present(self):
1544
1543
        self.properties_handler_registry.get('bugs_properties_handler')
1545
 
 
1546
 
 
1547
 
class TestLogForAuthors(TestCaseForLogFormatter):
1548
 
 
1549
 
    def setUp(self):
1550
 
        TestCaseForLogFormatter.setUp(self)
1551
 
        self.wt = self.make_standard_commit('nicky',
1552
 
            authors=['John Doe <jdoe@example.com>',
1553
 
                     'Jane Rey <jrey@example.com>'])
1554
 
 
1555
 
    def assertFormatterResult(self, formatter, who, result):
1556
 
        formatter_kwargs = dict()
1557
 
        if who is not None:
1558
 
            author_list_handler = log.author_list_registry.get(who)
1559
 
            formatter_kwargs['author_list_handler'] = author_list_handler
1560
 
        TestCaseForLogFormatter.assertFormatterResult(self, result,
1561
 
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
1562
 
 
1563
 
    def test_line_default(self):
1564
 
        self.assertFormatterResult(log.LineLogFormatter, None, """\
1565
 
1: John Doe 2005-11-22 add a
1566
 
""")
1567
 
 
1568
 
    def test_line_committer(self):
1569
 
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
1570
 
1: Lorem Ipsum 2005-11-22 add a
1571
 
""")
1572
 
 
1573
 
    def test_line_first(self):
1574
 
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
1575
 
1: John Doe 2005-11-22 add a
1576
 
""")
1577
 
 
1578
 
    def test_line_all(self):
1579
 
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
1580
 
1: John Doe, Jane Rey 2005-11-22 add a
1581
 
""")
1582
 
 
1583
 
 
1584
 
    def test_short_default(self):
1585
 
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
1586
 
    1 John Doe\t2005-11-22
1587
 
      add a
1588
 
 
1589
 
""")
1590
 
 
1591
 
    def test_short_committer(self):
1592
 
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
1593
 
    1 Lorem Ipsum\t2005-11-22
1594
 
      add a
1595
 
 
1596
 
""")
1597
 
 
1598
 
    def test_short_first(self):
1599
 
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
1600
 
    1 John Doe\t2005-11-22
1601
 
      add a
1602
 
 
1603
 
""")
1604
 
 
1605
 
    def test_short_all(self):
1606
 
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
1607
 
    1 John Doe, Jane Rey\t2005-11-22
1608
 
      add a
1609
 
 
1610
 
""")
1611
 
 
1612
 
    def test_long_default(self):
1613
 
        self.assertFormatterResult(log.LongLogFormatter, None, """\
1614
 
------------------------------------------------------------
1615
 
revno: 1
1616
 
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1617
 
committer: Lorem Ipsum <test@example.com>
1618
 
branch nick: nicky
1619
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1620
 
message:
1621
 
  add a
1622
 
""")
1623
 
 
1624
 
    def test_long_committer(self):
1625
 
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
1626
 
------------------------------------------------------------
1627
 
revno: 1
1628
 
committer: Lorem Ipsum <test@example.com>
1629
 
branch nick: nicky
1630
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1631
 
message:
1632
 
  add a
1633
 
""")
1634
 
 
1635
 
    def test_long_first(self):
1636
 
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
1637
 
------------------------------------------------------------
1638
 
revno: 1
1639
 
author: John Doe <jdoe@example.com>
1640
 
committer: Lorem Ipsum <test@example.com>
1641
 
branch nick: nicky
1642
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1643
 
message:
1644
 
  add a
1645
 
""")
1646
 
 
1647
 
    def test_long_all(self):
1648
 
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
1649
 
------------------------------------------------------------
1650
 
revno: 1
1651
 
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1652
 
committer: Lorem Ipsum <test@example.com>
1653
 
branch nick: nicky
1654
 
timestamp: Tue 2005-11-22 00:00:00 +0000
1655
 
message:
1656
 
  add a
1657
 
""")
1658
 
 
1659
 
    def test_gnu_changelog_default(self):
1660
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
1661
 
2005-11-22  John Doe  <jdoe@example.com>
1662
 
 
1663
 
\tadd a
1664
 
 
1665
 
""")
1666
 
 
1667
 
    def test_gnu_changelog_committer(self):
1668
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
1669
 
2005-11-22  Lorem Ipsum  <test@example.com>
1670
 
 
1671
 
\tadd a
1672
 
 
1673
 
""")
1674
 
 
1675
 
    def test_gnu_changelog_first(self):
1676
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
1677
 
2005-11-22  John Doe  <jdoe@example.com>
1678
 
 
1679
 
\tadd a
1680
 
 
1681
 
""")
1682
 
 
1683
 
    def test_gnu_changelog_all(self):
1684
 
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
1685
 
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
1686
 
 
1687
 
\tadd a
1688
 
 
1689
 
""")
1690
 
 
1691
 
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1692
 
 
1693
 
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1694
 
        # See test_merge_sorted_exclude_ancestry below for the difference with
1695
 
        # bt.per_branch.test_iter_merge_sorted_revision.
1696
 
        # TestIterMergeSortedRevisionsBushyGraph. 
1697
 
        # make_branch_with_alternate_ancestries
1698
 
        # and test_merge_sorted_exclude_ancestry
1699
 
        # See the FIXME in assertLogRevnos too.
1700
 
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1701
 
        # 1
1702
 
        # |\
1703
 
        # 2 \
1704
 
        # |  |
1705
 
        # |  1.1.1
1706
 
        # |  | \
1707
 
        # |  |  1.2.1
1708
 
        # |  | /
1709
 
        # |  1.1.2
1710
 
        # | /
1711
 
        # 3
1712
 
        builder.start_series()
1713
 
        builder.build_snapshot('1', None, [
1714
 
            ('add', ('', 'TREE_ROOT', 'directory', '')),])
1715
 
        builder.build_snapshot('1.1.1', ['1'], [])
1716
 
        builder.build_snapshot('2', ['1'], [])
1717
 
        builder.build_snapshot('1.2.1', ['1.1.1'], [])
1718
 
        builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
1719
 
        builder.build_snapshot('3', ['2', '1.1.2'], [])
1720
 
        builder.finish_series()
1721
 
        br = builder.get_branch()
1722
 
        br.lock_read()
1723
 
        self.addCleanup(br.unlock)
1724
 
        return br
1725
 
 
1726
 
    def assertLogRevnos(self, expected_revnos, b, start, end,
1727
 
                        exclude_common_ancestry, generate_merge_revisions=True):
1728
 
        # FIXME: the layering in log makes it hard to test intermediate levels,
1729
 
        # I wish adding filters with their parameters were easier...
1730
 
        # -- vila 20100413
1731
 
        iter_revs = log._calc_view_revisions(
1732
 
            b, start, end, direction='reverse',
1733
 
            generate_merge_revisions=generate_merge_revisions,
1734
 
            exclude_common_ancestry=exclude_common_ancestry)
1735
 
        self.assertEqual(expected_revnos,
1736
 
                         [revid for revid, revno, depth in iter_revs])
1737
 
 
1738
 
    def test_merge_sorted_exclude_ancestry(self):
1739
 
        b = self.make_branch_with_alternate_ancestries()
1740
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1741
 
                             b, '1', '3', exclude_common_ancestry=False)
1742
 
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1743
 
        # it should be mentioned even if merge_sort order will make it appear
1744
 
        # after 1.1.1
1745
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1746
 
                             b, '1.1.1', '3', exclude_common_ancestry=True)
1747
 
 
1748
 
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1749
 
        b = self.make_branch_with_alternate_ancestries()
1750
 
        self.assertLogRevnos(['3', '2'],
1751
 
                             b, '1', '3', exclude_common_ancestry=True,
1752
 
                             generate_merge_revisions=False)
1753
 
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
1754
 
                             b, '1', '3', exclude_common_ancestry=True,
1755
 
                             generate_merge_revisions=True)
1756