~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the BzrDir facility and any format specific tests.
18
18
 
59
59
from bzrlib.transport.memory import MemoryServer
60
60
from bzrlib.transport.nosmart import NoSmartTransportDecorator
61
61
from bzrlib.transport.readonly import ReadonlyTransportDecorator
62
 
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
 
62
from bzrlib.repofmt import knitrepo, weaverepo
63
63
 
64
64
 
65
65
class TestDefaultFormat(TestCase):
432
432
        """The default acquisition policy should create a standalone branch."""
433
433
        my_bzrdir = self.make_bzrdir('.')
434
434
        repo_policy = my_bzrdir.determine_repository_policy()
435
 
        repo, is_new = repo_policy.acquire_repository()
 
435
        repo = repo_policy.acquire_repository()
436
436
        self.assertEqual(repo.bzrdir.root_transport.base,
437
437
                         my_bzrdir.root_transport.base)
438
438
        self.assertFalse(repo.is_shared())
439
439
 
 
440
 
440
441
    def test_determine_stacking_policy(self):
441
442
        parent_bzrdir = self.make_bzrdir('.')
442
443
        child_bzrdir = self.make_bzrdir('child')
466
467
        self.assertEqual(child_branch.base,
467
468
                         new_child.open_branch().get_stacked_on_url())
468
469
 
469
 
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
470
 
        # Make stackable source branch with an unstackable repo format.
471
 
        source_bzrdir = self.make_bzrdir('source')
472
 
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
473
 
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
474
 
        # Make a directory with a default stacking policy
475
 
        parent_bzrdir = self.make_bzrdir('parent')
476
 
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
477
 
        parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
478
 
        # Clone source into directory
479
 
        target = source_bzrdir.clone(self.get_url('parent/target'))
480
 
 
481
470
    def test_sprout_obeys_stacking_policy(self):
482
471
        child_branch, new_child_transport = self.prepare_default_stacking()
483
472
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
752
741
                          transport)
753
742
 
754
743
    def test_sprout_recursive(self):
755
 
        tree = self.make_branch_and_tree('tree1',
756
 
                                         format='dirstate-with-subtree')
 
744
        tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
757
745
        sub_tree = self.make_branch_and_tree('tree1/subtree',
758
746
            format='dirstate-with-subtree')
759
 
        sub_tree.set_root_id('subtree-root')
760
747
        tree.add_reference(sub_tree)
761
748
        self.build_tree(['tree1/subtree/file'])
762
749
        sub_tree.add('file')
763
750
        tree.commit('Initial commit')
764
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
765
 
        tree2.lock_read()
766
 
        self.addCleanup(tree2.unlock)
 
751
        tree.bzrdir.sprout('tree2')
767
752
        self.failUnlessExists('tree2/subtree/file')
768
 
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
769
753
 
770
754
    def test_cloning_metadir(self):
771
755
        """Ensure that cloning metadir is suitable"""
1244
1228
        return _TestBzrDirFormat()
1245
1229
 
1246
1230
 
1247
 
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1248
 
    """Test Branch format for TestBzrDirSprout."""
1249
 
 
1250
 
 
1251
1231
class _TestBranch(bzrlib.branch.Branch):
1252
1232
    """Test Branch implementation for TestBzrDirSprout."""
1253
1233
 
1254
1234
    def __init__(self, *args, **kwargs):
1255
 
        self._format = _TestBranchFormat()
1256
1235
        super(_TestBranch, self).__init__(*args, **kwargs)
1257
1236
        self.calls = []
1258
1237
        self._parent = None
1306
1285
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1307
1286
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1308
1287
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1309
 
 
1310
 
 
1311
 
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1312
 
 
1313
 
    def test_pre_open_called(self):
1314
 
        calls = []
1315
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1316
 
        transport = self.get_transport('foo')
1317
 
        url = transport.base
1318
 
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1319
 
        self.assertEqual([transport.base], [t.base for t in calls])
1320
 
 
1321
 
    def test_pre_open_actual_exceptions_raised(self):
1322
 
        count = [0]
1323
 
        def fail_once(transport):
1324
 
            count[0] += 1
1325
 
            if count[0] == 1:
1326
 
                raise errors.BzrError("fail")
1327
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1328
 
        transport = self.get_transport('foo')
1329
 
        url = transport.base
1330
 
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1331
 
        self.assertEqual('fail', err._preformatted_string)