~bzr-pqm/bzr/bzr.dev

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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for the generic Tree.walkdirs interface."""
18
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
19
from bzrlib.osutils import has_symlinks
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
20
from bzrlib.tests.tree_implementations import TestCaseWithTree
21
22
23
class TestWalkdirs(TestCaseWithTree):
24
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
25
    def get_all_subdirs_expected(self, tree, symlinks):
26
        if symlinks:
27
            return [
28
                (('', tree.path2id('')),
29
                [
30
                 ('0file', '0file', 'file', None, '2file', 'file'),
31
                 ('1top-dir', '1top-dir', 'directory', None, '1top-dir', 'directory'),
32
                 (u'2utf\u1234file', u'2utf\u1234file', 'file', None,
33
                                         u'0utf\u1234file'.encode('utf8'), 'file'),
34
                 ('symlink', 'symlink', 'symlink', None, 'symlink', 'symlink')
35
                ]),
36
                (('1top-dir', '1top-dir'),
37
                [('1top-dir/0file-in-1topdir', '0file-in-1topdir', 'file', None, '1file-in-1topdir', 'file'),
38
                 ('1top-dir/1dir-in-1topdir', '1dir-in-1topdir', 'directory', None, '0dir-in-1topdir', 'directory'),
39
                ]),
40
                (('1top-dir/1dir-in-1topdir', '0dir-in-1topdir'),
41
                [
42
                ]),
43
                ]
44
        else:
45
            return [
46
                (('', tree.path2id('')),
47
                [
48
                 ('0file', '0file', 'file', None, '2file', 'file'),
49
                 ('1top-dir', '1top-dir', 'directory', None, '1top-dir', 'directory'),
50
                 (u'2utf\u1234file', u'2utf\u1234file', 'file', None,
51
                                         u'0utf\u1234file'.encode('utf8'), 'file'),
52
                ]),
53
                (('1top-dir', '1top-dir'),
54
                [('1top-dir/0file-in-1topdir', '0file-in-1topdir', 'file', None, '1file-in-1topdir', 'file'),
55
                 ('1top-dir/1dir-in-1topdir', '1dir-in-1topdir', 'directory', None, '0dir-in-1topdir', 'directory'),
56
                ]),
57
                (('1top-dir/1dir-in-1topdir', '0dir-in-1topdir'),
58
                [
59
                ]),
60
                ]
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
61
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
62
    def test_walkdir_root(self):
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
63
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(has_symlinks())
2255.2.84 by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids.
64
        tree.lock_read()
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
65
        expected_dirblocks = self.get_all_subdirs_expected(tree, has_symlinks())
1852.15.5 by Robert Collins
Add missing test_walkdirs test file.
66
        # test that its iterable by iterating
67
        result = []
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
68
        for dirinfo, block in tree.walkdirs():
69
            newblock = []
70
            for row in block:
71
                if row[4] is not None:
72
                    newblock.append(row[0:3] + (None,) + row[4:])
73
                else:
74
                    newblock.append(row)
75
            result.append((dirinfo, newblock))
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
76
        tree.unlock()
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
77
        # check each return value for debugging ease.
78
        for pos, item in enumerate(expected_dirblocks):
79
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
80
        self.assertEqual(len(expected_dirblocks), len(result))
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
81
            
82
    def test_walkdir_subtree(self):
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
83
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(has_symlinks())
2255.2.84 by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids.
84
        # test that its iterable by iterating
85
        result = []
86
        tree.lock_read()
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
87
        expected_dirblocks = self.get_all_subdirs_expected(tree, has_symlinks())[1:]
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
88
        for dirinfo, block in tree.walkdirs('1top-dir'):
89
            newblock = []
90
            for row in block:
91
                if row[4] is not None:
92
                    newblock.append(row[0:3] + (None,) + row[4:])
93
                else:
94
                    newblock.append(row)
95
            result.append((dirinfo, newblock))
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
96
        tree.unlock()
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
97
        # check each return value for debugging ease.
98
        for pos, item in enumerate(expected_dirblocks):
99
            self.assertEqual(item, result[pos])
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
100
        self.assertEqual(len(expected_dirblocks), len(result))