/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
1
# Copyright (C) 2008, 2009 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
0.64.334 by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan.
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
15
16
"""Direct tests of the revision_store classes."""
17
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
18
from .... import (
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
19
    branch,
20
    errors,
21
    osutils,
22
    tests,
23
    )
6670.4.1 by Jelmer Vernooij
Update imports.
24
from ....bzr import (
25
    inventory,
26
    )
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
27
from .. import (
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
28
    revision_store,
29
    )
6628.1.2 by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata.
30
from . import (
0.123.13 by Jelmer Vernooij
Check for availability of fastimport before running tests.
31
    FastimportFeature,
32
    )
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
33
34
35
class Test_TreeShim(tests.TestCase):
36
0.123.13 by Jelmer Vernooij
Check for availability of fastimport before running tests.
37
    _test_needs_features = [FastimportFeature]
38
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
39
    def invAddEntry(self, inv, path, file_id=None):
40
        if path.endswith('/'):
41
            path = path[:-1]
42
            kind = 'directory'
43
        else:
44
            kind = 'file'
45
        parent_path, basename = osutils.split(path)
46
        parent_id = inv.path2id(parent_path)
47
        inv.add(inventory.make_entry(kind, basename, parent_id, file_id))
48
49
    def make_trivial_basis_inv(self):
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
50
        basis_inv = inventory.Inventory(b'TREE_ROOT')
51
        self.invAddEntry(basis_inv, 'foo', b'foo-id')
52
        self.invAddEntry(basis_inv, 'bar/', b'bar-id')
53
        self.invAddEntry(basis_inv, 'bar/baz', b'baz-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
54
        return basis_inv
0.123.13 by Jelmer Vernooij
Check for availability of fastimport before running tests.
55
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
56
    def test_id2path_no_delta(self):
57
        basis_inv = self.make_trivial_basis_inv()
58
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
59
                                        inv_delta=[], content_provider=None)
6855.4.1 by Jelmer Vernooij
Yet more bees.
60
        self.assertEqual('', shim.id2path(b'TREE_ROOT'))
61
        self.assertEqual('foo', shim.id2path(b'foo-id'))
62
        self.assertEqual('bar', shim.id2path(b'bar-id'))
63
        self.assertEqual('bar/baz', shim.id2path(b'baz-id'))
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
64
        self.assertRaises(errors.NoSuchId, shim.id2path, b'qux-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
65
66
    def test_id2path_with_delta(self):
67
        basis_inv = self.make_trivial_basis_inv()
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
        foo_entry = inventory.make_entry(
69
            'file', 'foo2', b'TREE_ROOT', b'foo-id')
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
70
        inv_delta = [('foo', 'foo2', b'foo-id', foo_entry),
71
                     ('bar/baz', None, b'baz-id', None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
72
                     ]
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
73
74
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
75
                                        inv_delta=inv_delta,
76
                                        content_provider=None)
6855.4.1 by Jelmer Vernooij
Yet more bees.
77
        self.assertEqual('', shim.id2path(b'TREE_ROOT'))
78
        self.assertEqual('foo2', shim.id2path(b'foo-id'))
79
        self.assertEqual('bar', shim.id2path(b'bar-id'))
80
        self.assertRaises(errors.NoSuchId, shim.id2path, b'baz-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
81
82
    def test_path2id(self):
83
        basis_inv = self.make_trivial_basis_inv()
84
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
85
                                        inv_delta=[], content_provider=None)
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
86
        self.assertEqual(b'TREE_ROOT', shim.path2id(''))
7141.7.2 by Jelmer Vernooij
Fix more tests.
87
        self.assertEqual(b'bar-id', shim.path2id('bar'))
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
88
89
    def test_get_file_with_stat_content_in_stream(self):
90
        basis_inv = self.make_trivial_basis_inv()
91
92
        def content_provider(file_id):
6855.4.8 by Jelmer Vernooij
Fix some more tests.
93
            return b'content of\n' + file_id + b'\n'
0.123.13 by Jelmer Vernooij
Check for availability of fastimport before running tests.
94
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
95
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
96
                                        inv_delta=[],
97
                                        content_provider=content_provider)
7141.7.2 by Jelmer Vernooij
Fix more tests.
98
        f_obj, stat_val = shim.get_file_with_stat('bar/baz')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
99
        self.assertIs(None, stat_val)
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
100
        self.assertEqualDiff(b'content of\nbaz-id\n', f_obj.read())
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
101
102
    # TODO: Test when the content isn't in the stream, and we fall back to the
103
    #       repository that was passed in
104
105
    def test_get_symlink_target(self):
106
        basis_inv = self.make_trivial_basis_inv()
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
107
        ie = inventory.make_entry('symlink', 'link', b'TREE_ROOT', b'link-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
108
        ie.symlink_target = u'link-target'
109
        basis_inv.add(ie)
110
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
111
                                        inv_delta=[], content_provider=None)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
112
        self.assertEqual(u'link-target',
7141.7.2 by Jelmer Vernooij
Fix more tests.
113
                         shim.get_symlink_target('link'))
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
114
115
    def test_get_symlink_target_from_delta(self):
116
        basis_inv = self.make_trivial_basis_inv()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
117
        ie = inventory.make_entry('symlink', 'link', b'TREE_ROOT', b'link-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
118
        ie.symlink_target = u'link-target'
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
119
        inv_delta = [(None, 'link', b'link-id', ie)]
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
120
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
121
                                        inv_delta=inv_delta,
122
                                        content_provider=None)
6809.4.9 by Jelmer Vernooij
Fix some more tests.
123
        self.assertEqual(u'link-target',
7141.7.2 by Jelmer Vernooij
Fix more tests.
124
                         shim.get_symlink_target('link'))
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
125
126
    def test__delta_to_iter_changes(self):
127
        basis_inv = self.make_trivial_basis_inv()
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
128
        foo_entry = inventory.make_entry('file', 'foo2', b'bar-id', b'foo-id')
129
        link_entry = inventory.make_entry('symlink', 'link', b'TREE_ROOT',
130
                                          b'link-id')
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
131
        link_entry.symlink_target = u'link-target'
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
132
        inv_delta = [('foo', 'bar/foo2', b'foo-id', foo_entry),
133
                     ('bar/baz', None, b'baz-id', None),
134
                     (None, 'link', b'link-id', link_entry),
7143.15.2 by Jelmer Vernooij
Run autopep8.
135
                     ]
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
136
        shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv,
137
                                        inv_delta=inv_delta,
138
                                        content_provider=None)
139
        changes = list(shim._delta_to_iter_changes())
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
140
        expected = [(b'foo-id', ('foo', 'bar/foo2'), False, (True, True),
141
                     (b'TREE_ROOT', b'bar-id'), ('foo', 'foo2'),
7358.17.5 by Jelmer Vernooij
Fix more tests.
142
                     ('file', 'file'), (False, False), False),
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
143
                    (b'baz-id', ('bar/baz', None), True, (True, False),
144
                     (b'bar-id', None), ('baz', None),
7358.17.5 by Jelmer Vernooij
Fix more tests.
145
                     ('file', None), (False, None), False),
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
146
                    (b'link-id', (None, 'link'), True, (False, True),
147
                     (None, b'TREE_ROOT'), (None, 'link'),
7358.17.5 by Jelmer Vernooij
Fix more tests.
148
                     (None, 'symlink'), (None, False), False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
149
                    ]
0.115.12 by John Arbash Meinel
Add a bunch of direct tests for the _TreeShim interface.
150
        # from pprint import pformat
151
        # self.assertEqualDiff(pformat(expected), pformat(changes))
152
        self.assertEqual(expected, changes)