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 |
||
21 |
from bzrlib import tests |
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
22 |
from bzrlib.osutils import has_symlinks |
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
23 |
from bzrlib.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('')), |
|
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 |
]
|
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
46 |
if symlinks: |
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
47 |
dirblocks[0][1].append(('symlink', 'symlink', 'symlink', None, |
48 |
'symlink', 'symlink')) |
|
49 |
return dirblocks |
|
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
50 |
|
1852.15.5
by Robert Collins
Add missing test_walkdirs test file. |
51 |
def test_walkdir_root(self): |
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
52 |
tree = self.get_tree_with_subdirs_and_all_supported_content_types( |
53 |
has_symlinks()) |
|
2255.2.84
by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids. |
54 |
tree.lock_read() |
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
55 |
expected_dirblocks = self.get_all_subdirs_expected(tree, has_symlinks()) |
1852.15.5
by Robert Collins
Add missing test_walkdirs test file. |
56 |
# test that its iterable by iterating
|
57 |
result = [] |
|
1852.15.7
by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs. |
58 |
for dirinfo, block in tree.walkdirs(): |
59 |
newblock = [] |
|
60 |
for row in block: |
|
61 |
if row[4] is not None: |
|
62 |
newblock.append(row[0:3] + (None,) + row[4:]) |
|
63 |
else: |
|
64 |
newblock.append(row) |
|
65 |
result.append((dirinfo, newblock)) |
|
2255.2.18
by Robert Collins
Dirstate: all tree_implementation tests passing. |
66 |
tree.unlock() |
1852.15.7
by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs. |
67 |
# check each return value for debugging ease.
|
68 |
for pos, item in enumerate(expected_dirblocks): |
|
69 |
self.assertEqual(item, result[pos]) |
|
1852.15.11
by Robert Collins
Tree.walkdirs handles missing contents in workingtrees. |
70 |
self.assertEqual(len(expected_dirblocks), len(result)) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
71 |
|
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
72 |
def test_walkdir_subtree(self): |
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
73 |
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. |
74 |
# test that its iterable by iterating
|
75 |
result = [] |
|
76 |
tree.lock_read() |
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
77 |
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. |
78 |
for dirinfo, block in tree.walkdirs('1top-dir'): |
79 |
newblock = [] |
|
80 |
for row in block: |
|
81 |
if row[4] is not None: |
|
82 |
newblock.append(row[0:3] + (None,) + row[4:]) |
|
83 |
else: |
|
84 |
newblock.append(row) |
|
85 |
result.append((dirinfo, newblock)) |
|
2255.2.18
by Robert Collins
Dirstate: all tree_implementation tests passing. |
86 |
tree.unlock() |
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
87 |
# check each return value for debugging ease.
|
88 |
for pos, item in enumerate(expected_dirblocks): |
|
89 |
self.assertEqual(item, result[pos]) |
|
1852.15.11
by Robert Collins
Tree.walkdirs handles missing contents in workingtrees. |
90 |
self.assertEqual(len(expected_dirblocks), len(result)) |
3363.9.10
by Aaron Bentley
Handle dangling file-ids correctly |
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())) |