/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
17
"""Test that all Trees implement path_content_summary."""
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
18
19
import os
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
28
    features,
29
    per_tree,
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.tests.features import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
32
    SymlinkFeature,
33
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
34
35
36
class TestPathContentSummary(per_tree.TestCaseWithTree):
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
37
38
    def _convert_tree(self, tree):
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
39
        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
40
        result.lock_read()
41
        self.addCleanup(result.unlock)
42
        return result
43
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
44
    def check_content_summary_size(self, tree, summary, expected_size):
45
        # if the tree supports content filters, then it's allowed to leave out
46
        # the size because it might be difficult to compute.  otherwise, it
47
        # must be present and correct
48
        returned_size = summary[1]
49
        if returned_size == expected_size or (
7143.15.2 by Jelmer Vernooij
Run autopep8.
50
                tree.supports_content_filtering()
51
                and returned_size is None):
4595.11.17 by Martin Pool
Update tests for path_content_summary to reflect it may not return the size
52
            pass
53
        else:
54
            self.fail("invalid size in summary: %r" % (returned_size,))
55
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
56
    def test_symlink_content_summary(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
57
        self.requireFeature(SymlinkFeature)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
58
        tree = self.make_branch_and_tree('tree')
59
        os.symlink('target', 'tree/path')
60
        tree.add(['path'])
61
        summary = self._convert_tree(tree).path_content_summary('path')
62
        self.assertEqual(('symlink', None, None, 'target'), summary)
63
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
64
    def test_unicode_symlink_content_summary(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
65
        self.requireFeature(features.SymlinkFeature)
66
        self.requireFeature(features.UnicodeFilenameFeature)
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
67
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
68
        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.
69
        tree.add([u'\u03b2-path'])
70
        summary = self._convert_tree(tree).path_content_summary(u'\u03b2-path')
71
        self.assertEqual(('symlink', None, None, 'target'), summary)
72
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
73
    def test_unicode_symlink_target_summary(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
74
        self.requireFeature(features.SymlinkFeature)
75
        self.requireFeature(features.UnicodeFilenameFeature)
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
76
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
77
        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.
78
        tree.add(['link'])
79
        summary = self._convert_tree(tree).path_content_summary('link')
80
        self.assertEqual(('symlink', None, None, u'tree/\u03b2-path'), summary)
81
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
82
    def test_missing_content_summary(self):
83
        tree = self.make_branch_and_tree('tree')
84
        summary = self._convert_tree(tree).path_content_summary('path')
85
        self.assertEqual(('missing', None, None, None), summary)
86
87
    def test_file_content_summary_executable(self):
88
        tree = self.make_branch_and_tree('tree')
89
        self.build_tree(['tree/path'])
90
        tree.add(['path'])
7350.3.4 by Jelmer Vernooij
Use context managers.
91
        with tree.get_transform() as tt:
92
            tt.set_executability(True, tt.trans_id_tree_path('path'))
93
            tt.apply()
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
94
        summary = self._convert_tree(tree).path_content_summary('path')
95
        self.assertEqual(4, len(summary))
96
        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
97
        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
98
        # executable
99
        self.assertEqual(True, summary[2])
100
        # may have hash,
101
        self.assertSubset((summary[3],),
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
                          (None, b'0c352290ae1c26ca7f97d5b2906c4624784abd60'))
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
103
4789.15.1 by John Arbash Meinel
Have a defined result for Tree.path_content_summary() for unversioned files.
104
    def test_file_content_summary_not_versioned(self):
105
        tree = self.make_branch_and_tree('tree')
106
        self.build_tree(['tree/path'])
107
        tree = self._convert_tree(tree)
108
        summary = tree.path_content_summary('path')
109
        self.assertEqual(4, len(summary))
110
        if isinstance(tree, (per_tree.DirStateRevisionTree,
111
                             per_tree.RevisionTree)):
112
            self.assertEqual('missing', summary[0])
113
            self.assertIs(None, summary[2])
114
            self.assertIs(None, summary[3])
115
        elif isinstance(tree, transform._PreviewTree):
116
            self.expectFailure('PreviewTree returns "missing" for unversioned'
7143.15.2 by Jelmer Vernooij
Run autopep8.
117
                               'files', self.assertEqual, 'file', summary[0])
4789.15.1 by John Arbash Meinel
Have a defined result for Tree.path_content_summary() for unversioned files.
118
            self.assertEqual('file', summary[0])
119
        else:
120
            self.assertEqual('file', summary[0])
121
            self.check_content_summary_size(tree, summary, 22)
122
            self.assertEqual(False, summary[2])
123
        self.assertSubset((summary[3],),
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                          (None, b'0c352290ae1c26ca7f97d5b2906c4624784abd60'))
4789.15.1 by John Arbash Meinel
Have a defined result for Tree.path_content_summary() for unversioned files.
125
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
126
    def test_file_content_summary_non_exec(self):
127
        tree = self.make_branch_and_tree('tree')
128
        self.build_tree(['tree/path'])
129
        tree.add(['path'])
130
        summary = self._convert_tree(tree).path_content_summary('path')
131
        self.assertEqual(4, len(summary))
132
        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
133
        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
134
        # not executable
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
135
        self.assertEqual(False, summary[2])
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
136
        # may have hash,
137
        self.assertSubset((summary[3],),
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                          (None, b'0c352290ae1c26ca7f97d5b2906c4624784abd60'))
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
139
140
    def test_dir_content_summary(self):
141
        tree = self.make_branch_and_tree('tree')
142
        self.build_tree(['tree/path/'])
143
        tree.add(['path'])
7096.3.2 by Jelmer Vernooij
Fix some git tests.
144
        converted_tree = self._convert_tree(tree)
145
        summary = converted_tree.path_content_summary('path')
146
        if converted_tree.has_versioned_directories() or converted_tree.has_filename('path'):
147
            self.assertEqual(('directory', None, None, None), summary)
148
        else:
149
            self.assertEqual(('missing', None, None, None), summary)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
150
151
    def test_tree_content_summary(self):
152
        tree = self.make_branch_and_tree('tree')
153
        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.
154
            raise tests.TestNotApplicable("Tree references not supported.")
5786.1.1 by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference
155
        subtree = self.make_branch_and_tree('tree/path')
6926.2.8 by Jelmer Vernooij
Fix some more tests.
156
        subtree.commit('')
5786.1.1 by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference
157
        tree.add(['path'])
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
158
        summary = self._convert_tree(tree).path_content_summary('path')
159
        self.assertEqual(4, len(summary))
160
        self.assertEqual('tree-reference', summary[0])