/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
1
# Copyright (C) 2007, 2009 Canonical Ltd
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
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
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
26
from bzrlib.tests import per_tree
27
28
29
class TestPathContentSummary(per_tree.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):
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
32
        result = per_tree.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
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
37
    def check_content_summary_size(self, tree, summary, expected_size):
38
        # if the tree supports content filters, then it's allowed to leave out
39
        # the size because it might be difficult to compute.  otherwise, it
40
        # must be present and correct
41
        returned_size = summary[1]
42
        if returned_size == expected_size or (
43
            tree.supports_content_filtering()
44
            and returned_size is None):
45
            pass
46
        else:
47
            self.fail("invalid size in summary: %r" % (returned_size,))
48
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
49
    def test_symlink_content_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
50
        self.requireFeature(tests.SymlinkFeature)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
51
        tree = self.make_branch_and_tree('tree')
52
        os.symlink('target', 'tree/path')
53
        tree.add(['path'])
54
        summary = self._convert_tree(tree).path_content_summary('path')
55
        self.assertEqual(('symlink', None, None, 'target'), summary)
56
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
57
    def test_unicode_symlink_content_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
58
        self.requireFeature(tests.SymlinkFeature)
59
        self.requireFeature(tests.UnicodeFilenameFeature)
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
60
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
61
        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.
62
        tree.add([u'\u03b2-path'])
63
        summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path')
64
        self.assertEqual(('symlink', None, None, 'target'), summary)
65
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
66
    def test_unicode_symlink_target_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
67
        self.requireFeature(tests.SymlinkFeature)
68
        self.requireFeature(tests.UnicodeFilenameFeature)
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
69
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
70
        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.
71
        tree.add(['link'])
72
        summary = self._convert_tree(tree).path_content_summary('link')
73
        self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary)
74
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
75
    def test_missing_content_summary(self):
76
        tree = self.make_branch_and_tree('tree')
77
        summary = self._convert_tree(tree).path_content_summary('path')
78
        self.assertEqual(('missing', None, None, None), summary)
79
80
    def test_file_content_summary_executable(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
81
        if not osutils.supports_executable():
82
            raise tests.TestNotApplicable()
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
83
        tree = self.make_branch_and_tree('tree')
84
        self.build_tree(['tree/path'])
85
        tree.add(['path'])
86
        current_mode = os.stat('tree/path').st_mode
87
        os.chmod('tree/path', current_mode | 0100)
88
        summary = self._convert_tree(tree).path_content_summary('path')
89
        self.assertEqual(4, len(summary))
90
        self.assertEqual('file', summary[0])
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
91
        self.check_content_summary_size(tree, summary, 22)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
92
        # executable
93
        self.assertEqual(True, summary[2])
94
        # may have hash,
95
        self.assertSubset((summary[3],),
96
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
97
98
    def test_file_content_summary_non_exec(self):
99
        tree = self.make_branch_and_tree('tree')
100
        self.build_tree(['tree/path'])
101
        tree.add(['path'])
102
        summary = self._convert_tree(tree).path_content_summary('path')
103
        self.assertEqual(4, len(summary))
104
        self.assertEqual('file', summary[0])
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
105
        self.check_content_summary_size(tree, summary, 22)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
106
        # not executable
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
107
        if osutils.supports_executable:
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
108
            self.assertEqual(False, summary[2])
109
        else:
110
            self.assertEqual(None, summary[2])
111
        # may have hash,
112
        self.assertSubset((summary[3],),
113
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
114
115
    def test_dir_content_summary(self):
116
        tree = self.make_branch_and_tree('tree')
117
        self.build_tree(['tree/path/'])
118
        tree.add(['path'])
119
        summary = self._convert_tree(tree).path_content_summary('path')
120
        self.assertEqual(('directory', None, None, None), summary)
121
122
    def test_tree_content_summary(self):
123
        tree = self.make_branch_and_tree('tree')
124
        subtree = self.make_branch_and_tree('tree/path')
125
        tree.add(['path'])
126
        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.
127
            raise tests.TestNotApplicable("Tree references not supported.")
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
128
        summary = self._convert_tree(tree).path_content_summary('path')
129
        self.assertEqual(4, len(summary))
130
        self.assertEqual('tree-reference', summary[0])