336
336
self.assertTrue(S_ISDIR(t.stat('knits').st_mode))
337
337
self.check_knits(t)
339
class InterString(repository.InterRepository):
340
"""An inter-repository optimised code path for strings.
342
This is for use during testing where we use strings as repositories
340
class DummyRepository(object):
341
"""A dummy repository for testing."""
345
def supports_rich_root(self):
349
class InterDummy(repository.InterRepository):
350
"""An inter-repository optimised code path for DummyRepository.
352
This is for use during testing where we use DummyRepository as repositories
343
353
so that none of the default regsitered inter-repository classes will
348
358
def is_compatible(repo_source, repo_target):
349
"""InterString is compatible with strings-as-repos."""
350
return isinstance(repo_source, str) and isinstance(repo_target, str)
359
"""InterDummy is compatible with DummyRepository."""
360
return (isinstance(repo_source, DummyRepository) and
361
isinstance(repo_target, DummyRepository))
353
364
class TestInterRepository(TestCaseWithTransport):
359
370
# This also tests that the default registered optimised interrepository
360
371
# classes do not barf inappropriately when a surprising repository type
361
372
# is handed to them.
362
dummy_a = "Repository 1."
363
dummy_b = "Repository 2."
373
dummy_a = DummyRepository()
374
dummy_b = DummyRepository()
364
375
self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
366
377
def assertGetsDefaultInterRepository(self, repo_a, repo_b):
367
"""Asserts that InterRepository.get(repo_a, repo_b) -> the default."""
378
"""Asserts that InterRepository.get(repo_a, repo_b) -> the default.
380
The effective default is now InterSameDataRepository because there is
381
no actual sane default in the presence of incompatible data models.
368
383
inter_repo = repository.InterRepository.get(repo_a, repo_b)
369
self.assertEqual(repository.InterRepository,
384
self.assertEqual(repository.InterSameDataRepository,
370
385
inter_repo.__class__)
371
386
self.assertEqual(repo_a, inter_repo.source)
372
387
self.assertEqual(repo_b, inter_repo.target)
377
392
# and that it is correctly selected when given a repository
378
393
# pair that it returns true on for the is_compatible static method
380
dummy_a = "Repository 1."
381
dummy_b = "Repository 2."
382
repository.InterRepository.register_optimiser(InterString)
395
dummy_a = DummyRepository()
396
dummy_b = DummyRepository()
397
repo = self.make_repository('.')
398
# hack dummies to look like repo somewhat.
399
dummy_a._serializer = repo._serializer
400
dummy_b._serializer = repo._serializer
401
repository.InterRepository.register_optimiser(InterDummy)
384
# we should get the default for something InterString returns False
403
# we should get the default for something InterDummy returns False
386
self.assertFalse(InterString.is_compatible(dummy_a, None))
387
self.assertGetsDefaultInterRepository(dummy_a, None)
388
# and we should get an InterString for a pair it 'likes'
389
self.assertTrue(InterString.is_compatible(dummy_a, dummy_b))
405
self.assertFalse(InterDummy.is_compatible(dummy_a, repo))
406
self.assertGetsDefaultInterRepository(dummy_a, repo)
407
# and we should get an InterDummy for a pair it 'likes'
408
self.assertTrue(InterDummy.is_compatible(dummy_a, dummy_b))
390
409
inter_repo = repository.InterRepository.get(dummy_a, dummy_b)
391
self.assertEqual(InterString, inter_repo.__class__)
410
self.assertEqual(InterDummy, inter_repo.__class__)
392
411
self.assertEqual(dummy_a, inter_repo.source)
393
412
self.assertEqual(dummy_b, inter_repo.target)
395
repository.InterRepository.unregister_optimiser(InterString)
414
repository.InterRepository.unregister_optimiser(InterDummy)
396
415
# now we should get the default InterRepository object again.
397
416
self.assertGetsDefaultInterRepository(dummy_a, dummy_b)