~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1543
1543
    def test_bugs_handler_present(self):
1544
1544
        self.properties_handler_registry.get('bugs_properties_handler')
1545
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
 
1546
1691
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1547
1692
 
1548
1693
    def make_branch_with_alternate_ancestries(self, relpath='.'):
1579
1724
        return br
1580
1725
 
1581
1726
    def assertLogRevnos(self, expected_revnos, b, start, end,
1582
 
                        exclude_common_ancestry):
 
1727
                        exclude_common_ancestry, generate_merge_revisions=True):
1583
1728
        # FIXME: the layering in log makes it hard to test intermediate levels,
1584
1729
        # I wish adding filters with their parameters were easier...
1585
1730
        # -- vila 20100413
1586
1731
        iter_revs = log._calc_view_revisions(
1587
1732
            b, start, end, direction='reverse',
1588
 
            generate_merge_revisions=True,
 
1733
            generate_merge_revisions=generate_merge_revisions,
1589
1734
            exclude_common_ancestry=exclude_common_ancestry)
1590
1735
        self.assertEqual(expected_revnos,
1591
1736
                         [revid for revid, revno, depth in iter_revs])
1593
1738
    def test_merge_sorted_exclude_ancestry(self):
1594
1739
        b = self.make_branch_with_alternate_ancestries()
1595
1740
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1596
 
                             b, '1', '3', False)
 
1741
                             b, '1', '3', exclude_common_ancestry=False)
1597
1742
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1598
1743
        # it should be mentioned even if merge_sort order will make it appear
1599
1744
        # after 1.1.1
1600
1745
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1601
 
                             b, '1.1.1', '3', True)
 
1746
                             b, '1.1.1', '3', exclude_common_ancestry=True)
1602
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)
1603
1756