/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
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')
45
        os.symlink('target', u'tree/\u03b2-path')
46
        tree.add([u'\u03b2-path'])
47
        summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path')
48
        self.assertEqual(('symlink', None, None, 'target'), summary)
49
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
50
    def test_missing_content_summary(self):
51
        tree = self.make_branch_and_tree('tree')
52
        summary = self._convert_tree(tree).path_content_summary('path')
53
        self.assertEqual(('missing', None, None, None), summary)
54
55
    def test_file_content_summary_executable(self):
56
        if not supports_executable():
57
            raise TestNotApplicable()
58
        tree = self.make_branch_and_tree('tree')
59
        self.build_tree(['tree/path'])
60
        tree.add(['path'])
61
        current_mode = os.stat('tree/path').st_mode
62
        os.chmod('tree/path', current_mode | 0100)
63
        summary = self._convert_tree(tree).path_content_summary('path')
64
        self.assertEqual(4, len(summary))
65
        self.assertEqual('file', summary[0])
66
        # size must be known
67
        self.assertEqual(22, summary[1])
68
        # executable
69
        self.assertEqual(True, summary[2])
70
        # may have hash,
71
        self.assertSubset((summary[3],),
72
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
73
74
    def test_file_content_summary_non_exec(self):
75
        tree = self.make_branch_and_tree('tree')
76
        self.build_tree(['tree/path'])
77
        tree.add(['path'])
78
        summary = self._convert_tree(tree).path_content_summary('path')
79
        self.assertEqual(4, len(summary))
80
        self.assertEqual('file', summary[0])
81
        # size must be known
82
        self.assertEqual(22, summary[1])
83
        # not executable
84
        if supports_executable:
85
            self.assertEqual(False, summary[2])
86
        else:
87
            self.assertEqual(None, summary[2])
88
        # may have hash,
89
        self.assertSubset((summary[3],),
90
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
91
92
    def test_dir_content_summary(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(('directory', None, None, None), summary)
98
99
    def test_tree_content_summary(self):
100
        tree = self.make_branch_and_tree('tree')
101
        subtree = self.make_branch_and_tree('tree/path')
102
        tree.add(['path'])
103
        if not tree.branch.repository._format.supports_tree_reference:
104
            raise TestSkipped("Tree references not supported.")
105
        summary = self._convert_tree(tree).path_content_summary('path')
106
        self.assertEqual(4, len(summary))
107
        self.assertEqual('tree-reference', summary[0])