1413
1413
self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))
1416
class TestCachingParentsProviderExtras(tests.TestCaseWithTransport):
1417
"""Test the behaviour when parents are provided that were not requested."""
1420
super(TestCachingParentsProviderExtras, self).setUp()
1421
class ExtraParentsProvider(object):
1423
def get_parent_map(self, keys):
1424
return {'rev1': [], 'rev2': ['rev1',]}
1426
self.inst_pp = InstrumentedParentsProvider(ExtraParentsProvider())
1427
self.caching_pp = _mod_graph.CachingParentsProvider(
1428
get_parent_map=self.inst_pp.get_parent_map)
1430
def test_uncached(self):
1431
self.caching_pp.disable_cache()
1432
self.assertEqual({'rev1': []},
1433
self.caching_pp.get_parent_map(['rev1']))
1434
self.assertEqual(['rev1'], self.inst_pp.calls)
1435
self.assertIs(None, self.caching_pp._cache)
1437
def test_cache_initially_empty(self):
1438
self.assertEqual({}, self.caching_pp._cache)
1440
def test_cached(self):
1441
self.assertEqual({'rev1': []},
1442
self.caching_pp.get_parent_map(['rev1']))
1443
self.assertEqual(['rev1'], self.inst_pp.calls)
1444
self.assertEqual({'rev1': [], 'rev2': ['rev1']},
1445
self.caching_pp._cache)
1446
self.assertEqual({'rev1': []},
1447
self.caching_pp.get_parent_map(['rev1']))
1448
self.assertEqual(['rev1'], self.inst_pp.calls)
1450
def test_disable_cache_clears_cache(self):
1451
# Put something in the cache
1452
self.caching_pp.get_parent_map(['rev1'])
1453
self.assertEqual(2, len(self.caching_pp._cache))
1454
self.caching_pp.disable_cache()
1455
self.assertIs(None, self.caching_pp._cache)
1457
def test_enable_cache_raises(self):
1458
e = self.assertRaises(AssertionError, self.caching_pp.enable_cache)
1459
self.assertEqual('Cache enabled when already enabled.', str(e))
1461
def test_cache_misses(self):
1462
self.caching_pp.get_parent_map(['rev3'])
1463
self.caching_pp.get_parent_map(['rev3'])
1464
self.assertEqual(['rev3'], self.inst_pp.calls)
1466
def test_no_cache_misses(self):
1467
self.caching_pp.disable_cache()
1468
self.caching_pp.enable_cache(cache_misses=False)
1469
self.caching_pp.get_parent_map(['rev3'])
1470
self.caching_pp.get_parent_map(['rev3'])
1471
self.assertEqual(['rev3', 'rev3'], self.inst_pp.calls)
1473
def test_cache_extras(self):
1474
self.assertEqual({}, self.caching_pp.get_parent_map(['rev3']))
1475
self.assertEqual({'rev2': ['rev1']},
1476
self.caching_pp.get_parent_map(['rev2']))
1477
self.assertEqual(['rev3'], self.inst_pp.calls)
1416
1480
class TestCollapseLinearRegions(tests.TestCase):
1418
1482
def assertCollapsed(self, collapsed, original):