~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2007-04-17 20:10:04 UTC
  • mto: This revision was merged to the branch mainline in revision 2452.
  • Revision ID: john@arbash-meinel.com-20070417201004-1v7sim0tlt19l8o4
Make a Branch helper which can create a very basic MemoryTree with history.
This updates MutableTree to include 'set_parent_ids' which is helpful
when setting up simple tests.
It also creates a helper function in branch_implementations..TestCaseWithBranch
so that we can create a Branch which has a simple merge in it.
It also adds a test for revision_id_to_revno which previously did not have any
direct tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        made_control = self.make_bzrdir(relpath, format=format)
73
73
        return made_control.create_repository(shared=shared)
74
74
 
 
75
    def create_tree_with_merge(self):
 
76
        """Create a branch with a simple ancestry.
 
77
 
 
78
        The graph should look like:
 
79
            digraph H {
 
80
                "rev-1" -> "rev-2" -> "rev-3";
 
81
                "rev-1" -> "rev-1.1.1" -> "rev-3";
 
82
            }
 
83
 
 
84
        Or in ASCII:
 
85
            1 - 2 - 3
 
86
              \    /
 
87
               1.1.1
 
88
        """
 
89
        tree = self.make_branch_and_memory_tree('tree')
 
90
        tree.lock_write()
 
91
        try:
 
92
            tree.add('')
 
93
            tree.commit('first', rev_id='rev-1')
 
94
            tree.commit('second', rev_id='rev-2')
 
95
            # Uncommit that last commit
 
96
            tree.branch.set_last_revision_info(1, 'rev-1')
 
97
            tree.set_parent_ids(['rev-1'])
 
98
            tree.commit('alt-second', rev_id='rev-1.1.1')
 
99
            tree.branch.set_last_revision_info(2, 'rev-2')
 
100
            tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
 
101
            tree.commit('third', rev_id='rev-3')
 
102
        finally:
 
103
            tree.unlock()
 
104
 
 
105
        return tree
 
106
 
 
107
 
75
108
 
76
109
class TestBranch(TestCaseWithBranch):
77
110
 
90
123
        self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
91
124
        self.assertRaises(errors.ReservedId, br.append_revision, 'current:')
92
125
 
 
126
    def test_create_tree_with_merge(self):
 
127
        tree = self.create_tree_with_merge()
 
128
        ancestry_graph = tree.branch.repository.get_revision_graph('rev-3')
 
129
        self.assertEqual({'rev-1':[],
 
130
                          'rev-2':['rev-1'],
 
131
                          'rev-1.1.1':['rev-1'],
 
132
                          'rev-3':['rev-2', 'rev-1.1.1'],
 
133
                         }, ancestry_graph)
 
134
 
93
135
    def test_revision_ids_are_utf8(self):
94
136
        wt = self.make_branch_and_tree('tree')
95
137
        wt.commit('f', rev_id='rev1')