213
213
t.get('inventory.weave').read())
216
class InterString(repository.InterRepository):
217
"""An inter-repository optimised code path for strings.
219
This is for use during testing where we use strings as repositories
220
so that none of the default regsitered inter-repository classes will
225
def is_compatible(repo_source, repo_target):
226
"""InterString is compatible with strings-as-repos."""
227
return isinstance(repo_source, str) and isinstance(repo_target, str)
230
class TestInterRepository(TestCaseWithTransport):
232
def test_get_default_inter_repository(self):
233
# test that the InterRepository.get(repo_a, repo_b) probes
234
# for a inter_repo class where is_compatible(repo_a, repo_b) returns
235
# true and returns a default inter_repo otherwise.
236
# This also tests that the default registered optimised interrepository
237
# classes do not barf inappropriately when a surprising repository type
239
dummy_a = "Repository 1."
240
dummy_b = "Repository 2."
241
self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
243
def assertGetsDefaultInterRepository(self, repo_a, repo_b):
244
"""Asserts that InterRepository.get(repo_a, repo_b) -> the default."""
245
inter_repo = repository.InterRepository.get(repo_a, repo_b)
246
self.assertEqual(repository.InterRepository,
247
inter_repo.__class__)
248
self.assertEqual(repo_a, inter_repo.source)
249
self.assertEqual(repo_b, inter_repo.target)
251
def test_register_inter_repository_class(self):
252
# test that a optimised code path provider - a
253
# InterRepository subclass can be registered and unregistered
254
# and that it is correctly selected when given a repository
255
# pair that it returns true on for the is_compatible static method
257
dummy_a = "Repository 1."
258
dummy_b = "Repository 2."
259
repository.InterRepository.register_optimiser(InterString)
261
# we should get the default for something InterString returns False
263
self.assertFalse(InterString.is_compatible(dummy_a, None))
264
self.assertGetsDefaultInterRepository(dummy_a, None)
265
# and we should get an InterString for a pair it 'likes'
266
self.assertTrue(InterString.is_compatible(dummy_a, dummy_b))
267
inter_repo = repository.InterRepository.get(dummy_a, dummy_b)
268
self.assertEqual(InterString, inter_repo.__class__)
269
self.assertEqual(dummy_a, inter_repo.source)
270
self.assertEqual(dummy_b, inter_repo.target)
272
repository.InterRepository.unregister_optimiser(InterString)
273
# now we should get the default InterRepository object again.
274
self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
277
class TestInterWeaveRepo(TestCaseWithTransport):
279
def test_is_compatible_and_registered(self):
280
# InterWeaveRepo is compatible when either side
281
# is a format 5/6/7 branch
282
formats = [repository.RepositoryFormat5(),
283
repository.RepositoryFormat6(),
284
repository.RepositoryFormat7()]
285
repo_a = self.make_repository('a')
286
repo_b = self.make_repository('b')
287
# force incompatible left then right
288
repo_a._format = repository.RepositoryFormat4()
289
repo_b._format = formats[0]
290
is_compatible = repository.InterWeaveRepo.is_compatible
291
self.assertFalse(is_compatible(repo_a, repo_b))
292
self.assertFalse(is_compatible(repo_b, repo_a))
293
for source in formats:
294
repo_a._format = source
295
for target in formats:
296
repo_b._format = target
297
self.assertTrue(is_compatible(repo_a, repo_b))
298
self.assertEqual(repository.InterWeaveRepo,
299
repository.InterRepository.get(repo_a,