/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
1
# Copyright (C) 2007, 2008 Canonical Ltd
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
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 interface conformance of inventories of trees."""
18
19
20
from cStringIO import StringIO
21
import os
22
23
from bzrlib.diff import internal_diff
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
24
from bzrlib.mutabletree import MutableTree
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
25
from bzrlib.osutils import has_symlinks
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
27
from bzrlib.tests import SymlinkFeature, TestSkipped
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
28
from bzrlib.tests.tree_implementations import TestCaseWithTree
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
29
from bzrlib.transform import _PreviewTree
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
30
from bzrlib.uncommit import uncommit
31
32
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
33
def get_entry(tree, file_id):
34
    return tree.iter_entries_by_dir([file_id]).next()[1]
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
35
36
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
37
class TestEntryDiffing(TestCaseWithTree):
38
39
    def setUp(self):
40
        super(TestEntryDiffing, self).setUp()
41
        self.wt = self.make_branch_and_tree('.')
42
        self.branch = self.wt.branch
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
43
        open('file', 'wb').write('foo\n')
44
        open('binfile', 'wb').write('foo\n')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
45
        self.wt.add(['file'], ['fileid'])
46
        self.wt.add(['binfile'], ['binfileid'])
47
        if has_symlinks():
48
            os.symlink('target1', 'symlink')
49
            self.wt.add(['symlink'], ['linkid'])
50
        self.wt.commit('message_1', rev_id = '1')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
51
        open('file', 'wb').write('bar\n')
52
        open('binfile', 'wb').write('x' * 1023 + '\x00\n')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
53
        if has_symlinks():
54
            os.unlink('symlink')
55
            os.symlink('target2', 'symlink')
56
        self.tree_1 = self.branch.repository.revision_tree('1')
57
        self.inv_1 = self.branch.repository.get_inventory('1')
58
        self.file_1 = self.inv_1['fileid']
59
        self.file_1b = self.inv_1['binfileid']
60
        self.tree_2 = self.workingtree_to_test_tree(self.wt)
61
        self.tree_2.lock_read()
62
        self.addCleanup(self.tree_2.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
63
        self.file_2 = get_entry(self.tree_2, 'fileid')
64
        self.file_2b = get_entry(self.tree_2, 'binfileid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
65
        if has_symlinks():
66
            self.link_1 = self.inv_1['linkid']
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
67
            self.link_2 = get_entry(self.tree_2, 'linkid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
68
69
    def test_file_diff_deleted(self):
70
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
71
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
72
                             self.file_1.diff,
73
                             internal_diff,
74
                             "old_label", self.tree_1,
75
                             "/dev/null", None, None,
76
                             output)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
77
        self.assertEqual(output.getvalue(), "--- old_label\n"
78
                                            "+++ /dev/null\n"
79
                                            "@@ -1,1 +0,0 @@\n"
80
                                            "-foo\n"
81
                                            "\n")
82
83
    def test_file_diff_added(self):
84
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
85
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
86
                             self.file_1.diff,
87
                             internal_diff,
88
                             "new_label", self.tree_1,
89
                             "/dev/null", None, None,
90
                             output, reverse=True)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
91
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
92
                                            "+++ new_label\n"
93
                                            "@@ -0,0 +1,1 @@\n"
94
                                            "+foo\n"
95
                                            "\n")
96
97
    def test_file_diff_changed(self):
98
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
99
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
100
                             self.file_1.diff,
101
                             internal_diff,
102
                             "/dev/null", self.tree_1,
103
                             "new_label", self.file_2, self.tree_2,
104
                             output)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
105
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
106
                                            "+++ new_label\n"
107
                                            "@@ -1,1 +1,1 @@\n"
108
                                            "-foo\n"
109
                                            "+bar\n"
110
                                            "\n")
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
111
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
112
    def test_file_diff_binary(self):
113
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
114
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
115
                             self.file_1.diff,
116
                             internal_diff,
117
                             "/dev/null", self.tree_1,
118
                             "new_label", self.file_2b, self.tree_2,
119
                             output)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
120
        self.assertEqual(output.getvalue(),
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
121
                         "Binary files /dev/null and new_label differ\n")
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
122
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
123
    def test_link_diff_deleted(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
124
        self.requireFeature(SymlinkFeature)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
125
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
126
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
127
                             self.link_1.diff,
128
                             internal_diff, "old_label",
129
                             self.tree_1, "/dev/null", None, None,
130
                             output)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
131
        self.assertEqual(output.getvalue(),
132
                         "=== target was 'target1'\n")
133
134
    def test_link_diff_added(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
135
        self.requireFeature(SymlinkFeature)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
136
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
137
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
138
                             self.link_1.diff,
139
                             internal_diff,
140
                             "new_label", self.tree_1,
141
                             "/dev/null", None, None,
142
                             output, reverse=True)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
143
        self.assertEqual(output.getvalue(),
144
                         "=== target is 'target1'\n")
145
146
    def test_link_diff_changed(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
147
        self.requireFeature(SymlinkFeature)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
148
        output = StringIO()
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
149
        self.applyDeprecated(one_zero,
3009.2.32 by Aaron Bentley
InventoryEntry.diff is now deprecated
150
                             self.link_1.diff,
151
                             internal_diff,
152
                             "/dev/null", self.tree_1,
153
                             "new_label", self.link_2, self.tree_2,
154
                             output)
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
155
        self.assertEqual(output.getvalue(),
156
                         "=== target changed 'target1' => 'target2'\n")
157
158
159
class TestPreviousHeads(TestCaseWithTree):
160
161
    def setUp(self):
162
        # we want several inventories, that respectively
163
        # give use the following scenarios:
164
        # A) fileid not in any inventory (A),
165
        # B) fileid present in one inventory (B) and (A,B)
166
        # C) fileid present in two inventories, and they
167
        #   are not mutual descendents (B, C)
168
        # D) fileid present in two inventories and one is
169
        #   a descendent of the other. (B, D)
170
        super(TestPreviousHeads, self).setUp()
171
        self.wt = self.make_branch_and_tree('.')
172
        self.branch = self.wt.branch
173
        self.build_tree(['file'])
174
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
175
        self.inv_A = self.branch.repository.get_inventory('A')
176
        self.wt.add(['file'], ['fileid'])
177
        self.wt.commit('add file', rev_id='B')
178
        self.inv_B = self.branch.repository.get_inventory('B')
179
        uncommit(self.branch, tree=self.wt)
180
        self.assertEqual(self.branch.revision_history(), ['A'])
181
        self.wt.commit('another add of file', rev_id='C')
182
        self.inv_C = self.branch.repository.get_inventory('C')
183
        self.wt.add_parent_tree_id('B')
184
        self.wt.commit('merge in B', rev_id='D')
185
        self.inv_D = self.branch.repository.get_inventory('D')
186
        self.tree = self.workingtree_to_test_tree(self.wt)
187
        self.tree.lock_read()
188
        self.addCleanup(self.tree.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
189
        self.file_active = get_entry(self.tree, 'fileid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
190
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
191
            self.branch.repository.get_transaction())
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
192
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
193
    def get_previous_heads(self, inventories):
2776.3.1 by Robert Collins
* Deprecated method ``find_previous_heads`` on
194
        return self.applyDeprecated(zero_ninetyone,
195
            self.file_active.find_previous_heads,
196
            inventories,
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
197
            self.branch.repository.weave_store,
198
            self.branch.repository.get_transaction())
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
199
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
200
    def test_fileid_in_no_inventory(self):
201
        self.assertEqual({}, self.get_previous_heads([self.inv_A]))
202
203
    def test_fileid_in_one_inventory(self):
204
        self.assertEqual({'B':self.inv_B['fileid']},
205
                         self.get_previous_heads([self.inv_B]))
206
        self.assertEqual({'B':self.inv_B['fileid']},
207
                         self.get_previous_heads([self.inv_A, self.inv_B]))
208
        self.assertEqual({'B':self.inv_B['fileid']},
209
                         self.get_previous_heads([self.inv_B, self.inv_A]))
210
211
    def test_fileid_in_two_inventories_gives_both_entries(self):
212
        self.assertEqual({'B':self.inv_B['fileid'],
213
                          'C':self.inv_C['fileid']},
214
                          self.get_previous_heads([self.inv_B, self.inv_C]))
215
        self.assertEqual({'B':self.inv_B['fileid'],
216
                          'C':self.inv_C['fileid']},
217
                          self.get_previous_heads([self.inv_C, self.inv_B]))
218
219
    def test_fileid_in_two_inventories_already_merged_gives_head(self):
220
        self.assertEqual({'D':self.inv_D['fileid']},
221
                         self.get_previous_heads([self.inv_B, self.inv_D]))
222
        self.assertEqual({'D':self.inv_D['fileid']},
223
                         self.get_previous_heads([self.inv_D, self.inv_B]))
224
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
225
    # TODO: test two inventories with the same file revision
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
226
227
228
class TestInventory(TestCaseWithTree):
229
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
230
    def _set_up(self):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
231
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
232
        self.tree.lock_read()
233
        self.addCleanup(self.tree.unlock)
234
235
    def test_symlink_target(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
236
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
237
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
238
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
239
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
240
                'symlinks not accurately represented in working trees and'
241
                ' preview trees')
242
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
243
        self.assertEqual(entry.symlink_target, 'link-target')
244
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
245
    def test_symlink_target_tree(self):
246
        self.requireFeature(SymlinkFeature)
247
        self._set_up()
248
        self.assertEqual('link-target',
249
                         self.tree.get_symlink_target('symlink'))
250
251
    def test_kind_symlink(self):
252
        self.requireFeature(SymlinkFeature)
253
        self._set_up()
254
        self.assertEqual('symlink', self.tree.kind('symlink'))
255
        self.assertIs(None, self.tree.get_file_size('symlink'))
256
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
257
    def test_symlink(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
258
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
259
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
260
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
261
        self.assertEqual(entry.kind, 'symlink')
262
        self.assertEqual(None, entry.text_size)