~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-02 10:10:15 UTC
  • mfrom: (4723.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091002101015-hed4j97ksfqyu4mp
(vila) (trivial) Cleanup some dpush related tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
173
173
            "key\x00\x00\t\x00data\n"
174
174
            "\n", contents)
175
175
 
176
 
    def test_clear_cache(self):
177
 
        builder = GraphIndexBuilder(reference_lists=2)
178
 
        # This is a no-op, but the api should exist
179
 
        builder.clear_cache()
180
 
 
181
176
    def test_node_references_are_byte_offsets(self):
182
177
        builder = GraphIndexBuilder(reference_lists=1)
183
178
        builder.add_node(('reference', ), 'data', ([], ))
235
230
        builder.add_node(('2-key', ), '', (references, ))
236
231
        stream = builder.finish()
237
232
        contents = stream.read()
238
 
        self.assertEqualDiff(
 
233
        self.assertEqual(
239
234
            "Bazaar Graph Index 1\nnode_ref_lists=1\nkey_elements=1\nlen=1\n"
240
235
            "0\x00a\x00\x00\n"
241
236
            "1\x00a\x00\x00\n"
388
383
        size = trans.put_file('index', stream)
389
384
        return GraphIndex(trans, 'index', size)
390
385
 
391
 
    def test_clear_cache(self):
392
 
        index = self.make_index()
393
 
        # For now, we just want to make sure the api is available. As this is
394
 
        # old code, we don't really worry if it *does* anything.
395
 
        index.clear_cache()
396
 
 
397
386
    def test_open_bad_index_no_error(self):
398
387
        trans = self.get_transport()
399
388
        trans.put_bytes('name', "not an index\n")
1017
1006
        self.assertEqual(set(), missing_keys)
1018
1007
        self.assertEqual(set(), search_keys)
1019
1008
 
1020
 
    def test_supports_unlimited_cache(self):
1021
 
        builder = GraphIndexBuilder(0, key_elements=1)
1022
 
        stream = builder.finish()
1023
 
        trans = get_transport(self.get_url())
1024
 
        size = trans.put_file('index', stream)
1025
 
        # It doesn't matter what unlimited_cache does here, just that it can be
1026
 
        # passed
1027
 
        index = GraphIndex(trans, 'index', size, unlimited_cache=True)
1028
 
 
1029
1009
 
1030
1010
class TestCombinedGraphIndex(TestCaseWithMemoryTransport):
1031
1011
 
1082
1062
        index.insert_index(0, index1)
1083
1063
        self.assertEqual([(index1, ('key', ), '')], list(index.iter_all_entries()))
1084
1064
 
1085
 
    def test_clear_cache(self):
1086
 
        log = []
1087
 
 
1088
 
        class ClearCacheProxy(object):
1089
 
 
1090
 
            def __init__(self, index):
1091
 
                self._index = index
1092
 
 
1093
 
            def __getattr__(self, name):
1094
 
                return getattr(self._index)
1095
 
 
1096
 
            def clear_cache(self):
1097
 
                log.append(self._index)
1098
 
                return self._index.clear_cache()
1099
 
 
1100
 
        index = CombinedGraphIndex([])
1101
 
        index1 = self.make_index('name', 0, nodes=[(('key', ), '', ())])
1102
 
        index.insert_index(0, ClearCacheProxy(index1))
1103
 
        index2 = self.make_index('name', 0, nodes=[(('key', ), '', ())])
1104
 
        index.insert_index(1, ClearCacheProxy(index2))
1105
 
        # CombinedGraphIndex should call 'clear_cache()' on all children
1106
 
        index.clear_cache()
1107
 
        self.assertEqual(sorted([index1, index2]), sorted(log))
1108
 
 
1109
1065
    def test_iter_all_entries_empty(self):
1110
1066
        index = CombinedGraphIndex([])
1111
1067
        self.assertEqual([], list(index.iter_all_entries()))