/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-06-29 14:51:13 UTC
  • mfrom: (4489 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4490.
  • Revision ID: aaron@aaronbentley.com-20090629145113-3w350dxgqppnzo4g
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1471
1471
            self.addCleanup(lambda:self.cleanup(files))
1472
1472
        return files
1473
1473
 
 
1474
    def get_simple_key(self, suffix):
 
1475
        """Return a key for the object under test."""
 
1476
        if self.key_length == 1:
 
1477
            return (suffix,)
 
1478
        else:
 
1479
            return ('FileA',) + (suffix,)
 
1480
 
 
1481
    def test_add_lines(self):
 
1482
        f = self.get_versionedfiles()
 
1483
        key0 = self.get_simple_key('r0')
 
1484
        key1 = self.get_simple_key('r1')
 
1485
        key2 = self.get_simple_key('r2')
 
1486
        keyf = self.get_simple_key('foo')
 
1487
        f.add_lines(key0, [], ['a\n', 'b\n'])
 
1488
        if self.graph:
 
1489
            f.add_lines(key1, [key0], ['b\n', 'c\n'])
 
1490
        else:
 
1491
            f.add_lines(key1, [], ['b\n', 'c\n'])
 
1492
        keys = f.keys()
 
1493
        self.assertTrue(key0 in keys)
 
1494
        self.assertTrue(key1 in keys)
 
1495
        records = []
 
1496
        for record in f.get_record_stream([key0, key1], 'unordered', True):
 
1497
            records.append((record.key, record.get_bytes_as('fulltext')))
 
1498
        records.sort()
 
1499
        self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
 
1500
 
 
1501
    def test__add_text(self):
 
1502
        f = self.get_versionedfiles()
 
1503
        key0 = self.get_simple_key('r0')
 
1504
        key1 = self.get_simple_key('r1')
 
1505
        key2 = self.get_simple_key('r2')
 
1506
        keyf = self.get_simple_key('foo')
 
1507
        f._add_text(key0, [], 'a\nb\n')
 
1508
        if self.graph:
 
1509
            f._add_text(key1, [key0], 'b\nc\n')
 
1510
        else:
 
1511
            f._add_text(key1, [], 'b\nc\n')
 
1512
        keys = f.keys()
 
1513
        self.assertTrue(key0 in keys)
 
1514
        self.assertTrue(key1 in keys)
 
1515
        records = []
 
1516
        for record in f.get_record_stream([key0, key1], 'unordered', True):
 
1517
            records.append((record.key, record.get_bytes_as('fulltext')))
 
1518
        records.sort()
 
1519
        self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
 
1520
 
1474
1521
    def test_annotate(self):
1475
1522
        files = self.get_versionedfiles()
1476
1523
        self.get_diamond_files(files)
1520
1567
            trailing_eol=trailing_eol, nograph=not self.graph,
1521
1568
            left_only=left_only, nokeys=nokeys)
1522
1569
 
1523
 
    def test_add_lines_nostoresha(self):
 
1570
    def _add_content_nostoresha(self, add_lines):
1524
1571
        """When nostore_sha is supplied using old content raises."""
1525
1572
        vf = self.get_versionedfiles()
1526
1573
        empty_text = ('a', [])
1528
1575
        sample_text_no_nl = ('c', ["foo\n", "bar"])
1529
1576
        shas = []
1530
1577
        for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
1531
 
            sha, _, _ = vf.add_lines(self.get_simple_key(version), [], lines)
 
1578
            if add_lines:
 
1579
                sha, _, _ = vf.add_lines(self.get_simple_key(version), [],
 
1580
                                         lines)
 
1581
            else:
 
1582
                sha, _, _ = vf._add_text(self.get_simple_key(version), [],
 
1583
                                         ''.join(lines))
1532
1584
            shas.append(sha)
1533
1585
        # we now have a copy of all the lines in the vf.
1534
1586
        for sha, (version, lines) in zip(
1537
1589
            self.assertRaises(errors.ExistingContent,
1538
1590
                vf.add_lines, new_key, [], lines,
1539
1591
                nostore_sha=sha)
 
1592
            self.assertRaises(errors.ExistingContent,
 
1593
                vf._add_text, new_key, [], ''.join(lines),
 
1594
                nostore_sha=sha)
1540
1595
            # and no new version should have been added.
1541
1596
            record = vf.get_record_stream([new_key], 'unordered', True).next()
1542
1597
            self.assertEqual('absent', record.storage_kind)
1543
1598
 
 
1599
    def test_add_lines_nostoresha(self):
 
1600
        self._add_content_nostoresha(add_lines=True)
 
1601
 
 
1602
    def test__add_text_nostoresha(self):
 
1603
        self._add_content_nostoresha(add_lines=False)
 
1604
 
1544
1605
    def test_add_lines_return(self):
1545
1606
        files = self.get_versionedfiles()
1546
1607
        # save code by using the stock data insertion helper.
1692
1753
        self.capture_stream(files, entries, seen.add, parent_map)
1693
1754
        self.assertEqual(set(keys), seen)
1694
1755
 
1695
 
    def get_simple_key(self, suffix):
1696
 
        """Return a key for the object under test."""
1697
 
        if self.key_length == 1:
1698
 
            return (suffix,)
1699
 
        else:
1700
 
            return ('FileA',) + (suffix,)
1701
 
 
1702
1756
    def get_keys_and_sort_order(self):
1703
1757
        """Get diamond test keys list, and their sort ordering."""
1704
1758
        if self.key_length == 1: