~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1413
1413
        self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))
1414
1414
 
1415
1415
 
 
1416
class TestCachingParentsProviderExtras(tests.TestCaseWithTransport):
 
1417
    """Test the behaviour when parents are provided that were not requested."""
 
1418
 
 
1419
    def setUp(self):
 
1420
        super(TestCachingParentsProviderExtras, self).setUp()
 
1421
        class ExtraParentsProvider(object):
 
1422
 
 
1423
            def get_parent_map(self, keys):
 
1424
                return {'rev1': [], 'rev2': ['rev1',]}
 
1425
 
 
1426
        self.inst_pp = InstrumentedParentsProvider(ExtraParentsProvider())
 
1427
        self.caching_pp = _mod_graph.CachingParentsProvider(
 
1428
            get_parent_map=self.inst_pp.get_parent_map)
 
1429
 
 
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)
 
1436
 
 
1437
    def test_cache_initially_empty(self):
 
1438
        self.assertEqual({}, self.caching_pp._cache)
 
1439
 
 
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)
 
1449
 
 
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)
 
1456
 
 
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))
 
1460
 
 
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)
 
1465
 
 
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)
 
1472
 
 
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)
 
1478
 
 
1479
 
1416
1480
class TestCollapseLinearRegions(tests.TestCase):
1417
1481
 
1418
1482
    def assertCollapsed(self, collapsed, original):