~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: A. S. Budden
  • Date: 2011-05-06 07:08:13 UTC
  • mfrom: (5816.7.1 switch_parent_513709)
  • mto: This revision was merged to the branch mainline in revision 5835.
  • Revision ID: abudden@gmail.com-20110506070813-s5emnar6aorgnm42
Merged Vincent's improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
 
22
22
from bzrlib import (
23
 
    osutils,
24
 
    urlutils,
25
23
    branch,
26
24
    bzrdir,
27
25
    errors,
35
33
    script,
36
34
    test_server,
37
35
    )
 
36
from bzrlib.tests.blackbox import test_switch
38
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
39
38
from bzrlib.tests.script import run_script
40
39
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
521
520
            """ % locals())
522
521
 
523
522
 
524
 
class TestBranchParentLocation(TestCaseWithTransport):
525
 
 
526
 
    def setUp(self):
527
 
        """Set up a repository and branch ready for testing."""
528
 
        super(TestBranchParentLocation, self).setUp()
529
 
        self.script_runner = script.ScriptRunner()
530
 
        self.script_runner.run_script(self, '''
531
 
                $ bzr init-repo --no-trees repo
532
 
                Shared repository...
533
 
                Location:
534
 
                  shared repository: repo
535
 
                $ bzr init repo/trunk
536
 
                Created a repository branch...
537
 
                Using shared repository: ...
538
 
                ''')
539
 
 
540
 
    def assertParentCorrect(self, branch, expected_parent, name):
541
 
        """Verify that the parent is not None and is set correctly."""
542
 
        actual_parent = branch.get_parent()
543
 
        self.assertIsNot(actual_parent, None, name + "Parent not set")
544
 
        expected = urlutils.strip_trailing_slash(urlutils.normalize_url(expected_parent))
545
 
        actual = urlutils.strip_trailing_slash(urlutils.normalize_url(actual_parent))
546
 
        self.assertEquals(expected, actual, name + "Parent set incorrectly")
547
 
 
548
 
    def _create_checkout_and_branch(self, option, suffix):
549
 
        self.script_runner.run_script(self, '''
550
 
                $ bzr checkout %(option)s repo/trunk work_%(suffix)s_branch
551
 
                $ cd work_%(suffix)s_branch
552
 
                $ bzr branch --switch ../repo/trunk ../repo/branched_%(suffix)s
 
523
class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
 
524
 
 
525
    def _checkout_and_branch(self, option=''):
 
526
        self.script_runner.run_script(self, '''
 
527
                $ bzr checkout %(option)s repo/trunk checkout
 
528
                $ cd checkout
 
529
                $ bzr branch --switch ../repo/trunk ../repo/branched
553
530
                2>Branched 0 revision(s).
554
531
                2>Tree is up to date at revision 0.
555
 
                2>Switched to branch:...branched_%(suffix)s...
 
532
                2>Switched to branch:...branched...
556
533
                $ cd ..
557
534
                ''' % locals())
558
 
        bound_branch = branch.Branch.open_containing('work_%(suffix)s_branch' % locals())[0]
559
 
        master_branch = branch.Branch.open_containing('repo/branched_%(suffix)s' % locals())[0]
 
535
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
536
        master_branch = branch.Branch.open_containing('repo/branched')[0]
560
537
        return (bound_branch, master_branch)
561
538
 
562
539
    def test_branch_switch_parent_lightweight(self):
563
 
        """Verify parent directory for lightweight checkout using bzr branch --switch."""
564
 
        bb, mb = self._create_checkout_and_branch(option='--lightweight', suffix='lw')
565
 
        self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Checkout")
566
 
        self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
 
540
        """Lightweight checkout using bzr branch --switch."""
 
541
        bb, mb = self._checkout_and_branch(option='--lightweight')
 
542
        self.assertParent('repo/trunk', bb)
 
543
        self.assertParent('repo/trunk', mb)
567
544
 
568
545
    def test_branch_switch_parent_heavyweight(self):
569
 
        """Verify parent directory for heavyweight checkout using bzr branch --switch."""
570
 
        bb, mb = self._create_checkout_and_branch(option='', suffix='hw')
571
 
        self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Bound Branch")
572
 
        self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
 
546
        """Heavyweight checkout using bzr branch --switch."""
 
547
        bb, mb = self._checkout_and_branch()
 
548
        self.assertParent('repo/trunk', bb)
 
549
        self.assertParent('repo/trunk', mb)