/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)
6809.4.2 by Jelmer Vernooij
Swap arguments for annotate_iter.
39
        for revision, line in tree.annotate_iter('a'):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
40
            self.assertEqual('contents of a\n', line)
41
            self.assertEqual(tree_revision, revision)
42
        tree_revision = getattr(tree, 'get_revision_id', lambda: 'random:')()
6809.4.3 by Jelmer Vernooij
Fix annotate tests.
43
        for revision, line in tree.annotate_iter('a', default_revision='random:'):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
44
            self.assertEqual('contents of a\n', line)
45
            self.assertEqual(tree_revision, revision)
46
47
1551.15.52 by Aaron Bentley
Tweak from review comments
48
class TestPlanFileMerge(TestCaseWithTree):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
49
1551.15.52 by Aaron Bentley
Tweak from review comments
50
    def test_plan_file_merge(self):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
51
        work_a = self.make_branch_and_tree('wta')
6855.3.1 by Jelmer Vernooij
Several more fixes.
52
        self.build_tree_contents([('wta/file', b'a\nb\nc\nd\n')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
53
        work_a.add('file')
54
        file_id = work_a.path2id('file')
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
55
        work_a.commit('base version')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
56
        work_b = work_a.controldir.sprout('wtb').open_workingtree()
6855.3.1 by Jelmer Vernooij
Several more fixes.
57
        self.build_tree_contents([('wta/file', b'b\nc\nd\ne\n')])
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
58
        tree_a = self.workingtree_to_test_tree(work_a)
6861.2.3 by Jelmer Vernooij
Mark which merge types require plan_file_merge.
59
        if getattr(tree_a, 'plan_file_merge', None) is None:
6861.2.4 by Jelmer Vernooij
Fix import.
60
            raise tests.TestNotApplicable('Tree does not support plan_file_merge')
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
61
        tree_a.lock_read()
62
        self.addCleanup(tree_a.unlock)
6855.3.1 by Jelmer Vernooij
Several more fixes.
63
        self.build_tree_contents([('wtb/file', b'a\nc\nd\nf\n')])
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
64
        tree_b = self.workingtree_to_test_tree(work_b)
65
        tree_b.lock_read()
66
        self.addCleanup(tree_b.unlock)
67
        self.assertEqual([
3514.2.3 by John Arbash Meinel
Fix a failing test in tree_implementations
68
            ('killed-a', 'a\n'),
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
69
            ('killed-b', 'b\n'),
70
            ('unchanged', 'c\n'),
71
            ('unchanged', 'd\n'),
72
            ('new-a', 'e\n'),
73
            ('new-b', 'f\n'),
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
74
        ], list(tree_a.plan_file_merge(file_id, tree_b)))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
75
76
77
class TestReference(TestCaseWithTree):
78
79
    def skip_if_no_reference(self, tree):
80
        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.
81
            raise tests.TestNotApplicable('Tree references not supported')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
82
2100.3.27 by Aaron Bentley
Enable nested commits
83
    def create_nested(self):
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
84
        work_tree = self.make_branch_and_tree('wt')
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
85
        work_tree.lock_write()
86
        try:
87
            self.skip_if_no_reference(work_tree)
88
            subtree = self.make_branch_and_tree('wt/subtree')
6926.2.1 by Jelmer Vernooij
Some tree reference fixes.
89
            subtree.commit('foo')
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
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)
6926.2.1 by Jelmer Vernooij
Some tree reference fixes.
95
        return tree, subtree
2100.3.27 by Aaron Bentley
Enable nested commits
96
97
    def test_get_reference_revision(self):
6926.2.1 by Jelmer Vernooij
Some tree reference fixes.
98
        tree, subtree = 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)
6926.2.1 by Jelmer Vernooij
Some tree reference fixes.
101
        self.assertEqual(
102
            subtree.last_revision(),
103
            tree.get_reference_revision('subtree'))
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):
6926.2.1 by Jelmer Vernooij
Some tree reference fixes.
106
        tree, subtree = 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)
