~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1505
1505
        for plan_line, expected_line in zip(plan, AB_MERGE):
1506
1506
            self.assertEqual(plan_line, expected_line)
1507
1507
 
 
1508
 
 
1509
class GetDataStreamTests(KnitTests):
 
1510
    """Tests for get_data_stream."""
 
1511
 
1508
1512
    def test_get_stream_empty(self):
1509
1513
        """Get a data stream for an empty knit file."""
1510
1514
        k1 = self.make_test_knit()
1696
1700
            bytes = reader_callable(length)
1697
1701
            self.assertRecordContentEqual(k1, version_id, bytes)
1698
1702
 
 
1703
 
 
1704
class InsertDataStreamTests(KnitTests):
 
1705
    """Tests for insert_data_stream."""
 
1706
 
1699
1707
    def assertKnitFilesEqual(self, knit1, knit2):
1700
1708
        """Assert that the contents of the index and data files of two knits are
1701
1709
        equal.
1720
1728
            self.assertEqual(left.annotate(version),
1721
1729
                right.annotate(version))
1722
1730
 
1723
 
    def test_insert_data_stream_empty(self):
 
1731
    def test_empty_stream(self):
1724
1732
        """Inserting a data stream with no records should not put any data into
1725
1733
        the knit.
1726
1734
        """
1733
1741
                         k1.transport.get_bytes(k1._index._filename),
1734
1742
                         "The .kndx should have nothing apart from the header.")
1735
1743
 
1736
 
    def test_insert_data_stream_one_record(self):
 
1744
    def test_one_record(self):
1737
1745
        """Inserting a data stream with one record from a knit with one record
1738
1746
        results in byte-identical files.
1739
1747
        """
1744
1752
        target.insert_data_stream(data_stream)
1745
1753
        self.assertKnitFilesEqual(source, target)
1746
1754
 
1747
 
    def test_insert_data_stream_annotated_unannotated(self):
 
1755
    def test_annotated_stream_into_unannotated_knit(self):
1748
1756
        """Inserting an annotated datastream to an unannotated knit works."""
1749
1757
        # case one - full texts.
1750
1758
        source = self.make_test_knit(name='source', annotate=True)
1757
1765
        target.insert_data_stream(source.get_data_stream(['text-b']))
1758
1766
        self.assertKnitValuesEqual(source, target)
1759
1767
 
1760
 
    def test_insert_data_stream_unannotated_annotated(self):
 
1768
    def test_unannotated_stream_into_annotated_knit(self):
1761
1769
        """Inserting an unannotated datastream to an annotated knit works."""
1762
1770
        # case one - full texts.
1763
1771
        source = self.make_test_knit(name='source', annotate=False)
1770
1778
        target.insert_data_stream(source.get_data_stream(['text-b']))
1771
1779
        self.assertKnitValuesEqual(source, target)
1772
1780
 
1773
 
    def test_insert_data_stream_records_already_present(self):
 
1781
    def test_records_already_present(self):
1774
1782
        """Insert a data stream where some records are alreday present in the
1775
1783
        target, and some not.  Only the new records are inserted.
1776
1784
        """
1788
1796
        # record was not added a second time.
1789
1797
        self.assertKnitFilesEqual(source, target)
1790
1798
 
1791
 
    def test_insert_data_stream_multiple_records(self):
 
1799
    def test_multiple_records(self):
1792
1800
        """Inserting a data stream of all records from a knit with multiple
1793
1801
        records results in byte-identical files.
1794
1802
        """
1803
1811
        
1804
1812
        self.assertKnitFilesEqual(source, target)
1805
1813
 
1806
 
    def test_insert_data_stream_ghost_parent(self):
 
1814
    def test_ghost_parent(self):
1807
1815
        """Insert a data stream with a record that has a ghost parent."""
1808
1816
        # Make a knit with a record, text-a, that has a ghost parent.
1809
1817
        source = self.make_test_knit(name='source')
1824
1832
            target.get_parent_map(['text-a', 'text-ghost']))
1825
1833
        self.assertEqual(split_lines(TEXT_1), target.get_lines('text-a'))
1826
1834
 
1827
 
    def test_insert_data_stream_inconsistent_version_lines(self):
 
1835
    def test_inconsistent_version_lines(self):
1828
1836
        """Inserting a data stream which has different content for a version_id
1829
1837
        than already exists in the knit will raise KnitCorrupt.
1830
1838
        """
1838
1846
        self.assertRaises(
1839
1847
            errors.KnitCorrupt, target.insert_data_stream, data_stream)
1840
1848
 
1841
 
    def test_insert_data_stream_inconsistent_version_parents(self):
 
1849
    def test_inconsistent_version_parents(self):
1842
1850
        """Inserting a data stream which has different parents for a version_id
1843
1851
        than already exists in the knit will raise KnitCorrupt.
1844
1852
        """
1853
1861
        self.assertRaises(
1854
1862
            errors.KnitCorrupt, target.insert_data_stream, data_stream)
1855
1863
 
1856
 
    def test_insert_data_stream_unknown_format(self):
 
1864
    def test_unknown_stream_format(self):
1857
1865
        """A data stream in a different format to the target knit cannot be
1858
1866
        inserted.
1859
1867
 
1867
1875
            errors.KnitDataStreamUnknown,
1868
1876
            target.insert_data_stream, data_stream)
1869
1877
 
1870
 
    def test_insert_data_stream_bug_208418(self):
 
1878
    def test_bug_208418(self):
1871
1879
        """You can insert a stream with an incompatible format, even when:
1872
1880
          * the stream has a line-delta record,
1873
1881
          * whose parent is in the target, also stored as a line-delta
1897
1905
        target.insert_data_stream(data_stream)
1898
1906
        # No errors should have been raised.
1899
1907
 
1900
 
 
1901
 
    #  * test that a stream of "already present version, then new version"
1902
 
    #    inserts correctly.
1903
 
 
 
1908
    def test_line_delta_record_into_non_delta_knit(self):
 
1909
        # Make a data stream with a line-delta record
 
1910
        source = self.make_test_knit(name='source', delta=True)
 
1911
        base_lines = split_lines(TEXT_1)
 
1912
        source.add_lines('version-1', [], base_lines)
 
1913
        source.add_lines('version-2', ['version-1'], base_lines + ['a\n'])
 
1914
        # The second record should be a delta.
 
1915
        self.assertEqual('line-delta', source._index.get_method('version-2'))
 
1916
        data_stream = source.get_data_stream(['version-1', 'version-2'])
 
1917
 
 
1918
        # Insert the stream into a non-delta knit.
 
1919
        target = self.make_test_knit(name='target', delta=False)
 
1920
        target.insert_data_stream(data_stream)
 
1921
        
 
1922
        # Both versions are fulltexts in the target
 
1923
        self.assertEqual('fulltext', target._index.get_method('version-1'))
 
1924
        self.assertEqual('fulltext', target._index.get_method('version-2'))
 
1925
 
 
1926
 
 
1927
class DataStreamTests(KnitTests):
1904
1928
 
1905
1929
    def assertMadeStreamKnit(self, source_knit, versions, target_knit):
1906
1930
        """Assert that a knit made from a stream is as expected."""