~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Jelmer Vernooij
  • Date: 2011-01-11 04:40:57 UTC
  • mto: (5582.12.2 weave-plugin)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110111044057-oujyisxd4flaw7d2
Move weave repository tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
"""
24
24
 
25
25
from stat import S_ISDIR
26
 
import sys
27
26
 
28
27
import bzrlib
29
 
from bzrlib.errors import (NoSuchFile,
30
 
                           UnknownFormatError,
 
28
from bzrlib.errors import (UnknownFormatError,
31
29
                           UnsupportedFormatError,
32
30
                           )
33
31
from bzrlib import (
162
160
        repository.RepositoryFormat.unregister_format(format)
163
161
 
164
162
 
165
 
class TestFormat6(TestCaseWithTransport):
166
 
 
167
 
    def test_attribute__fetch_order(self):
168
 
        """Weaves need topological data insertion."""
169
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
170
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
171
 
        repo = RepositoryFormat6().initialize(control)
172
 
        self.assertEqual('topological', repo._format._fetch_order)
173
 
 
174
 
    def test_attribute__fetch_uses_deltas(self):
175
 
        """Weaves do not reuse deltas."""
176
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
177
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
178
 
        repo = RepositoryFormat6().initialize(control)
179
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
180
 
 
181
 
    def test_attribute__fetch_reconcile(self):
182
 
        """Weave repositories need a reconcile after fetch."""
183
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
184
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
185
 
        repo = RepositoryFormat6().initialize(control)
186
 
        self.assertEqual(True, repo._format._fetch_reconcile)
187
 
 
188
 
    def test_no_ancestry_weave(self):
189
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
190
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
191
 
        repo = RepositoryFormat6().initialize(control)
192
 
        # We no longer need to create the ancestry.weave file
193
 
        # since it is *never* used.
194
 
        self.assertRaises(NoSuchFile,
195
 
                          control.transport.get,
196
 
                          'ancestry.weave')
197
 
 
198
 
    def test_supports_external_lookups(self):
199
 
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
200
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
201
 
        repo = RepositoryFormat6().initialize(control)
202
 
        self.assertFalse(repo._format.supports_external_lookups)
203
 
 
204
 
 
205
 
class TestFormat7(TestCaseWithTransport):
206
 
 
207
 
    def test_attribute__fetch_order(self):
208
 
        """Weaves need topological data insertion."""
209
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
210
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
211
 
        repo = RepositoryFormat7().initialize(control)
212
 
        self.assertEqual('topological', repo._format._fetch_order)
213
 
 
214
 
    def test_attribute__fetch_uses_deltas(self):
215
 
        """Weaves do not reuse deltas."""
216
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
217
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
218
 
        repo = RepositoryFormat7().initialize(control)
219
 
        self.assertEqual(False, repo._format._fetch_uses_deltas)
220
 
 
221
 
    def test_attribute__fetch_reconcile(self):
222
 
        """Weave repositories need a reconcile after fetch."""
223
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
224
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
225
 
        repo = RepositoryFormat7().initialize(control)
226
 
        self.assertEqual(True, repo._format._fetch_reconcile)
227
 
 
228
 
    def test_disk_layout(self):
229
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
230
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
231
 
        repo = RepositoryFormat7().initialize(control)
232
 
        # in case of side effects of locking.
233
 
        repo.lock_write()
234
 
        repo.unlock()
235
 
        # we want:
236
 
        # format 'Bazaar-NG Repository format 7'
237
 
        # lock ''
238
 
        # inventory.weave == empty_weave
239
 
        # empty revision-store directory
240
 
        # empty weaves directory
241
 
        t = control.get_repository_transport(None)
242
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
243
 
                             t.get('format').read())
244
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
245
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
246
 
        self.assertEqualDiff('# bzr weave file v5\n'
247
 
                             'w\n'
248
 
                             'W\n',
249
 
                             t.get('inventory.weave').read())
250
 
        # Creating a file with id Foo:Bar results in a non-escaped file name on
251
 
        # disk.
252
 
        control.create_branch()
253
 
        tree = control.create_workingtree()
254
 
        tree.add(['foo'], ['Foo:Bar'], ['file'])
255
 
        tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
256
 
        try:
257
 
            tree.commit('first post', rev_id='first')
258
 
        except errors.IllegalPath:
259
 
            if sys.platform != 'win32':
260
 
                raise
261
 
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
262
 
                              ' in repo format 7')
263
 
            return
264
 
        self.assertEqualDiff(
265
 
            '# bzr weave file v5\n'
266
 
            'i\n'
267
 
            '1 7fe70820e08a1aac0ef224d9c66ab66831cc4ab1\n'
268
 
            'n first\n'
269
 
            '\n'
270
 
            'w\n'
271
 
            '{ 0\n'
272
 
            '. content\n'
273
 
            '}\n'
274
 
            'W\n',
275
 
            t.get('weaves/74/Foo%3ABar.weave').read())
276
 
 
277
 
    def test_shared_disk_layout(self):
278
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
279
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
280
 
        repo = RepositoryFormat7().initialize(control, shared=True)
281
 
        # we want:
282
 
        # format 'Bazaar-NG Repository format 7'
283
 
        # inventory.weave == empty_weave
284
 
        # empty revision-store directory
285
 
        # empty weaves directory
286
 
        # a 'shared-storage' marker file.
287
 
        # lock is not present when unlocked
288
 
        t = control.get_repository_transport(None)
289
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
290
 
                             t.get('format').read())
291
 
        self.assertEqualDiff('', t.get('shared-storage').read())
292
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
293
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
294
 
        self.assertEqualDiff('# bzr weave file v5\n'
295
 
                             'w\n'
296
 
                             'W\n',
297
 
                             t.get('inventory.weave').read())
298
 
        self.assertFalse(t.has('branch-lock'))
299
 
 
300
 
    def test_creates_lockdir(self):
301
 
        """Make sure it appears to be controlled by a LockDir existence"""
302
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
303
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
304
 
        repo = RepositoryFormat7().initialize(control, shared=True)
305
 
        t = control.get_repository_transport(None)
306
 
        # TODO: Should check there is a 'lock' toplevel directory,
307
 
        # regardless of contents
308
 
        self.assertFalse(t.has('lock/held/info'))
309
 
        repo.lock_write()
310
 
        try:
311
 
            self.assertTrue(t.has('lock/held/info'))
312
 
        finally:
313
 
            # unlock so we don't get a warning about failing to do so
314
 
            repo.unlock()
315
 
 
316
 
    def test_uses_lockdir(self):
317
 
        """repo format 7 actually locks on lockdir"""
318
 
        base_url = self.get_url()
319
 
        control = bzrdir.BzrDirMetaFormat1().initialize(base_url)
320
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
321
 
        repo = RepositoryFormat7().initialize(control, shared=True)
322
 
        t = control.get_repository_transport(None)
323
 
        repo.lock_write()
324
 
        repo.unlock()
325
 
        del repo
326
 
        # make sure the same lock is created by opening it
327
 
        repo = repository.Repository.open(base_url)
328
 
        repo.lock_write()
329
 
        self.assertTrue(t.has('lock/held/info'))
330
 
        repo.unlock()
331
 
        self.assertFalse(t.has('lock/held/info'))
332
 
 
333
 
    def test_shared_no_tree_disk_layout(self):
334
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
335
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
336
 
        repo = RepositoryFormat7().initialize(control, shared=True)
337
 
        repo.set_make_working_trees(False)
338
 
        # we want:
339
 
        # format 'Bazaar-NG Repository format 7'
340
 
        # lock ''
341
 
        # inventory.weave == empty_weave
342
 
        # empty revision-store directory
343
 
        # empty weaves directory
344
 
        # a 'shared-storage' marker file.
345
 
        t = control.get_repository_transport(None)
346
 
        self.assertEqualDiff('Bazaar-NG Repository format 7',
347
 
                             t.get('format').read())
348
 
        ## self.assertEqualDiff('', t.get('lock').read())
349
 
        self.assertEqualDiff('', t.get('shared-storage').read())
350
 
        self.assertEqualDiff('', t.get('no-working-trees').read())
351
 
        repo.set_make_working_trees(True)
352
 
        self.assertFalse(t.has('no-working-trees'))
353
 
        self.assertTrue(S_ISDIR(t.stat('revision-store').st_mode))
354
 
        self.assertTrue(S_ISDIR(t.stat('weaves').st_mode))
355
 
        self.assertEqualDiff('# bzr weave file v5\n'
356
 
                             'w\n'
357
 
                             'W\n',
358
 
                             t.get('inventory.weave').read())
359
 
 
360
 
    def test_supports_external_lookups(self):
361
 
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
362
 
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat7
363
 
        repo = RepositoryFormat7().initialize(control)
364
 
        self.assertFalse(repo._format.supports_external_lookups)
365
 
 
366
 
 
367
163
class TestFormatKnit1(TestCaseWithTransport):
368
164
 
369
165
    def test_attribute__fetch_order(self):
586
382
        self.assertGetsDefaultInterRepository(dummy_a, dummy_b)
587
383
 
588
384
 
589
 
class TestInterWeaveRepo(TestCaseWithTransport):
590
 
 
591
 
    def test_is_compatible_and_registered(self):
592
 
        # InterWeaveRepo is compatible when either side
593
 
        # is a format 5/6/7 branch
594
 
        from bzrlib.repofmt import knitrepo
595
 
        from bzrlib.plugins.weave_fmt.repository import (
596
 
            InterWeaveRepo, RepositoryFormat4, RepositoryFormat5,
597
 
            RepositoryFormat6, RepositoryFormat7)
598
 
        formats = [RepositoryFormat5(),
599
 
                   RepositoryFormat6(),
600
 
                   RepositoryFormat7()]
601
 
        incompatible_formats = [RepositoryFormat4(),
602
 
                                knitrepo.RepositoryFormatKnit1(),
603
 
                                ]
604
 
        repo_a = self.make_repository('a')
605
 
        repo_b = self.make_repository('b')
606
 
        is_compatible = InterWeaveRepo.is_compatible
607
 
        for source in incompatible_formats:
608
 
            # force incompatible left then right
609
 
            repo_a._format = source
610
 
            repo_b._format = formats[0]
611
 
            self.assertFalse(is_compatible(repo_a, repo_b))
612
 
            self.assertFalse(is_compatible(repo_b, repo_a))
613
 
        for source in formats:
614
 
            repo_a._format = source
615
 
            for target in formats:
616
 
                repo_b._format = target
617
 
                self.assertTrue(is_compatible(repo_a, repo_b))
618
 
        self.assertEqual(InterWeaveRepo,
619
 
                         repository.InterRepository.get(repo_a,
620
 
                                                        repo_b).__class__)
621
 
 
622
 
 
623
385
class TestRepositoryConverter(TestCaseWithTransport):
624
386
 
625
387
    def test_convert_empty(self):