1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test that all Tree's implement path_content_summary."""
21
from bzrlib.osutils import supports_executable
22
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable
23
from bzrlib.tests.tree_implementations import TestCaseWithTree
26
class TestPathContentSummary(TestCaseWithTree):
28
def _convert_tree(self, tree):
29
result = TestCaseWithTree._convert_tree(self, tree)
31
self.addCleanup(result.unlock)
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')
39
summary = self._convert_tree(tree).path_content_summary('path')
40
self.assertEqual(('symlink', None, None, 'target'), summary)
42
def test_missing_content_summary(self):
43
tree = self.make_branch_and_tree('tree')
44
summary = self._convert_tree(tree).path_content_summary('path')
45
self.assertEqual(('missing', None, None, None), summary)
47
def test_file_content_summary_executable(self):
48
if not supports_executable():
49
raise TestNotApplicable()
50
tree = self.make_branch_and_tree('tree')
51
self.build_tree(['tree/path'])
53
current_mode = os.stat('tree/path').st_mode
54
os.chmod('tree/path', current_mode | 0100)
55
summary = self._convert_tree(tree).path_content_summary('path')
56
self.assertEqual(4, len(summary))
57
self.assertEqual('file', summary[0])
59
self.assertEqual(22, summary[1])
61
self.assertEqual(True, summary[2])
63
self.assertSubset((summary[3],),
64
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
66
def test_file_content_summary_non_exec(self):
67
tree = self.make_branch_and_tree('tree')
68
self.build_tree(['tree/path'])
70
summary = self._convert_tree(tree).path_content_summary('path')
71
self.assertEqual(4, len(summary))
72
self.assertEqual('file', summary[0])
74
self.assertEqual(22, summary[1])
76
if supports_executable:
77
self.assertEqual(False, summary[2])
79
self.assertEqual(None, summary[2])
81
self.assertSubset((summary[3],),
82
(None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
84
def test_dir_content_summary(self):
85
tree = self.make_branch_and_tree('tree')
86
self.build_tree(['tree/path/'])
88
summary = self._convert_tree(tree).path_content_summary('path')
89
self.assertEqual(('directory', None, None, None), summary)
91
def test_tree_content_summary(self):
92
tree = self.make_branch_and_tree('tree')
93
subtree = self.make_branch_and_tree('tree/path')
95
if not tree.branch.repository._format.supports_tree_reference:
96
raise TestSkipped("Tree references not supported.")
97
summary = self._convert_tree(tree).path_content_summary('path')
98
self.assertEqual(4, len(summary))
99
self.assertEqual('tree-reference', summary[0])