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
|
|
|
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 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
21 |
from breezy import tests |
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
22 |
from breezy.mutabletree import MutableTree |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
23 |
from breezy.osutils import has_symlinks |
24 |
from breezy.tests.per_tree import TestCaseWithTree |
|
|
1852.15.5
by Robert Collins
Add missing test_walkdirs test file. |
25 |
|
26 |
||
27 |
class TestWalkdirs(TestCaseWithTree): |
|
28 |
||
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
29 |
def get_all_subdirs_expected(self, tree, symlinks): |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
30 |
empty_dirs_present = (tree.has_versioned_directories() |
31 |
or isinstance(tree, MutableTree)) |
|
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
32 |
empty_dirs_are_versioned = tree.has_versioned_directories() |
33 |
dirblocks = {} |
|
34 |
||
35 |
dirblocks[''] = [ |
|
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
36 |
('0file', '0file', 'file', None, 'file'), |
37 |
('1top-dir', '1top-dir', 'directory', None, 'directory'), |
|
38 |
(u'2utf\u1234file', u'2utf\u1234file', 'file', None, 'file')] |
|
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
39 |
|
40 |
dirblocks['1top-dir'] = [ |
|
41 |
('1top-dir/0file-in-1topdir', '0file-in-1topdir', |
|
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
42 |
'file', None, 'file')] |
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
43 |
if empty_dirs_present: |
44 |
dirblocks['1top-dir'].append( |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
45 |
('1top-dir/1dir-in-1topdir', '1dir-in-1topdir', 'directory', |
46 |
None if empty_dirs_are_versioned else os.stat( |
|
47 |
tree.abspath('1top-dir/1dir-in-1topdir')), |
|
48 |
'directory' if empty_dirs_are_versioned else None)) |
|
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
49 |
dirblocks['1top-dir/1dir-in-1topdir'] = [] |
|
2408.1.3
by Alexander Belchenko
tree_implementations: make usage of symlinks optional |
50 |
if symlinks: |
|
7096.3.6
by Jelmer Vernooij
Fix tests, on python 2 at least. |
51 |
dirblocks[''].append( |
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
52 |
('symlink', 'symlink', 'symlink', None, 'symlink')) |
53 |
return [(path, list(sorted(entries))) |
|
|
7116.1.1
by Jelmer Vernooij
Sort walkdir items. |
54 |
for (path, entries) in sorted(dirblocks.items())] |
|
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
55 |
|
|
1852.15.5
by Robert Collins
Add missing test_walkdirs test file. |
56 |
def test_walkdir_root(self): |
|
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
57 |
tree = self.get_tree_with_subdirs_and_all_supported_content_types( |
58 |
has_symlinks()) |
|
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
59 |
with tree.lock_read(): |
60 |
expected_dirblocks = self.get_all_subdirs_expected( |
|
61 |
tree, has_symlinks()) |
|
62 |
# test that its iterable by iterating
|
|
63 |
result = [] |
|
64 |
for dirinfo, block in tree.walkdirs(): |
|
65 |
newblock = [] |
|
66 |
for row in block: |
|
67 |
if row[4] is not None: |
|
68 |
newblock.append(row[0:3] + (None,) + row[4:]) |
|
69 |
else: |
|
70 |
newblock.append(row) |
|
71 |
result.append((dirinfo, newblock)) |
|
|
1852.15.7
by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs. |
72 |
# check each return value for debugging ease.
|
73 |
for pos, item in enumerate(expected_dirblocks): |
|
74 |
self.assertEqual(item, result[pos]) |
|
|
1852.15.11
by Robert Collins
Tree.walkdirs handles missing contents in workingtrees. |
75 |
self.assertEqual(len(expected_dirblocks), len(result)) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
76 |
|
|
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
77 |
def test_walkdir_subtree(self): |
|
6772.2.1
by Jelmer Vernooij
Avoid setting file ids in a few more cases. |
78 |
tree = self.get_tree_with_subdirs_and_all_supported_content_types( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
79 |
has_symlinks()) |
|
2255.2.84
by John Arbash Meinel
Remove now-unecessary encode/decode calls for revision ids. |
80 |
# test that its iterable by iterating
|
81 |
result = [] |
|
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
82 |
with tree.lock_read(): |
83 |
expected_dirblocks = self.get_all_subdirs_expected( |
|
84 |
tree, has_symlinks())[1:] |
|
85 |
for dirinfo, block in tree.walkdirs('1top-dir'): |
|
86 |
newblock = [] |
|
87 |
for row in block: |
|
88 |
if row[4] is not None: |
|
89 |
newblock.append(row[0:3] + (None,) + row[4:]) |
|
90 |
else: |
|
91 |
newblock.append(row) |
|
92 |
result.append((dirinfo, newblock)) |
|
|
1852.15.10
by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful. |
93 |
# check each return value for debugging ease.
|
94 |
for pos, item in enumerate(expected_dirblocks): |
|
95 |
self.assertEqual(item, result[pos]) |
|
|
1852.15.11
by Robert Collins
Tree.walkdirs handles missing contents in workingtrees. |
96 |
self.assertEqual(len(expected_dirblocks), len(result)) |
|
3363.9.10
by Aaron Bentley
Handle dangling file-ids correctly |
97 |
|
98 |
def test_walkdir_versioned_kind(self): |
|
99 |
work_tree = self.make_branch_and_tree('tree') |
|
100 |
self.build_tree(['tree/file', 'tree/dir/']) |
|
|
6772.2.1
by Jelmer Vernooij
Avoid setting file ids in a few more cases. |
101 |
work_tree.add(['file', 'dir']) |
|
3363.9.10
by Aaron Bentley
Handle dangling file-ids correctly |
102 |
os.unlink('tree/file') |
103 |
os.rmdir('tree/dir') |
|
104 |
tree = self._convert_tree(work_tree) |
|
105 |
tree.lock_read() |
|
106 |
self.addCleanup(tree.unlock) |
|
107 |
if tree.path2id('file') is None: |
|
108 |
raise tests.TestNotApplicable( |
|
109 |
'Tree type cannot represent dangling ids.') |
|
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
110 |
expected = [('', ([ |
111 |
('dir', 'dir', 'unknown', None, 'directory')] |
|
|
6862.5.1
by Jelmer Vernooij
Fix walkdirs tests for formats without versioned directories. |
112 |
if tree.has_versioned_directories() else []) + |
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
113 |
[('file', 'file', 'unknown', None, 'file')])] |
|
6862.5.1
by Jelmer Vernooij
Fix walkdirs tests for formats without versioned directories. |
114 |
if tree.has_versioned_directories(): |
|
7490.121.2
by Jelmer Vernooij
Fix some tests. |
115 |
expected.append(('dir', [])) |
|
3363.9.10
by Aaron Bentley
Handle dangling file-ids correctly |
116 |
self.assertEqual(expected, list(tree.walkdirs())) |