/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

merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the generic Tree.walkdirs interface."""
18
18
 
 
19
import os
 
20
 
 
21
from bzrlib import tests
19
22
from bzrlib.osutils import has_symlinks
20
23
from bzrlib.tests.tree_implementations import TestCaseWithTree
21
24
 
23
26
class TestWalkdirs(TestCaseWithTree):
24
27
 
25
28
    def get_all_subdirs_expected(self, tree, symlinks):
 
29
        dirblocks = [
 
30
            (('', tree.path2id('')),
 
31
             [('0file', '0file', 'file', None, '2file', 'file'),
 
32
              ('1top-dir', '1top-dir', 'directory', None,
 
33
               '1top-dir', 'directory'),
 
34
              (u'2utf\u1234file', u'2utf\u1234file', 'file', None,
 
35
               u'0utf\u1234file'.encode('utf8'), 'file'),
 
36
              ]),
 
37
            (('1top-dir', '1top-dir'),
 
38
             [('1top-dir/0file-in-1topdir', '0file-in-1topdir',
 
39
               'file', None, '1file-in-1topdir', 'file'),
 
40
              ('1top-dir/1dir-in-1topdir', '1dir-in-1topdir',
 
41
               'directory', None, '0dir-in-1topdir', 'directory'),
 
42
              ]),
 
43
            (('1top-dir/1dir-in-1topdir', '0dir-in-1topdir'),
 
44
             []),
 
45
            ]
26
46
        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
 
                ]
 
47
            dirblocks[0][1].append(('symlink', 'symlink', 'symlink', None,
 
48
                                    'symlink', 'symlink'))
 
49
        return dirblocks
61
50
 
62
51
    def test_walkdir_root(self):
63
 
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(has_symlinks())
 
52
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
 
53
            has_symlinks())
64
54
        tree.lock_read()
65
55
        expected_dirblocks = self.get_all_subdirs_expected(tree, has_symlinks())
66
56
        # test that its iterable by iterating
78
68
        for pos, item in enumerate(expected_dirblocks):
79
69
            self.assertEqual(item, result[pos])
80
70
        self.assertEqual(len(expected_dirblocks), len(result))
81
 
            
 
71
 
82
72
    def test_walkdir_subtree(self):
83
73
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(has_symlinks())
84
74
        # test that its iterable by iterating
98
88
        for pos, item in enumerate(expected_dirblocks):
99
89
            self.assertEqual(item, result[pos])
100
90
        self.assertEqual(len(expected_dirblocks), len(result))
 
91
 
 
92
    def test_walkdir_versioned_kind(self):
 
93
        work_tree = self.make_branch_and_tree('tree')
 
94
        work_tree.set_root_id('tree-root')
 
95
        self.build_tree(['tree/file', 'tree/dir/'])
 
96
        work_tree.add(['file', 'dir'], ['file-id', 'dir-id'])
 
97
        os.unlink('tree/file')
 
98
        os.rmdir('tree/dir')
 
99
        tree = self._convert_tree(work_tree)
 
100
        tree.lock_read()
 
101
        self.addCleanup(tree.unlock)
 
102
        if tree.path2id('file') is None:
 
103
            raise tests.TestNotApplicable(
 
104
                'Tree type cannot represent dangling ids.')
 
105
        expected = [(('', 'tree-root'), [
 
106
            ('dir', 'dir', 'unknown', None, 'dir-id', 'directory'),
 
107
            ('file', 'file', 'unknown', None, 'file-id', 'file')]),
 
108
            (('dir', 'dir-id'), [])]
 
109
        self.assertEqual(expected, list(tree.walkdirs()))