126
127
self.assertRaises(RevisionNotPresent,
127
128
f.annotate, 'foo')
130
f1 = self.get_file('1')
131
f1.add_lines('r0', [], ['a\n', 'b\n'])
132
f1.add_lines('r1', ['r0'], ['c\n', 'b\n'])
133
f2 = self.get_file('2')
136
self.assertTrue(f.has_version('r0'))
137
self.assertTrue(f.has_version('r1'))
139
verify_file(self.reopen_file('2'))
141
self.assertRaises(RevisionNotPresent,
142
f2.join, f1, version_ids=['r3'])
144
#f3 = self.get_file('1')
145
#f3.add_lines('r0', ['a\n', 'b\n'], [])
146
#f3.add_lines('r1', ['c\n', 'b\n'], ['r0'])
147
#f4 = self.get_file('2')
149
#self.assertTrue(f4.has_version('r0'))
150
#self.assertFalse(f4.has_version('r1'))
152
130
def test_walk(self):
153
131
f = self.get_file('1')
154
132
f.add_lines('r0', [], ['a\n', 'b\n'])
374
352
def test_detection(self):
375
353
print "TODO for merging: create a corrupted knit."
356
class InterString(versionedfile.InterVersionedFile):
357
"""An inter-versionedfile optimised code path for strings.
359
This is for use during testing where we use strings as versionedfiles
360
so that none of the default regsitered interversionedfile classes will
361
match - which lets us test the match logic.
365
def is_compatible(source, target):
366
"""InterString is compatible with strings-as-versionedfiles."""
367
return isinstance(source, str) and isinstance(target, str)
370
# TODO this and the InterRepository core logic should be consolidatable
371
# if we make the registry a separate class though we still need to
372
# test the behaviour in the active registry to catch failure-to-handle-
374
class TestInterVersionedFile(TestCaseWithTransport):
376
def test_get_default_inter_versionedfile(self):
377
# test that the InterVersionedFile.get(a, b) probes
378
# for a class where is_compatible(a, b) returns
379
# true and returns a default interversionedfile otherwise.
380
# This also tests that the default registered optimised interversionedfile
381
# classes do not barf inappropriately when a surprising versionedfile type
383
dummy_a = "VersionedFile 1."
384
dummy_b = "VersionedFile 2."
385
self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)
387
def assertGetsDefaultInterVersionedFile(self, a, b):
388
"""Asserts that InterVersionedFile.get(a, b) -> the default."""
389
inter = versionedfile.InterVersionedFile.get(a, b)
390
self.assertEqual(versionedfile.InterVersionedFile,
392
self.assertEqual(a, inter.source)
393
self.assertEqual(b, inter.target)
395
def test_register_inter_versionedfile_class(self):
396
# test that a optimised code path provider - a
397
# InterVersionedFile subclass can be registered and unregistered
398
# and that it is correctly selected when given a versionedfile
399
# pair that it returns true on for the is_compatible static method
401
dummy_a = "VersionedFile 1."
402
dummy_b = "VersionedFile 2."
403
versionedfile.InterVersionedFile.register_optimiser(InterString)
405
# we should get the default for something InterString returns False
407
self.assertFalse(InterString.is_compatible(dummy_a, None))
408
self.assertGetsDefaultInterVersionedFile(dummy_a, None)
409
# and we should get an InterString for a pair it 'likes'
410
self.assertTrue(InterString.is_compatible(dummy_a, dummy_b))
411
inter = versionedfile.InterVersionedFile.get(dummy_a, dummy_b)
412
self.assertEqual(InterString, inter.__class__)
413
self.assertEqual(dummy_a, inter.source)
414
self.assertEqual(dummy_b, inter.target)
416
versionedfile.InterVersionedFile.unregister_optimiser(InterString)
417
# now we should get the default InterVersionedFile object again.
418
self.assertGetsDefaultInterVersionedFile(dummy_a, dummy_b)