/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2009, 2011, 2012, 2016 Canonical Ltd
1551.9.21 by Aaron Bentley
Fix copyright statements
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1551.9.21 by Aaron Bentley
Fix copyright statements
16
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
17
from breezy import (
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
18
    errors,
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
19
    conflicts,
3363.15.4 by Aaron Bentley
Implement PreviewTree.get_file_sha1 properly
20
    osutils,
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
21
    revisiontree,
2255.2.180 by Martin Pool
merge dirstate
22
    tests,
6670.4.3 by Jelmer Vernooij
Fix more imports.
23
    )
24
from breezy.bzr import (
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
25
    workingtree_4,
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
26
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.tests import TestSkipped
28
from breezy.tests.per_tree import TestCaseWithTree
5967.7.1 by Martin Pool
Deprecate __contains__ on Tree and Inventory
29
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
30
31
class TestAnnotate(TestCaseWithTree):
2255.2.69 by John Arbash Meinel
Implement annotate_iter, get_revision_id, and walkdirs so that all tree_implementations now pass
32
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
33
    def test_annotate(self):
34
        work_tree = self.make_branch_and_tree('wt')
35
        tree = self.get_tree_no_parents_abc_content(work_tree)
36
        tree_revision = getattr(tree, 'get_revision_id', lambda: 'current:')()
2255.2.69 by John Arbash Meinel
Implement annotate_iter, get_revision_id, and walkdirs so that all tree_implementations now pass
37
        tree.lock_read()
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
38
        self.addCleanup(tree.unlock)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
39
        a_id = tree.path2id('a')
40
        for revision, line in tree.annotate_iter(a_id):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
41
            self.assertEqual('contents of a\n', line)
42
            self.assertEqual(tree_revision, revision)
43
        tree_revision = getattr(tree, 'get_revision_id', lambda: 'random:')()
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
44
        for revision, line in tree.annotate_iter(a_id, 'random:'):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
45
            self.assertEqual('contents of a\n', line)
46
            self.assertEqual(tree_revision, revision)
47
48
1551.15.52 by Aaron Bentley
Tweak from review comments
49
class TestPlanFileMerge(TestCaseWithTree):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
50
1551.15.52 by Aaron Bentley
Tweak from review comments
51
    def test_plan_file_merge(self):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
52
        work_a = self.make_branch_and_tree('wta')
53
        self.build_tree_contents([('wta/file', 'a\nb\nc\nd\n')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
54
        work_a.add('file')
55
        file_id = work_a.path2id('file')
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
56
        work_a.commit('base version')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
57
        work_b = work_a.controldir.sprout('wtb').open_workingtree()
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
58
        self.build_tree_contents([('wta/file', 'b\nc\nd\ne\n')])
59
        tree_a = self.workingtree_to_test_tree(work_a)
60
        tree_a.lock_read()
61
        self.addCleanup(tree_a.unlock)
62
        self.build_tree_contents([('wtb/file', 'a\nc\nd\nf\n')])
63
        tree_b = self.workingtree_to_test_tree(work_b)
64
        tree_b.lock_read()
65
        self.addCleanup(tree_b.unlock)
66
        self.assertEqual([
3514.2.3 by John Arbash Meinel
Fix a failing test in tree_implementations
67
            ('killed-a', 'a\n'),
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
68
            ('killed-b', 'b\n'),
69
            ('unchanged', 'c\n'),
70
            ('unchanged', 'd\n'),
71
            ('new-a', 'e\n'),
72
            ('new-b', 'f\n'),
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
73
        ], list(tree_a.plan_file_merge(file_id, tree_b)))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
74
75
76
class TestReference(TestCaseWithTree):
77
78
    def skip_if_no_reference(self, tree):
79
        if not getattr(tree, 'supports_tree_reference', lambda: False)():
3504.2.1 by John Arbash Meinel
Shortcut iter_references when we know references aren't supported.
80
            raise tests.TestNotApplicable('Tree references not supported')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
81
2100.3.27 by Aaron Bentley
Enable nested commits
82
    def create_nested(self):
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
83
        work_tree = self.make_branch_and_tree('wt')
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
84
        work_tree.lock_write()
85
        try:
86
            self.skip_if_no_reference(work_tree)
87
            subtree = self.make_branch_and_tree('wt/subtree')
88
            subtree.set_root_id('sub-root')
89
            subtree.commit('foo', rev_id='sub-1')
90
            work_tree.add_reference(subtree)
91
        finally:
92
            work_tree.unlock()
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
93
        tree = self._convert_tree(work_tree)
94
        self.skip_if_no_reference(tree)
2100.3.27 by Aaron Bentley
Enable nested commits
95
        return tree
96
97
    def test_get_reference_revision(self):
98
        tree = self.create_nested()
3504.2.1 by John Arbash Meinel
Shortcut iter_references when we know references aren't supported.
99
        tree.lock_read()
100
        self.addCleanup(tree.unlock)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
101
        path = tree.id2path('sub-root')
5967.7.1 by Martin Pool
Deprecate __contains__ on Tree and Inventory
102
        self.assertEqual('sub-1',
103
            tree.get_reference_revision('sub-root', path))
2100.3.27 by Aaron Bentley
Enable nested commits
104
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
105
    def test_iter_references(self):
2100.3.27 by Aaron Bentley
Enable nested commits
106
        tree = self.create_nested()
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
107
        tree.lock_read()
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
108
        self.addCleanup(tree.unlock)
6405.2.9 by Jelmer Vernooij
More test fixes.
109
        entry = tree.root_inventory['sub-root']
3504.2.1 by John Arbash Meinel
Shortcut iter_references when we know references aren't supported.
110
        self.assertEqual([(u'subtree', 'sub-root')],
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
111
            list(tree.iter_references()))
2255.2.166 by Martin Pool
(broken) Add Tree.get_root_id() & test
112
113
    def test_get_root_id(self):
114
        # trees should return some kind of root id; it can be none
115
        tree = self.make_branch_and_tree('tree')
116
        root_id = tree.get_root_id()
117
        if root_id is not None:
118
            self.assertIsInstance(root_id, str)
2255.2.180 by Martin Pool
merge dirstate
119
120
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
121
class TestFileIds(TestCaseWithTree):
122
123
    def test_id2path(self):
124
        # translate from file-id back to path
125
        work_tree = self.make_branch_and_tree('wt')
126
        tree = self.get_tree_no_parents_abc_content(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
127
        a_id = tree.path2id('a')
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
128
        tree.lock_read()
129
        try:
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
130
            self.assertEqual(u'a', tree.id2path(a_id))
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
131
            # other ids give an error- don't return None for this case
132
            self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
133
        finally:
134
            tree.unlock()
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
135
3146.8.16 by Aaron Bentley
Updates from review
136
    def test_all_file_ids(self):
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
137
        work_tree = self.make_branch_and_tree('wt')
138
        tree = self.get_tree_no_parents_abc_content(work_tree)
139
        tree.lock_read()
140
        self.addCleanup(tree.unlock)
3146.8.16 by Aaron Bentley
Updates from review
141
        self.assertEqual(tree.all_file_ids(),
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
142
                         {tree.path2id('a'), tree.path2id(''),
143
                          tree.path2id('b'), tree.path2id('b/c')})
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
144
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
145
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
146
class TestStoredKind(TestCaseWithTree):
147
148
    def test_stored_kind(self):
149
        tree = self.make_branch_and_tree('tree')
150
        work_tree = self.make_branch_and_tree('wt')
151
        tree = self.get_tree_no_parents_abc_content(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
152
        a_id = tree.path2id('a')
153
        b_id = tree.path2id('b')
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
154
        tree.lock_read()
155
        self.addCleanup(tree.unlock)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
156
        self.assertEqual('file', tree.stored_kind(a_id))
157
        self.assertEqual('directory', tree.stored_kind(b_id))
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
158
159
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
160
class TestFileContent(TestCaseWithTree):
161
162
    def test_get_file(self):
163
        work_tree = self.make_branch_and_tree('wt')
164
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
165
        a_id = tree.path2id('a')
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
166
        tree.lock_read()
6437.20.6 by Martin Packman
Poke test_get_file in bt.per_tree.test_tree to be more careful about cleanup
167
        self.addCleanup(tree.unlock)
168
        # Test lookup without path works
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
169
        file_without_path = tree.get_file(a_id)
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
170
        try:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
171
            lines = file_without_path.readlines()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
172
            self.assertEqual(['foobar\n'], lines)
6437.20.6 by Martin Packman
Poke test_get_file in bt.per_tree.test_tree to be more careful about cleanup
173
        finally:
174
            file_without_path.close()
175
        # Test lookup with path works
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
176
        file_with_path = tree.get_file(a_id, path='a')
6437.20.6 by Martin Packman
Poke test_get_file in bt.per_tree.test_tree to be more careful about cleanup
177
        try:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
178
            lines = file_with_path.readlines()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
179
            self.assertEqual(['foobar\n'], lines)
180
        finally:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
181
            file_with_path.close()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
182
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
183
    def test_get_file_text(self):
184
        work_tree = self.make_branch_and_tree('wt')
185
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
186
        a_id = tree.path2id('a')
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
187
        tree.lock_read()
188
        self.addCleanup(tree.unlock)
189
        # test read by file-id
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
190
        self.assertEqual('foobar\n', tree.get_file_text(a_id))
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
191
        # test read by path
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
192
        self.assertEqual('foobar\n', tree.get_file_text(a_id, path='a'))
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
193
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
194
    def test_get_file_lines(self):
195
        work_tree = self.make_branch_and_tree('wt')
196
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
197
        a_id = tree.path2id('a')
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
198
        tree.lock_read()
199
        self.addCleanup(tree.unlock)
200
        # test read by file-id
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
201
        self.assertEqual(['foobar\n'], tree.get_file_lines(a_id))
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
202
        # test read by path
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
203
        self.assertEqual(['foobar\n'], tree.get_file_lines(a_id, path='a'))
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
204
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
205
    def test_get_file_lines_multi_line_breaks(self):
206
        work_tree = self.make_branch_and_tree('wt')
207
        self.build_tree_contents([('wt/foobar', 'a\rb\nc\r\nd')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
208
        work_tree.add('foobar')
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
209
        tree = self._convert_tree(work_tree)
210
        tree.lock_read()
211
        self.addCleanup(tree.unlock)
212
        self.assertEqual(['a\rb\n', 'c\r\n', 'd'],
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
213
                         tree.get_file_lines(tree.path2id('foobar')))
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
214
215
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
216
class TestExtractFilesBytes(TestCaseWithTree):
217
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
218
    def test_iter_files_bytes(self):
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
219
        work_tree = self.make_branch_and_tree('wt')
220
        self.build_tree_contents([('wt/foo', 'foo'),
221
                                  ('wt/bar', 'bar'),
222
                                  ('wt/baz', 'baz')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
223
        work_tree.add(['foo', 'bar', 'baz'])
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
224
        tree = self._convert_tree(work_tree)
225
        tree.lock_read()
226
        self.addCleanup(tree.unlock)
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
227
        extracted = dict((i, ''.join(b)) for i, b in
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
228
                         tree.iter_files_bytes([(tree.path2id('foo'), 'id1'),
229
                                                (tree.path2id('bar'), 'id2'),
230
                                                (tree.path2id('baz'), 'id3')]))
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
231
        self.assertEqual('foo', extracted['id1'])
232
        self.assertEqual('bar', extracted['id2'])
233
        self.assertEqual('baz', extracted['id3'])
2708.1.11 by Aaron Bentley
Test and tweak error handling
234
        self.assertRaises(errors.NoSuchId, lambda: list(
235
                          tree.iter_files_bytes(
236
                          [('qux-id', 'file1-notpresent')])))
2748.2.2 by Lukáš Lalinsky
Add TestConflicts to tests.tree_implementations.test_tree. Update NEWS.
237
238
239
class TestConflicts(TestCaseWithTree):
240
241
    def test_conflicts(self):
242
        """Tree.conflicts() should return a ConflictList instance."""
243
        work_tree = self.make_branch_and_tree('wt')
244
        tree = self._convert_tree(work_tree)
2761.1.3 by Aaron Bentley
Update test to use assertIsInstance
245
        self.assertIsInstance(tree.conflicts(), conflicts.ConflictList)
3363.5.4 by Aaron Bentley
Fix iteration order of iter_entries_by_dir
246
247
248
class TestIterEntriesByDir(TestCaseWithTree):
249
250
    def test_iteration_order(self):
251
        work_tree = self.make_branch_and_tree('.')
252
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
253
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
254
        tree = self._convert_tree(work_tree)
255
        output_order = [p for p, e in tree.iter_entries_by_dir()]
256
        self.assertEqual(['', 'a', 'f', 'a/b', 'a/d', 'a/b/c', 'a/d/e', 'f/g'],
257
                         output_order)
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
258
259
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
260
class TestIterChildEntries(TestCaseWithTree):
261
262
    def test_iteration_order(self):
263
        work_tree = self.make_branch_and_tree('.')
264
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
265
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
266
        tree = self._convert_tree(work_tree)
267
        output = [e.name for e in
268
            tree.iter_child_entries(tree.get_root_id())]
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
269
        self.assertEqual({'a', 'f'}, set(output))
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
270
        output = [e.name for e in
271
            tree.iter_child_entries(tree.path2id('a'))]
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
272
        self.assertEqual({'b', 'd'}, set(output))
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
273
274
    def test_does_not_exist(self):
275
        work_tree = self.make_branch_and_tree('.')
276
        self.build_tree(['a/'])
277
        work_tree.add(['a'])
278
        tree = self._convert_tree(work_tree)
279
        self.assertRaises(errors.NoSuchId, lambda:
280
            list(tree.iter_child_entries('unknown')))
281
282
3363.12.7 by Aaron Bentley
Add HasId test
283
class TestHasId(TestCaseWithTree):
284
285
    def test_has_id(self):
286
        work_tree = self.make_branch_and_tree('tree')
287
        self.build_tree(['tree/file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
288
        work_tree.add('file')
289
        file_id = work_tree.path2id('file')
3363.12.7 by Aaron Bentley
Add HasId test
290
        tree = self._convert_tree(work_tree)
291
        tree.lock_read()
292
        self.addCleanup(tree.unlock)
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
293
        self.assertTrue(tree.has_id(file_id))
3363.12.7 by Aaron Bentley
Add HasId test
294
        self.assertFalse(tree.has_id('dir-id'))
3363.13.5 by Aaron Bentley
Merge with paths2ids
295
296
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
297
class TestExtras(TestCaseWithTree):
298
299
    def test_extras(self):
300
        work_tree = self.make_branch_and_tree('tree')
3363.13.4 by Aaron Bentley
Ensure versioned files are not listed by extras
301
        self.build_tree(['tree/file', 'tree/versioned-file'])
302
        work_tree.add(['file', 'versioned-file'])
303
        work_tree.commit('add files')
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
304
        work_tree.remove('file')
305
        tree = self._convert_tree(work_tree)
306
        if isinstance(tree,
307
                      (revisiontree.RevisionTree,
308
                       workingtree_4.DirStateRevisionTree)):
309
            expected = []
310
        else:
311
            expected = ['file']
312
        tree.lock_read()
313
        self.addCleanup(tree.unlock)
314
        self.assertEqual(expected, list(tree.extras()))
3363.15.1 by Aaron Bentley
Add test for has_id
315
3363.17.3 by Aaron Bentley
Merge with has_id
316
3363.15.4 by Aaron Bentley
Implement PreviewTree.get_file_sha1 properly
317
class TestGetFileSha1(TestCaseWithTree):
318
319
    def test_get_file_sha1(self):
320
        work_tree = self.make_branch_and_tree('tree')
321
        self.build_tree_contents([('tree/file', 'file content')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
322
        work_tree.add('file')
3363.15.4 by Aaron Bentley
Implement PreviewTree.get_file_sha1 properly
323
        tree = self._convert_tree(work_tree)
324
        tree.lock_read()
325
        self.addCleanup(tree.unlock)
326
        expected = osutils.sha_strings('file content')
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
327
        self.assertEqual(expected, tree.get_file_sha1(tree.path2id('file')))
5906.1.8 by Jelmer Vernooij
Tests.
328
329
330
class TestGetFileVerifier(TestCaseWithTree):
331
332
    def test_get_file_verifier(self):
333
        work_tree = self.make_branch_and_tree('tree')
334
        self.build_tree_contents([
335
            ('tree/file1', 'file content'),
336
            ('tree/file2', 'file content')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
337
        work_tree.add(['file1', 'file2'])
5906.1.8 by Jelmer Vernooij
Tests.
338
        tree = self._convert_tree(work_tree)
339
        tree.lock_read()
340
        self.addCleanup(tree.unlock)
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
341
        (kind, data) = tree.get_file_verifier(tree.path2id('file1'))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
342
        self.assertEqual(
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
343
            tree.get_file_verifier(tree.path2id('file1')),
344
            tree.get_file_verifier(tree.path2id('file2')))
5906.1.10 by Jelmer Vernooij
sha1 -> SHA1
345
        if kind == "SHA1":
5906.1.8 by Jelmer Vernooij
Tests.
346
            expected = osutils.sha_strings('file content')
347
            self.assertEqual(expected, data)
6110.6.1 by Jelmer Vernooij
Add Tree.has_versioned_directories.
348
349
350
class TestHasVersionedDirectories(TestCaseWithTree):
351
352
    def test_has_versioned_directories(self):
353
        work_tree = self.make_branch_and_tree('tree')
354
        tree = self._convert_tree(work_tree)
355
        self.assertSubset([tree.has_versioned_directories()], (True, False))