~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_map.py

Teach CHKMap how to iter items in 2-tuple keyspaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        self.addCleanup(repo.abort_write_group)
38
38
        return repo.chk_bytes
39
39
 
40
 
    def _get_map(self, a_dict, maximum_size=0, chk_bytes=None):
 
40
    def _get_map(self, a_dict, maximum_size=0, chk_bytes=None, key_width=1):
41
41
        if chk_bytes is None:
42
42
            chk_bytes = self.get_chk_bytes()
43
 
        root_key = CHKMap.from_dict(chk_bytes, a_dict, maximum_size=maximum_size)
 
43
        root_key = CHKMap.from_dict(chk_bytes, a_dict,
 
44
            maximum_size=maximum_size, key_width=key_width)
44
45
        chkmap = CHKMap(chk_bytes, root_key)
45
46
        return chkmap
46
47
 
251
252
        self.assertEqual({("a",): "content here"},
252
253
            self.to_dict(chkmap, [("a",)]))
253
254
 
 
255
    def test_iteritems_keys_prefixed_by_2_width_nodes(self):
 
256
        chkmap = self._get_map(
 
257
            {("a","a"):"content here", ("a", "b",):"more content",
 
258
             ("b", ""): 'boring content'},
 
259
            maximum_size=10, key_width=2)
 
260
        self.assertEqual(
 
261
            {("a", "a"): "content here", ("a", "b"): 'more content'},
 
262
            self.to_dict(chkmap, [("a",)]))
 
263
 
 
264
    def test_iteritems_keys_prefixed_by_2_width_one_leaf(self):
 
265
        chkmap = self._get_map(
 
266
            {("a","a"):"content here", ("a", "b",):"more content",
 
267
             ("b", ""): 'boring content'}, key_width=2)
 
268
        self.assertEqual(
 
269
            {("a", "a"): "content here", ("a", "b"): 'more content'},
 
270
            self.to_dict(chkmap, [("a",)]))
 
271
 
254
272
    def test___len__empty(self):
255
273
        chkmap = self._get_map({})
256
274
        self.assertEqual(0, len(chkmap))