/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/test_walkdirs.py

Update a clean branch with the dirstate improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
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
 
 
24
    def get_all_subdirs_expected(self, tree):
 
25
        return [
 
26
            (('', tree.inventory.root.file_id),
 
27
            [
 
28
             ('0file', '0file', 'file', None, '2file', 'file'),
 
29
             ('1top-dir', '1top-dir', 'directory', None, '1top-dir', 'directory'),
 
30
             (u'2utf\u1234file', u'2utf\u1234file', 'file', None, u'0utf\u1234file', 'file'),
 
31
             ('symlink', 'symlink', 'symlink', None, 'symlink', 'symlink')
 
32
            ]),
 
33
            (('1top-dir', '1top-dir'),
 
34
            [('1top-dir/0file-in-1topdir', '0file-in-1topdir', 'file', None, '1file-in-1topdir', 'file'),
 
35
             ('1top-dir/1dir-in-1topdir', '1dir-in-1topdir', 'directory', None, '0dir-in-1topdir', 'directory'),
 
36
            ]),
 
37
            (('1top-dir/1dir-in-1topdir', '0dir-in-1topdir'),
 
38
            [
 
39
            ]),
 
40
            ]
 
41
 
 
42
    def test_walkdir_root(self):
 
43
        tree = self.get_tree_with_subdirs_and_all_content_types()
 
44
        expected_dirblocks = self.get_all_subdirs_expected(tree)
 
45
        # test that its iterable by iterating
 
46
        result = []
 
47
        for dirinfo, block in tree.walkdirs():
 
48
            newblock = []
 
49
            for row in block:
 
50
                if row[4] is not None:
 
51
                    newblock.append(row[0:3] + (None,) + row[4:])
 
52
                else:
 
53
                    newblock.append(row)
 
54
            result.append((dirinfo, newblock))
 
55
        # check each return value for debugging ease.
 
56
        for pos, item in enumerate(expected_dirblocks):
 
57
            self.assertEqual(item, result[pos])
 
58
        self.assertEqual(len(expected_dirblocks), len(result))
 
59
            
 
60
    def test_walkdir_subtree(self):
 
61
        tree = self.get_tree_with_subdirs_and_all_content_types()
 
62
        expected_dirblocks = self.get_all_subdirs_expected(tree)[1:]
 
63
        # test that its iterable by iterating
 
64
        result = []
 
65
        for dirinfo, block in tree.walkdirs('1top-dir'):
 
66
            newblock = []
 
67
            for row in block:
 
68
                if row[4] is not None:
 
69
                    newblock.append(row[0:3] + (None,) + row[4:])
 
70
                else:
 
71
                    newblock.append(row)
 
72
            result.append((dirinfo, newblock))
 
73
        # check each return value for debugging ease.
 
74
        for pos, item in enumerate(expected_dirblocks):
 
75
            self.assertEqual(item, result[pos])
 
76
        self.assertEqual(len(expected_dirblocks), len(result))