~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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,
27
26
    revision as _mod_revision,
28
27
    )
29
28
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
30
29
from bzrlib.tests import TestCaseWithTransport
31
30
from bzrlib.tests import (
32
 
    KnownFailure,
 
31
    fixtures,
33
32
    HardlinkFeature,
 
33
    script,
34
34
    test_server,
35
35
    )
 
36
from bzrlib.tests.blackbox import test_switch
36
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
 
38
from bzrlib.tests.script import run_script
37
39
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
38
40
from bzrlib.workingtree import WorkingTree
39
41
 
180
182
        source.add('file1')
181
183
        source.commit('added file')
182
184
        out, err = self.run_bzr('branch source target --files-from source')
183
 
        self.failUnlessExists('target/file1')
 
185
        self.assertPathExists('target/file1')
184
186
 
185
187
    def test_branch_files_from_hardlink(self):
186
188
        self.requireFeature(HardlinkFeature)
209
211
    def test_branch_no_tree(self):
210
212
        self.example_branch('source')
211
213
        self.run_bzr('branch --no-tree source target')
212
 
        self.failIfExists('target/hello')
213
 
        self.failIfExists('target/goodbye')
 
214
        self.assertPathDoesNotExist('target/hello')
 
215
        self.assertPathDoesNotExist('target/goodbye')
214
216
 
215
217
    def test_branch_into_existing_dir(self):
216
218
        self.example_branch('a')
226
228
        # force operation
227
229
        self.run_bzr('branch a b --use-existing-dir')
228
230
        # check conflicts
229
 
        self.failUnlessExists('b/hello.moved')
230
 
        self.failIfExists('b/godbye.moved')
 
231
        self.assertPathExists('b/hello.moved')
 
232
        self.assertPathDoesNotExist('b/godbye.moved')
231
233
        # we can't branch into branch
232
234
        out,err = self.run_bzr('branch a b --use-existing-dir', retcode=3)
233
235
        self.assertEqual('', out)
270
272
        self.run_bzr('checkout --lightweight a b')
271
273
        self.assertLength(2, calls)
272
274
 
 
275
    def test_branch_fetches_all_tags(self):
 
276
        builder = self.make_branch_builder('source')
 
277
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
278
        source.tags.set_tag('tag-a', 'rev-2')
 
279
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
280
        self.run_bzr('branch source new-branch')
 
281
        new_branch = branch.Branch.open('new-branch')
 
282
        # The tag is present, and so is its revision.
 
283
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
 
284
        new_branch.repository.get_revision('rev-2')
 
285
 
273
286
 
274
287
class TestBranchStacked(TestCaseWithTransport):
275
288
    """Tests for branch --stacked"""
414
427
        # being too low. If rpc_count increases, more network roundtrips have
415
428
        # become necessary for this use case. Please do not adjust this number
416
429
        # upwards without agreement from bzr's network support maintainers.
417
 
        self.assertLength(38, self.hpss_calls)
 
430
        self.assertLength(36, self.hpss_calls)
418
431
 
419
432
    def test_branch_from_trivial_branch_streaming_acceptance(self):
420
433
        self.setup_smart_server_with_call_log()
429
442
        # being too low. If rpc_count increases, more network roundtrips have
430
443
        # become necessary for this use case. Please do not adjust this number
431
444
        # upwards without agreement from bzr's network support maintainers.
432
 
        self.assertLength(10, self.hpss_calls)
 
445
        self.assertLength(9, self.hpss_calls)
433
446
 
434
447
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
435
448
        self.setup_smart_server_with_call_log()
449
462
        # being too low. If rpc_count increases, more network roundtrips have
450
463
        # become necessary for this use case. Please do not adjust this number
451
464
        # upwards without agreement from bzr's network support maintainers.
452
 
        self.assertLength(15, self.hpss_calls)
 
465
        self.assertLength(14, self.hpss_calls)
 
