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