/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'])
7192.5.2 by Jelmer Vernooij
Fixes.
146
        tree.put_file_bytes_non_atomic('foo', b'content\n')
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'))
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
202
        with repo.lock_write():
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
203
            self.assertTrue(t.has('lock/held/info'))
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)
6973.7.8 by Jelmer Vernooij
Fix more tests.
233
        with t.get('format') as f:
234
            self.assertEqualDiff(b'Bazaar-NG Repository format 7',
235
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
236
        ## self.assertEqualDiff('', t.get('lock').read())
6973.7.8 by Jelmer Vernooij
Fix more tests.
237
        with t.get('shared-storage') as f:
238
            self.assertEqualDiff(b'', f.read())
239
        with t.get('no-working-trees') as f:
240
            self.assertEqualDiff(b'', f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
241
        repo.set_make_working_trees(True)
242
        self.assertFalse(t.has('no-working-trees'))
243
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
244
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
6973.7.8 by Jelmer Vernooij
Fix more tests.
245
        with t.get('inventory.weave') as f:
246
            self.assertEqualDiff(b'# bzr weave file v5\n'
247
                                 b'w\n'
248
                                 b'W\n',
249
                                 f.read())
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
250
251
    def test_supports_external_lookups(self):
252
        control = BzrDirMetaFormat1().initialize(self.get_url())
253
        repo = RepositoryFormat7().initialize(control)
254
        self.assertFalse(repo._format.supports_external_lookups)
255
256
257
class TestInterWeaveRepo(TestCaseWithTransport):
258
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
259
    def test_make_repository(self):
7385.2.1 by Jelmer Vernooij
Rename init-repo to init-shared-repo.
260
        out, err = self.run_bzr("init-shared-repository --format=weave a")
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
261
        self.assertEqual(out,
7143.15.2 by Jelmer Vernooij
Run autopep8.
262
                         """Standalone tree (format: weave)
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
263
Location:
264
  branch root: a
265
""")
7027.4.2 by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr.
266
        self.assertEqual(err, "")
6929.5.1 by Jelmer Vernooij
Don't explicitly specify repository format to fixed component bzrdirs (like weave).
267
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
268
    def test_is_compatible_and_registered(self):
269
        # InterWeaveRepo is compatible when either side
270
        # is a format 5/6/7 branch
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
271
        from ...bzr import knitrepo
5582.10.2 by Jelmer Vernooij
Move weave repository tests.
272
        formats = [RepositoryFormat5(),
273
                   RepositoryFormat6(),
274
                   RepositoryFormat7()]
275
        incompatible_formats = [RepositoryFormat4(),
276
                                knitrepo.RepositoryFormatKnit1(),
277
                                ]
278
        repo_a = self.make_repository('a')
279
        repo_b = self.make_repository('b')
280
        is_compatible = InterWeaveRepo.is_compatible
281
        for source in incompatible_formats:
282
            # force incompatible left then right
283
            repo_a._format = source
284
            repo_b._format = formats[0]
285
            self.assertFalse(is_compatible(repo_a, repo_b))
286
            self.assertFalse(is_compatible(repo_b, repo_a))
287
        for source in formats:
288
            repo_a._format = source
289
            for target in formats:
290
                repo_b._format = target
291
                self.assertTrue(is_compatible(repo_a, repo_b))
292
        self.assertEqual(InterWeaveRepo,
293
                         InterRepository.get(repo_a, repo_b).__class__)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
294
295
6855.3.1 by Jelmer Vernooij
Several more fixes.
296
_working_inventory_v4 = b"""<inventory file_id="TREE_ROOT">
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
297
<entry file_id="bar-20050901064931-73b4b1138abc9cd2" kind="file" name="bar" parent_id="TREE_ROOT" />
298
<entry file_id="foo-20050801201819-4139aa4a272f4250" kind="directory" name="foo" parent_id="TREE_ROOT" />
299
<entry file_id="bar-20050824000535-6bc48cfad47ed134" kind="file" name="bar" parent_id="foo-20050801201819-4139aa4a272f4250" />
300
</inventory>"""
301
302
6855.3.1 by Jelmer Vernooij
Several more fixes.
303
_revision_v4 = b"""<revision committer="Martin Pool &lt;mbp@sourcefrog.net&gt;"
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
304
    inventory_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
305
    inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
306
    revision_id="mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9"
307
    timestamp="1125907235.212"
308
    timezone="36000">
309
<message>- start splitting code for xml (de)serialization away from objects
310
  preparatory to supporting multiple formats by a single library
311
</message>
312
<parents>
313
<revision_ref revision_id="mbp@sourcefrog.net-20050905063503-43948f59fa127d92" revision_sha1="7bdf4cc8c5bdac739f8cf9b10b78cf4b68f915ff" />
314
</parents>
315
</revision>
316
"""
317
318
319
class TestSerializer(TestCase):
320
    """Test serializer"""
321
322
    def test_registry(self):
323
        self.assertIs(xml4.serializer_v4,
324
                      serializer_format_registry.get('4'))
325
326
    def test_canned_inventory(self):
327
        """Test unpacked a canned inventory v4 file."""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
328
        inp = BytesIO(_working_inventory_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
329
        inv = xml4.serializer_v4.read_inventory(inp)
330
        self.assertEqual(len(inv), 4)
6973.7.5 by Jelmer Vernooij
s/file/open.
331
        self.assertTrue(inv.has_id(b'bar-20050901064931-73b4b1138abc9cd2'))
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
332
333
    def test_unpack_revision(self):
334
        """Test unpacking a canned revision v4"""
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
335
        inp = BytesIO(_revision_v4)
5582.10.56 by Jelmer Vernooij
move xml4 to weave plugin.
336
        rev = xml4.serializer_v4.read_revision(inp)
337
        eq = self.assertEqual
338
        eq(rev.committer,
339
           "Martin Pool <mbp@sourcefrog.net>")
340
        eq(rev.inventory_id,
341
           "mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9")
342
        eq(len(rev.parent_ids), 1)
343
        eq(rev.parent_ids[0],
344
           "mbp@sourcefrog.net-20050905063503-43948f59fa127d92")