~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testbranch.py

  • Committer: Robert Collins
  • Date: 2005-09-29 02:55:34 UTC
  • mfrom: (1185.1.47)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050929025534-1782933743abbfd5
update with integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os
17
18
from bzrlib.selftest import TestCaseInTempDir
18
 
 
19
 
 
20
 
class TestAppendRevisions(TestCaseInTempDir):
21
 
    """Test appending more than one revision"""
 
19
from bzrlib.branch import Branch, copy_stores, copy_branch
 
20
from bzrlib.commit import commit
 
21
from bzrlib.errors import NoSuchRevision, UnlistableBranch
 
22
 
 
23
class TestBranch(TestCaseInTempDir):
 
24
 
22
25
    def test_append_revisions(self):
23
 
        from bzrlib.branch import Branch
 
26
        """Test appending more than one revision"""
24
27
        br = Branch.initialize(".")
25
28
        br.append_revision("rev1")
26
29
        self.assertEquals(br.revision_history(), ["rev1",])
27
30
        br.append_revision("rev2", "rev3")
28
31
        self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
29
32
 
30
 
 
 
33
    def test_copy_stores(self):
 
34
        """Copy the stores from one branch to another"""
 
35
        os.mkdir('a')
 
36
        br_a = Branch.initialize("a")
 
37
        file('a/b', 'wb').write('b')
 
38
        br_a.add('b')
 
39
        commit(br_a, "silly commit")
 
40
 
 
41
        os.mkdir('b')
 
42
        br_b = Branch.initialize("b")
 
43
        self.assertRaises(NoSuchRevision, br_b.get_revision, 
 
44
                          br_a.revision_history()[0])
 
45
        copy_stores(br_a, br_b)
 
46
        rev = br_b.get_revision(br_a.revision_history()[0])
 
47
        tree = br_b.revision_tree(br_a.revision_history()[0])
 
48
        for file_id in tree:
 
49
            if tree.inventory[file_id].kind == "file":
 
50
                tree.get_file(file_id).read()
 
51
        return br_a, br_b
 
52
 
 
53
    def test_copy_branch(self):
 
54
        """Copy the stores from one branch to another"""
 
55
        br_a, br_b = self.test_copy_stores()
 
56
        commit(br_b, "silly commit")
 
57
        os.mkdir('c')
 
58
        br_c = copy_branch(br_a, 'c', basis_branch=br_b)
 
59
        self.assertEqual(br_a.revision_history(), br_c.revision_history())
 
60
        assert br_b.last_patch() not in br_c.revision_history()
 
61
        br_c.get_revision(br_b.last_patch())
31
62
# TODO: rewrite this as a regular unittest, without relying on the displayed output        
32
63
#         >>> from bzrlib.commit import commit
33
64
#         >>> bzrlib.trace.silent = True