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