~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-12 03:07:05 UTC
  • mfrom: (3350.3.22 data_stream_revamp)
  • Revision ID: pqm@pqm.ubuntu.com-20080512030705-nvl2q1tuls904eru
Deprecate bzrlib.versionedfiles.VersionedFile.join.

Show diffs side-by-side

added added

removed removed

Lines of Context:
370
370
        self.assertEqual({'rev-id-1':(['foo\n', 'bar\n'], sha1sum)}, contents)
371
371
 
372
372
        raw_contents = list(data.read_records_iter_raw(records))
373
 
        self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
 
373
        self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
374
374
 
375
375
    def test_not_enough_lines(self):
376
376
        sha1sum = sha.new('foo\n').hexdigest()
387
387
 
388
388
        # read_records_iter_raw won't detect that sort of mismatch/corruption
389
389
        raw_contents = list(data.read_records_iter_raw(records))
390
 
        self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
 
390
        self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
391
391
 
392
392
    def test_too_many_lines(self):
393
393
        sha1sum = sha.new('foo\nbar\n').hexdigest()
405
405
 
406
406
        # read_records_iter_raw won't detect that sort of mismatch/corruption
407
407
        raw_contents = list(data.read_records_iter_raw(records))
408
 
        self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
 
408
        self.assertEqual([('rev-id-1', gz_txt, sha1sum)], raw_contents)
409
409
 
410
410
    def test_mismatched_version_id(self):
411
411
        sha1sum = sha.new('foo\nbar\n').hexdigest()
1056
1056
        """
1057
1057
        index_memo = knit._index.get_position(version_id)
1058
1058
        record = (version_id, index_memo)
1059
 
        [(_, expected_content)] = list(knit._data.read_records_iter_raw([record]))
 
1059
        [(_, expected_content, _)] = list(knit._data.read_records_iter_raw([record]))
1060
1060
        self.assertEqual(expected_content, candidate_content)
1061
1061
 
1062
1062
 
1293
1293
        self.assertEquals(origins[1], ('text-1', 'b\n'))
1294
1294
        self.assertEquals(origins[2], ('text-1', 'c\n'))
1295
1295
 
1296
 
    def _test_join_with_factories(self, k1_factory, k2_factory):
1297
 
        k1 = make_file_knit('test1', get_transport('.'), factory=k1_factory, create=True)
1298
 
        k1.add_lines('text-a', [], ['a1\n', 'a2\n', 'a3\n'])
1299
 
        k1.add_lines('text-b', ['text-a'], ['a1\n', 'b2\n', 'a3\n'])
1300
 
        k1.add_lines('text-c', [], ['c1\n', 'c2\n', 'c3\n'])
1301
 
        k1.add_lines('text-d', ['text-c'], ['c1\n', 'd2\n', 'd3\n'])
1302
 
        k1.add_lines('text-m', ['text-b', 'text-d'], ['a1\n', 'b2\n', 'd3\n'])
1303
 
        k2 = make_file_knit('test2', get_transport('.'), factory=k2_factory, create=True)
1304
 
        count = k2.join(k1, version_ids=['text-m'])
1305
 
        self.assertEquals(count, 5)
1306
 
        self.assertTrue(k2.has_version('text-a'))
1307
 
        self.assertTrue(k2.has_version('text-c'))
1308
 
        origins = k2.annotate('text-m')
1309
 
        self.assertEquals(origins[0], ('text-a', 'a1\n'))
1310
 
        self.assertEquals(origins[1], ('text-b', 'b2\n'))
1311
 
        self.assertEquals(origins[2], ('text-d', 'd3\n'))
1312
 
 
1313
 
    def test_knit_join_plain_to_plain(self):
1314
 
        """Test joining a plain knit with a plain knit."""
1315
 
        self._test_join_with_factories(KnitPlainFactory(), KnitPlainFactory())
1316
 
 
1317
 
    def test_knit_join_anno_to_anno(self):
1318
 
        """Test joining an annotated knit with an annotated knit."""
1319
 
        self._test_join_with_factories(None, None)
1320
 
 
1321
 
    def test_knit_join_anno_to_plain(self):
1322
 
        """Test joining an annotated knit with a plain knit."""
1323
 
        self._test_join_with_factories(None, KnitPlainFactory())
1324
 
 
1325
 
    def test_knit_join_plain_to_anno(self):
1326
 
        """Test joining a plain knit with an annotated knit."""
1327
 
        self._test_join_with_factories(KnitPlainFactory(), None)
1328
 
 
1329
1296
    def test_reannotate(self):
1330
1297
        k1 = make_file_knit('knit1', get_transport('.'),
1331
1298
                               factory=KnitAnnotateFactory(), create=True)
1336
1303
 
1337
1304
        k2 = make_file_knit('test2', get_transport('.'),
1338
1305
                               factory=KnitAnnotateFactory(), create=True)
1339
 
        k2.join(k1, version_ids=['text-b'])
 
1306
        k2.insert_record_stream(k1.get_record_stream(k1.versions(),
 
1307
            'unordered', False))
1340
1308
 
1341
1309
        # 2
1342
1310
        k1.add_lines('text-X', ['text-b'], ['a\n', 'b\n'])
1346
1314
        k2.add_lines('text-Y', ['text-b'], ['b\n', 'c\n'])
1347
1315
 
1348
1316
        # test-c will have index 3
1349
 
        k1.join(k2, version_ids=['text-c'])
 
1317
        k1.insert_record_stream(k2.get_record_stream(['text-c'],
 
1318
            'unordered', False))
1350
1319
 
1351
1320
        lines = k1.get_lines('text-c')
1352
1321
        self.assertEquals(lines, ['z\n', 'c\n'])
2817
2786
        target_knit = self.make_test_knit(name='annotated', annotate=True)
2818
2787
        source_knit.add_lines("A", [], ["Foo\n"])
2819
2788
        # Give the target A, so we can try to thunk across to it.
2820
 
        target_knit.join(source_knit)
 
2789
        target_knit.insert_record_stream(source_knit.get_record_stream(['A'],
 
2790
            'unordered', False))
2821
2791
        index, access = self.get_index_access(target_knit,
2822
2792
            source_knit.get_data_stream([]))
2823
2793
        raw_data = list(access.get_raw_records([(True, "A", None, None)]))[0]