~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-21 11:35:35 UTC
  • mfrom: (6089.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20110821113535-5pi9vz6tx6wdf62m
(vila) Merge 2.4 into trunk (including fix for #614713, #735417,
 #609187 and #812928) (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1744
1744
        self.assertEqual(set([NULL_REVISION, 'tip', 'tag', 'mid']), recipe[2])
1745
1745
        self.assertEqual(0, recipe[3])
1746
1746
        self.assertTrue(result.is_empty())
1747
 
 
1748
 
 
1749
 
class TestSearchResultFromParentMap(TestGraphBase):
1750
 
 
1751
 
    def assertSearchResult(self, start_keys, stop_keys, key_count, parent_map,
1752
 
                           missing_keys=()):
1753
 
        (start, stop, count) = _mod_graph.search_result_from_parent_map(
1754
 
            parent_map, missing_keys)
1755
 
        self.assertEqual((sorted(start_keys), sorted(stop_keys), key_count),
1756
 
                         (sorted(start), sorted(stop), count))
1757
 
 
1758
 
    def test_no_parents(self):
1759
 
        self.assertSearchResult([], [], 0, {})
1760
 
        self.assertSearchResult([], [], 0, None)
1761
 
 
1762
 
    def test_ancestry_1(self):
1763
 
        self.assertSearchResult(['rev4'], [NULL_REVISION], len(ancestry_1),
1764
 
                                ancestry_1)
1765
 
 
1766
 
    def test_ancestry_2(self):
1767
 
        self.assertSearchResult(['rev1b', 'rev4a'], [NULL_REVISION],
1768
 
                                len(ancestry_2), ancestry_2)
1769
 
        self.assertSearchResult(['rev1b', 'rev4a'], [],
1770
 
                                len(ancestry_2)+1, ancestry_2,
1771
 
                                missing_keys=[NULL_REVISION])
1772
 
 
1773
 
    def test_partial_search(self):
1774
 
        parent_map = dict((k,extended_history_shortcut[k])
1775
 
                          for k in ['e', 'f'])
1776
 
        self.assertSearchResult(['e', 'f'], ['d', 'a'], 2,
1777
 
                                parent_map)
1778
 
        parent_map.update((k,extended_history_shortcut[k])
1779
 
                          for k in ['d', 'a'])
1780
 
        self.assertSearchResult(['e', 'f'], ['c', NULL_REVISION], 4,
1781
 
                                parent_map)
1782
 
        parent_map['c'] = extended_history_shortcut['c']
1783
 
        self.assertSearchResult(['e', 'f'], ['b'], 6,
1784
 
                                parent_map, missing_keys=[NULL_REVISION])
1785
 
        parent_map['b'] = extended_history_shortcut['b']
1786
 
        self.assertSearchResult(['e', 'f'], [], 7,
1787
 
                                parent_map, missing_keys=[NULL_REVISION])
1788
 
 
1789
 
 
1790
 
class TestLimitedSearchResultFromParentMap(TestGraphBase):
1791
 
 
1792
 
    def assertSearchResult(self, start_keys, stop_keys, key_count, parent_map,
1793
 
                           missing_keys, tip_keys, depth):
1794
 
        (start, stop, count) = _mod_graph.limited_search_result_from_parent_map(
1795
 
            parent_map, missing_keys, tip_keys, depth)
1796
 
        self.assertEqual((sorted(start_keys), sorted(stop_keys), key_count),
1797
 
                         (sorted(start), sorted(stop), count))
1798
 
 
1799
 
    def test_empty_ancestry(self):
1800
 
        self.assertSearchResult([], [], 0, {}, (), ['tip-rev-id'], 10)
1801
 
 
1802
 
    def test_ancestry_1(self):
1803
 
        self.assertSearchResult(['rev4'], ['rev1'], 4,
1804
 
                                ancestry_1, (), ['rev1'], 10)
1805
 
        self.assertSearchResult(['rev2a', 'rev2b'], ['rev1'], 2,
1806
 
                                ancestry_1, (), ['rev1'], 1)
1807
 
 
1808
 
 
1809
 
    def test_multiple_heads(self):
1810
 
        self.assertSearchResult(['e', 'f'], ['a'], 5,
1811
 
                                extended_history_shortcut, (), ['a'], 10)
1812
 
        # Note that even though we only take 1 step back, we find 'f', which
1813
 
        # means the described search will still find d and c.
1814
 
        self.assertSearchResult(['f'], ['a'], 4,
1815
 
                                extended_history_shortcut, (), ['a'], 1)
1816
 
        self.assertSearchResult(['f'], ['a'], 4,
1817
 
                                extended_history_shortcut, (), ['a'], 2)