339
341
self.check_knits(t)
344
class KnitRepositoryStreamTests(test_knit.KnitTests):
345
"""Tests for knitrepo._get_stream_as_bytes."""
347
def test_get_stream_as_bytes(self):
349
k1 = self.make_test_knit()
350
k1.add_lines('text-a', [], test_knit.split_lines(test_knit.TEXT_1))
352
# Serialise it, check the output.
353
bytes = knitrepo._get_stream_as_bytes(k1, ['text-a'])
354
data = bencode.bdecode(bytes)
355
format, record = data
356
self.assertEqual('knit-plain', format)
357
self.assertEqual(['text-a', ['fulltext'], []], record[:3])
358
self.assertRecordContentEqual(k1, 'text-a', record[3])
360
def test_get_stream_as_bytes_all(self):
361
"""Get a serialised data stream for all the records in a knit.
363
Much like test_get_stream_all, except for get_stream_as_bytes.
365
k1 = self.make_test_knit()
366
# Insert the same data as BasicKnitTests.test_knit_join, as they seem
367
# to cover a range of cases (no parents, one parent, multiple parents).
369
('text-a', [], test_knit.TEXT_1),
370
('text-b', ['text-a'], test_knit.TEXT_1),
371
('text-c', [], test_knit.TEXT_1),
372
('text-d', ['text-c'], test_knit.TEXT_1),
373
('text-m', ['text-b', 'text-d'], test_knit.TEXT_1),
375
expected_data_list = [
376
# version, options, parents
377
('text-a', ['fulltext'], []),
378
('text-b', ['line-delta'], ['text-a']),
379
('text-c', ['fulltext'], []),
380
('text-d', ['line-delta'], ['text-c']),
381
('text-m', ['line-delta'], ['text-b', 'text-d']),
383
for version_id, parents, lines in test_data:
384
k1.add_lines(version_id, parents, test_knit.split_lines(lines))
386
bytes = knitrepo._get_stream_as_bytes(
387
k1, ['text-a', 'text-b', 'text-c', 'text-d', 'text-m'])
389
data = bencode.bdecode(bytes)
391
self.assertEqual('knit-plain', format)
393
for expected, actual in zip(expected_data_list, data):
394
expected_version = expected[0]
395
expected_options = expected[1]
396
expected_parents = expected[2]
397
version, options, parents, bytes = actual
398
self.assertEqual(expected_version, version)
399
self.assertEqual(expected_options, options)
400
self.assertEqual(expected_parents, parents)
401
self.assertRecordContentEqual(k1, version, bytes)
342
404
class DummyRepository(object):
343
405
"""A dummy repository for testing."""