/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.7.83 by John Arbash Meinel
Update some obvious copyright headers to include 2007.
1
# Copyright (C) 2006, 2007 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
17
from bzrlib import (
18
    errors,
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
19
    conflicts,
20
    revisiontree,
2255.2.180 by Martin Pool
merge dirstate
21
    tests,
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
22
    workingtree_4,
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
23
    )
2338.4.4 by Marien Zwart
Increase test coverage.
24
from bzrlib.tests import TestSkipped
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
25
from bzrlib.tests.tree_implementations import TestCaseWithTree
26
27
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
28
1551.9.16 by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree
29
    def test_annotate(self):
30
        work_tree = self.make_branch_and_tree('wt')
31
        tree = self.get_tree_no_parents_abc_content(work_tree)
32
        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
33
        tree.lock_read()
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
34
        self.addCleanup(tree.unlock)
35
        for revision, line in tree.annotate_iter('a-id'):
36
            self.assertEqual('contents of a\n', line)
37
            self.assertEqual(tree_revision, revision)
38
        tree_revision = getattr(tree, 'get_revision_id', lambda: 'random:')()
39
        for revision, line in tree.annotate_iter('a-id', 'random:'):
40
            self.assertEqual('contents of a\n', line)
41
            self.assertEqual(tree_revision, revision)
42
43
1551.15.52 by Aaron Bentley
Tweak from review comments
44
class TestPlanFileMerge(TestCaseWithTree):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
45
1551.15.52 by Aaron Bentley
Tweak from review comments
46
    def test_plan_file_merge(self):
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
47
        work_a = self.make_branch_and_tree('wta')
48
        self.build_tree_contents([('wta/file', 'a\nb\nc\nd\n')])
49
        work_a.add('file', 'file-id')
50
        work_a.commit('base version')
51
        work_b = work_a.bzrdir.sprout('wtb').open_workingtree()
52
        self.build_tree_contents([('wta/file', 'b\nc\nd\ne\n')])
53
        tree_a = self.workingtree_to_test_tree(work_a)
54
        tree_a.lock_read()
55
        self.addCleanup(tree_a.unlock)
56
        self.build_tree_contents([('wtb/file', 'a\nc\nd\nf\n')])
57
        tree_b = self.workingtree_to_test_tree(work_b)
58
        tree_b.lock_read()
59
        self.addCleanup(tree_b.unlock)
60
        self.assertEqual([
3514.2.3 by John Arbash Meinel
Fix a failing test in tree_implementations
61
            ('killed-a', 'a\n'),
1551.15.48 by Aaron Bentley
Add tests for annotate and plan_merge
62
            ('killed-b', 'b\n'),
63
            ('unchanged', 'c\n'),
64
            ('unchanged', 'd\n'),
65
            ('new-a', 'e\n'),
66
            ('new-b', 'f\n'),
1551.15.52 by Aaron Bentley
Tweak from review comments
67
        ], list(tree_a.plan_file_merge('file-id', tree_b)))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
68
69
70
class TestReference(TestCaseWithTree):
71
72
    def skip_if_no_reference(self, tree):
73
        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.
74
            raise tests.TestNotApplicable('Tree references not supported')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
75
2100.3.27 by Aaron Bentley
Enable nested commits
76
    def create_nested(self):
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
77
        work_tree = self.make_branch_and_tree('wt')
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
78
        work_tree.lock_write()
79
        try:
80
            self.skip_if_no_reference(work_tree)
81
            subtree = self.make_branch_and_tree('wt/subtree')
82
            subtree.set_root_id('sub-root')
83
            subtree.commit('foo', rev_id='sub-1')
84
            work_tree.add_reference(subtree)
85
        finally:
86
            work_tree.unlock()
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
87
        tree = self._convert_tree(work_tree)
88
        self.skip_if_no_reference(tree)
2100.3.27 by Aaron Bentley
Enable nested commits
89
        return tree
