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