/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Aaron Bentley
  • Date: 2009-03-12 07:00:36 UTC
  • mfrom: (4125 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4127.
  • Revision ID: aaron@aaronbentley.com-20090312070036-am7ni53tebog0090
Merge bzr.dev into destructive-shelve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2009 Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
746
746
                self.assertEqual(expected, progress.updates)
747
747
            return lines
748
748
        lines = iter_with_versions(['child', 'otherchild'],
749
 
                                   [('Walking content.', 0, 2),
750
 
                                    ('Walking content.', 1, 2),
751
 
                                    ('Walking content.', 2, 2)])
 
749
                                   [('Walking content', 0, 2),
 
750
                                    ('Walking content', 1, 2),
 
751
                                    ('Walking content', 2, 2)])
752
752
        # we must see child and otherchild
753
753
        self.assertTrue(lines[('child\n', 'child')] > 0)
754
754
        self.assertTrue(lines[('otherchild\n', 'otherchild')] > 0)
755
755
        # we dont care if we got more than that.
756
756
 
757
757
        # test all lines
758
 
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
759
 
                                          ('Walking content.', 1, 5),
760
 
                                          ('Walking content.', 2, 5),
761
 
                                          ('Walking content.', 3, 5),
762
 
                                          ('Walking content.', 4, 5),
763
 
                                          ('Walking content.', 5, 5)])
 
758
        lines = iter_with_versions(None, [('Walking content', 0, 5),
 
759
                                          ('Walking content', 1, 5),
 
760
                                          ('Walking content', 2, 5),
 
761
                                          ('Walking content', 3, 5),
 
762
                                          ('Walking content', 4, 5),
 
763
                                          ('Walking content', 5, 5)])
764
764
        # all lines must be seen at least once
765
765
        self.assertTrue(lines[('base\n', 'base')] > 0)
766
766
        self.assertTrue(lines[('lancestor\n', 'lancestor')] > 0)
1493
1493
            trailing_eol=trailing_eol, nograph=not self.graph,
1494
1494
            left_only=left_only)
1495
1495
 
 
1496
    def test_add_lines_nostoresha(self):
 
1497
        """When nostore_sha is supplied using old content raises."""
 
1498
        vf = self.get_versionedfiles()
 
1499
        empty_text = ('a', [])
 
1500
        sample_text_nl = ('b', ["foo\n", "bar\n"])
 
1501
        sample_text_no_nl = ('c', ["foo\n", "bar"])
 
1502
        shas = []
 
1503
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
 
1504
            sha, _, _ = vf.add_lines(self.get_simple_key(version), [], lines)
 
1505
            shas.append(sha)
 
1506
        # we now have a copy of all the lines in the vf.
 
1507
        for sha, (version, lines) in zip(
 
1508
            shas, (empty_text, sample_text_nl, sample_text_no_nl)):
 
1509
            new_key = self.get_simple_key(version + "2")
 
1510
            self.assertRaises(errors.ExistingContent,
 
1511
                vf.add_lines, new_key, [], lines,
 
1512
                nostore_sha=sha)
 
1513
            # and no new version should have been added.
 
1514
            record = vf.get_record_stream([new_key], 'unordered', True).next()
 
1515
            self.assertEqual('absent', record.storage_kind)
 
1516
 
1496
1517
    def test_add_lines_return(self):
1497
1518
        files = self.get_versionedfiles()
1498
1519
        # save code by using the stock data insertion helper.
1615
1636
                }
1616
1637
        return keys, sort_order
1617
1638
 
 
1639
    def get_keys_and_groupcompress_sort_order(self):
 
1640
        """Get diamond test keys list, and their groupcompress sort ordering."""
 
1641
        if self.key_length == 1:
 
1642
            keys = [('merged',), ('left',), ('right',), ('base',)]
 
1643
            sort_order = {('merged',):0, ('left',):1, ('right',):1, ('base',):2}
 
1644
        else:
 
1645
            keys = [
 
1646
                ('FileA', 'merged'), ('FileA', 'left'), ('FileA', 'right'),
 
1647
                ('FileA', 'base'),
 
1648
                ('FileB', 'merged'), ('FileB', 'left'), ('FileB', 'right'),
 
1649
                ('FileB', 'base'),
 
1650
                ]
 
1651
            sort_order = {
 
1652
                ('FileA', 'merged'):0, ('FileA', 'left'):1, ('FileA', 'right'):1,
 
1653
                ('FileA', 'base'):2,
 
1654
                ('FileB', 'merged'):3, ('FileB', 'left'):4, ('FileB', 'right'):4,
 
1655
                ('FileB', 'base'):5,
 
1656
                }
 
1657
        return keys, sort_order
 
1658
 
1618
1659
    def test_get_record_stream_interface_ordered(self):
1619
1660
        """each item in a stream has to provide a regular interface."""
1620
1661
        files = self.get_versionedfiles()
1648
1689
 
1649
1690
        self.assertStreamOrder(sort_order, seen, keys)
1650
1691
 
 
1692
    def test_get_record_stream_interface_groupcompress(self):
 
1693
        """each item in a stream has to provide a regular interface."""
 
1694
        files = self.get_versionedfiles()
 
1695
        self.get_diamond_files(files)
 
1696
        keys, sort_order = self.get_keys_and_groupcompress_sort_order()
 
1697
        parent_map = files.get_parent_map(keys)
 
1698
        entries = files.get_record_stream(keys, 'groupcompress', False)
 
1699
        seen = []
 
1700
        self.capture_stream(files, entries, seen.append, parent_map)
 
1701
        self.assertStreamOrder(sort_order, seen, keys)
 
1702
 
1651
1703
    def assertStreamOrder(self, sort_order, seen, keys):
1652
1704
        self.assertEqual(len(set(seen)), len(keys))
1653
1705
        if self.key_length == 1:
2252
2304
            return lines
2253
2305
        lines = iter_with_keys(
2254
2306
            [self.get_simple_key('child'), self.get_simple_key('otherchild')],
2255
 
            [('Walking content.', 0, 2),
2256
 
             ('Walking content.', 1, 2),
2257
 
             ('Walking content.', 2, 2)])
 
2307
            [('Walking content', 0, 2),
 
2308
             ('Walking content', 1, 2),
 
2309
             ('Walking content', 2, 2)])
2258
2310
        # we must see child and otherchild
2259
2311
        self.assertTrue(lines[('child\n', self.get_simple_key('child'))] > 0)
2260
2312
        self.assertTrue(
2263
2315
 
2264
2316
        # test all lines
2265
2317
        lines = iter_with_keys(files.keys(),
2266
 
            [('Walking content.', 0, 5),
2267
 
             ('Walking content.', 1, 5),
2268
 
             ('Walking content.', 2, 5),
2269
 
             ('Walking content.', 3, 5),
2270
 
             ('Walking content.', 4, 5),
2271
 
             ('Walking content.', 5, 5)])
 
2318
            [('Walking content', 0, 5),
 
2319
             ('Walking content', 1, 5),
 
2320
             ('Walking content', 2, 5),
 
2321
             ('Walking content', 3, 5),
 
2322
             ('Walking content', 4, 5),
 
2323
             ('Walking content', 5, 5)])
2272
2324
        # all lines must be seen at least once
2273
2325
        self.assertTrue(lines[('base\n', self.get_simple_key('base'))] > 0)
2274
2326
        self.assertTrue(