~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-06 06:59:03 UTC
  • mfrom: (5051.5.1 subunit)
  • Revision ID: pqm@pqm.ubuntu.com-20100406065903-y9dxgwmog1pmw7dz
Use subunit when running tests in PQM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
23
23
    branch,
24
24
    bzrdir,
25
25
    errors,
 
26
    repository,
26
27
    revision as _mod_revision,
27
28
    )
28
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
29
 
from bzrlib.tests import TestCaseWithTransport
 
30
from bzrlib.tests.blackbox import ExternalBase
30
31
from bzrlib.tests import (
31
 
    fixtures,
 
32
    KnownFailure,
32
33
    HardlinkFeature,
33
 
    script,
34
34
    test_server,
35
35
    )
36
 
from bzrlib.tests.blackbox import test_switch
37
36
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
 
from bzrlib.tests.script import run_script
39
37
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
40
38
from bzrlib.workingtree import WorkingTree
41
39
 
42
40
 
43
 
class TestBranch(TestCaseWithTransport):
 
41
class TestBranch(ExternalBase):
44
42
 
45
43
    def example_branch(self, path='.'):
46
44
        tree = self.make_branch_and_tree(path)
61
59
        self.assertFalse(b._transport.has('branch-name'))
62
60
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
63
61
 
64
 
    def test_branch_broken_pack(self):
65
 
        """branching with a corrupted pack file."""
66
 
        self.example_branch('a')
67
 
        #now add some random corruption
68
 
        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
69
 
        with open(fname, 'rb+') as f:
70
 
            f.seek(750)
71
 
            f.write("\xff")
72
 
        self.run_bzr_error(['Corruption while decompressing repository file'], 
73
 
                            'branch a b', retcode=3)
74
 
 
75
62
    def test_branch_switch_no_branch(self):
76
63
        # No branch in the current directory:
77
64
        #  => new branch will be created, but switch fails
187
174
        target_stat = os.stat('target/file1')
188
175
        self.assertEqual(source_stat, target_stat)
189
176
 
190
 
    def test_branch_files_from(self):
191
 
        source = self.make_branch_and_tree('source')
192
 
        self.build_tree(['source/file1'])
193
 
        source.add('file1')
194
 
        source.commit('added file')
195
 
        out, err = self.run_bzr('branch source target --files-from source')
196
 
        self.assertPathExists('target/file1')
197
 
 
198
 
    def test_branch_files_from_hardlink(self):
199
 
        self.requireFeature(HardlinkFeature)
200
 
        source = self.make_branch_and_tree('source')
201
 
        self.build_tree(['source/file1'])
202
 
        source.add('file1')
203
 
        source.commit('added file')
204
 
        source.bzrdir.sprout('second')
205
 
        out, err = self.run_bzr('branch source target --files-from second'
206
 
                                ' --hardlink')
207
 
        source_stat = os.stat('source/file1')
208
 
        second_stat = os.stat('second/file1')
209
 
        target_stat = os.stat('target/file1')
210
 
        self.assertNotEqual(source_stat, target_stat)
211
 
        self.assertEqual(second_stat, target_stat)
212
 
 
213
177
    def test_branch_standalone(self):
214
178
        shared_repo = self.make_repository('repo', shared=True)
215
179
        self.example_branch('source')
222
186
    def test_branch_no_tree(self):
223
187
        self.example_branch('source')
224
188
        self.run_bzr('branch --no-tree source target')
225
 
        self.assertPathDoesNotExist('target/hello')
226
 
        self.assertPathDoesNotExist('target/goodbye')
 
189
        self.failIfExists('target/hello')
 
190
        self.failIfExists('target/goodbye')
227
191
 
228
192
    def test_branch_into_existing_dir(self):
229
193
        self.example_branch('a')
239
203
        # force operation
240
204
        self.run_bzr('branch a b --use-existing-dir')
241
205
        # check conflicts
