/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/test_tree.py

  • Committer: Ian Clatworthy
  • Date: 2008-12-15 06:18:29 UTC
  • mfrom: (3905 +trunk)
  • mto: (3586.1.23 views-ui)
  • mto: This revision was merged to the branch mainline in revision 4030.
  • Revision ID: ian.clatworthy@canonical.com-20081215061829-c8qwa93g71u9fsh5
merge bzr.dev 3905

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib import (
18
18
    errors,
 
19
    conflicts,
 
20
    osutils,
 
21
    revisiontree,
19
22
    tests,
20
 
    conflicts,
 
23
    workingtree_4,
21
24
    )
22
25
from bzrlib.tests import TestSkipped
23
26
from bzrlib.tests.tree_implementations import TestCaseWithTree
160
163
        finally:
161
164
            tree.unlock()
162
165
 
 
166
    def test_get_file_text(self):
 
167
        work_tree = self.make_branch_and_tree('wt')
 
168
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
 
169
        tree.lock_read()
 
170
        self.addCleanup(tree.unlock)
 
171
        # test read by file-id
 
172
        self.assertEqual('foobar\n', tree.get_file_text('a-id'))
 
173
        # test read by path
 
174
        self.assertEqual('foobar\n', tree.get_file_text('a-id', path='a'))
 
175
 
 
176
    def test_get_file_lines(self):
 
177
        work_tree = self.make_branch_and_tree('wt')
 
178
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
 
179
        tree.lock_read()
 
180
        self.addCleanup(tree.unlock)
 
181
        # test read by file-id
 
182
        self.assertEqual(['foobar\n'], tree.get_file_lines('a-id'))
 
183
        # test read by path
 
184
        self.assertEqual(['foobar\n'], tree.get_file_lines('a-id', path='a'))
 
185
 
 
186
    def test_get_file_lines_multi_line_breaks(self):
 
187
        work_tree = self.make_branch_and_tree('wt')
 
188
        self.build_tree_contents([('wt/foobar', 'a\rb\nc\r\nd')])
 
189
        work_tree.add('foobar', 'foobar-id')
 
190
        tree = self._convert_tree(work_tree)
 
191
        tree.lock_read()
 
192
        self.addCleanup(tree.unlock)
 
193
        self.assertEqual(['a\rb\n', 'c\r\n', 'd'],
 
194
                         tree.get_file_lines('foobar-id'))
 
195
 
163
196
 
164
197
class TestExtractFilesBytes(TestCaseWithTree):
165
198
 
203
236
        output_order = [p for p, e in tree.iter_entries_by_dir()]
204
237
        self.assertEqual(['', 'a', 'f', 'a/b', 'a/d', 'a/b/c', 'a/d/e', 'f/g'],
205
238
                         output_order)
 
239
 
 
240
 
 
241
class TestHasId(TestCaseWithTree):
 
242
 
 
243
    def test_has_id(self):
 
244
        work_tree = self.make_branch_and_tree('tree')
 
245
        self.build_tree(['tree/file'])
 
246
        work_tree.add('file', 'file-id')
 
247
        tree = self._convert_tree(work_tree)
 
248
        tree.lock_read()
 
249
        self.addCleanup(tree.unlock)
 
250
        self.assertTrue(tree.has_id('file-id'))
 
251
        self.assertFalse(tree.has_id('dir-id'))
 
252
 
 
253
    def test___contains__(self):
 
254
        work_tree = self.make_branch_and_tree('tree')
 
255
        self.build_tree(['tree/file'])
 
256
        work_tree.add('file', 'file-id')
 
257
        tree = self._convert_tree(work_tree)
 
258
        tree.lock_read()
 
259
        self.addCleanup(tree.unlock)
 
260
        self.assertTrue('file-id' in tree)
 
261
        self.assertFalse('dir-id' in tree)
 
262
 
 
263
 
 
264
class TestExtras(TestCaseWithTree):
 
265
 
 
266
    def test_extras(self):
 
267
        work_tree = self.make_branch_and_tree('tree')
 
268
        self.build_tree(['tree/file', 'tree/versioned-file'])
 
269
        work_tree.add(['file', 'versioned-file'])
 
270
        work_tree.commit('add files')
 
271
        work_tree.remove('file')
 
272
        tree = self._convert_tree(work_tree)
 
273
        if isinstance(tree,
 
274
                      (revisiontree.RevisionTree,
 
275
                       workingtree_4.DirStateRevisionTree)):
 
276
            expected = []
 
277
        else:
 
278
            expected = ['file']
 
279
        tree.lock_read()
 
280
        self.addCleanup(tree.unlock)
 
281
        self.assertEqual(expected, list(tree.extras()))
 
282
 
 
283
 
 
284
class TestGetFileSha1(TestCaseWithTree):
 
285
 
 
286
    def test_get_file_sha1(self):
 
287
        work_tree = self.make_branch_and_tree('tree')
 
288
        self.build_tree_contents([('tree/file', 'file content')])
 
289
        work_tree.add('file', 'file-id')
 
290
        tree = self._convert_tree(work_tree)
 
291
        tree.lock_read()
 
292
        self.addCleanup(tree.unlock)
 
293
        expected = osutils.sha_strings('file content')
 
294
        self.assertEqual(expected, tree.get_file_sha1('file-id'))