/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)
6973.7.8 by Jelmer Vernooij
Fix more tests.
133
        with t.get('format') as f:
134
            self.assertEqualDiff(b'Bazaar-NG Repository format 7',
135
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
136
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
137
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
6973.7.8 by Jelmer Vernooij
Fix more tests.
138
        with t.get('inventory.weave') as f:
139
            self.assertEqualDiff(b'# bzr weave file v5\n'
140
                                 b'w\n'
141
                                 b'W\n',
142
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
143
        # Creating a file with id Foo:Bar results in a non-escaped file name on
144
        # disk.
145
        control.create_branch()
146
        tree = control.create_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
147
        tree.add(['foo'], [b'Foo:Bar'], ['file'])
6963.2.18 by Jelmer Vernooij
Add bees to some of bp.weave_fmt.
148
        tree.put_file_bytes_non_atomic('foo', b'content\n', b'Foo:Bar')
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
149
        try:
6855.4.1 by Jelmer Vernooij
Yet more bees.
150
            tree.commit('first post', rev_id=b'first')
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
151
        except IllegalPath:
152
            if sys.platform != 'win32':
153
                raise
154
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
155
                              ' in repo format 7')
156
            return
6973.7.8 by Jelmer Vernooij
Fix more tests.
157
        with t.get('weaves/74/Foo%3ABar.weave') as f:
158
            self.assertEqualDiff(
159
                b'# bzr weave file v5\n'
160
                b'i\n'
161
                b'1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
162
                b'n first\n'
163
                b'\n'
164
                b'w\n'
165
                b'{ 0\n'
166
                b'. content\n'
167
                b'}\n'
168
                b'W\n',
169
                f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
170
171
    def test_shared_disk_layout(self):
172
        control = BzrDirMetaFormat1().initialize(self.get_url())
173
        repo = RepositoryFormat7().initialize(control, shared=True)
174
        # we want:
175
        # format 'Bazaar-NG Repository format 7'
176
        # inventory.weave == empty_weave
177
        # empty revision-store directory
178
        # empty weaves directory
179
        # a 'shared-storage' marker file.
180
        # lock is not present when unlocked
181
        t = control.get_repository_transport(None)
6973.7.8 by Jelmer Vernooij
Fix more tests.
182
        with t.get('format') as f:
183
            self.assertEqualDiff(b'Bazaar-NG Repository format 7',
184
                                 f.read())
185
        with t.get('shared-storage') as f:
186
            self.assertEqualDiff(b'', f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
187
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
188
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
6973.7.8 by Jelmer Vernooij
Fix more tests.
189
        with t.get('inventory.weave') as f:
190
            self.assertEqualDiff(b'# bzr weave file v5\n'
191
                                 b'w\n'
192
                                 b'W\n',
193
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
194
        self.assertFalse(t.has('branch-lock'))
195
196
    def test_creates_lockdir(self):
197
        """Make sure it appears to be controlled by a LockDir existence"""
198
        control = BzrDirMetaFormat1().initialize(self.get_url())
199
        repo = RepositoryFormat7().initialize(control, shared=True)
200
        t = control.get_repository_transport(None)
201
        # TODO: Should check there is a 'lock' toplevel directory,
202
        # regardless of contents
203
        self.assertFalse(t.has('lock/held/info'))
204
        repo.lock_write()
205
        try:
206
            self.assertTrue(t.has('lock/held/info'))
207
        finally:
208
            # unlock so we don't get a warning about failing to do so
209
            repo.unlock()
210
211
    def test_uses_lockdir(self):
212
        """repo format 7 actually locks on lockdir"""
213
        base_url = self.get_url()
214
        control = BzrDirMetaFormat1().initialize(base_url)
215
        repo = RepositoryFormat7().initialize(control, shared=True)
216
        t = control.get_repository_transport(None)
217
        repo.lock_write()
218
        repo.unlock()
219
        del repo
220
        # make sure the same lock is created by opening it
221
        repo = Repository.open(base_url)
222
        repo.lock_write()
223
        self.assertTrue(t.has('lock/held/info'))
224
        repo.unlock()
225
        self.assertFalse(t.has('lock/held/info'))
226
227
    def test_shared_no_tree_disk_layout(self):
228
        control = BzrDirMetaFormat1().initialize(self.get_url())
229
        repo = RepositoryFormat7().initialize(control, shared=True)
230
        repo.set_make_working_trees(False)
231
        # we want:
232
        # format 'Bazaar-NG Repository format 7'
233
        # lock ''
234
        # inventory.weave == empty_weave
235
        # empty revision-store directory
236
        # empty weaves directory
237
        # a 'shared-storage' marker file.
238
        t = control.get_repository_transport(None)
6973.7.8 by Jelmer Vernooij
Fix more tests.
239
        with t.get('format') as f:
240
            self.assertEqualDiff(b'Bazaar-NG Repository format 7',
241
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
242
        ## self.assertEqualDiff('', t.get('lock').read())
6973.7.8 by Jelmer Vernooij
Fix more tests.
243
        with t.get('shared-storage') as f:
244
            self.assertEqualDiff(b'', f.read())
245
        with t.get('no-working-trees') as f:
246
            self.assertEqualDiff(b'', f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
247
        repo.set_make_working_trees(True)
248
        self.assertFalse(t.has('no-working-trees'))
249
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
250
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
6973.7.8 by Jelmer Vernooij
Fix more tests.
251
        with t.get('inventory.weave') as f:
252
            self.assertEqualDiff(b'# bzr weave file v5\n'
253
                                 b'w\n'
254
                                 b'W\n',
255
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
256
257
    def test_supports_external_lookups(self):
258
        control = BzrDirMetaFormat1().initialize(self.get_url())
259
        repo = RepositoryFormat7().initialize(control)
260
        self.assertFalse(repo._format.supports_external_lookups)
261
262
263
class TestInterWeaveRepo(TestCaseWithTransport):
264
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
265
    def test_make_repository(self):
266
        out, err = self.run_bzr("init-repository --format=weave a")
267
        self.assertEqual(out,
7027.4.2 by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr.
268
"""Standalone tree (format: weave)
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
269
Location:
270
  branch root: a
271
""")
7027.4.2 by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr.
272
        self.assertEqual(err, "")
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
273
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
274
    def test_is_compatible_and_registered(self):
275
        # InterWeaveRepo is compatible when either side
276
        # is a format 5/6/7 branch
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
277
        from ...bzr import knitrepo
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
278
        formats = [RepositoryFormat5(),
279
                   RepositoryFormat6(),
280
                   RepositoryFormat7()]
281
        incompatible_formats = [RepositoryFormat4(),
282
                                knitrepo.RepositoryFormatKnit1(),
283
                                ]
284
        repo_a = self.make_repository('a')
285
        repo_b = self.make_repository('b')
286
        is_compatible = InterWeaveRepo.is_compatible
287
        for source in incompatible_formats:
288
            # force incompatible left then right
289
            repo_a._format = source
290
            repo_b._format = formats[0]
291
            self.assertFalse(is_compatible(repo_a, repo_b))
292
            self.assertFalse(is_compatible(repo_b, repo_a))
293
        for source in formats:
294
            repo_a._format = source
295
            for target in formats:
296
                repo_b._format = target
297
                self.assertTrue(is_compatible(repo_a, repo_b))
298
        self.assertEqual(InterWeaveRepo,
299
                         InterRepository.get(repo_a, repo_b).__class__)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
300
301
6855.3.1 by Jelmer Vernooij
Several more fixes.
302
_working_inventory_v4 = b"""<inventory file_id="TREE_ROOT">
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
303
<entry file_id="bar-20050901064931-73b4b1138abc9cd2" kind="file" name="bar" parent_id="TREE_ROOT" />
304
<entry file_id="foo-20050801201819-4139aa4a272f4250" kind="directory" name="foo" parent_id="TREE_ROOT" />
305
<entry file_id="bar-20050824000535-6bc48cfad47ed134" kind="file" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" />
306
</inventory>"""
307
308
6855.3.1 by Jelmer Vernooij
Several more fixes.
309
_revision_v4 = b"""<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
310
    inventory_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
311
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
312
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
313
    timestamp="1125907235.212"
314
    timezone="36000">
315
<message>- start splitting code for xml (de)serialization away from objects
316
  preparatory to supporting multiple formats by a single library
317
</message>
318
<parents>
319
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" revision_sha1="7bdf4cc8c5bdac739f8cf9b10b78cf4b68f915ff" />
320
</parents>
321
</revision>
322
"""
323
324
325
class TestSerializer(TestCase):
326
    """Test serializer"""
327
328
    def test_registry(self):
329
        self.assertIs(xml4.serializer_v4,
330
                      serializer_format_registry.get('4'))
331
332
    def test_canned_inventory(self):
333
        """Test unpacked a canned inventory v4 file."""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
334
        inp = BytesIO(_working_inventory_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
335
        inv = xml4.serializer_v4.read_inventory(inp)
336
        self.assertEqual(len(inv), 4)
6973.7.5 by Jelmer Vernooij
s/file/open.
337
        self.assertTrue(inv.has_id(b'bar-20050901064931-73b4b1138abc9cd2'))
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
338
339
    def test_unpack_revision(self):
340
        """Test unpacking a canned revision v4"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
341
        inp = BytesIO(_revision_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
342
        rev = xml4.serializer_v4.read_revision(inp)
343
        eq = self.assertEqual
344
        eq(rev.committer,
345
           "Martin Pool <mbp@sourcefrog.net>")
346
        eq(rev.inventory_id,
347
           "mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9")
348
        eq(len(rev.parent_ids), 1)
349
        eq(rev.parent_ids[0],
350
           "mbp@sourcefrog.net-20050905063503-43948f59fa127d92")