242
 
        self.assertPathExists('b/hello.moved')
243
 
        self.assertPathDoesNotExist('b/godbye.moved')
 
206
        self.failUnlessExists('b/hello.moved')
 
207
        self.failIfExists('b/godbye.moved')
244
208
        # we can't branch into branch
245
209
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
246
210
        self.assertEqual('', out)
253
217
        b = branch.Branch.open('b')
254
218
        self.assertEndsWith(b.get_bound_location(), '/a/')
255
219
 
256
 
    def test_branch_with_post_branch_init_hook(self):
257
 
        calls = []
258
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
259
 
            calls.append, None)
260
 
        self.assertLength(0, calls)
261
 
        self.example_branch('a')
262
 
        self.assertLength(1, calls)
263
 
        self.run_bzr('branch a b')
264
 
        self.assertLength(2, calls)
265
 
 
266
 
    def test_checkout_with_post_branch_init_hook(self):
267
 
        calls = []
268
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
269
 
            calls.append, None)
270
 
        self.assertLength(0, calls)
271
 
        self.example_branch('a')
272
 
        self.assertLength(1, calls)
273
 
        self.run_bzr('checkout a b')
274
 
        self.assertLength(2, calls)
275
 
 
276
 
    def test_lightweight_checkout_with_post_branch_init_hook(self):
277
 
        calls = []
278
 
        branch.Branch.hooks.install_named_hook('post_branch_init',
279
 
            calls.append, None)
280
 
        self.assertLength(0, calls)
281
 
        self.example_branch('a')
282
 
        self.assertLength(1, calls)
283
 
        self.run_bzr('checkout --lightweight a b')
284
 
        self.assertLength(2, calls)
285
 
 
286
 
    def test_branch_fetches_all_tags(self):
287
 
        builder = self.make_branch_builder('source')
288
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
289
 
        source.tags.set_tag('tag-a', 'rev-2')
290
 
        # Now source has a tag not in its ancestry.  Make a branch from it.
291
 
        self.run_bzr('branch source new-branch')
292
 
        new_branch = branch.Branch.open('new-branch')
293
 
        # The tag is present, and so is its revision.
294
 
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
295
 
        new_branch.repository.get_revision('rev-2')
296
 
 
297
 
 
298
 
class TestBranchStacked(TestCaseWithTransport):
 
220
 
 
221
class TestBranchStacked(ExternalBase):
299
222
    """Tests for branch --stacked"""
300
223
 
301
224
    def assertRevisionInRepository(self, repo_path, revid):
423
346
            err)
424
347
 
425
348
 
426
 
class TestSmartServerBranching(TestCaseWithTransport):
 
349
class TestSmartServerBranching(ExternalBase):
427
350
 
428
351
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
429
352
        self.setup_smart_server_with_call_log()
438
361
        # being too low. If rpc_count increases, more network roundtrips have
439
362
        # become necessary for this use case. Please do not adjust this number
440
363
        # upwards without agreement from bzr's network support maintainers.
441
 
        self.assertLength(36, self.hpss_calls)
 
364
        self.assertLength(38, self.hpss_calls)
442
365
 
443
366
    def test_branch_from_trivial_branch_streaming_acceptance(self):
444
367
        self.setup_smart_server_with_call_log()
453
376
        # being too low. If rpc_count increases, more network roundtrips have
454
377
        # become necessary for this use case. Please do not adjust this number
455
378
        # upwards without agreement from bzr's network support maintainers.
456
 
        self.assertLength(9, self.hpss_calls)
 
379
        self.assertLength(10, self.hpss_calls)
457
380
 
458
381
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
459
382
        self.setup_smart_server_with_call_log()
473
396
        # being too low. If rpc_count increases, more network roundtrips have
474
397
        # become necessary for this use case. Please do not adjust this number
475
398
        # upwards without agreement from bzr's network support maintainers.
476
 
        self.assertLength(14, self.hpss_calls)
