~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

  • Committer: Robert Collins
  • Date: 2005-08-23 06:52:09 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050823065209-81cd5962c401751b
move io redirection into each test case from the global runner

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
import os
18
 
 
19
 
 
20
 
from bzrlib import (
21
 
    missing,
22
 
    tests,
23
 
    )
24
 
from bzrlib.missing import (
25
 
    iter_log_revisions,
26
 
    )
27
 
from bzrlib.tests import TestCaseWithTransport
28
 
from bzrlib.workingtree import WorkingTree
29
 
 
30
 
 
31
 
class TestMissing(TestCaseWithTransport):
32
 
 
33
 
    def assertUnmerged(self, expected, source, target, restrict='all',
34
 
                       backward=False):
35
 
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
36
 
                                         backward=backward)
37
 
        self.assertEqual(expected, unmerged)
38
 
 
39
 
    def test_find_unmerged(self):
40
 
        original_tree = self.make_branch_and_tree('original')
41
 
        original = original_tree.branch
42
 
        puller_tree = self.make_branch_and_tree('puller')
43
 
        puller = puller_tree.branch
44
 
        merger_tree = self.make_branch_and_tree('merger')
45
 
        merger = merger_tree.branch
46
 
        self.assertUnmerged(([], []), original, puller)
47
 
        original_tree.commit('a', rev_id='a')
48
 
        self.assertUnmerged(([('1', 'a')], []), original, puller)
49
 
        puller_tree.pull(original)
50
 
        self.assertUnmerged(([], []), original, puller)
51
 
        merger_tree.pull(original)
52
 
        original_tree.commit('b', rev_id='b')
53
 
        original_tree.commit('c', rev_id='c')
54
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
55
 
                            original, puller)
56
 
        self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
57
 
                            original, puller, backward=True)
58
 
 
59
 
        puller_tree.pull(original)
60
 
        self.assertUnmerged(([], []), original, puller)
61
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
62
 
                            original, merger)
63
 
        merger_tree.merge_from_branch(original)
64
 
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
65
 
                            original, merger)
66
 
        merger_tree.commit('d', rev_id='d')
67
 
        self.assertUnmerged(([], [('2', 'd')]), original, merger)
68
 
 
69
 
    def test_iter_log_revisions(self):
70
 
        base_tree = self.make_branch_and_tree('base')
71
 
        self.build_tree(['base/a'])
72
 
        base_tree.add(['a'], ['a-id'])
73
 
        base_tree.commit('add a', rev_id='b-1')
74
 
 
75
 
        child_tree = base_tree.bzrdir.sprout('child').open_workingtree()
76
 
 
77
 
        self.build_tree(['child/b'])
78
 
        child_tree.add(['b'], ['b-id'])
79
 
        child_tree.commit('adding b', rev_id='c-2')
80
 
 
81
 
        child_tree.remove(['a'])
82
 
        child_tree.commit('removing a', rev_id='c-3')
83
 
 
84
 
        self.build_tree_contents([('child/b', 'new contents for b\n')])
85
 
        child_tree.commit('modifying b', rev_id='c-4')
86
 
 
87
 
        child_tree.rename_one('b', 'c')
88
 
        child_tree.commit('rename b=>c', rev_id='c-5')
89
 
 
90
 
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
91
 
                                                        child_tree.branch)
92
 
        results = list(iter_log_revisions(base_extra,
93
 
                            base_tree.branch.repository,
94
 
                            verbose=True))
95
 
        self.assertEqual([], results)
96
 
 
97
 
        results = list(iter_log_revisions(child_extra,
98
 
                            child_tree.branch.repository,
99
 
                            verbose=True))
100
 
        self.assertEqual(4, len(results))
101
 
 
102
 
        r0,r1,r2,r3 = results
103
 
 
104
 
        self.assertEqual([('2', 'c-2'), ('3', 'c-3'),
105
 
                          ('4', 'c-4'), ('5', 'c-5'),],
106
 
                         [(r.revno, r.rev.revision_id) for r in results])
107
 
 
108
 
        delta0 = r0.delta
109
 
        self.assertNotEqual(None, delta0)
110
 
        self.assertEqual([('b', 'b-id', 'file')], delta0.added)
111
 
        self.assertEqual([], delta0.removed)
112
 
        self.assertEqual([], delta0.renamed)
