~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-04 18:51:39 UTC
  • mfrom: (2961.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071104185139-kaio3sneodg2kp71
Authentication ring implementation (read-only)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
 
19
19
 
20
 
from bzrlib import (
21
 
    missing,
22
 
    tests,
23
 
    )
24
20
from bzrlib.missing import (
 
21
    find_unmerged,
 
22
    iter_log_data,
25
23
    iter_log_revisions,
26
24
    )
 
25
from bzrlib.symbol_versioning import zero_seventeen
27
26
from bzrlib.tests import TestCaseWithTransport
28
27
from bzrlib.workingtree import WorkingTree
29
28
 
30
29
 
31
30
class TestMissing(TestCaseWithTransport):
32
31
 
33
 
    def assertUnmerged(self, expected, source, target, restrict='all'):
34
 
        unmerged = missing.find_unmerged(source, target, restrict=restrict)
35
 
        self.assertEqual(expected, unmerged)
36
 
            
37
32
    def test_find_unmerged(self):
38
33
        original_tree = self.make_branch_and_tree('original')
39
34
        original = original_tree.branch
41
36
        puller = puller_tree.branch
42
37
        merger_tree = self.make_branch_and_tree('merger')
43
38
        merger = merger_tree.branch
44
 
        self.assertUnmerged(([], []), original, puller)
 
39
        self.assertEqual(find_unmerged(original, puller), ([], []))
45
40
        original_tree.commit('a', rev_id='a')
46
 
        self.assertUnmerged(([(1, 'a')], []), original, puller)
 
41
        self.assertEqual(find_unmerged(original, puller), ([(1, u'a')], []))
47
42
        puller_tree.pull(original)
48
 
        self.assertUnmerged(([], []), original, puller)
 
43
        self.assertEqual(find_unmerged(original, puller), ([], []))
49
44
        merger_tree.pull(original)
50
45
        original_tree.commit('b', rev_id='b')
51
46
        original_tree.commit('c', rev_id='c')
52
 
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
53
 
                            original, puller)
 
47
        self.assertEqual(find_unmerged(original, puller), ([(2, u'b'), 
 
48
                                                            (3, u'c')], []))
54
49
 
55
50
        puller_tree.pull(original)
56
 
        self.assertUnmerged(([], []), original, puller)
57
 
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
58
 
                            original, merger)
 
51
        self.assertEqual(find_unmerged(original, puller), ([], []))
 
52
        self.assertEqual(find_unmerged(original, merger), ([(2, u'b'), 
 
53
                                                            (3, u'c')], []))
59
54
        merger_tree.merge_from_branch(original)
60
 
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
61
 
                            original, merger)
 
55
        self.assertEqual(find_unmerged(original, merger), ([(2, u'b'), 
 
56
                                                            (3, u'c')], []))
62
57
        merger_tree.commit('d', rev_id='d')
63
 
        self.assertUnmerged(([], [(2, 'd')]), original, merger)
 
58
        self.assertEqual(find_unmerged(original, merger), ([], [(2, 'd')]))
 
59
 
 
60
    def test_iter_log_data(self):
 
61
        base_tree = self.make_branch_and_tree('base')
 
62
        self.build_tree(['base/a'])
 
63
        base_tree.add(['a'], ['a-id'])
 
64
        base_tree.commit('add a', rev_id='b-1')
 
65
 
 
66
        child_tree = base_tree.bzrdir.sprout('child').open_workingtree()
 
67
 
 
68
        self.build_tree(['child/b'])
 
69
        child_tree.add(['b'], ['b-id'])
 
70
        child_tree.commit('adding b', rev_id='c-2')
 
71
 
 
72
        child_tree.remove(['a'])
 
73
        child_tree.commit('removing a', rev_id='c-3')
 
74
 
 
75
        self.build_tree_contents([('child/b', 'new contents for b\n')])
 
76
        child_tree.commit('modifying b', rev_id='c-4')
 
77
 
 
78
        child_tree.rename_one('b', 'c')
 
79
        child_tree.commit('rename b=>c', rev_id='c-5')
 
80
 
 
81
        base_extra, child_extra = find_unmerged(base_tree.branch,
 
82
                                                child_tree.branch)
 
83
        results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
 
84
                            base_extra,
 
85
                            base_tree.branch.repository,
 
86
                            verbose=True))
 
87
        self.assertEqual([], results)
 
88
 
 
89
        results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
 
90
                            child_extra,
 
91
                            child_tree.branch.repository,
 
92
                            verbose=True))
 
93
        self.assertEqual(4, len(results))
 
94
 
 
95
        r0,r1,r2,r3 = results
 
96
 
 
97
        self.assertEqual((2, 'c-2'), (r0[0], r0[1].revision_id))
 
98
        self.assertEqual((3, 'c-3'), (r1[0], r1[1].revision_id))
 
