1471
1473
self.addCleanup(lambda:self.cleanup(files))
1476
def get_simple_key(self, suffix):
1477
"""Return a key for the object under test."""
1478
if self.key_length == 1:
1481
return ('FileA',) + (suffix,)
1483
def test_add_lines(self):
1484
f = self.get_versionedfiles()
1485
key0 = self.get_simple_key('r0')
1486
key1 = self.get_simple_key('r1')
1487
key2 = self.get_simple_key('r2')
1488
keyf = self.get_simple_key('foo')
1489
f.add_lines(key0, [], ['a\n', 'b\n'])
1491
f.add_lines(key1, [key0], ['b\n', 'c\n'])
1493
f.add_lines(key1, [], ['b\n', 'c\n'])
1495
self.assertTrue(key0 in keys)
1496
self.assertTrue(key1 in keys)
1498
for record in f.get_record_stream([key0, key1], 'unordered', True):
1499
records.append((record.key, record.get_bytes_as('fulltext')))
1501
self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
1503
def test__add_text(self):
1504
f = self.get_versionedfiles()
1505
key0 = self.get_simple_key('r0')
1506
key1 = self.get_simple_key('r1')
1507
key2 = self.get_simple_key('r2')
1508
keyf = self.get_simple_key('foo')
1509
f._add_text(key0, [], 'a\nb\n')
1511
f._add_text(key1, [key0], 'b\nc\n')
1513
f._add_text(key1, [], 'b\nc\n')
1515
self.assertTrue(key0 in keys)
1516
self.assertTrue(key1 in keys)
1518
for record in f.get_record_stream([key0, key1], 'unordered', True):
1519
records.append((record.key, record.get_bytes_as('fulltext')))
1521
self.assertEqual([(key0, 'a\nb\n'), (key1, 'b\nc\n')], records)
1474
1523
def test_annotate(self):
1475
1524
files = self.get_versionedfiles()
1476
1525
self.get_diamond_files(files)
1510
1559
self.assertRaises(RevisionNotPresent,
1511
1560
files.annotate, prefix + ('missing-key',))
1562
def test_check_no_parameters(self):
1563
files = self.get_versionedfiles()
1565
def test_check_progressbar_parameter(self):
1566
"""A progress bar can be supplied because check can be a generator."""
1567
pb = ui.ui_factory.nested_progress_bar()
1568
self.addCleanup(pb.finished)
1569
files = self.get_versionedfiles()
1570
files.check(progress_bar=pb)
1572
def test_check_with_keys_becomes_generator(self):
1573
files = self.get_versionedfiles()
1574
self.get_diamond_files(files)
1576
entries = files.check(keys=keys)
1578
# Texts output should be fulltexts.
1579
self.capture_stream(files, entries, seen.add,
1580
files.get_parent_map(keys), require_fulltext=True)
1581
# All texts should be output.
1582
self.assertEqual(set(keys), seen)
1513
1584
def test_construct(self):
1514
1585
"""Each parameterised test can be constructed on a transport."""
1515
1586
files = self.get_versionedfiles()
1520
1591
trailing_eol=trailing_eol, nograph=not self.graph,
1521
1592
left_only=left_only, nokeys=nokeys)
1523
def test_add_lines_nostoresha(self):
1594
def _add_content_nostoresha(self, add_lines):
1524
1595
"""When nostore_sha is supplied using old content raises."""
1525
1596
vf = self.get_versionedfiles()
1526
1597
empty_text = ('a', [])
1528
1599
sample_text_no_nl = ('c', ["foo\n", "bar"])
1530
1601
for version, lines in (empty_text, sample_text_nl, sample_text_no_nl):
1531
sha, _, _ = vf.add_lines(self.get_simple_key(version), [], lines)
1603
sha, _, _ = vf.add_lines(self.get_simple_key(version), [],
1606
sha, _, _ = vf._add_text(self.get_simple_key(version), [],
1532
1608
shas.append(sha)
1533
1609
# we now have a copy of all the lines in the vf.
1534
1610
for sha, (version, lines) in zip(
1537
1613
self.assertRaises(errors.ExistingContent,
1538
1614
vf.add_lines, new_key, [], lines,
1539
1615
nostore_sha=sha)
1616
self.assertRaises(errors.ExistingContent,
1617
vf._add_text, new_key, [], ''.join(lines),
1540
1619
# and no new version should have been added.
1541
1620
record = vf.get_record_stream([new_key], 'unordered', True).next()
1542
1621
self.assertEqual('absent', record.storage_kind)
1623
def test_add_lines_nostoresha(self):
1624
self._add_content_nostoresha(add_lines=True)
1626
def test__add_text_nostoresha(self):
1627
self._add_content_nostoresha(add_lines=False)
1544
1629
def test_add_lines_return(self):
1545
1630
files = self.get_versionedfiles()
1546
1631
# save code by using the stock data insertion helper.
1653
1738
f.get_record_stream([key_b], 'unordered', True
1654
1739
).next().get_bytes_as('fulltext'))
1741
def test_get_known_graph_ancestry(self):
1742
f = self.get_versionedfiles()
1744
raise TestNotApplicable('ancestry info only relevant with graph.')
1745
key_a = self.get_simple_key('a')
1746
key_b = self.get_simple_key('b')
1747
key_c = self.get_simple_key('c')
1753
f.add_lines(key_a, [], ['\n'])
1754
f.add_lines(key_b, [key_a], ['\n'])
1755
f.add_lines(key_c, [key_a, key_b], ['\n'])
1756
kg = f.get_known_graph_ancestry([key_c])
1757
self.assertIsInstance(kg, _mod_graph.KnownGraph)
1758
self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
1760
def test_known_graph_with_fallbacks(self):
1761
f = self.get_versionedfiles('files')
1763
raise TestNotApplicable('ancestry info only relevant with graph.')
1764
if getattr(f, 'add_fallback_versioned_files', None) is None:
1765
raise TestNotApplicable("%s doesn't support fallbacks"
1766
% (f.__class__.__name__,))
1767
key_a = self.get_simple_key('a')
1768
key_b = self.get_simple_key('b')
1769
key_c = self.get_simple_key('c')
1770
# A only in fallback
1775
g = self.get_versionedfiles('fallback')
1776
g.add_lines(key_a, [], ['\n'])
1777
f.add_fallback_versioned_files(g)
1778
f.add_lines(key_b, [key_a], ['\n'])
1779
f.add_lines(key_c, [key_a, key_b], ['\n'])
1780
kg = f.get_known_graph_ancestry([key_c])
1781
self.assertEqual([key_a, key_b, key_c], list(kg.topo_sort()))
1656
1783
def test_get_record_stream_empty(self):
1657
1784
"""An empty stream can be requested without error."""
1658
1785
f = self.get_versionedfiles()
1669
1796
'knit-delta-closure', 'knit-delta-closure-ref',
1670
1797
'groupcompress-block', 'groupcompress-block-ref'])
1672
def capture_stream(self, f, entries, on_seen, parents):
1799
def capture_stream(self, f, entries, on_seen, parents,
1800
require_fulltext=False):
1673
1801
"""Capture a stream for testing."""
1674
1802
for factory in entries:
1675
1803
on_seen(factory.key)
1692
1822
self.capture_stream(files, entries, seen.add, parent_map)
1693
1823
self.assertEqual(set(keys), seen)
1695
def get_simple_key(self, suffix):
1696
"""Return a key for the object under test."""
1697
if self.key_length == 1:
1700
return ('FileA',) + (suffix,)
1702
1825
def get_keys_and_sort_order(self):
1703
1826
"""Get diamond test keys list, and their sort ordering."""
1704
1827
if self.key_length == 1:
2193
def test_get_annotator(self):
2194
files = self.get_versionedfiles()
2195
self.get_diamond_files(files)
2196
origin_key = self.get_simple_key('origin')
2197
base_key = self.get_simple_key('base')
2198
left_key = self.get_simple_key('left')
2199
right_key = self.get_simple_key('right')
2200
merged_key = self.get_simple_key('merged')
2201
# annotator = files.get_annotator()
2202
# introduced full text
2203
origins, lines = files.get_annotator().annotate(origin_key)
2204
self.assertEqual([(origin_key,)], origins)
2205
self.assertEqual(['origin\n'], lines)
2207
origins, lines = files.get_annotator().annotate(base_key)
2208
self.assertEqual([(base_key,)], origins)
2210
origins, lines = files.get_annotator().annotate(merged_key)
2219
# Without a graph everything is new.
2226
self.assertRaises(RevisionNotPresent,
2227
files.get_annotator().annotate, self.get_simple_key('missing-key'))
2070
2229
def test_get_parent_map(self):
2071
2230
files = self.get_versionedfiles()
2072
2231
if self.key_length == 1:
2547
2706
self.assertRaises(NotImplementedError,
2548
2707
self.texts.add_mpdiffs, [])
2550
def test_check(self):
2551
self.assertTrue(self.texts.check())
2709
def test_check_noerrors(self):
2553
2712
def test_insert_record_stream(self):
2554
2713
self.assertRaises(NotImplementedError, self.texts.insert_record_stream,