~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-22 17:15:45 UTC
  • mto: (3514.4.6 merge_lca_multi)
  • mto: This revision was merged to the branch mainline in revision 3590.
  • Revision ID: john@arbash-meinel.com-20080722171545-51t59bf7uij8aftx
Add an action for modifying an existing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
28
28
    
29
 
    def assertTreeShape(self, expected_shape, tree):
30
 
        """Check that the tree shape matches expectations."""
31
 
        tree.lock_read()
32
 
        try:
33
 
            entries = [(path, ie.file_id, ie.kind)
34
 
                       for path, ie in tree.iter_entries_by_dir()]
35
 
        finally:
36
 
            tree.unlock()
37
 
        self.assertEqual(expected_shape, entries)
38
 
 
39
29
    def test_create(self):
40
30
        """Test the constructor api."""
41
31
        builder = BranchBuilder(self.get_transport().clone('foo'))
82
72
            [rev_id1],
83
73
            branch.repository.get_revision(branch.last_revision()).parent_ids)
84
74
 
85
 
    def test_build_snapshot(self):
 
75
 
 
76
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
 
77
 
 
78
    def assertTreeShape(self, expected_shape, tree):
 
79
        """Check that the tree shape matches expectations."""
 
80
        tree.lock_read()
 
81
        try:
 
82
            entries = [(path, ie.file_id, ie.kind)
 
83
                       for path, ie in tree.iter_entries_by_dir()]
 
84
        finally:
 
85
            tree.unlock()
 
86
        self.assertEqual(expected_shape, entries)
 
87
 
 
88
    def build_a_rev(self):
86
89
        builder = BranchBuilder(self.get_transport().clone('foo'))
87
90
        rev_id1 = builder.build_snapshot(None, 'A-id',
88
91
            [('add', ('', 'a-root-id', 'directory', None)),
89
92
             ('add', ('a', 'a-id', 'file', 'contents'))])
90
93
        self.assertEqual('A-id', rev_id1)
 
94
        return builder
 
95
 
 
96
    def test_add_one_file(self):
 
97
        builder = self.build_a_rev()
91
98
        branch = builder.get_branch()
92
 
        self.assertEqual((1, rev_id1), branch.last_revision_info())
93
 
        rev_tree = branch.repository.revision_tree(rev_id1)
 
99
        self.assertEqual((1, 'A-id'), branch.last_revision_info())
 
100
        rev_tree = branch.repository.revision_tree('A-id')
94
101
        rev_tree.lock_read()
95
102
        self.addCleanup(rev_tree.unlock)
96
103
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
97
104
                              (u'a', 'a-id', 'file')], rev_tree)
98
105
        self.assertEqual('contents', rev_tree.get_file_text('a-id'))
99
106
 
100
 
    def test_build_snapshot_add_content(self):
101
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
102
 
        rev_id1 = builder.build_snapshot(None, 'A-id',
103
 
            [('add', ('', 'a-root-id', 'directory', None)),
104
 
             ('add', ('a', 'a-id', 'file', 'contents'))])
105
 
        self.assertEqual('A-id', rev_id1)
 
107
    def test_add_second_file(self):
 
108
        builder = self.build_a_rev()
106
109
        rev_id2 = builder.build_snapshot(None, 'B-id',
107
110
            [('add', ('b', 'b-id', 'file', 'content_b'))])
108
111
        self.assertEqual('B-id', rev_id2)
115
118
                              (u'a', 'a-id', 'file'),
116
119
                              (u'b', 'b-id', 'file')], rev_tree)
117
120
        self.assertEqual('content_b', rev_tree.get_file_text('b-id'))
 
121
 
 
122
    def test_modify_file(self):
 
123
        builder = self.build_a_rev()
 
124
        rev_id2 = builder.build_snapshot(None, 'B-id',
 
125
            [('modify', ('a-id', 'new\ncontent\n'))])
 
126
        self.assertEqual('B-id', rev_id2)
 
127
        branch = builder.get_branch()
 
128
        rev_tree = branch.repository.revision_tree(rev_id2)
 
129
        rev_tree.lock_read()
 
130
        self.addCleanup(rev_tree.unlock)
 
131
        self.assertEqual('new\ncontent\n', rev_tree.get_file_text('a-id'))