~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the BzrDir facility and any format specific tests.
18
18
 
19
 
For interface contract tests, see tests/bzr_dir_implementations.
 
19
For interface contract tests, see tests/per_bzr_dir.
20
20
"""
21
21
 
22
22
import os
23
 
import os.path
24
 
from StringIO import StringIO
25
23
import subprocess
26
24
import sys
27
25
 
31
29
    help_topics,
32
30
    repository,
33
31
    osutils,
34
 
    symbol_versioning,
35
32
    remote,
36
33
    urlutils,
37
34
    win32utils,
47
44
    TestCaseWithMemoryTransport,
48
45
    TestCaseWithTransport,
49
46
    TestSkipped,
50
 
    test_sftp_transport
51
47
    )
52
48
from bzrlib.tests import(
53
49
    http_server,
59
55
from bzrlib.transport.memory import MemoryServer
60
56
from bzrlib.transport.nosmart import NoSmartTransportDecorator
61
57
from bzrlib.transport.readonly import ReadonlyTransportDecorator
62
 
from bzrlib.repofmt import knitrepo, weaverepo
 
58
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
63
59
 
64
60
 
65
61
class TestDefaultFormat(TestCase):
432
428
        """The default acquisition policy should create a standalone branch."""
433
429
        my_bzrdir = self.make_bzrdir('.')
434
430
        repo_policy = my_bzrdir.determine_repository_policy()
435
 
        repo = repo_policy.acquire_repository()
 
431
        repo, is_new = repo_policy.acquire_repository()
436
432
        self.assertEqual(repo.bzrdir.root_transport.base,
437
433
                         my_bzrdir.root_transport.base)
438
434
        self.assertFalse(repo.is_shared())
439
435
 
440
 
 
441
436
    def test_determine_stacking_policy(self):
442
437
        parent_bzrdir = self.make_bzrdir('.')
443
438
        child_bzrdir = self.make_bzrdir('child')
467
462
        self.assertEqual(child_branch.base,
468
463
                         new_child.open_branch().get_stacked_on_url())
469
464
 
 
465
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
 
466
        # Make stackable source branch with an unstackable repo format.
 
467
        source_bzrdir = self.make_bzrdir('source')
 
468
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
469
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
 
470
        # Make a directory with a default stacking policy
 
471
        parent_bzrdir = self.make_bzrdir('parent')
 
472
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
 
473
        parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
 
474
        # Clone source into directory
 
475
        target = source_bzrdir.clone(self.get_url('parent/target'))
 
476
 
470
477
    def test_sprout_obeys_stacking_policy(self):
471
478
        child_branch, new_child_transport = self.prepare_default_stacking()
472
479
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
741
748
                          transport)
742
749
 
743
750
    def test_sprout_recursive(self):
744
 
        tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
 
751
        tree = self.make_branch_and_tree('tree1',
 
752
                                         format='dirstate-with-subtree')
745
753
        sub_tree = self.make_branch_and_tree('tree1/subtree',
746
754
            format='dirstate-with-subtree')
 
755
        sub_tree.set_root_id('subtree-root')
747
756
        tree.add_reference(sub_tree)
748
757
        self.build_tree(['tree1/subtree/file'])
749
758
        sub_tree.add('file')
750
759
        tree.commit('Initial commit')
751
 
        tree.bzrdir.sprout('tree2')
 
760
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
761
        tree2.lock_read()
 
762
        self.addCleanup(tree2.unlock)
752
763
        self.failUnlessExists('tree2/subtree/file')
 
764
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
753
765
 
754
766
    def test_cloning_metadir(self):
755
767
        """Ensure that cloning metadir is suitable"""
1228
1240
        return _TestBzrDirFormat()
1229
1241
 
1230
1242
 
 
1243
class _TestBranchFormat(bzrlib.branch.BranchFormat):
 
1244
    """Test Branch format for TestBzrDirSprout."""
 
1245
 
 
1246
 
1231
1247
class _TestBranch(bzrlib.branch.Branch):
1232
1248
    """Test Branch implementation for TestBzrDirSprout."""
1233
1249
 
1234
1250
    def __init__(self, *args, **kwargs):
 
1251
        self._format = _TestBranchFormat()
1235
1252
        super(_TestBranch, self).__init__(*args, **kwargs)
1236
1253
        self.calls = []
1237
1254
        self._parent = None
1285
1302
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1286
1303
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1287
1304
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
 
1305
 
 
1306
 
 
1307
class TestBzrDirHooks(TestCaseWithMemoryTransport):
 
1308
 
 
1309
    def test_pre_open_called(self):
 
1310
        calls = []
 
1311
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
 
1312
        transport = self.get_transport('foo')
 
1313
        url = transport.base
 
1314
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
 
1315
        self.assertEqual([transport.base], [t.base for t in calls])
 
1316
 
 
1317
    def test_pre_open_actual_exceptions_raised(self):
 
1318
        count = [0]
 
1319
        def fail_once(transport):
 
1320
            count[0] += 1
 
1321
            if count[0] == 1:
 
1322
                raise errors.BzrError("fail")
 
1323
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
 
1324
        transport = self.get_transport('foo')
 
1325
        url = transport.base
 
1326
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
 
1327
        self.assertEqual('fail', err._preformatted_string)