~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-04 22:20:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6190.
  • Revision ID: jelmer@samba.org-20111004222049-d9glniyleu0pppzd
Add a load_plugin_translations method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    branch,
28
28
    bzrdir,
 
29
    config,
29
30
    controldir,
30
31
    errors,
31
32
    help_topics,
285
286
        self.build_tree(["foo/", "bar/"], transport=t)
286
287
        def check_format(format, url):
287
288
            format.initialize(url)
288
 
            t = _mod_transport.get_transport(url)
 
289
            t = _mod_transport.get_transport_from_path(url)
289
290
            found_format = bzrdir.BzrDirFormat.find_format(t)
290
291
            self.assertIsInstance(found_format, format.__class__)
291
292
        check_format(BzrDirFormatTest1(), "foo")
294
295
    def test_find_format_nothing_there(self):
295
296
        self.assertRaises(NotBranchError,
296
297
                          bzrdir.BzrDirFormat.find_format,
297
 
                          _mod_transport.get_transport('.'))
 
298
                          _mod_transport.get_transport_from_path('.'))
298
299
 
299
300
    def test_find_format_unknown_format(self):
300
301
        t = self.get_transport()
302
303
        t.put_bytes('.bzr/branch-format', '')
303
304
        self.assertRaises(UnknownFormatError,
304
305
                          bzrdir.BzrDirFormat.find_format,
305
 
                          _mod_transport.get_transport('.'))
 
306
                          _mod_transport.get_transport_from_path('.'))
306
307
 
307
308
    def test_register_unregister_format(self):
308
309
        format = SampleBzrDirFormat()
316
317
        # which bzrdir.open_containing will refuse (not supported)
317
318
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
318
319
        # but open_downlevel will work
319
 
        t = _mod_transport.get_transport(url)
 
320
        t = _mod_transport.get_transport_from_url(url)
320
321
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
321
322
        # unregister the format
322
323
        bzrdir.BzrProber.formats.remove(format.get_format_string())
512
513
        # Clone source into directory
513
514
        target = source_bzrdir.clone(self.get_url('parent/target'))
514
515
 
 
516
    def test_format_initialize_on_transport_ex_stacked_on(self):
 
517
        # trunk is a stackable format.  Note that its in the same server area
 
518
        # which is what launchpad does, but not sufficient to exercise the
 
519
        # general case.
 
520
        trunk = self.make_branch('trunk', format='1.9')
 
521
        t = self.get_transport('stacked')
 
522
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
 
523
        repo_name = old_fmt.repository_format.network_name()
 
524
        # Should end up with a 1.9 format (stackable)
 
525
        repo, control, require_stacking, repo_policy = \
 
526
            old_fmt.initialize_on_transport_ex(t,
 
527
                    repo_format_name=repo_name, stacked_on='../trunk',
 
528
                    stack_on_pwd=t.base)
 
529
        if repo is not None:
 
530
            # Repositories are open write-locked
 
531
            self.assertTrue(repo.is_write_locked())
 
532
            self.addCleanup(repo.unlock)
 
533
        else:
 
534
            repo = control.open_repository()
 
535
        self.assertIsInstance(control, bzrdir.BzrDir)
 
536
        opened = bzrdir.BzrDir.open(t.base)
 
537
        if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
 
538
            self.assertEqual(control._format.network_name(),
 
539
                old_fmt.network_name())
 
540
            self.assertEqual(control._format.network_name(),
 
541
                opened._format.network_name())
 
542
        self.assertEqual(control.__class__, opened.__class__)
 
543
        self.assertLength(1, repo._fallback_repositories)
 
544
 
515
545
    def test_sprout_obeys_stacking_policy(self):
516
546
        child_branch, new_child_transport = self.prepare_default_stacking()
517
547
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
710
740
    def test_open_containing_from_transport(self):
711
741
        self.assertRaises(NotBranchError,
712
742
            bzrdir.BzrDir.open_containing_from_transport,
713
 
            _mod_transport.get_transport(self.get_readonly_url('')))
 
743
            _mod_transport.get_transport_from_url(self.get_readonly_url('')))
714
744
        self.assertRaises(NotBranchError,
715
745
            bzrdir.BzrDir.open_containing_from_transport,
716
 
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
 
746
            _mod_transport.get_transport_from_url(
 
747
                self.get_readonly_url('g/p/q')))
717
748
        control = bzrdir.BzrDir.create(self.get_url())
718
749
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
719
 
            _mod_transport.get_transport(self.get_readonly_url('')))
 
750
            _mod_transport.get_transport_from_url(
 
751
                self.get_readonly_url('')))
720
752
        self.assertEqual('', relpath)
721
753
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
722
 
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
 
754
            _mod_transport.get_transport_from_url(
 
755
                self.get_readonly_url('g/p/q')))
723
756
        self.assertEqual('g/p/q', relpath)
724
757
 
725
758
    def test_open_containing_tree_or_branch(self):
898
931
        def evaluate(bzrdir):
899
932
            try:
900
933
                repo = bzrdir.open_repository()
901
 
            except NoRepositoryPresent:
 
934
            except errors.NoRepositoryPresent:
902
935
                return True, bzrdir.root_transport.base
903
936
            else:
904
937
                return False, bzrdir.root_transport.base
1208
1241
 
1209
1242
    def __init__(self, *args, **kwargs):
1210
1243
        super(_TestBzrDir, self).__init__(*args, **kwargs)
1211
 
        self.test_branch = _TestBranch()
 
1244
        self.test_branch = _TestBranch(self.transport)
1212
1245
        self.test_branch.repository = self.create_repository()
1213
1246
 
1214
1247
    def open_branch(self, unsupported=False):
1225
1258
class _TestBranch(bzrlib.branch.Branch):
1226
1259
    """Test Branch implementation for TestBzrDirSprout."""
1227
1260
 
1228
 
    def __init__(self, *args, **kwargs):
 
1261
    def __init__(self, transport, *args, **kwargs):
1229
1262
        self._format = _TestBranchFormat()
 
1263
        self._transport = transport
 
1264
        self.base = transport.base
1230
1265
        super(_TestBranch, self).__init__(*args, **kwargs)
1231
1266
        self.calls = []
1232
1267
        self._parent = None
1233
1268
 
1234
1269
    def sprout(self, *args, **kwargs):
1235
1270
        self.calls.append('sprout')
1236
 
        return _TestBranch()
 
1271
        return _TestBranch(self._transport)
1237
1272
 
1238
1273
    def copy_content_into(self, destination, revision_id=None):
1239
1274
        self.calls.append('copy_content_into')
1244
1279
    def get_parent(self):
1245
1280
        return self._parent
1246
1281
 
 
1282
    def _get_config(self):
 
1283
        return config.TransportConfig(self._transport, 'branch.conf')
 
1284
 
1247
1285
    def set_parent(self, parent):
1248
1286
        self._parent = parent
1249
1287