~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2009, 2011, 2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
105
105
        tree = self.create_nested()
106
106
        tree.lock_read()
107
107
        self.addCleanup(tree.unlock)
108
 
        entry = tree.inventory['sub-root']
 
108
        entry = tree.root_inventory['sub-root']
109
109
        self.assertEqual([(u'subtree', 'sub-root')],
110
110
            list(tree.iter_references()))
111
111
 
158
158
        work_tree = self.make_branch_and_tree('wt')
159
159
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
160
160
        tree.lock_read()
161
 
        try:
162
 
            # Test lookup without path works
163
 
            lines = tree.get_file('a-id').readlines()
164
 
            self.assertEqual(['foobar\n'], lines)
165
 
            # Test lookup with path works
166
 
            lines = tree.get_file('a-id', path='a').readlines()
167
 
            self.assertEqual(['foobar\n'], lines)
168
 
        finally:
169
 
            tree.unlock()
 
161
        self.addCleanup(tree.unlock)
 
162
        # Test lookup without path works
 
163
        file_without_path = tree.get_file('a-id')
 
164
        try:
 
165
            lines = file_without_path.readlines()
 
166
            self.assertEqual(['foobar\n'], lines)
 
167
        finally:
 
168
            file_without_path.close()
 
169
        # Test lookup with path works
 
170
        file_with_path = tree.get_file('a-id', path='a')
 
171
        try:
 
172
            lines = file_with_path.readlines()
 
173
            self.assertEqual(['foobar\n'], lines)
 
174
        finally:
 
175
            file_with_path.close()
170
176
 
171
177
    def test_get_file_text(self):
172
178
        work_tree = self.make_branch_and_tree('wt')
243
249
                         output_order)
244
250
 
245
251
 
 
252
class TestIterChildEntries(TestCaseWithTree):
 
253
 
 
254
    def test_iteration_order(self):
 
255
        work_tree = self.make_branch_and_tree('.')
 
256
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d/', 'a/d/e', 'f/', 'f/g'])
 
257
        work_tree.add(['a', 'a/b', 'a/b/c', 'a/d', 'a/d/e', 'f', 'f/g'])
 
258
        tree = self._convert_tree(work_tree)
 
259
        output = [e.name for e in
 
260
            tree.iter_child_entries(tree.get_root_id())]
 
261
        self.assertEqual(set(['a', 'f']), set(output))
 
262
        output = [e.name for e in
 
263
            tree.iter_child_entries(tree.path2id('a'))]
 
264
        self.assertEqual(set(['b', 'd']), set(output))
 
265
 
 
266
    def test_does_not_exist(self):
 
267
        work_tree = self.make_branch_and_tree('.')
 
268
        self.build_tree(['a/'])
 
269
        work_tree.add(['a'])
 
270
        tree = self._convert_tree(work_tree)
 
271
        self.assertRaises(errors.NoSuchId, lambda:
 
272
            list(tree.iter_child_entries('unknown')))
 
273
 
 
274
 
246
275
class TestHasId(TestCaseWithTree):
247
276
 
248
277
    def test_has_id(self):
303
332
        self.addCleanup(tree.unlock)
304
333
        expected = osutils.sha_strings('file content')
305
334
        self.assertEqual(expected, tree.get_file_sha1('file-id'))
 
335
 
 
336
 
 
337
class TestGetFileVerifier(TestCaseWithTree):
 
338
 
 
339
    def test_get_file_verifier(self):
 
340
        work_tree = self.make_branch_and_tree('tree')
 
341
        self.build_tree_contents([
 
342
            ('tree/file1', 'file content'),
 
343
            ('tree/file2', 'file content')])
 
344
        work_tree.add(['file1', 'file2'], ['file-id-1', 'file-id-2'])
 
345
        tree = self._convert_tree(work_tree)
 
346
        tree.lock_read()
 
347
        self.addCleanup(tree.unlock)
 
348
        (kind, data) = tree.get_file_verifier('file-id-1')
 
349
        self.assertEqual(
 
350
            tree.get_file_verifier('file-id-1'),
 
351
            tree.get_file_verifier('file-id-2'))
 
352
        if kind == "SHA1":
 
353
            expected = osutils.sha_strings('file content')
 
354
            self.assertEqual(expected, data)
 
355
 
 
356
 
 
357
class TestHasVersionedDirectories(TestCaseWithTree):
 
358
 
 
359
    def test_has_versioned_directories(self):
 
360
        work_tree = self.make_branch_and_tree('tree')
 
361
        tree = self._convert_tree(work_tree)
 
362
        self.assertSubset([tree.has_versioned_directories()], (True, False))