~bzr-pqm/bzr/bzr.dev

1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
1
# Copyright (C) 2006 by 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
"""Tests for the InterTree.compare() function."""
18
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
19
from bzrlib import errors
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
20
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees
21
22
23
class TestCompare(TestCaseWithTwoTrees):
24
25
    def test_compare_empty_trees(self):
26
        tree1 = self.make_branch_and_tree('1')
27
        tree2 = self.make_to_branch_and_tree('2')
28
        tree1 = self.get_tree_no_parents_no_content(tree1)
29
        tree2 = self.get_to_tree_no_parents_no_content(tree2)
30
        d = self.intertree_class(tree1, tree2).compare()
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
31
        self.assertEqual([], d.added)
32
        self.assertEqual([], d.modified)
33
        self.assertEqual([], d.removed)
34
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
35
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
36
37
    def test_empty_to_abc_content(self):
38
        tree1 = self.make_branch_and_tree('1')
39
        tree2 = self.make_to_branch_and_tree('2')
40
        tree1 = self.get_tree_no_parents_no_content(tree1)
41
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
42
        d = self.intertree_class(tree1, tree2).compare()
43
        self.assertEqual([('a', 'a-id', 'file'),
44
                          ('b', 'b-id', 'directory'),
45
                          ('b/c', 'c-id', 'file'),
46
                         ], d.added)
47
        self.assertEqual([], d.modified)
48
        self.assertEqual([], d.removed)
49
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
50
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
51
52
    def test_abc_content_to_empty(self):
53
        tree1 = self.make_branch_and_tree('1')
54
        tree2 = self.make_to_branch_and_tree('2')
55
        tree1 = self.get_tree_no_parents_abc_content(tree1)
56
        tree2 = self.get_to_tree_no_parents_no_content(tree2)
57
        d = self.intertree_class(tree1, tree2).compare()
58
        self.assertEqual([], d.added)
59
        self.assertEqual([], d.modified)
60
        self.assertEqual([('a', 'a-id', 'file'),
61
                          ('b', 'b-id', 'directory'),
62
                          ('b/c', 'c-id', 'file'),
63
                         ], d.removed)
64
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
65
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
66
67
    def test_content_modification(self):
68
        tree1 = self.make_branch_and_tree('1')
69
        tree2 = self.make_to_branch_and_tree('2')
70
        tree1 = self.get_tree_no_parents_abc_content(tree1)
71
        tree2 = self.get_to_tree_no_parents_abc_content_2(tree2)
72
        d = self.intertree_class(tree1, tree2).compare()
73
        self.assertEqual([], d.added)
74
        self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
75
        self.assertEqual([], d.removed)
76
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
77
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
78
        
79
    def test_meta_modification(self):
80
        tree1 = self.make_branch_and_tree('1')
81
        tree2 = self.make_to_branch_and_tree('2')
82
        tree1 = self.get_tree_no_parents_abc_content(tree1)
83
        tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
84
        d = self.intertree_class(tree1, tree2).compare()
85
        self.assertEqual([], d.added)
86
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
87
        self.assertEqual([], d.removed)
88
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
89
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
90
91
    def test_file_rename(self):
92
        tree1 = self.make_branch_and_tree('1')
93
        tree2 = self.make_to_branch_and_tree('2')
94
        tree1 = self.get_tree_no_parents_abc_content(tree1)
95
        tree2 = self.get_to_tree_no_parents_abc_content_4(tree2)
96
        d = self.intertree_class(tree1, tree2).compare()
97
        self.assertEqual([], d.added)
98
        self.assertEqual([], d.modified)
99
        self.assertEqual([], d.removed)
