~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-04 11:44:18 UTC
  • mto: (5816.6.16 bazaar_source)
  • mto: This revision was merged to the branch mainline in revision 5835.
  • Revision ID: abudden@gmail.com-20110504114418-yvvint7ih1gm046u
Moved test harnesses into test_switch and test_branch as these are the commands that are being tested.

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,
23
24
    branch,
24
25
    bzrdir,
25
26
    errors,
30
31
from bzrlib.tests import (
31
32
    fixtures,
32
33
    HardlinkFeature,
 
34
    script,
33
35
    test_server,
34
36
    )
35
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
516
518
            2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
517
519
            2>bzr: ERROR: Not a branch...
518
520
            """ % locals())
 
521
 
 
522
 
 
523
class TestBranchParentLocation(TestCaseWithTransport):
 
524
 
 
525
    def setUp(self):
 
526
        """Set up a repository and branch ready for testing."""
 
527
        super(TestBranchParentLocation, self).setUp()
 
528
        self.script_runner = script.ScriptRunner()
 
529
        self.script_runner.run_script(self, '''
 
530
                $ bzr init-repo --no-trees repo
 
531
                Shared repository...
 
532
                Location:
 
533
                  shared repository: repo
 
534
                $ bzr init repo/trunk
 
535
                Created a repository branch...
 
536
                Using shared repository: ...
 
537
                ''')
 
538
 
 
539
    def assertParentCorrect(self, branch, expected_parent):
 
540
        """Verify that the parent is not None and is set correctly.
 
541
        
 
542
        @param branch: Branch for which to check parent.
 
543
        @param expected_parent: Expected parent as a list of strings for each component:
 
544
            each element in the list is compared.
 
545
        """
 
546
        parent = branch.get_parent()
 
547
        self.assertIsNot(parent, None, "Parent not set")
 
548
        # Get the last 'n' path elements from the parent where 'n' is the length of
 
549
        # the expected_parent, so if ['repo', 'branch'] is passed, get the last two
 
550
        # components for comparison.
 
551
        actual_parent = osutils.splitpath(parent.rstrip(r'\/'))[-len(expected_parent):]
 
552
        self.assertEquals(expected_parent, actual_parent, "Parent set incorrectly")
 
553
 
 
554
    def test_branch_switch_parent_lightweight(self):
 
555
        """Verify parent directory for lightweight checkout using bzr branch --switch."""
 
556
        self.script_runner.run_script(self, '''
 
557
                $ bzr checkout --lightweight repo/trunk work_lw_branch
 
558
                $ cd work_lw_branch
 
559
                $ bzr branch --switch ../repo/trunk ../repo/branched_lw
 
560
                2>Branched 0 revision(s).
 
561
                2>Tree is up to date at revision 0.
 
562
                2>Switched to branch:...branched_lw...
 
563
                ''')
 
564
        b = branch.Branch.open_containing('work_lw_branch')[0]
 
565
        self.assertParentCorrect(b, ['repo','trunk'])
 
566
 
 
567
    def test_branch_switch_parent_heavyweight(self):
 
568
        """Verify parent directory for heavyweight checkout using bzr branch --switch."""
 
569
        self.script_runner.run_script(self, '''
 
570
                $ bzr checkout repo/trunk work_hw_branch
 
571
                $ cd work_hw_branch
 
572
                $ bzr branch --switch ../repo/trunk ../repo/branched_hw
 
573
                2>Branched 0 revision(s).
 
574
                2>Tree is up to date at revision 0.
 
575
                2>Switched to branch:...branched_hw...
 
576
                ''')
 
577
        b = branch.Branch.open_containing('work_hw_branch')[0]
 
578
        self.assertParentCorrect(b, ['repo','trunk'])