141
137
except NotImplementedError:
144
def test_add_reserved(self):
146
self.assertRaises(errors.ReservedId,
147
vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
149
self.assertRaises(errors.ReservedId,
150
vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
152
def test_get_reserved(self):
154
self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
155
self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
156
self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
157
self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
159
140
def test_get_delta(self):
160
141
f = self.get_file()
161
142
sha1s = self._setup_for_deltas(f)
214
195
self.assertEqual(expected_delta, deltas['noeol'])
215
196
# smoke tests for eol support - two noeol in a row same content
216
197
expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
217
[(0, 1, 2, [('noeolsecond', 'line\n'), ('noeolsecond', 'line\n')])]),
198
[(0, 1, 2, [(u'noeolsecond', 'line\n'), (u'noeolsecond', 'line\n')])]),
218
199
('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True,
219
200
[(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
220
201
self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
221
202
self.assertTrue(deltas['noeolsecond'] in expected_deltas)
222
203
# two no-eol in a row, different content
223
204
expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True,
224
[(1, 2, 1, [('noeolnotshared', 'phone\n')])])
205
[(1, 2, 1, [(u'noeolnotshared', 'phone\n')])])
225
206
self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
226
207
self.assertEqual(expected_delta, deltas['noeolnotshared'])
227
208
# eol folling a no-eol with content change
228
209
expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False,
229
[(0, 1, 1, [('eol', 'phone\n')])])
210
[(0, 1, 1, [(u'eol', 'phone\n')])])
230
211
self.assertEqual(['phone\n'], f.get_lines('eol'))
231
212
self.assertEqual(expected_delta, deltas['eol'])
232
213
# eol folling a no-eol with content change
233
214
expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False,
234
[(0, 1, 1, [('eolline', 'line\n')])])
215
[(0, 1, 1, [(u'eolline', 'line\n')])])
235
216
self.assertEqual(['line\n'], f.get_lines('eolline'))
236
217
self.assertEqual(expected_delta, deltas['eolline'])
237
218
# eol with no parents
238
219
expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
239
[(0, 0, 1, [('noeolbase', 'line\n')])])
220
[(0, 0, 1, [(u'noeolbase', 'line\n')])])
240
221
self.assertEqual(['line'], f.get_lines('noeolbase'))
241
222
self.assertEqual(expected_delta, deltas['noeolbase'])
242
223
# eol with two parents, in inverse insertion order
243
224
expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
244
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]),
225
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]),
245
226
('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
246
[(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]))
227
[(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]))
247
228
self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
248
229
#self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
598
565
'otherchild\n':0,
600
progress = InstrumentedProgress()
601
567
# iterate over the lines
602
for line in vf.iter_lines_added_or_present_in_versions(versions,
568
for line in vf.iter_lines_added_or_present_in_versions(versions):
605
if []!= progress.updates:
606
self.assertEqual(expected, progress.updates)
608
lines = iter_with_versions(['child', 'otherchild'],
609
[('Walking content.', 0, 2),
610
('Walking content.', 1, 2),
611
('Walking content.', 2, 2)])
571
lines = iter_with_versions(['child', 'otherchild'])
612
572
# we must see child and otherchild
613
573
self.assertTrue(lines['child\n'] > 0)
614
574
self.assertTrue(lines['otherchild\n'] > 0)
615
575
# we dont care if we got more than that.
618
lines = iter_with_versions(None, [('Walking content.', 0, 5),
619
('Walking content.', 1, 5),
620
('Walking content.', 2, 5),
621
('Walking content.', 3, 5),
622
('Walking content.', 4, 5),
623
('Walking content.', 5, 5)])
578
lines = iter_with_versions(None)
624
579
# all lines must be seen at least once
625
580
self.assertTrue(lines['base\n'] > 0)
626
581
self.assertTrue(lines['lancestor\n'] > 0)
684
636
self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
685
637
self.assertRaises(NotImplementedError, vf.get_graph_with_ghosts)
687
vf = self.reopen_file()
688
639
# test key graph related apis: getncestry, _graph, get_parents
690
641
# - these are ghost unaware and must not be reflect ghosts
691
self.assertEqual(['notbxbfse'], vf.get_ancestry('notbxbfse'))
692
self.assertEqual([], vf.get_parents('notbxbfse'))
693
self.assertEqual({'notbxbfse':[]}, vf.get_graph())
694
self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
695
vf.has_version, parent_id_unicode))
696
self.assertFalse(vf.has_version(parent_id_utf8))
642
self.assertEqual([u'notbxbfse'], vf.get_ancestry(u'notbxbfse'))
643
self.assertEqual([], vf.get_parents(u'notbxbfse'))
644
self.assertEqual({u'notbxbfse':[]}, vf.get_graph())
645
self.assertFalse(vf.has_version(u'b\xbfse'))
697
646
# we have _with_ghost apis to give us ghost information.
698
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
699
self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
700
self.assertEqual({'notbxbfse':[parent_id_utf8]}, vf.get_graph_with_ghosts())
701
self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
702
vf.has_ghost, parent_id_unicode))
703
self.assertTrue(vf.has_ghost(parent_id_utf8))
647
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
648
self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
649
self.assertEqual({u'notbxbfse':[u'b\xbfse']}, vf.get_graph_with_ghosts())
650
self.assertTrue(vf.has_ghost(u'b\xbfse'))
704
651
# if we add something that is a ghost of another, it should correct the
705
652
# results of the prior apis
706
self.callDeprecated([osutils._revision_id_warning],
707
vf.add_lines, parent_id_unicode, [], [])
708
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry(['notbxbfse']))
709
self.assertEqual([parent_id_utf8], vf.get_parents('notbxbfse'))
710
self.assertEqual({parent_id_utf8:[],
711
'notbxbfse':[parent_id_utf8],
653
vf.add_lines(u'b\xbfse', [], [])
654
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry([u'notbxbfse']))
655
self.assertEqual([u'b\xbfse'], vf.get_parents(u'notbxbfse'))
656
self.assertEqual({u'b\xbfse':[],
657
u'notbxbfse':[u'b\xbfse'],
714
self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
715
vf.has_version, parent_id_unicode))
716
self.assertTrue(vf.has_version(parent_id_utf8))
660
self.assertTrue(vf.has_version(u'b\xbfse'))
717
661
# we have _with_ghost apis to give us ghost information.
718
self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
719
self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
720
self.assertEqual({parent_id_utf8:[],
721
'notbxbfse':[parent_id_utf8],
662
self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
663
self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
664
self.assertEqual({u'b\xbfse':[],
665
u'notbxbfse':[u'b\xbfse'],
723
667
vf.get_graph_with_ghosts())
724
self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
725
vf.has_ghost, parent_id_unicode))
726
self.assertFalse(vf.has_ghost(parent_id_utf8))
668
self.assertFalse(vf.has_ghost(u'b\xbfse'))
728
670
def test_add_lines_with_ghosts_after_normal_revs(self):
729
671
# some versioned file formats allow lines to be added with parent