/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1852.16.5 by John Arbash Meinel
[merge] bzr.dev 2255, resolve conflicts, update copyrights
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
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
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
16
17
"""Tests for the generic Tree.walkdirs interface."""
18
3363.9.10 by Aaron Bentley
Handle dangling file-ids correctly
19
import os
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import tests
22
from breezy.osutils import has_symlinks
23
from breezy.tests.per_tree import TestCaseWithTree
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
24
25
26
class TestWalkdirs(TestCaseWithTree):
27
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
28
    def get_all_subdirs_expected(self, tree, symlinks):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
29
        dirblocks = [
30
            (('', tree.path2id('')),
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
31
             [('0file', '0file', 'file', None, tree.path2id('0file'), 'file'),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
32
              ('1top-dir', '1top-dir', 'directory', None,
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
33
               tree.path2id('1top-dir'), 'directory'),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
34
              (u'2utf\u1234file', u'2utf\u1234file', 'file', None,
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
35
               tree.path2id(u'2utf\u1234file'), 'file'),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
36
              ]),
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
37
            (('1top-dir', tree.path2id('1top-dir')),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
38
             [('1top-dir/0file-in-1topdir', '0file-in-1topdir',
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
39
               'file', None, tree.path2id('1top-dir/0file-in-1topdir'), 'file'),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
40
              ('1top-dir/1dir-in-1topdir', '1dir-in-1topdir',
6883.18.1 by Jelmer Vernooij
Support walkdirs when used for trees without versioned directories.
41
               'directory',
6883.18.2 by Jelmer Vernooij
Fix tests.
42
               None if tree.has_versioned_directories() else os.stat(tree.abspath('1top-dir/1dir-in-1topdir')),
6883.18.1 by Jelmer Vernooij
Support walkdirs when used for trees without versioned directories.
43
               tree.path2id('1top-dir/1dir-in-1topdir'),
6883.18.2 by Jelmer Vernooij
Fix tests.
44
               'directory' if tree.has_versioned_directories() else None,
45
              )]),
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
46
            (('1top-dir/1dir-in-1topdir', tree.path2id('1top-dir/1dir-in-1topdir')),
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
47
             []),
48
            ]
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
49
        if symlinks:
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
50
            dirblocks[0][1].append(('symlink', 'symlink', 'symlink', None,
6883.18.2 by Jelmer Vernooij
Fix tests.
51
                                    tree.path2id('symlink'), 'symlink'))
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
52
        return dirblocks
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
53
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
54
    def test_walkdir_root(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
55
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
56
            has_symlinks())
2255.2.84 by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids.
57
        tree.lock_read()
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
58
        expected_dirblocks = self.get_all_subdirs_expected(tree, has_symlinks())
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
59
        # test that its iterable by iterating
60
        result = []
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
61
        for dirinfo, block in tree.walkdirs():
62
            newblock = []
63
            for row in block:
64
                if row[4] is not None:
65
                    newblock.append(row[0:3] + (None,) + row[4:])
66
                else:
67
                    newblock.append(row)
68
            result.append((dirinfo, newblock))
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
69
        tree.unlock()
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
70
        # check each return value for debugging ease.
71
        for pos, item in enumerate(expected_dirblocks):
72
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
73
        self.assertEqual(len(expected_dirblocks), len(result))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
74
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
75
    def test_walkdir_subtree(self):
6772.2.1 by Jelmer Vernooij
Avoid setting file ids in a few more cases.
76
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
77
                has_symlinks())
2255.2.84 by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids.
78
        # test that its iterable by iterating
79
        result = []
80
        tree.lock_read()
6772.2.1 by Jelmer Vernooij
Avoid setting file ids in a few more cases.
81
        expected_dirblocks = self.get_all_subdirs_expected(
82
                tree, has_symlinks())[1:]
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
83
        for dirinfo, block in tree.walkdirs('1top-dir'):
84
            newblock = []
85
            for row in block:
86
                if row[4] is not None:
87
                    newblock.append(row[0:3] + (None,) + row[4:])
88
                else:
89
                    newblock.append(row)
90
            result.append((dirinfo, newblock))
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
91
        tree.unlock()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
92
        # check each return value for debugging ease.
93
        for pos, item in enumerate(expected_dirblocks):
94
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
95
        self.assertEqual(len(expected_dirblocks), len(result))
3363.9.10 by Aaron Bentley
Handle dangling file-ids correctly
96
97
    def test_walkdir_versioned_kind(self):
98
        work_tree = self.make_branch_and_tree('tree')
99
        self.build_tree(['tree/file', 'tree/dir/'])
6772.2.1 by Jelmer Vernooij
Avoid setting file ids in a few more cases.
100
        work_tree.add(['file', 'dir'])
101
        file_id = work_tree.path2id('file')
102
        dir_id = work_tree.path2id('dir')
3363.9.10 by Aaron Bentley
Handle dangling file-ids correctly
103
        os.unlink('tree/file')
104
        os.rmdir('tree/dir')
105
        tree = self._convert_tree(work_tree)
106
        tree.lock_read()
107
        self.addCleanup(tree.unlock)
108
        if tree.path2id('file') is None:
109
            raise tests.TestNotApplicable(
110
                'Tree type cannot represent dangling ids.')
6862.5.1 by Jelmer Vernooij
Fix walkdirs tests for formats without versioned directories.
111
        expected = [(('', work_tree.path2id('')), ([
112
            ('dir', 'dir', 'unknown', None, dir_id, 'directory')]
113
            if tree.has_versioned_directories() else []) +
114
            [('file', 'file', 'unknown', None, file_id, 'file')])]
115
        if tree.has_versioned_directories():
116
            expected.append((('dir', dir_id), []))
3363.9.10 by Aaron Bentley
Handle dangling file-ids correctly
117
        self.assertEqual(expected, list(tree.walkdirs()))