~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-21 19:02:34 UTC
  • mto: This revision was merged to the branch mainline in revision 3460.
  • Revision ID: john@arbash-meinel.com-20080521190234-oijes1jniav97axe
Start working on a new Graph api to make finding revision numbers faster.

The current implementation traverses all ancestors. We'll do better by seeding the
information with known revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1228
1228
            ['h', 'i', 'j', 'y'], 'j', ['z'])
1229
1229
 
1230
1230
 
 
1231
class TestGraphFindRevno(tests.TestCase):
 
1232
    """Test an api that should be able to compute a revno"""
 
1233
 
 
1234
    def make_graph(self, ancestors):
 
1235
        return _mod_graph.Graph(_mod_graph.DictParentsProvider(ancestors))
 
1236
 
 
1237
    def assertFindRevno(self, revno, graph, target_id, known_ids):
 
1238
        """Assert the output of Graph.find_revno()"""
 
1239
        actual = graph.find_revno(target_id, known_ids)
 
1240
        self.assertEqual(revno, actual)
 
1241
 
 
1242
    def test_nothing_known(self):
 
1243
        graph = self.make_graph(ancestry_1)
 
1244
        self.assertFindRevno(1, graph, 'rev1', [])
 
1245
        self.assertFindRevno(2, graph, 'rev2a', [])
 
1246
        self.assertFindRevno(2, graph, 'rev2b', [])
 
1247
        self.assertFindRevno(3, graph, 'rev3', [])
 
1248
        self.assertFindRevno(4, graph, 'rev4', [])
 
1249
 
 
1250
    def test_rev_is_ghost(self):
 
1251
        graph = self.make_graph(ancestry_1)
 
1252
        e = self.assertRaises(errors.GhostRevisionsHaveNoRevno,
 
1253
                              graph.find_revno, 'rev_missing', [])
 
1254
        self.assertEqual('rev_missing', e.revision_id)
 
1255
        self.assertEqual('rev_missing', e.ghost_revision_id)
 
1256
 
 
1257
    def test_ancestor_is_ghost(self):
 
1258
        graph = self.make_graph({'rev':['parent']})
 
1259
        e = self.assertRaises(errors.GhostRevisionsHaveNoRevno,
 
1260
                              graph.find_revno, 'rev', [])
 
1261
        self.assertEqual('rev', e.revision_id)
 
1262
        self.assertEqual('parent', e.ghost_revision_id)
 
1263
 
 
1264
 
1231
1265
class TestCachingParentsProvider(tests.TestCase):
1232
1266
 
1233
1267
    def setUp(self):