90
91
    def test_get_reference_revision(self):
92
        tree = self.create_nested()
3504.2.1 by John Arbash Meinel
Shortcut iter_references when we know references aren't supported.
93
        tree.lock_read()
94
        self.addCleanup(tree.unlock)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
95
        path = tree.id2path('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.
96
        self.assertEqual('sub-1', tree.get_reference_revision('sub-root', path))
2100.3.27 by Aaron Bentley
Enable nested commits
97
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.
98
    def test_iter_references(self):
2100.3.27 by Aaron Bentley
Enable nested commits
99
        tree = self.create_nested()
2255.2.158 by Martin Pool
Most of the integration of dirstate and subtree
100
        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.
101
        self.addCleanup(tree.unlock)
102
        entry = tree.inventory['sub-root']
3504.2.1 by John Arbash Meinel
Shortcut iter_references when we know references aren't supported.
103
        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.
104
            list(tree.iter_references()))
2255.2.166 by Martin Pool
(broken) Add Tree.get_root_id() & test
105
106
    def test_get_root_id(self):
107
        # trees should return some kind of root id; it can be none
108
        tree = self.make_branch_and_tree('tree')
109
        root_id = tree.get_root_id()
110
        if root_id is not None:
111
            self.assertIsInstance(root_id, str)
2255.2.180 by Martin Pool
merge dirstate
112
113
2255.11.5 by Martin Pool
Tree.id2path should raise NoSuchId, not return None.
114
class TestFileIds(TestCaseWithTree):
115
116
    def test_id2path(self):
117
        # translate from file-id back to path
118
        work_tree = self.make_branch_and_tree('wt')
119
        tree = self.get_tree_no_parents_abc_content(work_tree)
120
        tree.lock_read()
121
        try:
122
            self.assertEqual(u'a', tree.id2path('a-id'))
123
            # other ids give an error- don't return None for this case
124
            self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
125
        finally:
126
            tree.unlock()
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
127
3146.8.16 by Aaron Bentley
Updates from review
128
    def test_all_file_ids(self):
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
129
        work_tree = self.make_branch_and_tree('wt')
130
        tree = self.get_tree_no_parents_abc_content(work_tree)
131
        tree.lock_read()
132
        self.addCleanup(tree.unlock)
3146.8.16 by Aaron Bentley
Updates from review
133
        self.assertEqual(tree.all_file_ids(),
3146.8.2 by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case
134
                         set(['b-id', 'root-id', 'c-id', 'a-id']))
135
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
136
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
137
class TestStoredKind(TestCaseWithTree):
138
139
    def test_stored_kind(self):
140
        tree = self.make_branch_and_tree('tree')
141
        work_tree = self.make_branch_and_tree('wt')
142
        tree = self.get_tree_no_parents_abc_content(work_tree)
143
        tree.lock_read()
144
        self.addCleanup(tree.unlock)
145
        self.assertEqual('file', tree.stored_kind('a-id'))
146
        self.assertEqual('directory', tree.stored_kind('b-id'))
147
148
2743.3.5 by Ian Clatworthy
Incorporate feedback from abentley
149
class TestFileContent(TestCaseWithTree):
150
151
    def test_get_file(self):
152
        work_tree = self.make_branch_and_tree('wt')
153
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
154
        tree.lock_read()
155
        try:
156
            # Test lookup without path works
157
            lines = tree.get_file('a-id').readlines()
158
            self.assertEqual(['foobar\n'], lines)
159
            # Test lookup with path works
160
            lines = tree.get_file('a-id', path='a').readlines()
161
            self.assertEqual(['foobar\n'], lines)
162
        finally:
163
            tree.unlock()
164
165
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
166
class TestExtractFilesBytes(TestCaseWithTree):
167
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
168
    def test_iter_files_bytes(self):