466
 
 
467
    def test_branch_from_branch_with_tags(self):
 
468
        self.setup_smart_server_with_call_log()
 
469
        builder = self.make_branch_builder('source')
 
470
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
471
        source.tags.set_tag('tag-a', 'rev-2')
 
472
        source.tags.set_tag('tag-missing', 'missing-rev')
 
473
        # Now source has a tag not in its ancestry.  Make a branch from it.
 
474
        self.reset_smart_call_log()
 
475
        out, err = self.run_bzr(['branch', self.get_url('source'), 'target'])
 
476
        # This figure represent the amount of work to perform this use case. It
 
477
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
478
        # being too low. If rpc_count increases, more network roundtrips have
 
479
        # become necessary for this use case. Please do not adjust this number
 
480
        # upwards without agreement from bzr's network support maintainers.
 
481
        self.assertLength(9, self.hpss_calls)
 
482
 
 
483
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
 
484
        self.setup_smart_server_with_call_log()
 
485
        t = self.make_branch_and_tree('from')
 
486
        for count in range(9):
 
487
            t.commit(message='commit %d' % count)
 
488
        self.reset_smart_call_log()
 
489
        out, err = self.run_bzr(['branch', '--stacked', self.get_url('from'),
 
490
            'local-target'])
 
491
        # XXX: the number of hpss calls for this case isn't deterministic yet,
 
492
        # so we can't easily assert about the number of calls.
 
493
        #self.assertLength(XXX, self.hpss_calls)
 
494
        # We can assert that none of the calls were readv requests for rix
 
495
        # files, though (demonstrating that at least get_parent_map calls are
 
496
        # not using VFS RPCs).
 
497
        readvs_of_rix_files = [
 
498
            c for c in self.hpss_calls
 
499
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
500
        self.assertLength(0, readvs_of_rix_files)
453
501
 
454
502
 
455
503
class TestRemoteBranch(TestCaseWithSFTPServer):
475
523
        # Ensure that no working tree what created remotely
476
524
        self.assertFalse(t.has('remote/file'))
477
525
 
 
526
 
 
527
class TestDeprecatedAliases(TestCaseWithTransport):
 
528
 
 
529
    def test_deprecated_aliases(self):
 
530
        """bzr branch can be called clone or get, but those names are deprecated.
 
531
 
 
532
        See bug 506265.
 
533
        """
 
534
        for command in ['clone', 'get']:
 
535
            run_script(self, """
 
536
            $ bzr %(command)s A B
 
537
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
 
538
            2>bzr: ERROR: Not a branch...
 
539
            """ % locals())
 
540
 
 
541
 
 
542
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
543
 
 
544
    def _checkout_and_branch(self, option=''):
 
545
        self.script_runner.run_script(self, '''
 
546
                $ bzr checkout %(option)s repo/trunk checkout
 
547
                $ cd checkout
 
548
                $ bzr branch --switch ../repo/trunk ../repo/branched
 
549
                2>Branched 0 revision(s).
 
550
                2>Tree is up to date at revision 0.
 
551
                2>Switched to branch:...branched...
 
552
                $ cd ..
 
553
                ''' % locals())
 
554
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
555
        master_branch = branch.Branch.open_containing('repo/branched')[0]
 
556
        return (bound_branch, master_branch)
 
557
 
 
558
    def test_branch_switch_parent_lightweight(self):
 
559
        """Lightweight checkout using bzr branch --switch."""
 
560
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
561
        self.assertParent('repo/trunk', bb)
 
562
        self.assertParent('repo/trunk', mb)
 
563
 
 
564
    def test_branch_switch_parent_heavyweight(self):
 
565
        """Heavyweight checkout using bzr branch --switch."""
 
566
        bb, mb = self._checkout_and_branch()
 
567
        self.assertParent('repo/trunk', bb)
 
568
        self.assertParent('repo/trunk', mb)