/brz/remove-bazaar

To get this branch, use:
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Test that all Tree's implement path_content_summary."""
18
19
import os
20
21
from bzrlib.osutils import supports_executable
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
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)
46
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'])
52
        tree.add(['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])
58
        # size must be known
59
        self.assertEqual(22, summary[1])
60
        # executable
61
        self.assertEqual(True, summary[2])
62
        # may have hash,
63
        self.assertSubset((summary[3],),
64
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
65
66
    def test_file_content_summary_non_exec(self):
67
        tree = self.make_branch_and_tree('tree')
68
        self.build_tree(['tree/path'])
69
        tree.add(['path'])
70
        summary = self._convert_tree(tree).path_content_summary('path')
71
        self.assertEqual(4, len(summary))
72
        self.assertEqual('file', summary[0])
73
        # size must be known
74
        self.assertEqual(22, summary[1])
75
        # not executable
76
        if supports_executable:
77
            self.assertEqual(False, summary[2])
78
        else:
79
            self.assertEqual(None, summary[2])
80
        # may have hash,
81
        self.assertSubset((summary[3],),
82
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
83
84
    def test_dir_content_summary(self):
85
        tree = self.make_branch_and_tree('tree')
86
        self.build_tree(['tree/path/'])
87
        tree.add(['path'])
88
        summary = self._convert_tree(tree).path_content_summary('path')
89
        self.assertEqual(('directory', None, None, None), summary)
90
91
    def test_tree_content_summary(self):
92
        tree = self.make_branch_and_tree('tree')
93
        subtree = self.make_branch_and_tree('tree/path')
94
        tree.add(['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])