~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

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
24
24
    )
25
25
from bzrlib.tests import TestSkipped
26
26
from bzrlib.tests.per_tree import TestCaseWithTree
 
27
from bzrlib.symbol_versioning import (
 
28
    deprecated_in,
 
29
    )
 
30
 
27
31
 
28
32
class TestAnnotate(TestCaseWithTree):
29
33
 
94
98
        tree.lock_read()
95
99
        self.addCleanup(tree.unlock)
96
100
        path = tree.id2path('sub-root')
97
 
        self.assertEqual('sub-1', tree.get_reference_revision('sub-root', path))
 
101
        self.assertEqual('sub-1',
 
102
            tree.get_reference_revision('sub-root', path))
98
103
 
99
104
    def test_iter_references(self):
100
105
        tree = self.create_nested()
101
106
        tree.lock_read()
102
107
        self.addCleanup(tree.unlock)
103
 
        entry = tree.inventory['sub-root']
 
108
        entry = tree.root_inventory['sub-root']
104
109
        self.assertEqual([(u'subtree', 'sub-root')],
105
110
            list(tree.iter_references()))
106
111
 
153
158
        work_tree = self.make_branch_and_tree('wt')
154
159
        tree = self.get_tree_no_parents_abc_content_2(work_tree)
155
160
        tree.lock_read()
156
 
        try:
157
 
            # Test lookup without path works
158
 
            lines = tree.get_file('a-id').readlines()
159
 
            self.assertEqual(['foobar\n'], lines)
160
 
            # Test lookup with path works
161
 
            lines = tree.get_file('a-id', path='a').readlines()
162
 
            self.assertEqual(['foobar\n'], lines)
163
 
        finally:
164
 
            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()
165
176
 
166
177
    def test_get_file_text(self):
167
178
        work_tree = self.make_branch_and_tree('wt')
238
249
                         output_order)
239
250
 
240
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
 
241
275
class TestHasId(TestCaseWithTree):
242
276
 
243
277
    def test_has_id(self):
257
291
        tree = self._convert_tree(work_tree)
258
292
        tree.lock_read()
259
293
        self.addCleanup(tree.unlock)
260
 
        self.assertTrue('file-id' in tree)
261
 
        self.assertFalse('dir-id' in tree)
 
294
        self.assertTrue(
 
295
            self.applyDeprecated(
 
296
                deprecated_in((2, 4, 0)),
 
297
                tree.__contains__, 'file-id'))
 
298
        self.assertFalse(
 
299
            self.applyDeprecated(
 
300
                deprecated_in((2, 4, 0)),
 
301
                tree.__contains__, 'dir-id'))
262
302
 
263
303
 
264
304
class TestExtras(TestCaseWithTree):
292
332
        self.addCleanup(tree.unlock)
293
333
        expected = osutils.sha_strings('file content')
294
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))