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