~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_versionedfile.py

  • Committer: Martin Pool
  • Date: 2009-09-14 01:48:28 UTC
  • mfrom: (4685 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090914014828-ydr9rlkdfq2sv57z
Merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
from bzrlib import (
28
28
    errors,
 
29
    graph as _mod_graph,
29
30
    groupcompress,
30
31
    knit as _mod_knit,
31
32
    osutils,
32
33
    progress,
 
34
    ui,
33
35
    )
34
36
from bzrlib.errors import (
35
37
                           RevisionNotPresent,
1557
1559
        self.assertRaises(RevisionNotPresent,
1558
1560
            files.annotate, prefix + ('missing-key',))
1559
1561
 
1560
 
    def test_get_annotator(self):
 
1562
    def test_check_no_parameters(self):
 
1563
        files = self.get_versionedfiles()
 
1564
 
 
1565
    def test_check_progressbar_parameter(self):
 
1566
        """A progress bar can be supplied because check can be a generator."""
 
1567
        pb = ui.ui_factory.nested_progress_bar()
 
1568
        self.addCleanup(pb.finished)
 
1569
        files = self.get_versionedfiles()
 
1570
        files.check(progress_bar=pb)
 
1571
 
 
1572
    def test_check_with_keys_becomes_generator(self):
1561
1573
        files = self.get_versionedfiles()
1562
1574
        self.get_diamond_files(files)
1563
 
        origin_key = self.get_simple_key('origin')
1564
 
        base_key = self.get_simple_key('base')
1565
 
        left_key = self.get_simple_key('left')
1566
 
        right_key = self.get_simple_key('right')
1567
 
        merged_key = self.get_simple_key('merged')
1568
 
        # annotator = files.get_annotator()
1569
 
        # introduced full text
1570
 
        origins, lines = files.get_annotator().annotate(origin_key)
1571
 
        self.assertEqual([(origin_key,)], origins)
1572
 
        self.assertEqual(['origin\n'], lines)
1573
 
        # a delta
1574
 
        origins, lines = files.get_annotator().annotate(base_key)
1575
 
        self.assertEqual([(base_key,)], origins)
1576
 
        # a merge
1577
 
        origins, lines = files.get_annotator().annotate(merged_key)
1578
 
        if self.graph:
1579
 
            self.assertEqual([
1580
 
                (base_key,),
1581
 
                (left_key,),
1582
 
                (right_key,),
1583
 
                (merged_key,),
1584
 
                ], origins)
1585
 
        else:
1586
 
            # Without a graph everything is new.
1587
 
            self.assertEqual([
1588
 
                (merged_key,),
1589
 
                (merged_key,),
1590
 
                (merged_key,),
1591
 
                (merged_key,),
1592
 
                ], origins)
1593
 
        self.assertRaises(RevisionNotPresent,
1594
 
            files.get_annotator().annotate, self.get_simple_key('missing-key'))
 
1575
        keys = files.keys()
 
1576
        entries = files.check(keys=keys)
 
1577
        seen = set()
 
1578
        # Texts output should be fulltexts.
 
1579
        self.capture_stream(files, entries, seen.add,
 
1580
            files.get_parent_map(keys), require_fulltext=True)
 
1581
        # All texts should be output.
 
1582
        self.assertEqual(set(keys), seen)
1595
1583
 
1596
1584
    def test_construct(self):
1597
1585
        """Each parameterised test can be constructed on a transport."""
1750
1738
            f.get_record_stream([key_b], 'unordered', True
1751
1739
                ).next().get_bytes_as('fulltext'))
1752
1740
 
 
1741
    def test_get_known_graph_ancestry(self):
 
1742
        f = self.get_versionedfiles()
 
1743
        if not self.graph:
 
1744
            raise TestNotApplicable('ancestry info only relevant with graph.')
 
1745
        key_a = self.get_simple_key('a')
 
1746
        key_b = self.get_simple_key('b')
 
1747
        key_c = self.get_simple_key('c')
 
1748
        # A
 
1749
        # |\
 
1750
        # | B
 
1751
        # |/
 
1752
        # C
 
1753
        f.add_lines(key_a, [], ['\n'])
 
1754
        f.add_lines(key_b, [key_a], ['\n'])
 
1755
        f.add_lines(key_c, [key_a, key_b], ['\n'])
 
1756
        kg = f.get_known_graph_ancestry([key_c])
 
1757
        self.assertIsInstance(kg, _mod_graph.KnownGraph)
 
1758
        self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
 
1759
 
 
1760
    def test_known_graph_with_fallbacks(self):
 
1761
        f = self.get_versionedfiles('files')
 
1762
        if not self.graph:
 
1763
            raise TestNotApplicable('ancestry info only relevant with graph.')
 
1764
        if getattr(f, 'add_fallback_versioned_files', None) is None:
 
1765
            raise TestNotApplicable("%s doesn't support fallbacks"
 
1766
                                    % (f.__class__.__name__,))
 
1767
        key_a = self.get_simple_key('a')
 
1768
        key_b = self.get_simple_key('b')
 
1769
        key_c = self.get_simple_key('c')
 
1770
        # A     only in fallback
 
1771
        # |\
 
1772
        # | B
 
1773
        # |/
 
1774
        # C
 
1775
        g = self.get_versionedfiles('fallback')
 
1776
        g.add_lines(key_a, [], ['\n'])
 
1777
        f.add_fallback_versioned_files(g)
 
1778
        f.add_lines(key_b, [key_a], ['\n'])
 
1779
        f.add_lines(key_c, [key_a, key_b], ['\n'])
 
1780
        kg = f.get_known_graph_ancestry([key_c])
 
1781
        self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
 
1782
 
1753
1783
    def test_get_record_stream_empty(self):
1754
1784
        """An empty stream can be requested without error."""
1755
1785
        f = self.get_versionedfiles()
1766
1796
             'knit-delta-closure', 'knit-delta-closure-ref',
1767
1797
             'groupcompress-block', 'groupcompress-block-ref'])
