bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
1 |
# Copyright (C) 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
|
|
|
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 |
|
17 |
"""Test that all Tree's implement path_content_summary."""
|
|
18 |
||
19 |
import os |
|
20 |
||
|
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
21 |
from bzrlib.osutils import supports_executable, _fs_enc |
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
22 |
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable |
23 |
from bzrlib.tests.tree_implementations import TestCaseWithTree |
|
24 |
||
25 |
||
26 |
class TestPathContentSummary(TestCaseWithTree): |
|
27 |
||
28 |
def _convert_tree(self, tree): |
|
29 |
result = TestCaseWithTree._convert_tree(self, tree) |
|
30 |
result.lock_read() |
|
31 |
self.addCleanup(result.unlock) |
|
32 |
return result |
|
33 |
||
34 |
def test_symlink_content_summary(self): |
|
35 |
self.requireFeature(SymlinkFeature) |
|
36 |
tree = self.make_branch_and_tree('tree') |
|
37 |
os.symlink('target', 'tree/path') |
|
38 |
tree.add(['path']) |
|
39 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
40 |
self.assertEqual(('symlink', None, None, 'target'), summary) |
|
41 |
||
|
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
42 |
def test_unicode_symlink_content_summary(self): |
43 |
self.requireFeature(SymlinkFeature) |
|
44 |
tree = self.make_branch_and_tree('tree') |
|
|
3949.6.6
by Jelmer Vernooij
Skip unicode symlink tests on non-unicode file systems. |
45 |
try: |
46 |
os.symlink('target', u'tree/\u03b2-path'.encode(_fs_enc)) |
|
47 |
except UnicodeError: |
|
48 |
raise TestSkipped( |
|
49 |
'This platform does not support unicode file paths.') |
|
50 |
||
|
3949.6.1
by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename. |
51 |
tree.add([u'\u03b2-path']) |
52 |
summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path') |
|
53 |
self.assertEqual(('symlink', None, None, 'target'), summary) |
|
54 |
||
|
4095.3.1
by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets. |
55 |
def test_unicode_symlink_target_summary(self): |
56 |
self.requireFeature(SymlinkFeature) |
|
57 |
tree = self.make_branch_and_tree('tree') |
|
58 |
try: |
|
59 |
os.symlink(u'tree/\u03b2-path'.encode(_fs_enc), 'tree/link') |
|
60 |
except UnicodeError: |
|
61 |
raise TestSkipped( |
|
62 |
'This platform does not support unicode file paths.') |
|
63 |
||
64 |
tree.add(['link']) |
|
65 |
summary = self._convert_tree(tree).path_content_summary('link') |
|
66 |
self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary) |
|
67 |
||
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
68 |
def test_missing_content_summary(self): |
69 |
tree = self.make_branch_and_tree('tree') |
|
70 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
71 |
self.assertEqual(('missing', None, None, None), summary) |
|
72 |
||
73 |
def test_file_content_summary_executable(self): |
|
74 |
if not supports_executable(): |
|
75 |
raise TestNotApplicable() |
|
76 |
tree = self.make_branch_and_tree('tree') |
|
77 |
self.build_tree(['tree/path']) |
|
78 |
tree.add(['path']) |
|
79 |
current_mode = os.stat('tree/path').st_mode |
|
80 |
os.chmod('tree/path', current_mode | 0100) |
|
81 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
82 |
self.assertEqual(4, len(summary)) |
|
83 |
self.assertEqual('file', summary[0]) |
|
84 |
# size must be known
|
|
85 |
self.assertEqual(22, summary[1]) |
|
86 |
# executable
|
|
87 |
self.assertEqual(True, summary[2]) |
|
88 |
# may have hash,
|
|
89 |
self.assertSubset((summary[3],), |
|
90 |
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60')) |
|
91 |
||
92 |
def test_file_content_summary_non_exec(self): |
|
93 |
tree = self.make_branch_and_tree('tree') |
|
94 |
self.build_tree(['tree/path']) |
|
95 |
tree.add(['path']) |
|
96 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
97 |
self.assertEqual(4, len(summary)) |
|
98 |
self.assertEqual('file', summary[0]) |
|
99 |
# size must be known
|
|
100 |
self.assertEqual(22, summary[1]) |
|
101 |
# not executable
|
|
102 |
if supports_executable: |
|
103 |
self.assertEqual(False, summary[2]) |
|
104 |
else: |
|
105 |
self.assertEqual(None, summary[2]) |
|
106 |
# may have hash,
|
|
107 |
self.assertSubset((summary[3],), |
|
108 |
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60')) |
|
109 |
||
110 |
def test_dir_content_summary(self): |
|
111 |
tree = self.make_branch_and_tree('tree') |
|
112 |
self.build_tree(['tree/path/']) |
|
113 |
tree.add(['path']) |
|
114 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
115 |
self.assertEqual(('directory', None, None, None), summary) |
|
116 |
||
117 |
def test_tree_content_summary(self): |
|
118 |
tree = self.make_branch_and_tree('tree') |
|
119 |
subtree = self.make_branch_and_tree('tree/path') |
|
120 |
tree.add(['path']) |
|
121 |
if not tree.branch.repository._format.supports_tree_reference: |
|
122 |
raise TestSkipped("Tree references not supported.") |
|
123 |
summary = self._convert_tree(tree).path_content_summary('path') |
|
124 |
self.assertEqual(4, len(summary)) |
|
125 |
self.assertEqual('tree-reference', summary[0]) |