/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
1
# Copyright (C) 2011, 2016 Canonical Ltd
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for weave repositories.
18
19
For interface tests see tests/per_repository/*.py.
20
21
"""
22
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
23
from __future__ import absolute_import
24
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
25
from stat import S_ISDIR
26
import sys
27
6670.4.6 by Jelmer Vernooij
Fix some more imports.
28
from ...bzr.bzrdir import (
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
29
    BzrDirMetaFormat1,
30
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
31
from ...errors import (
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
32
    IllegalPath,
33
    NoSuchFile,
34
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
35
from ...repository import (
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
36
    InterRepository,
37
    Repository,
38
    )
6670.4.12 by Jelmer Vernooij
Move inventorytree to breezy.bzr.
39
from ...bzr.serializer import (
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
40
    format_registry as serializer_format_registry,
41
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
42
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
43
    BytesIO,
44
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
45
from ...tests import (
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
46
    TestCase,
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
47
    TestCaseWithTransport,
48
    )
49
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
50
from . import xml4
51
from .bzrdir import (
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
52
    BzrDirFormat6,
53
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
54
from .repository import (
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
55
    InterWeaveRepo,
56
    RepositoryFormat4,
57
    RepositoryFormat5,
58
    RepositoryFormat6,
59
    RepositoryFormat7,
60
    )
61
62
63
class TestFormat6(TestCaseWithTransport):
64
65
    def test_attribute__fetch_order(self):
66
        """Weaves need topological data insertion."""
67
        control = BzrDirFormat6().initialize(self.get_url())
68
        repo = RepositoryFormat6().initialize(control)
69
        self.assertEqual('topological', repo._format._fetch_order)
70
71
    def test_attribute__fetch_uses_deltas(self):
72
        """Weaves do not reuse deltas."""
73
        control = BzrDirFormat6().initialize(self.get_url())
74
        repo = RepositoryFormat6().initialize(control)
75
        self.assertEqual(False, repo._format._fetch_uses_deltas)
76
77
    def test_attribute__fetch_reconcile(self):
78
        """Weave repositories need a reconcile after fetch."""
79
        control = BzrDirFormat6().initialize(self.get_url())
80
        repo = RepositoryFormat6().initialize(control)
81
        self.assertEqual(True, repo._format._fetch_reconcile)
82
83
    def test_no_ancestry_weave(self):
84
        control = BzrDirFormat6().initialize(self.get_url())
85
        repo = RepositoryFormat6().initialize(control)
86
        # We no longer need to create the ancestry.weave file
87
        # since it is *never* used.
88
        self.assertRaises(NoSuchFile,
89
                          control.transport.get,
90
                          'ancestry.weave')
91
92
    def test_supports_external_lookups(self):
93
        control = BzrDirFormat6().initialize(self.get_url())
94
        repo = RepositoryFormat6().initialize(control)
95
        self.assertFalse(repo._format.supports_external_lookups)
96
97
98
99
100
class TestFormat7(TestCaseWithTransport):
101
102
    def test_attribute__fetch_order(self):
103
        """Weaves need topological data insertion."""
104
        control = BzrDirMetaFormat1().initialize(self.get_url())
105
        repo = RepositoryFormat7().initialize(control)
106
        self.assertEqual('topological', repo._format._fetch_order)
107
108
    def test_attribute__fetch_uses_deltas(self):
109
        """Weaves do not reuse deltas."""
110
        control = BzrDirMetaFormat1().initialize(self.get_url())
111
        repo = RepositoryFormat7().initialize(control)
112
        self.assertEqual(False, repo._format._fetch_uses_deltas)
113
114
    def test_attribute__fetch_reconcile(self):
115
        """Weave repositories need a reconcile after fetch."""
116
        control = BzrDirMetaFormat1().initialize(self.get_url())
117
        repo = RepositoryFormat7().initialize(control)
118
        self.assertEqual(True, repo._format._fetch_reconcile)
119
120
    def test_disk_layout(self):
121
        control = BzrDirMetaFormat1().initialize(self.get_url())
122
        repo = RepositoryFormat7().initialize(control)
123
        # in case of side effects of locking.
124
        repo.lock_write()
125
        repo.unlock()
126
        # we want:
127
        # format 'Bazaar-NG Repository format 7'
128
        # lock ''
129
        # inventory.weave == empty_weave
130
        # empty revision-store directory
131
        # empty weaves directory
132
        t = control.get_repository_transport(None)
133
        self.assertEqualDiff('Bazaar-NG Repository format 7',
134
                             t.get('format').read())
135
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
136
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
137
        self.assertEqualDiff('# bzr weave file v5\n'
138
                             'w\n'
139
                             'W\n',
140
                             t.get('inventory.weave').read())
141
        # Creating a file with id Foo:Bar results in a non-escaped file name on
142
        # disk.
143
        control.create_branch()
144
        tree = control.create_workingtree()
145
        tree.add(['foo'], ['Foo:Bar'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
146
        tree.put_file_bytes_non_atomic('foo', 'content\n', 'Foo:Bar')
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
147
        try:
148
            tree.commit('first post', rev_id='first')
149
        except IllegalPath:
150
            if sys.platform != 'win32':
151
                raise
152
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
153
                              ' in repo format 7')
154
            return
155
        self.assertEqualDiff(
156
            '# bzr weave file v5\n'
157
            'i\n'
158
            '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
159
            'n first\n'
160
            '\n'
161
            'w\n'
162
            '{ 0\n'
163
            '. content\n'
164
            '}\n'
165
            'W\n',
166
            t.get('weaves/74/Foo%3ABar.weave').read())
167
168
    def test_shared_disk_layout(self):
169
        control = BzrDirMetaFormat1().initialize(self.get_url())
170
        repo = RepositoryFormat7().initialize(control, shared=True)
171
        # we want:
172
        # format 'Bazaar-NG Repository format 7'
173
        # inventory.weave == empty_weave
174
        # empty revision-store directory
175
        # empty weaves directory
176
        # a 'shared-storage' marker file.
177
        # lock is not present when unlocked
178
        t = control.get_repository_transport(None)
179
        self.assertEqualDiff('Bazaar-NG Repository format 7',
180
                             t.get('format').read())
181
        self.assertEqualDiff('', t.get('shared-storage').read())
182
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
183
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
184
        self.assertEqualDiff('# bzr weave file v5\n'
185
                             'w\n'
186
                             'W\n',
187
                             t.get('inventory.weave').read())
188
        self.assertFalse(t.has('branch-lock'))
189
190
    def test_creates_lockdir(self):
191
        """Make sure it appears to be controlled by a LockDir existence"""
192
        control = BzrDirMetaFormat1().initialize(self.get_url())
193
        repo = RepositoryFormat7().initialize(control, shared=True)
194
        t = control.get_repository_transport(None)
195
        # TODO: Should check there is a 'lock' toplevel directory,
196
        # regardless of contents
197
        self.assertFalse(t.has('lock/held/info'))
198
        repo.lock_write()
199
        try:
200
            self.assertTrue(t.has('lock/held/info'))
201
        finally:
202
            # unlock so we don't get a warning about failing to do so
203
            repo.unlock()
204
205
    def test_uses_lockdir(self):
206
        """repo format 7 actually locks on lockdir"""
207
        base_url = self.get_url()
208
        control = BzrDirMetaFormat1().initialize(base_url)
209
        repo = RepositoryFormat7().initialize(control, shared=True)
210
        t = control.get_repository_transport(None)
211
        repo.lock_write()
212
        repo.unlock()
213
        del repo
214
        # make sure the same lock is created by opening it
215
        repo = Repository.open(base_url)
216
        repo.lock_write()
217
        self.assertTrue(t.has('lock/held/info'))
218
        repo.unlock()
219
        self.assertFalse(t.has('lock/held/info'))
220
221
    def test_shared_no_tree_disk_layout(self):
222
        control = BzrDirMetaFormat1().initialize(self.get_url())
223
        repo = RepositoryFormat7().initialize(control, shared=True)
224
        repo.set_make_working_trees(False)
225
        # we want:
226
        # format 'Bazaar-NG Repository format 7'
227
        # lock ''
228
        # inventory.weave == empty_weave
229
        # empty revision-store directory
230
        # empty weaves directory
231
        # a 'shared-storage' marker file.
232
        t = control.get_repository_transport(None)
233
        self.assertEqualDiff('Bazaar-NG Repository format 7',
234
                             t.get('format').read())
235
        ## self.assertEqualDiff('', t.get('lock').read())
236
        self.assertEqualDiff('', t.get('shared-storage').read())
237
        self.assertEqualDiff('', t.get('no-working-trees').read())
238
        repo.set_make_working_trees(True)
239
        self.assertFalse(t.has('no-working-trees'))
240
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
241
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
242
        self.assertEqualDiff('# bzr weave file v5\n'
243
                             'w\n'
244
                             'W\n',
245
                             t.get('inventory.weave').read())
246
247
    def test_supports_external_lookups(self):
248
        control = BzrDirMetaFormat1().initialize(self.get_url())
249
        repo = RepositoryFormat7().initialize(control)
250
        self.assertFalse(repo._format.supports_external_lookups)
251
252
253
class TestInterWeaveRepo(TestCaseWithTransport):
254
255
    def test_is_compatible_and_registered(self):
256
        # InterWeaveRepo is compatible when either side
257
        # is a format 5/6/7 branch
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
258
        from ...bzr import knitrepo
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
259
        formats = [RepositoryFormat5(),
260
                   RepositoryFormat6(),
261
                   RepositoryFormat7()]
262
        incompatible_formats = [RepositoryFormat4(),
263
                                knitrepo.RepositoryFormatKnit1(),
264
                                ]
265
        repo_a = self.make_repository('a')
266
        repo_b = self.make_repository('b')
267
        is_compatible = InterWeaveRepo.is_compatible
268
        for source in incompatible_formats:
269
            # force incompatible left then right
270
            repo_a._format = source
271
            repo_b._format = formats[0]
272
            self.assertFalse(is_compatible(repo_a, repo_b))
273
            self.assertFalse(is_compatible(repo_b, repo_a))
274
        for source in formats:
275
            repo_a._format = source
276
            for target in formats:
277
                repo_b._format = target
278
                self.assertTrue(is_compatible(repo_a, repo_b))
279
        self.assertEqual(InterWeaveRepo,
280
                         InterRepository.get(repo_a, repo_b).__class__)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
281
282
283
_working_inventory_v4 = """<inventory file_id="TREE_ROOT">
284
<entry file_id="bar-20050901064931-73b4b1138abc9cd2" kind="file" name="bar" parent_id="TREE_ROOT" />
285
<entry file_id="foo-20050801201819-4139aa4a272f4250" kind="directory" name="foo" parent_id="TREE_ROOT" />
286
<entry file_id="bar-20050824000535-6bc48cfad47ed134" kind="file" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" />
287
</inventory>"""
288
289
290
_revision_v4 = """<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
291
    inventory_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
292
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
293
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
294
    timestamp="1125907235.212"
295
    timezone="36000">
296
<message>- start splitting code for xml (de)serialization away from objects
297
  preparatory to supporting multiple formats by a single library
298
</message>
299
<parents>
300
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" revision_sha1="7bdf4cc8c5bdac739f8cf9b10b78cf4b68f915ff" />
301
</parents>
302
</revision>
303
"""
304
305
306
class TestSerializer(TestCase):
307
    """Test serializer"""
308
309
    def test_registry(self):
310
        self.assertIs(xml4.serializer_v4,
311
                      serializer_format_registry.get('4'))
312
313
    def test_canned_inventory(self):
314
        """Test unpacked a canned inventory v4 file."""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
315
        inp = BytesIO(_working_inventory_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
316
        inv = xml4.serializer_v4.read_inventory(inp)
317
        self.assertEqual(len(inv), 4)
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
318
        self.assertTrue(inv.has_id('bar-20050901064931-73b4b1138abc9cd2'))
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
319
320
    def test_unpack_revision(self):
321
        """Test unpacking a canned revision v4"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
322
        inp = BytesIO(_revision_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
323
        rev = xml4.serializer_v4.read_revision(inp)
324
        eq = self.assertEqual
325
        eq(rev.committer,
326
           "Martin Pool <mbp@sourcefrog.net>")
327
        eq(rev.inventory_id,
328
           "mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9")
329
        eq(len(rev.parent_ids), 1)
330
        eq(rev.parent_ids[0],
331
           "mbp@sourcefrog.net-20050905063503-43948f59fa127d92")