1768
1798
 
1769
 
    def capture_stream(self, f, entries, on_seen, parents):
 
1799
    def capture_stream(self, f, entries, on_seen, parents,
 
1800
        require_fulltext=False):
1770
1801
        """Capture a stream for testing."""
1771
1802
        for factory in entries:
1772
1803
            on_seen(factory.key)
1777
1808
            self.assertEqual(parents[factory.key], factory.parents)
1778
1809
            self.assertIsInstance(factory.get_bytes_as(factory.storage_kind),
1779
1810
                str)
 
1811
            if require_fulltext:
 
1812
                factory.get_bytes_as('fulltext')
1780
1813
 
1781
1814
    def test_get_record_stream_interface(self):
1782
1815
        """each item in a stream has to provide a regular interface."""
2157
2190
        else:
2158
2191
            return None
2159
2192
 
 
2193
    def test_get_annotator(self):
 
2194
        files = self.get_versionedfiles()
 
2195
        self.get_diamond_files(files)
 
2196
        origin_key = self.get_simple_key('origin')
 
2197
        base_key = self.get_simple_key('base')
 
2198
        left_key = self.get_simple_key('left')
 
2199
        right_key = self.get_simple_key('right')
 
2200
        merged_key = self.get_simple_key('merged')
 
2201
        # annotator = files.get_annotator()
 
2202
        # introduced full text
 
2203
        origins, lines = files.get_annotator().annotate(origin_key)
 
2204
        self.assertEqual([(origin_key,)], origins)
 
2205
        self.assertEqual(['origin\n'], lines)
 
2206
        # a delta
 
2207
        origins, lines = files.get_annotator().annotate(base_key)
 
2208
        self.assertEqual([(base_key,)], origins)
 
2209
        # a merge
 
2210
        origins, lines = files.get_annotator().annotate(merged_key)
 
2211
        if self.graph:
 
2212
            self.assertEqual([
 
2213
                (base_key,),
 
2214
                (left_key,),
 
2215
                (right_key,),
 
2216
                (merged_key,),
 
2217
                ], origins)
 
2218
        else:
 
2219
            # Without a graph everything is new.
 
2220
            self.assertEqual([
 
2221
                (merged_key,),
 
2222
                (merged_key,),
 
2223
                (merged_key,),
 
2224
                (merged_key,),
 
2225
                ], origins)
 
2226
        self.assertRaises(RevisionNotPresent,
 
2227
            files.get_annotator().annotate, self.get_simple_key('missing-key'))
 
2228
 
2160
2229
    def test_get_parent_map(self):
2161
2230
        files = self.get_versionedfiles()
2162
2231
        if self.key_length == 1:
2637
2706
        self.assertRaises(NotImplementedError,
2638
2707
                self.texts.add_mpdiffs, [])
2639
2708
 
2640
 
    def test_check(self):
2641
 
        self.assertTrue(self.texts.check())
 
2709
    def test_check_noerrors(self):
 
2710
        self.texts.check()
2642
2711
 
2643
2712
    def test_insert_record_stream(self):
2644
2713
        self.assertRaises(NotImplementedError, self.texts.insert_record_stream,