2708.1.1 by Aaron Bentley
Implement Tree.extract_files
169
        work_tree = self.make_branch_and_tree('wt')
170
        self.build_tree_contents([('wt/foo', 'foo'),
171
                                  ('wt/bar', 'bar'),
172
                                  ('wt/baz', 'baz')])
173
        work_tree.add(['foo', 'bar', 'baz'], ['foo-id', 'bar-id', 'baz-id'])
174
        tree = self._convert_tree(work_tree)
175
        tree.lock_read()
176
        self.addCleanup(tree.unlock)
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
177
        extracted = dict((i, ''.join(b)) for i, b in
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
178
                         tree.iter_files_bytes([('foo-id', 'id1'),
179
                                                ('bar-id', 'id2'),
180
                                                ('baz-id', 'id3')]))
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
181
        self.assertEqual('foo', extracted['id1'])
182
        self.assertEqual('bar', extracted['id2'])
183
        self.assertEqual('baz', extracted['id3'])
2708.1.11 by Aaron Bentley
Test and tweak error handling
184
        self.assertRaises(errors.NoSuchId, lambda: list(
185
                          tree.iter_files_bytes(
186
                          [('qux-id', 'file1-notpresent')])))
2748.2.2 by Lukáš Lalinsky
Add TestConflicts to tests.tree_implementations.test_tree. Update NEWS.
187
188
189
class TestConflicts(TestCaseWithTree):
190
191
    def test_conflicts(self):
192
        """Tree.conflicts() should return a ConflictList instance."""
193
        work_tree = self.make_branch_and_tree('wt')
194
        tree = self._convert_tree(work_tree)
2761.1.3 by Aaron Bentley
Update test to use assertIsInstance
195
        self.assertIsInstance(tree.conflicts(), conflicts.ConflictList)
3363.5.4 by Aaron Bentley
Fix iteration order of iter_entries_by_dir
196
197
198
class TestIterEntriesByDir(TestCaseWithTree):
199
200
    def test_iteration_order(self):
201
        work_tree = self.make_branch_and_tree('.')
202
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
203
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
204
        tree = self._convert_tree(work_tree)
205
        output_order = [p for p, e in tree.iter_entries_by_dir()]
206
        self.assertEqual(['', 'a', 'f', 'a/b', 'a/d', 'a/b/c', 'a/d/e', 'f/g'],
207
                         output_order)
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
208
209
3363.12.7 by Aaron Bentley
Add HasId test
210
class TestHasId(TestCaseWithTree):
211
212
    def test_has_id(self):
213
        work_tree = self.make_branch_and_tree('tree')
214
        self.build_tree(['tree/file'])
215
        work_tree.add('file', 'file-id')
216
        tree = self._convert_tree(work_tree)
217
        tree.lock_read()
218
        self.addCleanup(tree.unlock)
219
        self.assertTrue(tree.has_id('file-id'))
220
        self.assertFalse(tree.has_id('dir-id'))
3363.13.5 by Aaron Bentley
Merge with paths2ids
221
222
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
223
class TestExtras(TestCaseWithTree):
224
225
    def test_extras(self):
226
        work_tree = self.make_branch_and_tree('tree')
3363.13.4 by Aaron Bentley
Ensure versioned files are not listed by extras
227
        self.build_tree(['tree/file', 'tree/versioned-file'])
228
        work_tree.add(['file', 'versioned-file'])
229
        work_tree.commit('add files')
3363.13.1 by Aaron Bentley
Implement PreviewTree.extras
230
        work_tree.remove('file')
231
        tree = self._convert_tree(work_tree)
232
        if isinstance(tree,
233
                      (revisiontree.RevisionTree,
234
                       workingtree_4.DirStateRevisionTree)):
235
            expected = []
236
        else:
237
            expected = ['file']
238
        tree.lock_read()
239
        self.addCleanup(tree.unlock)
240
        self.assertEqual(expected, list(tree.extras()))