~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2007, 2009, 2010 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,
4789.16.1 by John Arbash Meinel
Tweak the PreviewTree.path_content_summary tests for executablity on windows.
24
    transform,
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
25
    )
26
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
27
from bzrlib.tests import per_tree
28
29
30
class TestPathContentSummary(per_tree.TestCaseWithTree):
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
31
32
    def _convert_tree(self, tree):
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
33
        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
34
        result.lock_read()
35
        self.addCleanup(result.unlock)
36
        return result
37
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
38
    def check_content_summary_size(self, tree, summary, expected_size):
39
        # if the tree supports content filters, then it's allowed to leave out
40
        # the size because it might be difficult to compute.  otherwise, it
41
        # must be present and correct
42
        returned_size = summary[1]
43
        if returned_size == expected_size or (
44
            tree.supports_content_filtering()
45
            and returned_size is None):
46
            pass
47
        else:
48
            self.fail("invalid size in summary: %r" % (returned_size,))
49
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
50
    def test_symlink_content_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
51
        self.requireFeature(tests.SymlinkFeature)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
52
        tree = self.make_branch_and_tree('tree')
53
        os.symlink('target', 'tree/path')
54
        tree.add(['path'])
55
        summary = self._convert_tree(tree).path_content_summary('path')
56
        self.assertEqual(('symlink', None, None, 'target'), summary)
57
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
58
    def test_unicode_symlink_content_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
59
        self.requireFeature(tests.SymlinkFeature)
60
        self.requireFeature(tests.UnicodeFilenameFeature)
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
61
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
62
        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.
63
        tree.add([u'\u03b2-path'])
64
        summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path')
65
        self.assertEqual(('symlink', None, None, 'target'), summary)
66
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
67
    def test_unicode_symlink_target_summary(self):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
68
        self.requireFeature(tests.SymlinkFeature)
69
        self.requireFeature(tests.UnicodeFilenameFeature)
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
70
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
71
        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.
72
        tree.add(['link'])
73
        summary = self._convert_tree(tree).path_content_summary('link')
74
        self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary)
75
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
76
    def test_missing_content_summary(self):
77
        tree = self.make_branch_and_tree('tree')
78
        summary = self._convert_tree(tree).path_content_summary('path')
79
        self.assertEqual(('missing', None, None, None), summary)
80
81
    def test_file_content_summary_executable(self):
82
        tree = self.make_branch_and_tree('tree')
83
        self.build_tree(['tree/path'])
84
        tree.add(['path'])
4789.16.1 by John Arbash Meinel
Tweak the PreviewTree.path_content_summary tests for executablity on windows.
85
        tt = transform.TreeTransform(tree)
86
        self.addCleanup(tt.finalize)
87
        tt.set_executability(True, tt.trans_id_tree_path('path'))
88
        tt.apply()
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
89
        summary = self._convert_tree(tree).path_content_summary('path')
90
        self.assertEqual(4, len(summary))
91
        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
92
        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
93
        # executable
94
        self.assertEqual(True, summary[2])
95
        # may have hash,
96
        self.assertSubset((summary[3],),
97
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
98
4789.15.1 by John Arbash Meinel
Have a defined result for Tree.path_content_summary() for unversioned files.
99
    def test_file_content_summary_not_versioned(self):
100
        tree = self.make_branch_and_tree('tree')
101
        self.build_tree(['tree/path'])
102
        tree = self._convert_tree(tree)
103
        summary = tree.path_content_summary('path')
104
        self.assertEqual(4, len(summary))
105
        if isinstance(tree, (per_tree.DirStateRevisionTree,
106
                             per_tree.RevisionTree)):
107
            self.assertEqual('missing', summary[0])
108
            self.assertIs(None, summary[2])
109
            self.assertIs(None, summary[3])
110
        elif isinstance(tree, transform._PreviewTree):
111
            self.expectFailure('PreviewTree returns "missing" for unversioned'
112
                'files', self.assertEqual, 'file', summary[0])
113
            self.assertEqual('file', summary[0])
114
        else:
115
            self.assertEqual('file', summary[0])
116
            self.check_content_summary_size(tree, summary, 22)
117
            self.assertEqual(False, summary[2])
118
        self.assertSubset((summary[3],),
119
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
120
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
121
    def test_file_content_summary_non_exec(self):
122
        tree = self.make_branch_and_tree('tree')
123
        self.build_tree(['tree/path'])
124
        tree.add(['path'])
125
        summary = self._convert_tree(tree).path_content_summary('path')
126
        self.assertEqual(4, len(summary))
127
        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
128
        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
129
        # not executable
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
130
        if osutils.supports_executable:
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
131
            self.assertEqual(False, summary[2])
132
        else:
133
            self.assertEqual(None, summary[2])
134
        # may have hash,
135
        self.assertSubset((summary[3],),
136
            (None, '0c352290ae1c26ca7f97d5b2906c4624784abd60'))
137
138
    def test_dir_content_summary(self):
139
        tree = self.make_branch_and_tree('tree')
140
        self.build_tree(['tree/path/'])
141
        tree.add(['path'])
142
        summary = self._convert_tree(tree).path_content_summary('path')
143
        self.assertEqual(('directory', None, None, None), summary)
144
145
    def test_tree_content_summary(self):
146
        tree = self.make_branch_and_tree('tree')
147
        subtree = self.make_branch_and_tree('tree/path')
148
        tree.add(['path'])
149
        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.
150
            raise tests.TestNotApplicable("Tree references not supported.")
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
151
        summary = self._convert_tree(tree).path_content_summary('path')
152
        self.assertEqual(4, len(summary))
153
        self.assertEqual('tree-reference', summary[0])