~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-16 08:26:29 UTC
  • mfrom: (4145.1.6 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090316082629-xuzqut3b3ur5bn3b
(robertc) Add a new repository method refresh_data to allow clean
        handling of _real_repositories after inserting a stream via the
        smart server. (Robert Collins, Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
19
 
For interface contract tests, see tests/per_bzr_dir.
 
19
For interface contract tests, see tests/bzr_dir_implementations.
20
20
"""
21
21
 
22
22
import os
 
23
import os.path
 
24
from StringIO import StringIO
23
25
import subprocess
24
26
import sys
25
27
 
29
31
    help_topics,
30
32
    repository,
31
33
    osutils,
 
34
    symbol_versioning,
32
35
    remote,
33
36
    urlutils,
34
37
    win32utils,
36
39
    )
37
40
import bzrlib.branch
38
41
from bzrlib.errors import (NotBranchError,
39
 
                           NoColocatedBranchSupport,
40
42
                           UnknownFormatError,
41
43
                           UnsupportedFormatError,
42
44
                           )
45
47
    TestCaseWithMemoryTransport,
46
48
    TestCaseWithTransport,
47
49
    TestSkipped,
 
50
    test_sftp_transport
48
51
    )
49
52
from bzrlib.tests import(
50
53
    http_server,
51
54
    http_utils,
52
55
    )
53
56
from bzrlib.tests.test_http import TestWithTransport_pycurl
54
 
from bzrlib.transport import (
55
 
    get_transport,
56
 
    memory,
57
 
    )
 
57
from bzrlib.transport import get_transport
58
58
from bzrlib.transport.http._urllib import HttpTransport_urllib
 
59
from bzrlib.transport.memory import MemoryServer
59
60
from bzrlib.transport.nosmart import NoSmartTransportDecorator
60
61
from bzrlib.transport.readonly import ReadonlyTransportDecorator
61
62
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
148
149
        new = topics.get_detail('current-formats')
149
150
        rest = topics.get_detail('other-formats')
150
151
        experimental, deprecated = rest.split('Deprecated formats')
151
 
        self.assertContainsRe(new, 'formats-help')
 
152
        self.assertContainsRe(new, 'bzr help formats')
152
153
        self.assertContainsRe(new,
153
154
                ':knit:\n    \(native\) \(default\) Format using knits\n')
154
155
        self.assertContainsRe(experimental,
207
208
        """See BzrDir.open_repository."""
208
209
        return SampleRepository(self)
209
210
 
210
 
    def create_branch(self, name=None):
 
211
    def create_branch(self):
211
212
        """See BzrDir.create_branch."""
212
 
        if name is not None:
213
 
            raise NoColocatedBranchSupport(self)
214
213
        return SampleBranch(self)
215
214
 
216
215
    def create_workingtree(self):
359
358
 
360
359
    def test_create_branch_convenience_root(self):
361
360
        """Creating a branch at the root of a fs should work."""
362
 
        self.vfs_transport_factory = memory.MemoryServer
 
361
        self.vfs_transport_factory = MemoryServer
363
362
        # outside a repo the default convenience output is a repo+branch_tree
364
363
        format = bzrdir.format_registry.make_bzrdir('knit')
365
364
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
471
470
        # Make stackable source branch with an unstackable repo format.
472
471
        source_bzrdir = self.make_bzrdir('source')
473
472
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
474
 
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
475
 
            source_bzrdir)
 
473
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
476
474
        # Make a directory with a default stacking policy
477
475
        parent_bzrdir = self.make_bzrdir('parent')
478
476
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
571
569
 
572
570
    def setUp(self):
573
571
        super(ChrootedTests, self).setUp()
574
 
        if not self.vfs_transport_factory == memory.MemoryServer:
 
572
        if not self.vfs_transport_factory == MemoryServer:
575
573
            self.transport_readonly_server = http_server.HttpServer
576
574
 
577
575
    def local_branch_path(self, branch):
1055
1053
 
1056
1054
    def setUp(self):
1057
1055
        super(NonLocalTests, self).setUp()
1058
 
        self.vfs_transport_factory = memory.MemoryServer
 
1056
        self.vfs_transport_factory = MemoryServer
1059
1057
 
1060
1058
    def test_create_branch_convenience(self):
1061
1059
        # outside a repo the default convenience output is a repo+branch_tree
1158
1156
    _transport = HttpTransport_urllib
1159
1157
 
1160
1158
    def _qualified_url(self, host, port):
1161
 
        result = 'http+urllib://%s:%s' % (host, port)
1162
 
        self.permit_url(result)
1163
 
        return result
 
1159
        return 'http+urllib://%s:%s' % (host, port)
1164
1160
 
1165
1161
 
1166
1162
 
1170
1166
    """Tests redirections for pycurl implementation"""
1171
1167
 
1172
1168
    def _qualified_url(self, host, port):
1173
 
        result = 'http+pycurl://%s:%s' % (host, port)
1174
 
        self.permit_url(result)
1175
 
        return result
 
1169
        return 'http+pycurl://%s:%s' % (host, port)
1176
1170
 
1177
1171
 
1178
1172
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1182
1176
    _transport = NoSmartTransportDecorator
1183
1177
 
1184
1178
    def _qualified_url(self, host, port):
1185
 
        result = 'nosmart+http://%s:%s' % (host, port)
1186
 
        self.permit_url(result)
1187
 
        return result
 
1179
        return 'nosmart+http://%s:%s' % (host, port)
1188
1180
 
1189
1181
 
1190
1182
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1194
1186
    _transport = ReadonlyTransportDecorator
1195
1187
 
1196
1188
    def _qualified_url(self, host, port):
1197
 
        result = 'readonly+http://%s:%s' % (host, port)
1198
 
        self.permit_url(result)
1199
 
        return result
 
1189
        return 'readonly+http://%s:%s' % (host, port)
1200
1190
 
1201
1191
 
1202
1192
class TestDotBzrHidden(TestCaseWithTransport):
1316
1306
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1317
1307
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1318
1308
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1319
 
 
1320
 
 
1321
 
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1322
 
 
1323
 
    def test_pre_open_called(self):
1324
 
        calls = []
1325
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1326
 
        transport = self.get_transport('foo')
1327
 
        url = transport.base
1328
 
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1329
 
        self.assertEqual([transport.base], [t.base for t in calls])
1330
 
 
1331
 
    def test_pre_open_actual_exceptions_raised(self):
1332
 
        count = [0]
1333
 
        def fail_once(transport):
1334
 
            count[0] += 1
1335
 
            if count[0] == 1:
1336
 
                raise errors.BzrError("fail")
1337
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1338
 
        transport = self.get_transport('foo')
1339
 
        url = transport.base
1340
 
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1341
 
        self.assertEqual('fail', err._preformatted_string)
1342
 
 
1343
 
    def test_post_repo_init(self):
1344
 
        from bzrlib.bzrdir import RepoInitHookParams
1345
 
        calls = []
1346
 
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1347
 
            calls.append, None)
1348
 
        self.make_repository('foo')
1349
 
        self.assertLength(1, calls)
1350
 
        params = calls[0]
1351
 
        self.assertIsInstance(params, RepoInitHookParams)
1352
 
        self.assertTrue(hasattr(params, 'bzrdir'))
1353
 
        self.assertTrue(hasattr(params, 'repository'))