~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2009-02-23 15:29:35 UTC
  • mfrom: (3943.7.7 bzr.code_style_cleanup)
  • mto: This revision was merged to the branch mainline in revision 4033.
  • Revision ID: john@arbash-meinel.com-20090223152935-oel9m92mwcc6nb4h
Merge the removal of all trailing whitespace, and resolve conflicts.

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
 
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,
44
47
    TestCaseWithMemoryTransport,
45
48
    TestCaseWithTransport,
46
49
    TestSkipped,
 
50
    test_sftp_transport
47
51
    )
48
52
from bzrlib.tests import(
49
53
    http_server,
55
59
from bzrlib.transport.memory import MemoryServer
56
60
from bzrlib.transport.nosmart import NoSmartTransportDecorator
57
61
from bzrlib.transport.readonly import ReadonlyTransportDecorator
58
 
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
 
62
from bzrlib.repofmt import knitrepo, weaverepo
59
63
 
60
64
 
61
65
class TestDefaultFormat(TestCase):
145
149
        new = topics.get_detail('current-formats')
146
150
        rest = topics.get_detail('other-formats')
147
151
        experimental, deprecated = rest.split('Deprecated formats')
148
 
        self.assertContainsRe(new, 'formats-help')
 
152
        self.assertContainsRe(new, 'bzr help formats')
149
153
        self.assertContainsRe(new,
150
154
                ':knit:\n    \(native\) \(default\) Format using knits\n')
151
155
        self.assertContainsRe(experimental,
428
432
        """The default acquisition policy should create a standalone branch."""
429
433
        my_bzrdir = self.make_bzrdir('.')
430
434
        repo_policy = my_bzrdir.determine_repository_policy()
431
 
        repo, is_new = repo_policy.acquire_repository()
 
435
        repo = repo_policy.acquire_repository()
432
436
        self.assertEqual(repo.bzrdir.root_transport.base,
433
437
                         my_bzrdir.root_transport.base)
434
438
        self.assertFalse(repo.is_shared())
435
439
 
 
440
 
436
441
    def test_determine_stacking_policy(self):
437
442
        parent_bzrdir = self.make_bzrdir('.')
438
443
        child_bzrdir = self.make_bzrdir('child')
462
467
        self.assertEqual(child_branch.base,
463
468
                         new_child.open_branch().get_stacked_on_url())
464
469
 
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
 
 
477
470
    def test_sprout_obeys_stacking_policy(self):
478
471
        child_branch, new_child_transport = self.prepare_default_stacking()
479
472
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
748
741
                          transport)
749
742
 
750
743
    def test_sprout_recursive(self):
751
 
        tree = self.make_branch_and_tree('tree1',
752
 
                                         format='dirstate-with-subtree')
 
744
        tree = self.make_branch_and_tree('tree1', format='dirstate-with-subtree')
753
745
        sub_tree = self.make_branch_and_tree('tree1/subtree',
754
746
            format='dirstate-with-subtree')
755
 
        sub_tree.set_root_id('subtree-root')
756
747
        tree.add_reference(sub_tree)
757
748
        self.build_tree(['tree1/subtree/file'])
758
749
        sub_tree.add('file')
759
750
        tree.commit('Initial commit')
760
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
761
 
        tree2.lock_read()
762
 
        self.addCleanup(tree2.unlock)
 
751
        tree.bzrdir.sprout('tree2')
763
752
        self.failUnlessExists('tree2/subtree/file')
764
 
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
765
753
 
766
754
    def test_cloning_metadir(self):
767
755
        """Ensure that cloning metadir is suitable"""
1152
1140
    _transport = HttpTransport_urllib
1153
1141
 
1154
1142
    def _qualified_url(self, host, port):
1155
 
        result = 'http+urllib://%s:%s' % (host, port)
1156
 
        self.permit_url(result)
1157
 
        return result
 
1143
        return 'http+urllib://%s:%s' % (host, port)
1158
1144
 
1159
1145
 
1160
1146
 
1164
1150
    """Tests redirections for pycurl implementation"""
1165
1151
 
1166
1152
    def _qualified_url(self, host, port):
1167
 
        result = 'http+pycurl://%s:%s' % (host, port)
1168
 
        self.permit_url(result)
1169
 
        return result
 
1153
        return 'http+pycurl://%s:%s' % (host, port)
1170
1154
 
1171
1155
 
1172
1156
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1176
1160
    _transport = NoSmartTransportDecorator
1177
1161
 
1178
1162
    def _qualified_url(self, host, port):
1179
 
        result = 'nosmart+http://%s:%s' % (host, port)
1180
 
        self.permit_url(result)
1181
 
        return result
 
1163
        return 'nosmart+http://%s:%s' % (host, port)
1182
1164
 
1183
1165
 
1184
1166
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1188
1170
    _transport = ReadonlyTransportDecorator
1189
1171
 
1190
1172
    def _qualified_url(self, host, port):
1191
 
        result = 'readonly+http://%s:%s' % (host, port)
1192
 
        self.permit_url(result)
1193
 
        return result
 
1173
        return 'readonly+http://%s:%s' % (host, port)
1194
1174
 
1195
1175
 
1196
1176
class TestDotBzrHidden(TestCaseWithTransport):
1248
1228
        return _TestBzrDirFormat()
1249
1229
 
1250
1230
 
1251
 
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1252
 
    """Test Branch format for TestBzrDirSprout."""
1253
 
 
1254
 
 
1255
1231
class _TestBranch(bzrlib.branch.Branch):
1256
1232
    """Test Branch implementation for TestBzrDirSprout."""
1257
1233
 
1258
1234
    def __init__(self, *args, **kwargs):
1259
 
        self._format = _TestBranchFormat()
1260
1235
        super(_TestBranch, self).__init__(*args, **kwargs)
1261
1236
        self.calls = []
1262
1237
        self._parent = None
1310
1285
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1311
1286
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1312
1287
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1313
 
 
1314
 
 
1315
 
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1316
 
 
1317
 
    def test_pre_open_called(self):
1318
 
        calls = []
1319
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1320
 
        transport = self.get_transport('foo')
1321
 
        url = transport.base
1322
 
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1323
 
        self.assertEqual([transport.base], [t.base for t in calls])
1324
 
 
1325
 
    def test_pre_open_actual_exceptions_raised(self):
1326
 
        count = [0]
1327
 
        def fail_once(transport):
1328
 
            count[0] += 1
1329
 
            if count[0] == 1:
1330
 
                raise errors.BzrError("fail")
1331
 
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1332
 
        transport = self.get_transport('foo')
1333
 
        url = transport.base
1334
 
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1335
 
        self.assertEqual('fail', err._preformatted_string)