6926.2.2 by Jelmer Vernooij
More fixes.
109
        self.assertEqual(
110
            [(u'subtree', subtree.get_root_id())],
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
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
120
    def test_is_versioned(self):
6856 by Jelmer Vernooij
Merge lp:~jelmer/brz/is-versioned.
121
        tree = self.make_branch_and_tree('tree')
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
122
        self.assertTrue(tree.is_versioned(''))
123
        self.assertFalse(tree.is_versioned('blah'))
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
124
        self.build_tree(['tree/dir/', 'tree/dir/file'])
125
        self.assertFalse(tree.is_versioned('dir'))
126
        self.assertFalse(tree.is_versioned('dir/'))
127
        tree.add(['dir', 'dir/file'])
128
        self.assertTrue(tree.is_versioned('dir'))
129
        self.assertTrue(tree.is_versioned('dir/'))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
130
2255.2.180 by Martin Pool
merge dirstate
131
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
132
class TestFileIds(TestCaseWithTree):
133
134
    def test_id2path(self):
135
        # translate from file-id back to path
136
        work_tree = self.make_branch_and_tree('wt')
137
        tree = self.get_tree_no_parents_abc_content(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
138
        a_id = tree.path2id('a')
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
139
        with tree.lock_read():
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
140
            self.assertEqual(u'a', tree.id2path(a_id))
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
141
            # other ids give an error- don't return None for this case
142
            self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
143
3146.8.16 by Aaron Bentley
Updates from review
144
    def test_all_file_ids(self):
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
145
        work_tree = self.make_branch_and_tree('wt')
146
        tree = self.get_tree_no_parents_abc_content(work_tree)
147
        tree.lock_read()
148
        self.addCleanup(tree.unlock)
3146.8.16 by Aaron Bentley
Updates from review
149
        self.assertEqual(tree.all_file_ids(),
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
150
                         {tree.path2id('a'), tree.path2id(''),
151
                          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
152
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
153
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
154
class TestStoredKind(TestCaseWithTree):
155
156
    def test_stored_kind(self):
157
        tree = self.make_branch_and_tree('tree')
158
        work_tree = self.make_branch_and_tree('wt')
159
        tree = self.get_tree_no_parents_abc_content(work_tree)
160
        tree.lock_read()
161
        self.addCleanup(tree.unlock)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
162
        self.assertEqual('file', tree.stored_kind('a'))
163
        self.assertEqual('directory', tree.stored_kind('b'))
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
164
165
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
166
class TestFileContent(TestCaseWithTree):
167
168
    def test_get_file(self):
169
        work_tree = self.make_branch_and_tree('wt')
170
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
171
        a_id = tree.path2id('a')
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
172
        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
173
        self.addCleanup(tree.unlock)
174
        # Test lookup without path works
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
175
        file_without_path = tree.get_file('a')
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
176
        try:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
177
            lines = file_without_path.readlines()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
178
            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
179
        finally:
180
            file_without_path.close()
181
        # Test lookup with path works
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
182
        file_with_path = tree.get_file('a', a_id)
6437.20.6 by Martin Packman
Poke test_get_file in bt.per_tree.test_tree to be more careful about cleanup
183
        try:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
184
            lines = file_with_path.readlines()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
185
            self.assertEqual(['foobar\n'], lines)
186
        finally:
6437.20.2 by Wouter van Heyst
close files returned by transport.get
187
            file_with_path.close()
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
188
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
189
    def test_get_file_text(self):
190
        work_tree = self.make_branch_and_tree('wt')
191
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
192
        a_id = tree.path2id('a')
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
193
        tree.lock_read()
194
        self.addCleanup(tree.unlock)
195
        # test read by file-id
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
196
        self.assertEqual('foobar\n', tree.get_file_text('a', a_id))
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
197
        # test read by path
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
198
        self.assertEqual('foobar\n', tree.get_file_text('a'))
3774.1.1 by Aaron Bentley
Test Tree.get_file_text() and supply default implementation.
199
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
200
    def test_get_file_lines(self):
201
        work_tree = self.make_branch_and_tree('wt')
202
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
203
        a_id = tree.path2id('a')
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
204
        tree.lock_read()
205
        self.addCleanup(tree.unlock)
206
        # test read by file-id
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
207
        self.assertEqual(['foobar\n'], tree.get_file_lines('a', a_id))
3774.1.2 by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation
208
        # test read by path
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
209
        self.assertEqual(['foobar\n'], tree.get_file_lines('a'))
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
210
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
211
    def test_get_file_lines_multi_line_breaks(self):
212
        work_tree = self.make_branch_and_tree('wt')
6855.3.1 by Jelmer Vernooij
Several more fixes.
213
        self.build_tree_contents([('wt/foobar', b'a\rb\nc\r\nd')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
214
        work_tree.add('foobar')
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
215
        tree = self._convert_tree(work_tree)
216
        tree.lock_read()
217
        self.addCleanup(tree.unlock)
218
        self.assertEqual(['a\rb\n', 'c\r\n', 'd'],
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
219
                         tree.get_file_lines('foobar'))
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
220
221
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
222
class TestExtractFilesBytes(TestCaseWithTree):
223
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
224
    def test_iter_files_bytes(self):
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
225
        work_tree = self.make_branch_and_tree('wt')
6855.3.1 by Jelmer Vernooij
Several more fixes.
226
        self.build_tree_contents([('wt/foo', b'foo'),
227
                                  ('wt/bar', b'bar'),
228
                                  ('wt/baz', b'baz')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
229
        work_tree.add(['foo', 'bar', 'baz'])
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
230
        tree = self._convert_tree(work_tree)
231
        tree.lock_read()
232
        self.addCleanup(tree.unlock)
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
233
        extracted = dict((i, ''.join(b)) for i, b in
6874.2.1 by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids.
234
                         tree.iter_files_bytes([('foo', 'id1'),
235
                                                ('bar', 'id2'),
236
                                                ('baz', 'id3')]))
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
237
        self.assertEqual('foo', extracted['id1'])
238
        self.assertEqual('bar', extracted['id2'])
239
        self.assertEqual('baz', extracted['id3'])
6874.2.1 by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids.
240
        self.assertRaises(errors.NoSuchFile, lambda: list(
2708.1.11 by Aaron Bentley
Test and tweak error handling
241
                          tree.iter_files_bytes(
6874.2.1 by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids.
242
                          [('qux', 'file1-notpresent')])))
2748.2.2 by Lukáš Lalinsky
Add TestConflicts to tests.tree_implementations.test_tree. Update NEWS.
243
244
245
class TestConflicts(TestCaseWithTree):
246
247
    def test_conflicts(self):
248
        """Tree.conflicts() should return a ConflictList instance."""
249
        work_tree = self.make_branch_and_tree('wt')
250
        tree = self._convert_tree(work_tree)
2761.1.3 by Aaron Bentley
Update test to use assertIsInstance
251
        self.assertIsInstance(tree.conflicts(), conflicts.ConflictList)
3363.5.4 by Aaron Bentley
Fix iteration order of iter_entries_by_dir
252
253
254
class TestIterEntriesByDir(TestCaseWithTree):
255
256
    def test_iteration_order(self):
257
        work_tree = self.make_branch_and_tree('.')
258
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
259
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
260
        tree = self._convert_tree(work_tree)
261
        output_order = [p for p, e in tree.iter_entries_by_dir()]
262
        self.assertEqual(['', 'a', 'f', 'a/b', 'a/d', 'a/b/c', 'a/d/e', 'f/g'],
263
                         output_order)
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
264
265
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
266
class TestIterChildEntries(TestCaseWithTree):
267
268
    def test_iteration_order(self):
269
        work_tree = self.make_branch_and_tree('.')
270
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
271
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
272
        tree = self._convert_tree(work_tree)
273
        output = [e.name for e in
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
274
            tree.iter_child_entries('', tree.get_root_id())]
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
275
        self.assertEqual({'a', 'f'}, set(output))
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
276
        output = [e.name for e in
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
277
            tree.iter_child_entries('a', tree.path2id('a'))]
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
278
        self.assertEqual({'b', 'd'}, set(output))
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
279
280
    def test_does_not_exist(self):
281
        work_tree = self.make_branch_and_tree('.')
282
        self.build_tree(['a/'])
283
        work_tree.add(['a'])
284
        tree = self._convert_tree(work_tree)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
285
        self.assertRaises(errors.NoSuchFile, lambda:
6471.1.3 by Jelmer Vernooij
Add Tree.iter_child_entries.
286
            list(tree.iter_child_entries('unknown')))
287
288
3363.12.7 by Aaron Bentley
Add HasId test
289
class TestHasId(TestCaseWithTree):
290
291
    def test_has_id(self):
292
        work_tree = self.make_branch_and_tree('tree')
293
        self.build_tree(['tree/file'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
294
        work_tree.add('file')
295
        file_id = work_tree.path2id('file')
3363.12.7 by Aaron Bentley
Add HasId test
296
        tree = self._convert_tree(work_tree)
297
        tree.lock_read()
298
        self.addCleanup(tree.unlock)
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
299
        self.assertTrue(tree.has_id(file_id))
3363.12.7 by Aaron Bentley
Add HasId test
300
        self.assertFalse(tree.has_id('dir-id'))
3363.13.5 by Aaron Bentley
Merge with paths2ids
301
302
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
303
class TestExtras(TestCaseWithTree):
304
305
    def test_extras(self):
306
        work_tree = self.make_branch_and_tree('tree')
3363.13.4 by Aaron Bentley
Ensure versioned files are not listed by extras
307
        self.build_tree(['tree/file', 'tree/versioned-file'])
308
        work_tree.add(['file', 'versioned-file'])
309
        work_tree.commit('add files')
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
310
        work_tree.remove('file')
311
        tree = self._convert_tree(work_tree)
312
        if isinstance(tree,
313
                      (revisiontree.RevisionTree,
314
                       workingtree_4.DirStateRevisionTree)):
315
            expected = []
316
        else:
317
            expected = ['file']
318
        tree.lock_read()
319
        self.addCleanup(tree.unlock)
320
        self.assertEqual(expected, list(tree.extras()))
3363.15.1 by Aaron Bentley
Add test for has_id
321
3363.17.3 by Aaron Bentley
Merge with has_id
322
3363.15.4 by Aaron Bentley
Implement PreviewTree.get_file_sha1 properly
323
class TestGetFileSha1(TestCaseWithTree):
324
325
    def test_get_file_sha1(self):
326
        work_tree = self.make_branch_and_tree('tree')
6855.3.1 by Jelmer Vernooij
Several more fixes.
327
        self.build_tree_contents([('tree/file', b'file content')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
328
        work_tree.add('file')
3363.15.4 by Aaron Bentley
Implement PreviewTree.get_file_sha1 properly
329
        tree = self._convert_tree(work_tree)
330
        tree.lock_read()
331
        self.addCleanup(tree.unlock)
332
        expected = osutils.sha_strings('file content')
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
333
        self.assertEqual(expected, tree.get_file_sha1('file'))
5906.1.8 by Jelmer Vernooij
Tests.
334
335
336
class TestGetFileVerifier(TestCaseWithTree):
337
338
    def test_get_file_verifier(self):
339
        work_tree = self.make_branch_and_tree('tree')
340
        self.build_tree_contents([
6855.3.1 by Jelmer Vernooij
Several more fixes.
341
            ('tree/file1', b'file content'),
342
            ('tree/file2', b'file content')])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
343
        work_tree.add(['file1', 'file2'])
5906.1.8 by Jelmer Vernooij
Tests.
344
        tree = self._convert_tree(work_tree)
345
        tree.lock_read()
346
        self.addCleanup(tree.unlock)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
347
        (kind, data) = tree.get_file_verifier('file1')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
348
        self.assertEqual(
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
349
            tree.get_file_verifier('file1'),
350
            tree.get_file_verifier('file2'))
5906.1.10 by Jelmer Vernooij
sha1 -> SHA1
351
        if kind == "SHA1":
5906.1.8 by Jelmer Vernooij
Tests.
352
            expected = osutils.sha_strings('file content')
353
            self.assertEqual(expected, data)
6110.6.1 by Jelmer Vernooij
Add Tree.has_versioned_directories.
354
355
356
class TestHasVersionedDirectories(TestCaseWithTree):
357
358
    def test_has_versioned_directories(self):
359
        work_tree = self.make_branch_and_tree('tree')
360
        tree = self._convert_tree(work_tree)
6883.5.22 by Jelmer Vernooij
Review comments.
361
        self.assertIn(tree.has_versioned_directories(), (True, False))
6883.5.17 by Jelmer Vernooij
Add Tree.supports_rename_tracking().
362
363
364
class TestSupportsRenameTracking(TestCaseWithTree):
365
366
    def test_supports_rename_tracking(self):
367
        work_tree = self.make_branch_and_tree('tree')
368
        tree = self._convert_tree(work_tree)
369
        self.assertSubset([tree.supports_rename_tracking()], (True, False))