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