4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
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
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
16 |
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
17 |
"""Test that all Trees implement path_content_summary."""
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
18 |
|
19 |
import os |
|
20 |
||
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
21 |
from bzrlib import ( |
22 |
osutils, |
|
23 |
tests, |
|
4789.16.1
by John Arbash Meinel
Tweak the PreviewTree.path_content_summary tests for executablity on windows. |
24 |
transform, |
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
25 |
)
|
26 |
||
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
27 |
from bzrlib.tests import ( |
28 |
features, |
|
29 |
per_tree, |
|
30 |
)
|
|
31 |
from bzrlib.tests.features import ( |
|
32 |
SymlinkFeature, |
|
33 |
)
|
|
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
34 |
|
35 |
||
36 |
class TestPathContentSummary(per_tree.TestCaseWithTree): |
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
37 |
|
38 |
def _convert_tree(self, tree): |
|
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
39 |
result = per_tree.TestCaseWithTree._convert_tree(self, tree) |
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
40 |
result.lock_read() |
41 |
self.addCleanup(result.unlock) |
|
42 |
return result |
|
43 |
||
4595.11.17
by Martin Pool
Update tests for path_content_summary to reflect it may not return the size |
44 |
def check_content_summary_size(self, tree, summary, expected_size): |
45 |
# if the tree supports content filters, then it's allowed to leave out
|
|
46 |
# the size because it might be difficult to compute. otherwise, it
|
|
47 |
# must be present and correct
|
|
48 |
returned_size = summary[1] |
|
49 |
if returned_size == expected_size or ( |
|
50 |
tree.supports_content_filtering() |
|
51 |
and returned_size is None): |
|
52 |
pass
|
|
53 |
else: |
|
54 |
self.fail("invalid size in summary: %r" % (returned_size,)) |
|
55 |
||
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
56 |
def test_symlink_content_summary(self): |
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
57 |
self.requireFeature(SymlinkFeature) |
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
58 |
tree = self.make_branch_and_tree('tree') |
59 |
os.symlink('target', 'tree/path') |
|
60 |
tree.add(['path']) |
|
61 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
62 |
self.assertEqual(('symlink', None, None, 'target'), summary) |
|
63 |
||
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
64 |
def test_unicode_symlink_content_summary(self): |
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
65 |
self.requireFeature(features.SymlinkFeature) |
66 |
self.requireFeature(features.UnicodeFilenameFeature) |
|
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
67 |
tree = self.make_branch_and_tree('tree') |
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
68 |
os.symlink('target', u'tree/\u03b2-path'.encode(osutils._fs_enc)) |
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
69 |
tree.add([u'\u03b2-path']) |
70 |
summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path') |
|
71 |
self.assertEqual(('symlink', None, None, 'target'), summary) |
|
72 |
||
4095.3.1
by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets. |
73 |
def test_unicode_symlink_target_summary(self): |
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
74 |
self.requireFeature(features.SymlinkFeature) |
75 |
self.requireFeature(features.UnicodeFilenameFeature) |
|
4095.3.1
by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets. |
76 |
tree = self.make_branch_and_tree('tree') |
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
77 |
os.symlink(u'tree/\u03b2-path'.encode(osutils._fs_enc), 'tree/link') |
4095.3.1
by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets. |
78 |
tree.add(['link']) |
79 |
summary = self._convert_tree(tree).path_content_summary('link') |
|
80 |
self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary) |
|
81 |
||
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
82 |
def test_missing_content_summary(self): |
83 |
tree = self.make_branch_and_tree('tree') |
|
84 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
85 |
self.assertEqual(('missing', None, None, None), summary) |
|
86 |
||
87 |
def test_file_content_summary_executable(self): |
|
88 |
tree = self.make_branch_and_tree('tree') |
|
89 |
self.build_tree(['tree/path']) |
|
90 |
tree.add(['path']) |
|
4789.16.1
by John Arbash Meinel
Tweak the PreviewTree.path_content_summary tests for executablity on windows. |
91 |
tt = transform.TreeTransform(tree) |
92 |
self.addCleanup(tt.finalize) |
|
93 |
tt.set_executability(True, tt.trans_id_tree_path('path')) |
|
94 |
tt.apply() |
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
95 |
summary = self._convert_tree(tree).path_content_summary('path') |
96 |
self.assertEqual(4, len(summary)) |
|
97 |
self.assertEqual('file', summary[0]) |
|
4595.11.17
by Martin Pool
Update tests for path_content_summary to reflect it may not return the size |
98 |
self.check_content_summary_size(tree, summary, 22) |
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
99 |
# executable
|
100 |
self.assertEqual(True, summary[2]) |
|
101 |
# may have hash,
|
|
102 |
self.assertSubset((summary[3],), |
|
103 |
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60')) |
|
104 |
||
4789.15.1
by John Arbash Meinel
Have a defined result for Tree.path_content_summary() for unversioned files. |
105 |
def test_file_content_summary_not_versioned(self): |
106 |
tree = self.make_branch_and_tree('tree') |
|
107 |
self.build_tree(['tree/path']) |
|
108 |
tree = self._convert_tree(tree) |
|
109 |
summary = tree.path_content_summary('path') |
|
110 |
self.assertEqual(4, len(summary)) |
|
111 |
if isinstance(tree, (per_tree.DirStateRevisionTree, |
|
112 |
per_tree.RevisionTree)): |
|
113 |
self.assertEqual('missing', summary[0]) |
|
114 |
self.assertIs(None, summary[2]) |
|
115 |
self.assertIs(None, summary[3]) |
|
116 |
elif isinstance(tree, transform._PreviewTree): |
|
117 |
self.expectFailure('PreviewTree returns "missing" for unversioned' |
|
118 |
'files', self.assertEqual, 'file', summary[0]) |
|
119 |
self.assertEqual('file', summary[0]) |
|
120 |
else: |
|
121 |
self.assertEqual('file', summary[0]) |
|
122 |
self.check_content_summary_size(tree, summary, 22) |
|
123 |
self.assertEqual(False, summary[2]) |
|
124 |
self.assertSubset((summary[3],), |
|
125 |
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60')) |
|
126 |
||
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
127 |
def test_file_content_summary_non_exec(self): |
128 |
tree = self.make_branch_and_tree('tree') |
|
129 |
self.build_tree(['tree/path']) |
|
130 |
tree.add(['path']) |
|
131 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
132 |
self.assertEqual(4, len(summary)) |
|
133 |
self.assertEqual('file', summary[0]) |
|
4595.11.17
by Martin Pool
Update tests for path_content_summary to reflect it may not return the size |
134 |
self.check_content_summary_size(tree, summary, 22) |
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
135 |
# not executable
|
6379.7.1
by Jelmer Vernooij
Add and use WorkingTree._supports_executable. |
136 |
self.assertEqual(False, summary[2]) |
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
137 |
# may have hash,
|
138 |
self.assertSubset((summary[3],), |
|
139 |
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60')) |
|
140 |
||
141 |
def test_dir_content_summary(self): |
|
142 |
tree = self.make_branch_and_tree('tree') |
|
143 |
self.build_tree(['tree/path/']) |
|
144 |
tree.add(['path']) |
|
145 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
146 |
self.assertEqual(('directory', None, None, None), summary) |
|
147 |
||
148 |
def test_tree_content_summary(self): |
|
149 |
tree = self.make_branch_and_tree('tree') |
|
150 |
if not tree.branch.repository._format.supports_tree_reference: |
|
4285.2.1
by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests. |
151 |
raise tests.TestNotApplicable("Tree references not supported.") |
5786.1.1
by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference |
152 |
subtree = self.make_branch_and_tree('tree/path') |
153 |
tree.add(['path']) |
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
154 |
summary = self._convert_tree(tree).path_content_summary('path') |
155 |
self.assertEqual(4, len(summary)) |
|
156 |
self.assertEqual('tree-reference', summary[0]) |