99
        self.assertEqual((4, 'c-4'), (r2[0], r2[1].revision_id))
 
100
        self.assertEqual((5, 'c-5'), (r3[0], r3[1].revision_id))
 
101
 
 
102
        delta0 = r0[2]
 
103
        self.assertNotEqual(None, delta0)
 
104
        self.assertEqual([('b', 'b-id', 'file')], delta0.added)
 
105
        self.assertEqual([], delta0.removed)
 
106
        self.assertEqual([], delta0.renamed)
 
107
        self.assertEqual([], delta0.modified)
 
108
 
 
109
        delta1 = r1[2]
 
110
        self.assertNotEqual(None, delta1)
 
111
        self.assertEqual([], delta1.added)
 
112
        self.assertEqual([('a', 'a-id', 'file')], delta1.removed)
 
113
        self.assertEqual([], delta1.renamed)
 
114
        self.assertEqual([], delta1.modified)
 
115
 
 
116
        delta2 = r2[2]
 
117
        self.assertNotEqual(None, delta2)
 
118
        self.assertEqual([], delta2.added)
 
119
        self.assertEqual([], delta2.removed)
 
120
        self.assertEqual([], delta2.renamed)
 
121
        self.assertEqual([('b', 'b-id', 'file', True, False)], delta2.modified)
 
122
 
 
123
        delta3 = r3[2]
 
124
        self.assertNotEqual(None, delta3)
 
125
        self.assertEqual([], delta3.added)
 
126
        self.assertEqual([], delta3.removed)
 
127
        self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
 
128
                         delta3.renamed)
 
129
        self.assertEqual([], delta3.modified)
64
130
 
65
131
    def test_iter_log_revisions(self):
66
132
        base_tree = self.make_branch_and_tree('base')
83
149
        child_tree.rename_one('b', 'c')
84
150
        child_tree.commit('rename b=>c', rev_id='c-5')
85
151
 
86
 
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
87
 
                                                        child_tree.branch)
 
152
        base_extra, child_extra = find_unmerged(base_tree.branch,
 
153
                                                child_tree.branch)
88
154
        results = list(iter_log_revisions(base_extra, 
89
155
                            base_tree.branch.repository,
90
156
                            verbose=True))
130
196
        self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
131
197
                         delta3.renamed)
132
198
        self.assertEqual([], delta3.modified)
133
 
 
134
 
 
135
 
class TestFindUnmerged(tests.TestCaseWithTransport):
136
 
 
137
 
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
138
 
                       restrict):
139
 
        """Check the output of find_unmerged_mainline_revisions"""
140
 
        local_extra, remote_extra = missing.find_unmerged(
141
 
                                        local_branch, remote_branch, restrict)
142
 
        self.assertEqual(local, local_extra)
143
 
        self.assertEqual(remote, remote_extra)
144
 
 
145
 
    def test_same_branch(self):
146
 
        tree = self.make_branch_and_tree('tree')
147
 
        rev1 = tree.commit('one')
148
 
        tree.lock_read()
149
 
        self.addCleanup(tree.unlock)
150
 
        self.assertUnmerged([], [], tree.branch, tree.branch, 'all')
151
 
 
152
 
    def test_one_ahead(self):
153
 
        tree = self.make_branch_and_tree('tree')
154
 
        rev1 = tree.commit('one')
155
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
 
        rev2 = tree2.commit('two')
157
 
        tree.lock_read()
158
 
        self.addCleanup(tree.unlock)
159
 
        tree2.lock_read()
160
 
        self.addCleanup(tree2.unlock)
161
 
        self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
162
 
        self.assertUnmerged([(2, rev2)], [], tree2.branch, tree.branch, 'all')
163
 
 
164
 
    def test_restrict(self):
165
 
        tree = self.make_branch_and_tree('tree')
166
 
        rev1 = tree.commit('one')
167
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
168
 
        rev2 = tree2.commit('two')
169
 
        tree.lock_read()
170
 
        self.addCleanup(tree.unlock)
171
 
        tree2.lock_read()
172
 
        self.addCleanup(tree2.unlock)
173
 
        self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
174
 
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
175
 
        self.assertUnmerged(None, [(2, rev2)], tree.branch, tree2.branch,
176
 
                                               'remote')
177
 
 
178
 
    def test_merged(self):
179
 
        tree = self.make_branch_and_tree('tree')
180
 
        rev1 = tree.commit('one')
181
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
182
 
        rev2 = tree2.commit('two')
183
 
        rev3 = tree2.commit('three')
184
 
        tree.merge_from_branch(tree2.branch)
185
 
        rev4 = tree.commit('four')
186
 
 
187
 
        tree.lock_read()
188
 
        self.addCleanup(tree.unlock)
189
 
        tree2.lock_read()
190
 
        self.addCleanup(tree2.unlock)
191
 
 
192
 
        self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')