13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests for indices."""
558
558
# not create a new transport request, and should return False (cannot
559
559
# be in the index) - even when the byte location we ask for is outside
560
560
# the parsed region
562
562
result = index._lookup_keys_via_location([(4000, self.make_key(40))])
563
563
self.assertEqual(
564
564
[((4000, self.make_key(40)),
922
922
index = self.make_index(nodes=[(('key', ), 'value', ())])
925
# XXX: external_references tests are duplicated in test_btree_index. We
926
# probably should have per_graph_index tests...
927
def test_external_references_no_refs(self):
928
index = self.make_index(ref_lists=0, nodes=[])
929
self.assertRaises(ValueError, index.external_references, 0)
931
def test_external_references_no_results(self):
932
index = self.make_index(ref_lists=1, nodes=[
933
(('key',), 'value', ([],))])
934
self.assertEqual(set(), index.external_references(0))
936
def test_external_references_missing_ref(self):
937
missing_key = ('missing',)
938
index = self.make_index(ref_lists=1, nodes=[
939
(('key',), 'value', ([missing_key],))])
940
self.assertEqual(set([missing_key]), index.external_references(0))
942
def test_external_references_multiple_ref_lists(self):
943
missing_key = ('missing',)
944
index = self.make_index(ref_lists=2, nodes=[
945
(('key',), 'value', ([], [missing_key]))])
946
self.assertEqual(set([]), index.external_references(0))
947
self.assertEqual(set([missing_key]), index.external_references(1))
949
def test_external_references_two_records(self):
950
index = self.make_index(ref_lists=1, nodes=[
951
(('key-1',), 'value', ([('key-2',)],)),
952
(('key-2',), 'value', ([],)),
954
self.assertEqual(set([]), index.external_references(0))
957
926
class TestCombinedGraphIndex(TestCaseWithMemoryTransport):
1078
1047
self.assertEqual(set([(index1, ('name', ), 'data', ((('ref', ), ), )),
1079
1048
(index2, ('ref', ), 'refdata', ((), ))]),
1080
1049
set(index.iter_entries([('name', ), ('ref', )])))
1082
1051
def test_iter_all_keys_dup_entry(self):
1083
1052
index1 = self.make_index('1', 1, nodes=[
1084
1053
(('name', ), 'data', ([('ref', )], )),
1089
1058
self.assertEqual(set([(index1, ('name', ), 'data', ((('ref',),),)),
1090
1059
(index1, ('ref', ), 'refdata', ((), ))]),
1091
1060
set(index.iter_entries([('name', ), ('ref', )])))
1093
1062
def test_iter_missing_entry_empty(self):
1094
1063
index = CombinedGraphIndex([])
1095
1064
self.assertEqual([], list(index.iter_entries([('a', )])))
1104
1073
index2 = self.make_index('2')
1105
1074
index = CombinedGraphIndex([index1, index2])
1106
1075
self.assertEqual([], list(index.iter_entries([('a', )])))
1108
1077
def test_iter_entry_present_one_index_only(self):
1109
1078
index1 = self.make_index('1', nodes=[(('key', ), '', ())])
1110
1079
index2 = self.make_index('2', nodes=[])