100
        self.assertEqual([('a', 'd', 'a-id', 'file', False, False)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
101
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
102
103
    def test_file_rename_and_modification(self):
104
        tree1 = self.make_branch_and_tree('1')
105
        tree2 = self.make_to_branch_and_tree('2')
106
        tree1 = self.get_tree_no_parents_abc_content(tree1)
107
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
108
        d = self.intertree_class(tree1, tree2).compare()
109
        self.assertEqual([], d.added)
110
        self.assertEqual([], d.modified)
111
        self.assertEqual([], d.removed)
112
        self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
113
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
114
115
    def test_file_rename_and_meta_modification(self):
116
        tree1 = self.make_branch_and_tree('1')
117
        tree2 = self.make_to_branch_and_tree('2')
118
        tree1 = self.get_tree_no_parents_abc_content(tree1)
119
        tree2 = self.get_to_tree_no_parents_abc_content_6(tree2)
120
        d = self.intertree_class(tree1, tree2).compare()
121
        self.assertEqual([], d.added)
122
        self.assertEqual([], d.modified)
123
        self.assertEqual([], d.removed)
124
        self.assertEqual([('b/c', 'e', 'c-id', 'file', False, True)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
125
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
126
127
    def test_empty_to_abc_content_a_only(self):
128
        tree1 = self.make_branch_and_tree('1')
129
        tree2 = self.make_to_branch_and_tree('2')
130
        tree1 = self.get_tree_no_parents_no_content(tree1)
131
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
132
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
133
        self.assertEqual([('a', 'a-id', 'file')], d.added)
134
        self.assertEqual([], d.modified)
135
        self.assertEqual([], d.removed)
136
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
137
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
138
139
    def test_empty_to_abc_content_a_and_c_only(self):
140
        tree1 = self.make_branch_and_tree('1')
141
        tree2 = self.make_to_branch_and_tree('2')
142
        tree1 = self.get_tree_no_parents_no_content(tree1)
143
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
144
        d = self.intertree_class(tree1, tree2).compare(
145
            specific_files=['a', 'b/c'])
146
        self.assertEqual(
147
            [('a', 'a-id', 'file'), ('b/c', 'c-id', 'file')],
148
            d.added)
149
        self.assertEqual([], d.modified)
150
        self.assertEqual([], d.removed)
151
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
152
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
153
154
    def test_empty_to_abc_content_b_only(self):
155
        """Restricting to a dir matches the children of the dir."""
156
        tree1 = self.make_branch_and_tree('1')
157
        tree2 = self.make_to_branch_and_tree('2')
158
        tree1 = self.get_tree_no_parents_no_content(tree1)
159
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
160
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
161
        self.assertEqual(
162
            [('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')],
163
            d.added)
164
        self.assertEqual([], d.modified)
165
        self.assertEqual([], d.removed)
166
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
167
        self.assertEqual([], d.unchanged)
168
169
    def test_unchanged_with_renames_and_modifications(self):
170
        """want_unchanged should generate a list of unchanged entries."""
171
        tree1 = self.make_branch_and_tree('1')
172
        tree2 = self.make_to_branch_and_tree('2')
173
        tree1 = self.get_tree_no_parents_abc_content(tree1)
174
        tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
175
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
176
        self.assertEqual([], d.added)
177
        self.assertEqual([], d.modified)
178
        self.assertEqual([], d.removed)
179
        self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
180
        self.assertEqual(
181
            [(u'b', 'b-id', 'directory'), (u'b/c', 'c-id', 'file')],
182
            d.unchanged)
183
184
    def test_extra_trees_finds_ids(self):
185
        """Ask for a delta between two trees with a path present in a third."""
186
        tree1 = self.make_branch_and_tree('1')
187
        tree2 = self.make_to_branch_and_tree('2')
188
        tree1 = self.get_tree_no_parents_abc_content(tree1)
189
        tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
190
        # the type of tree-3 does not matter - it is used as a lookup, not
191
        # a dispatch
192
        tree3 = self.make_branch_and_tree('3')
193
        tree3 = self.get_tree_no_parents_abc_content_6(tree3)
194
        # tree 3 has 'e' which is 'c-id'. Tree 1 has c-id at b/c, and Tree 2
195
        # has c-id at b/c with its exec flag toggled.
196
        # without extra_trees, we should get no modifications from this
197
        # so do one, to be sure the test is valid.
198
        d = self.intertree_class(tree1, tree2).compare(
199
            specific_files=['e'])
200
        self.assertEqual([], d.modified)
201
        # now give it an additional lookup:
202
        d = self.intertree_class(tree1, tree2).compare(
203
            specific_files=['e'], extra_trees=[tree3])
204
        self.assertEqual([], d.added)
205
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
206
        self.assertEqual([], d.removed)
207
        self.assertEqual([], d.renamed)
208
        self.assertEqual([], d.unchanged)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
209
210
    def test_require_versioned(self):
211
        # this does not quite robustly test, as it is passing in missing paths
212
        # rather than present-but-not-versioned paths. At the moment there is
213
        # no mechanism for managing the test trees (which are readonly) to 
214
        # get present-but-not-versioned files for trees that can do that.
215
        tree1 = self.make_branch_and_tree('1')
216
        tree2 = self.make_to_branch_and_tree('2')
217
        tree1 = self.get_tree_no_parents_no_content(tree1)
218
        tree2 = self.get_to_tree_no_parents_abc_content(tree2)
219
        self.assertRaises(errors.PathsNotVersionedError, 
220
            self.intertree_class(tree1, tree2).compare,
221
            specific_files=['d'],
222
            require_versioned=True)