477
 
 
478
 
    def test_branch_from_branch_with_tags(self):
479
 
        self.setup_smart_server_with_call_log()
480
 
        builder = self.make_branch_builder('source')
481
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
482
 
        source.tags.set_tag('tag-a', 'rev-2')
483
 
        source.tags.set_tag('tag-missing', 'missing-rev')
484
 
        # Now source has a tag not in its ancestry.  Make a branch from it.
485
 
        self.reset_smart_call_log()
486
 
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
487
 
        # This figure represent the amount of work to perform this use case. It
488
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
489
 
        # being too low. If rpc_count increases, more network roundtrips have
490
 
        # become necessary for this use case. Please do not adjust this number
491
 
        # upwards without agreement from bzr's network support maintainers.
492
 
        self.assertLength(9, self.hpss_calls)
493
 
 
494
 
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
495
 
        self.setup_smart_server_with_call_log()
496
 
        t = self.make_branch_and_tree('from')
497
 
        for count in range(9):
498
 
            t.commit(message='commit %d' % count)
499
 
        self.reset_smart_call_log()
500
 
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
501
 
            'local-target'])
502
 
        # XXX: the number of hpss calls for this case isn't deterministic yet,
503
 
        # so we can't easily assert about the number of calls.
504
 
        #self.assertLength(XXX, self.hpss_calls)
505
 
        # We can assert that none of the calls were readv requests for rix
506
 
        # files, though (demonstrating that at least get_parent_map calls are
507
 
        # not using VFS RPCs).
508
 
        readvs_of_rix_files = [
509
 
            c for c in self.hpss_calls
510
 
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
511
 
        self.assertLength(0, readvs_of_rix_files)
 
399
        self.assertLength(15, self.hpss_calls)
512
400
 
513
401
 
514
402
class TestRemoteBranch(TestCaseWithSFTPServer):
534
422
        # Ensure that no working tree what created remotely
535
423
        self.assertFalse(t.has('remote/file'))
536
424
 
537
 
 
538
 
class TestDeprecatedAliases(TestCaseWithTransport):
539
 
 
540
 
    def test_deprecated_aliases(self):
541
 
        """bzr branch can be called clone or get, but those names are deprecated.
542
 
 
543
 
        See bug 506265.
544
 
        """
545
 
        for command in ['clone', 'get']:
546
 
            run_script(self, """
547
 
            $ bzr %(command)s A B
548
 
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
549
 
            2>bzr: ERROR: Not a branch...
550
 
            """ % locals())
551
 
 
552
 
 
553
 
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
554
 
 
555
 
    def _checkout_and_branch(self, option=''):
556
 
        self.script_runner.run_script(self, '''
557
 
                $ bzr checkout %(option)s repo/trunk checkout
558
 
                $ cd checkout
559
 
                $ bzr branch --switch ../repo/trunk ../repo/branched
560
 
                2>Branched 0 revision(s).
561
 
                2>Tree is up to date at revision 0.
562
 
                2>Switched to branch:...branched...
563
 
                $ cd ..
564
 
                ''' % locals())
565
 
        bound_branch = branch.Branch.open_containing('checkout')[0]
566
 
        master_branch = branch.Branch.open_containing('repo/branched')[0]
567
 
        return (bound_branch, master_branch)
568
 
 
569
 
    def test_branch_switch_parent_lightweight(self):
570
 
        """Lightweight checkout using bzr branch --switch."""
571
 
        bb, mb = self._checkout_and_branch(option='--lightweight')
572
 
        self.assertParent('repo/trunk', bb)
573
 
        self.assertParent('repo/trunk', mb)
574
 
 
575
 
    def test_branch_switch_parent_heavyweight(self):
576
 
        """Heavyweight checkout using bzr branch --switch."""
577
 
        bb, mb = self._checkout_and_branch()
578
 
        self.assertParent('repo/trunk', bb)
579
 
        self.assertParent('repo/trunk', mb)