113
 
        self.assertEqual([], delta0.modified)
114
 
 
115
 
        delta1 = r1.delta
116
 
        self.assertNotEqual(None, delta1)
117
 
        self.assertEqual([], delta1.added)
118
 
        self.assertEqual([('a', 'a-id', 'file')], delta1.removed)
119
 
        self.assertEqual([], delta1.renamed)
120
 
        self.assertEqual([], delta1.modified)
121
 
 
122
 
        delta2 = r2.delta
123
 
        self.assertNotEqual(None, delta2)
124
 
        self.assertEqual([], delta2.added)
125
 
        self.assertEqual([], delta2.removed)
126
 
        self.assertEqual([], delta2.renamed)
127
 
        self.assertEqual([('b', 'b-id', 'file', True, False)], delta2.modified)
128
 
 
129
 
        delta3 = r3.delta
130
 
        self.assertNotEqual(None, delta3)
131
 
        self.assertEqual([], delta3.added)
132
 
        self.assertEqual([], delta3.removed)
133
 
        self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
134
 
                         delta3.renamed)
135
 
        self.assertEqual([], delta3.modified)
136
 
 
137
 
 
138
 
class TestFindUnmerged(tests.TestCaseWithTransport):
139
 
 
140
 
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
141
 
                       restrict, include_merges=False,
142
 
                       backward=False):
143
 
        """Check the output of find_unmerged_mainline_revisions"""
144
 
        local_extra, remote_extra = missing.find_unmerged(
145
 
                                        local_branch, remote_branch, restrict,
146
 
                                        include_merges=include_merges,
147
 
                                        backward=backward)
148
 
        self.assertEqual(local, local_extra)
149
 
        self.assertEqual(remote, remote_extra)
150
 
 
151
 
    def test_same_branch(self):
152
 
        tree = self.make_branch_and_tree('tree')
153
 
        rev1 = tree.commit('one')
154
 
        tree.lock_read()
155
 
        self.addCleanup(tree.unlock)
156
 
        self.assertUnmerged([], [], tree.branch, tree.branch, 'all')
157
 
 
158
 
    def test_one_ahead(self):
159
 
        tree = self.make_branch_and_tree('tree')
160
 
        rev1 = tree.commit('one')
161
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
162
 
        rev2 = tree2.commit('two')
163
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
164
 
        self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch, 'all')
165
 
 
166
 
    def test_restrict(self):
167
 
        tree = self.make_branch_and_tree('tree')
168
 
        rev1 = tree.commit('one')
169
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
170
 
        rev2 = tree2.commit('two')
171
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
172
 
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
173
 
        self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
174
 
                                               'remote')
175
 
 
176
 
    def test_merged(self):
177
 
        tree = self.make_branch_and_tree('tree')
178
 
        rev1 = tree.commit('one')
179
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
180
 
        rev2 = tree2.commit('two')
181
 
        rev3 = tree2.commit('three')
182
 
        tree.merge_from_branch(tree2.branch)
183
 
        rev4 = tree.commit('four')
184
 
 
185
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch, 'all')
186
 
 
187
 
    def test_include_merges(self):
188
 
        tree = self.make_branch_and_tree('tree')
189
 
        rev1 = tree.commit('one', rev_id='rev1')
190
 
 
191
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
192
 
        rev2 = tree2.commit('two', rev_id='rev2')
193
 
        rev3 = tree2.commit('three', rev_id='rev3')
194
 
 
195
 
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
196
 
        rev4 = tree3.commit('four', rev_id='rev4')
197
 
        rev5 = tree3.commit('five', rev_id='rev5')
198
 
 
199
 
        tree2.merge_from_branch(tree3.branch)
200
 
        rev6 = tree2.commit('six', rev_id='rev6')
201
 
 
202
 
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3',0 ),
203
 
                                 ('4', 'rev6', 0),
204
 
                                 ('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
205
 
                                 ],
206
 
                            tree.branch, tree2.branch, 'all',
207
 
                            include_merges=True)
208
 
 
209
 
        self.assertUnmerged([], [('4', 'rev6', 0),
210
 
                                 ('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
211
 
                                 ('3', 'rev3',0 ), ('2', 'rev2', 0),
212
 
                                 ],
213
 
                            tree.branch, tree2.branch, 'all',
214
 
                            include_merges=True,
215
 
                            backward=True)