Rev 4822: Add a GraphThunkIdsToKeys as a tested class. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-convert-kg-heads
John Arbash Meinel
john at arbash-meinel.com
Mon Nov 30 03:16:25 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b4-convert-kg-heads
------------------------------------------------------------
revno: 4822
revision-id: john at arbash-meinel.com-20091130031622-qqr6g04iv5g8zl5n
parent: john at arbash-meinel.com-20091122053626-xgsgd01p2ld22hqj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b4-convert-kg-heads
timestamp: Sun 2009-11-29 21:16:22 -0600
message:
Add a GraphThunkIdsToKeys as a tested class.
-------------- next part --------------
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py 2009-09-14 01:48:28 +0000
+++ b/bzrlib/graph.py 2009-11-30 03:16:22 +0000
@@ -1679,6 +1679,19 @@
return result
+class GraphThunkIdsToKeys(object):
+ """Forwards calls about 'ids' to be about keys internally."""
+
+ def __init__(self, graph):
+ self._graph = graph
+
+ def heads(self, ids):
+ """See Graph.heads()"""
+ as_keys = [(i,) for i in ids]
+ head_keys = self._graph.heads(as_keys)
+ return set([h[0] for h in head_keys])
+
+
_counters = [0,0,0,0,0,0,0]
try:
from bzrlib._known_graph_pyx import KnownGraph
=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py 2009-08-04 04:36:34 +0000
+++ b/bzrlib/tests/test_graph.py 2009-11-30 03:16:22 +0000
@@ -1582,6 +1582,24 @@
self.assertCollapsed(d, d)
+class TestGraphThunkIdsToKeys(tests.TestCase):
+
+ def test_heads(self):
+ # A
+ # |\
+ # B C
+ # |/
+ # D
+ d = {('D',): [('B',), ('C',)], ('C',):[('A',)],
+ ('B',): [('A',)], ('A',): []}
+ g = _mod_graph.Graph(_mod_graph.DictParentsProvider(d))
+ graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
+ self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'A'])))
+ self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'B'])))
+ self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C'])))
+ self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C'])))
+
+
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
"""Tests for bzrlib.graph.PendingAncestryResult."""
More information about the bazaar-commits
mailing list