~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_bzrdir/test_bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-29 21:35:05 UTC
  • mfrom: (4576 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4577.
  • Revision ID: john@arbash-meinel.com-20090729213505-tkqsvy1zfpocu75w
Merge bzr.dev 4576 in prep for NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
                          TestNotApplicable,
54
54
                          TestSkipped,
55
55
                          )
56
 
from bzrlib.tests.bzrdir_implementations import TestCaseWithBzrDir
 
56
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
57
57
from bzrlib.trace import mutter
58
58
from bzrlib.transport import get_transport
59
59
from bzrlib.transport.local import LocalTransport
 
60
from bzrlib.ui import (
 
61
    CannedInputUIFactory,
 
62
    )
60
63
from bzrlib.upgrade import upgrade
61
64
from bzrlib.remote import RemoteBzrDir, RemoteRepository
62
65
from bzrlib.repofmt import weaverepo
1246
1249
        self.assertTrue(repo.is_write_locked())
1247
1250
        repo.unlock()
1248
1251
 
 
1252
    def test_format_initialize_on_transport_ex_default_stack_on(self):
 
1253
        # When initialize_on_transport_ex uses a stacked-on branch because of
 
1254
        # a stacking policy on the target, the location of the fallback
 
1255
        # repository is the same as the external location of the stacked-on
 
1256
        # branch.
 
1257
        balloon = self.make_bzrdir('balloon')
 
1258
        if isinstance(balloon, bzrdir.BzrDirMetaFormat1):
 
1259
            stack_on = self.make_branch('stack-on', format='1.9')
 
1260
        else:
 
1261
            stack_on = self.make_branch('stack-on')
 
1262
        config = self.make_bzrdir('.').get_config()
 
1263
        try:
 
1264
            config.set_default_stack_on('stack-on')
 
1265
        except errors.BzrError:
 
1266
            raise TestNotApplicable('Only relevant for stackable formats.')
 
1267
        # Initialize a bzrdir subject to the policy.
 
1268
        t = self.get_transport('stacked')
 
1269
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
 
1270
        repo_name = repo_fmt.repository_format.network_name()
 
1271
        repo, control = self.assertInitializeEx(
 
1272
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
 
1273
        if control is None:
 
1274
            # uninitialisable format
 
1275
            return
 
1276
        # There's one fallback repo, with a public location.
 
1277
        self.assertLength(1, repo._fallback_repositories)
 
1278
        fallback_repo = repo._fallback_repositories[0]
 
1279
        self.assertEqual(
 
1280
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
 
1281
        # The bzrdir creates a branch in stacking-capable format.
 
1282
        new_branch = control.create_branch()
 
1283
        self.assertTrue(new_branch._format.supports_stacking())
 
1284
 
1249
1285
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1250
1286
        t = self.get_transport('dir')
1251
1287
        repo, control = self.assertInitializeEx(t)
1741
1777
        # ours
1742
1778
        self.old_factory = bzrlib.ui.ui_factory
1743
1779
        self.addCleanup(self.restoreFactory)
1744
 
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1745
1780
 
1746
1781
    def restoreFactory(self):
1747
1782
        bzrlib.ui.ui_factory = self.old_factory
1767
1802
            return
1768
1803
        # only one yes needed here: it should only be unlocking
1769
1804
        # the repo
1770
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
 
1805
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1771
1806
        try:
1772
1807
            repo.bzrdir.break_lock()
1773
1808
        except NotImplementedError:
1798
1833
            # two yes's : branch and repository. If the repo in this
1799
1834
            # dir is inappropriately accessed, 3 will be needed, and
1800
1835
            # we'll see that because the stream will be fully consumed
1801
 
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1836
            bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1802
1837
            # determine if the repository will have been locked;
1803
1838
            this_repo_locked = \
1804
1839
                thisdir.open_repository().get_physical_lock_status()
1805
1840
            master.bzrdir.break_lock()
1806
1841
            if this_repo_locked:
1807
1842
                # only two ys should have been read
1808
 
                self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1843
                self.assertEqual([True],
 
1844
                    bzrlib.ui.ui_factory.responses)
1809
1845
            else:
1810
1846
                # only one y should have been read
1811
 
                self.assertEqual("y\ny\n", bzrlib.ui.ui_factory.stdin.read())
 
1847
                self.assertEqual([True, True],
 
1848
                    bzrlib.ui.ui_factory.responses)
1812
1849
            # we should be able to lock a newly opened branch now
1813
1850
            branch = master.bzrdir.open_branch()
1814
1851
            branch.lock_write()
1832
1869
        tree = self.make_branch_and_tree('.')
1833
1870
        tree.lock_write()
1834
1871
        # three yes's : tree, branch and repository.
1835
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
 
1872
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1836
1873
        try:
1837
1874
            tree.bzrdir.break_lock()
1838
1875
        except (NotImplementedError, errors.LockActive):
1842
1879
            # object.
1843
1880
            tree.unlock()
1844
1881
            return
1845
 
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1882
        self.assertEqual([True],
 
1883
                bzrlib.ui.ui_factory.responses)
1846
1884
        lock_tree = tree.bzrdir.open_workingtree()
1847
1885
        lock_tree.lock_write()
1848
1886
        lock_tree.unlock()