~bzr-pqm/bzr/bzr.dev

3770.1.1 by John Arbash Meinel
First draft of a basic dump-btree command.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3770.1.1 by John Arbash Meinel
First draft of a basic dump-btree command.
16
#
17
18
"""Tests of the 'bzr dump-btree' command."""
19
20
from bzrlib import (
21
    btree_index,
22
    tests,
23
    )
24
from bzrlib.tests import (
25
    http_server,
26
    )
27
28
29
class TestDumpBtree(tests.TestCaseWithTransport):
30
31
    def create_sample_btree_index(self):
32
        builder = btree_index.BTreeBuilder(
33
            reference_lists=1, key_elements=2)
34
        builder.add_node(('test', 'key1'), 'value', ((('ref', 'entry'),),))
35
        builder.add_node(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))
36
        builder.add_node(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))
37
        out_f = builder.finish()
38
        try:
39
            self.build_tree_contents([('test.btree', out_f.read())])
40
        finally:
41
            out_f.close()
42
43
    def test_dump_btree_smoke(self):
44
        self.create_sample_btree_index()
45
        out, err = self.run_bzr('dump-btree test.btree')
46
        self.assertEqualDiff(
47
            "(('test', 'key1'), 'value', ((('ref', 'entry'),),))\n"
48
            "(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))\n"
49
            "(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))\n",
50
            out)
51
52
    def test_dump_btree_http_smoke(self):
53
        self.transport_readonly_server = http_server.HttpServer
54
        self.create_sample_btree_index()
55
        url = self.get_readonly_url('test.btree')
56
        out, err = self.run_bzr(['dump-btree', url])
57
        self.assertEqualDiff(
58
            "(('test', 'key1'), 'value', ((('ref', 'entry'),),))\n"
59
            "(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))\n"
60
            "(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))\n",
61
            out)
3770.1.2 by John Arbash Meinel
Add a --raw output for dump-btree.
62
63
    def test_dump_btree_raw_smoke(self):
64
        self.create_sample_btree_index()
65
        out, err = self.run_bzr('dump-btree test.btree --raw')
66
        self.assertEqualDiff(
67
            'Root node:\n'
68
            'B+Tree Graph Index 2\n'
69
            'node_ref_lists=1\n'
70
            'key_elements=2\n'
71
            'len=3\n'
72
            'row_lengths=1\n'
73
            '\n'
3770.1.3 by John Arbash Meinel
Simplify the --raw mode.
74
            'Page 0\n'
3770.1.2 by John Arbash Meinel
Add a --raw output for dump-btree.
75
            'type=leaf\n'
76
            'test\0key1\0ref\0entry\0value\n'
77
            'test\0key2\0ref\0entry2\0value2\n'
78
            'test2\0key3\0ref\0entry3\0value3\n'
79
            '\n',
80
            out)