~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2008, 2009, 2010, 2012, 2016 Canonical Ltd
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
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
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
16
17
"""Tests for content filtering conformance"""
18
4443.2.7 by Ian Clatworthy
test and fix for revert with content filtering
19
import os
20
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
21
from bzrlib.controldir import ControlDir
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
22
from bzrlib.filters import ContentFilter
4443.2.6 by Ian Clatworthy
test switch with content filtering
23
from bzrlib.switch import switch
4393.3.9 by Ian Clatworthy
add test for filtered -> non-filtered branching
24
from bzrlib.workingtree import WorkingTree
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
25
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
26
27
3368.2.22 by Ian Clatworthy
more changes from abentley's review
28
def _converter_helper(chunks, fn):
29
    result = []
30
    for chunk in chunks:
31
        result.append(getattr(chunk, fn)())
32
    return iter(result)
33
34
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
35
def _swapcase(chunks, context=None):
3368.2.22 by Ian Clatworthy
more changes from abentley's review
36
    """A converter that swaps the case of text."""
37
    return _converter_helper(chunks, 'swapcase')
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
38
39
40
def _uppercase(chunks, context=None):
3368.2.22 by Ian Clatworthy
more changes from abentley's review
41
    """A converter that converts text to uppercase."""
42
    return _converter_helper(chunks, 'upper')
43
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
44
45
def _lowercase(chunks, context=None):
3368.2.22 by Ian Clatworthy
more changes from abentley's review
46
    """A converter that converts text to lowercase."""
47
    return _converter_helper(chunks, 'lower')
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
48
49
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
50
_trailer_string = '\nend string\n'
51
52
53
def _append_text(chunks, context=None):
54
    """A content filter that appends a string to the end of the file.
55
56
    This tests filters that change the length."""
57
    return chunks + [_trailer_string]
58
59
60
def _remove_appended_text(chunks, context=None):
61
    """Remove the appended text."""
62
63
    text = ''.join(chunks)
64
    if text.endswith(_trailer_string):
65
        text = text[:-len(_trailer_string)]
66
    return [text]
67
68
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
69
class TestWorkingTreeWithContentFilters(TestCaseWithWorkingTree):
70
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
71
    def create_cf_tree(self, txt_reader, txt_writer, dir='.'):
4393.3.9 by Ian Clatworthy
add test for filtered -> non-filtered branching
72
        tree = self.make_branch_and_tree(dir)
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
73
        def _content_filter_stack(path=None, file_id=None):
74
            if path.endswith('.txt'):
3368.2.22 by Ian Clatworthy
more changes from abentley's review
75
                return [ContentFilter(txt_reader, txt_writer)]
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
76
            else:
77
                return []
3368.2.22 by Ian Clatworthy
more changes from abentley's review
78
        tree._content_filter_stack = _content_filter_stack
79
        self.build_tree_contents([
4393.3.9 by Ian Clatworthy
add test for filtered -> non-filtered branching
80
            (dir + '/file1.txt', 'Foo Txt'),
81
            (dir + '/file2.bin', 'Foo Bin')])
3368.2.22 by Ian Clatworthy
more changes from abentley's review
82
        tree.add(['file1.txt', 'file2.bin'])
83
        tree.commit('commit raw content')
84
        txt_fileid = tree.path2id('file1.txt')
85
        bin_fileid = tree.path2id('file2.bin')
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
86
        return tree, txt_fileid, bin_fileid
87
88
    def create_cf_tree_with_two_revisions(self, txt_reader, txt_writer,
89
        dir='.'):
90
        tree = self.make_branch_and_tree(dir)
91
        def _content_filter_stack(path=None, file_id=None):
92
            if path.endswith('.txt'):
93
                return [ContentFilter(txt_reader, txt_writer)]
94
            else:
95
                return []
96
        tree._content_filter_stack = _content_filter_stack
97
        self.build_tree_contents([
98
            (dir + '/file1.txt', 'Foo Txt'),
99
            (dir + '/file2.bin', 'Foo Bin'),
100
            (dir + '/file3.txt', 'Bar Txt'),
101
            ])
102
        tree.add(['file1.txt', 'file2.bin', 'file3.txt'])
103
        tree.commit('commit raw content')
4634.102.6 by Ian Clatworthy
more test improvements
104
        fileid_1 = tree.path2id('file1.txt')
105
        fileid_2 = tree.path2id('file2.bin')
106
        fileid_3 = tree.path2id('file3.txt')
107
        # Commit another revision with various changes. We make sure
4634.103.2 by Ian Clatworthy
back out rename tests - they need to come later
108
        # the change includes a modification, an addition and a deletion.
109
        # Renames are more complex and need a separate set of tests later.
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
110
        self.build_tree_contents([
111
            (dir + '/file1.txt', 'Foo ROCKS!'),
4634.102.6 by Ian Clatworthy
more test improvements
112
            (dir + '/file4.txt', 'Hello World'),
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
113
            ])
4634.102.6 by Ian Clatworthy
more test improvements
114
        tree.add(['file4.txt'])
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
115
        tree.remove(['file3.txt'], keep_files=False)
116
        tree.commit("change, add and rename stuff")
4634.102.6 by Ian Clatworthy
more test improvements
117
        fileid_4 = tree.path2id('file4.txt')
118
        return tree, fileid_1, fileid_2, fileid_3, fileid_4
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
119
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
120
    def patch_in_content_filter(self):
4634.89.1 by Ian Clatworthy
(igc) Merge fix for reverting content filtered files
121
        # Patch in a custom, symmetric content filter stack. It's pretty gross
122
        # that we need to monkey-patch a class method to do this, bit it's
123
        # the easiest way currently given we don't have easy access to the
124
        # WorkingTree after it is created but before the filter stack is used
125
        # to populate content.
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
126
        def new_stack(tree, path=None, file_id=None):
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
127
            if path.endswith('.txt'):
128
                return [ContentFilter(_swapcase, _swapcase)]
129
            else:
130
                return []
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
131
        self.overrideAttr(WorkingTree, '_content_filter_stack', new_stack)
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
132
133
    def assert_basis_content(self, expected_content, branch, file_id):
4443.2.4 by Ian Clatworthy
add test for pull
134
        # Note: We need to use try/finally here instead of addCleanup()
135
        # as the latter leaves the read lock in place too long
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
136
        basis = branch.basis_tree()
137
        basis.lock_read()
4443.2.4 by Ian Clatworthy
add test for pull
138
        try:
139
            self.assertEqual(expected_content, basis.get_file_text(file_id))
140
        finally:
141
            basis.unlock()
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
142
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
143
    def test_symmetric_content_filtering(self):
144
        # test handling when read then write gives back the initial content
3368.2.22 by Ian Clatworthy
more changes from abentley's review
145
        tree, txt_fileid, bin_fileid = self.create_cf_tree(
146
            txt_reader=_swapcase, txt_writer=_swapcase)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
147
        # Check that the basis tree has the expected content
3368.2.22 by Ian Clatworthy
more changes from abentley's review
148
        basis = tree.basis_tree()
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
149
        basis.lock_read()
150
        self.addCleanup(basis.unlock)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
151
        if tree.supports_content_filtering():
152
            expected = "fOO tXT"
153
        else:
154
            expected = "Foo Txt"
155
        self.assertEqual(expected, basis.get_file_text(txt_fileid))
3368.2.22 by Ian Clatworthy
more changes from abentley's review
156
        self.assertEqual('Foo Bin', basis.get_file_text(bin_fileid))
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
157
        # Check that the working tree has the original content
3368.2.22 by Ian Clatworthy
more changes from abentley's review
158
        tree.lock_read()
159
        self.addCleanup(tree.unlock)
160
        self.assertEqual('Foo Txt', tree.get_file(txt_fileid,
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
161
            filtered=False).read())
3368.2.22 by Ian Clatworthy
more changes from abentley's review
162
        self.assertEqual('Foo Bin', tree.get_file(bin_fileid,
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
163
            filtered=False).read())
164
165
    def test_readonly_content_filtering(self):
166
        # test handling with a read filter but no write filter
3368.2.22 by Ian Clatworthy
more changes from abentley's review
167
        tree, txt_fileid, bin_fileid = self.create_cf_tree(
168
            txt_reader=_uppercase, txt_writer=None)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
169
        # Check that the basis tree has the expected content
3368.2.22 by Ian Clatworthy
more changes from abentley's review
170
        basis = tree.basis_tree()
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
171
        basis.lock_read()
172
        self.addCleanup(basis.unlock)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
173
        if tree.supports_content_filtering():
174
            expected = "FOO TXT"
175
        else:
176
            expected = "Foo Txt"
177
        self.assertEqual(expected, basis.get_file_text(txt_fileid))
3368.2.22 by Ian Clatworthy
more changes from abentley's review
178
        self.assertEqual('Foo Bin', basis.get_file_text(bin_fileid))
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
179
        # We expect the workingtree content to be unchanged (for now at least)
3368.2.22 by Ian Clatworthy
more changes from abentley's review
180
        tree.lock_read()
181
        self.addCleanup(tree.unlock)
182
        self.assertEqual('Foo Txt', tree.get_file(txt_fileid,
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
183
            filtered=False).read())
3368.2.22 by Ian Clatworthy
more changes from abentley's review
184
        self.assertEqual('Foo Bin', tree.get_file(bin_fileid,
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
185
            filtered=False).read())
4393.3.9 by Ian Clatworthy
add test for filtered -> non-filtered branching
186
187
    def test_branch_source_filtered_target_not(self):
188
        # Create a source branch with content filtering
189
        source, txt_fileid, bin_fileid = self.create_cf_tree(
190
            txt_reader=_uppercase, txt_writer=_lowercase, dir='source')
191
        if not source.supports_content_filtering():
192
            return
193
        self.assertFileEqual("Foo Txt", 'source/file1.txt')
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
194
        self.assert_basis_content("FOO TXT", source, txt_fileid)
4393.3.9 by Ian Clatworthy
add test for filtered -> non-filtered branching
195
196
        # Now branch it
197
        self.run_bzr('branch source target')
198
        target = WorkingTree.open('target')
199
        # Even though the content in source and target are different
200
        # due to different filters, iter_changes should be clean
201
        self.assertFileEqual("FOO TXT", 'target/file1.txt')
202
        changes = target.changes_from(source.basis_tree())
203
        self.assertFalse(changes.has_changed())
4393.3.10 by Ian Clatworthy
add test for non-filtered -> filtered branching
204
205
    def test_branch_source_not_filtered_target_is(self):
206
        # Create a source branch with content filtering
207
        source, txt_fileid, bin_fileid = self.create_cf_tree(
208
            txt_reader=None, txt_writer=None, dir='source')
209
        if not source.supports_content_filtering():
210
            return
211
        self.assertFileEqual("Foo Txt", 'source/file1.txt')
4443.2.3 by Ian Clatworthy
refactor some content filtering tests in preparation for adding more
212
        self.assert_basis_content("Foo Txt", source, txt_fileid)
213
214
        # Now patch in content filtering and branch the source
215
        self.patch_in_content_filter()
4393.3.10 by Ian Clatworthy
add test for non-filtered -> filtered branching
216
        self.run_bzr('branch source target')
217
        target = WorkingTree.open('target')
218
        # Even though the content in source and target are different
219
        # due to different filters, iter_changes should be clean
220
        self.assertFileEqual("fOO tXT", 'target/file1.txt')
221
        changes = target.changes_from(source.basis_tree())
222
        self.assertFalse(changes.has_changed())
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
223
4595.11.4 by Martin Pool
TestWorkingTreeWithContentFilters.test_path_content_summary is a known fail
224
    def test_path_content_summary(self):
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
225
        """path_content_summary should always talk about the canonical form."""
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
226
        # see https://bugs.launchpad.net/bzr/+bug/415508
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
227
        #
228
        # set up a tree where the canonical form has a string added to the
229
        # end
230
        source, txt_fileid, bin_fileid = self.create_cf_tree(
231
            txt_reader=_append_text,
232
            txt_writer=_remove_appended_text,
233
            dir='source')
234
        if not source.supports_content_filtering():
235
            return
236
        source.lock_read()
237
        self.addCleanup(source.unlock)
238
239
        expected_canonical_form = 'Foo Txt\nend string\n'
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
240
        self.assertEqual(source.get_file(txt_fileid, filtered=True).read(),
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
241
            expected_canonical_form)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
242
        self.assertEqual(source.get_file(txt_fileid, filtered=False).read(),
4595.11.3 by Martin Pool
Add test for path_content_summary with content filtering
243
            'Foo Txt')
244
245
        # results are: kind, size, executable, sha1_or_link_target
246
        result = source.path_content_summary('file1.txt')
4595.11.11 by Martin Pool
Split out _file_content_summary from path_content_summary and let it return None for size
247
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
248
        self.assertEqual(result,
4595.11.11 by Martin Pool
Split out _file_content_summary from path_content_summary and let it return None for size
249
            ('file', None, False, None))
250
251
        # we could give back the length of the canonical form, but in general
252
        # that will be expensive to compute, so it's acceptable to just return
253
        # None.
4443.2.4 by Ian Clatworthy
add test for pull
254
255
    def test_content_filtering_applied_on_pull(self):
256
        # Create a source branch with two revisions
4634.102.6 by Ian Clatworthy
more test improvements
257
        source, fileid_1, fileid_2, fileid_3, fileid_4 = \
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
258
            self.create_cf_tree_with_two_revisions(txt_reader=None,
259
            txt_writer=None, dir='source')
4443.2.4 by Ian Clatworthy
add test for pull
260
        if not source.supports_content_filtering():
261
            return
262
        self.assertFileEqual("Foo ROCKS!", 'source/file1.txt')
4634.102.6 by Ian Clatworthy
more test improvements
263
        self.assert_basis_content("Foo ROCKS!", source, fileid_1)
4443.2.4 by Ian Clatworthy
add test for pull
264
265
        # Now patch in content filtering and branch from revision 1
266
        self.patch_in_content_filter()
267
        self.run_bzr('branch -r1 source target')
268
        target = WorkingTree.open('target')
4634.103.1 by Ian Clatworthy
Handle additions and modfications
269
        self.assert_basis_content("Foo Txt", target, fileid_1)
4443.2.4 by Ian Clatworthy
add test for pull
270
        self.assertFileEqual("fOO tXT", 'target/file1.txt')
4634.103.1 by Ian Clatworthy
Handle additions and modfications
271
        self.assert_basis_content("Foo Bin", target, fileid_2)
272
        self.assertFileEqual("Foo Bin", 'target/file2.bin')
4634.102.6 by Ian Clatworthy
more test improvements
273
        self.assert_basis_content("Bar Txt", target, fileid_3)
4634.103.1 by Ian Clatworthy
Handle additions and modfications
274
        self.assertFileEqual("bAR tXT", 'target/file3.txt')
4443.2.4 by Ian Clatworthy
add test for pull
275
276
        # Pull the latter change and check the target tree is updated
277
        self.run_bzr('pull -d target')
4634.102.6 by Ian Clatworthy
more test improvements
278
        self.assert_basis_content("Foo ROCKS!", target, fileid_1)
4443.2.4 by Ian Clatworthy
add test for pull
279
        self.assertFileEqual("fOO rocks!", 'target/file1.txt')
4634.103.1 by Ian Clatworthy
Handle additions and modfications
280
        self.assert_basis_content("Foo Bin", target, fileid_2)
4634.102.6 by Ian Clatworthy
more test improvements
281
        self.assert_basis_content("Hello World", target, fileid_4)
282
        self.assertFileEqual("hELLO wORLD", 'target/file4.txt')
4443.2.5 by Ian Clatworthy
test merge with content filtering
283
284
    def test_content_filtering_applied_on_merge(self):
285
        # Create a source branch with two revisions
4634.102.6 by Ian Clatworthy
more test improvements
286
        source, fileid_1, fileid_2, fileid_3, fileid_4 = \
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
287
            self.create_cf_tree_with_two_revisions(txt_reader=None,
288
            txt_writer=None, dir='source')
4443.2.5 by Ian Clatworthy
test merge with content filtering
289
        if not source.supports_content_filtering():
290
            return
4634.102.6 by Ian Clatworthy
more test improvements
291
        self.assert_basis_content("Foo ROCKS!", source, fileid_1)
4443.2.5 by Ian Clatworthy
test merge with content filtering
292
        self.assertFileEqual("Foo ROCKS!", 'source/file1.txt')
4634.103.1 by Ian Clatworthy
Handle additions and modfications
293
        self.assert_basis_content("Foo Bin", source, fileid_2)
294
        self.assert_basis_content("Hello World", source, fileid_4)
295
        self.assertFileEqual("Hello World", 'source/file4.txt')
4443.2.5 by Ian Clatworthy
test merge with content filtering
296
297
        # Now patch in content filtering and branch from revision 1
298
        self.patch_in_content_filter()
299
        self.run_bzr('branch -r1 source target')
300
        target = WorkingTree.open('target')
4634.102.6 by Ian Clatworthy
more test improvements
301
        self.assert_basis_content("Foo Txt", target, fileid_1)
4443.2.5 by Ian Clatworthy
test merge with content filtering
302
        self.assertFileEqual("fOO tXT", 'target/file1.txt')
4634.102.6 by Ian Clatworthy
more test improvements
303
        self.assertFileEqual("Foo Bin", 'target/file2.bin')
304
        self.assertFileEqual("bAR tXT", 'target/file3.txt')
4443.2.5 by Ian Clatworthy
test merge with content filtering
305
306
        # Merge the latter change and check the target tree is updated
307
        self.run_bzr('merge -d target source')
308
        self.assertFileEqual("fOO rocks!", 'target/file1.txt')
4634.102.6 by Ian Clatworthy
more test improvements
309
        self.assertFileEqual("hELLO wORLD", 'target/file4.txt')
4443.2.5 by Ian Clatworthy
test merge with content filtering
310
311
        # Commit the merge and check the right content is stored
312
        target.commit("merge file1.txt changes from source")
4634.102.6 by Ian Clatworthy
more test improvements
313
        self.assert_basis_content("Foo ROCKS!", target, fileid_1)
314
        self.assert_basis_content("Hello World", target, fileid_4)
4443.2.6 by Ian Clatworthy
test switch with content filtering
315
316
    def test_content_filtering_applied_on_switch(self):
317
        # Create a source branch with two revisions
4634.102.6 by Ian Clatworthy
more test improvements
318
        source, fileid_1, fileid_2, fileid_3, fileid_4 = \
4634.102.5 by Ian Clatworthy
expand content filtering merge to include a rename
319
            self.create_cf_tree_with_two_revisions(txt_reader=None,
320
            txt_writer=None, dir='branch-a')
4443.2.6 by Ian Clatworthy
test switch with content filtering
321
        if not source.supports_content_filtering():
322
            return
323
324
        # Now patch in content filtering and branch from revision 1
325
        self.patch_in_content_filter()
326
        self.run_bzr('branch -r1 branch-a branch-b')
327
328
        # Now create a lightweight checkout referring to branch-b
329
        self.run_bzr('checkout --lightweight branch-b checkout')
330
        self.assertFileEqual("fOO tXT", 'checkout/file1.txt')
331
332
        # Switch it to branch-b and check the tree is updated
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
333
        checkout_control_dir = ControlDir.open_containing('checkout')[0]
4443.2.6 by Ian Clatworthy
test switch with content filtering
334
        switch(checkout_control_dir, source.branch)
335
        self.assertFileEqual("fOO rocks!", 'checkout/file1.txt')
4634.102.6 by Ian Clatworthy
more test improvements
336
        self.assertFileEqual("hELLO wORLD", 'checkout/file4.txt')
4443.2.7 by Ian Clatworthy
test and fix for revert with content filtering
337
4634.88.1 by Ian Clatworthy
Correctly revert trees with content filters
338
    def test_content_filtering_applied_on_revert_delete(self):
4443.2.7 by Ian Clatworthy
test and fix for revert with content filtering
339
        # Create a source branch with content filtering
340
        source, txt_fileid, bin_fileid = self.create_cf_tree(
341
            txt_reader=_uppercase, txt_writer=_lowercase, dir='source')
342
        if not source.supports_content_filtering():
343
            return
344
        self.assertFileEqual("Foo Txt", 'source/file1.txt')
345
        self.assert_basis_content("FOO TXT", source, txt_fileid)
346
347
        # Now delete the file, revert it and check the content
348
        os.unlink('source/file1.txt')
349
        self.assertFalse(os.path.exists('source/file1.txt'))
350
        source.revert(['file1.txt'])
351
        self.assertTrue(os.path.exists('source/file1.txt'))
352
        # Note: we don't get back exactly what was in the tree
353
        # previously because lower(upper(text)) is a lossy transformation
354
        self.assertFileEqual("foo txt", 'source/file1.txt')
4634.88.1 by Ian Clatworthy
Correctly revert trees with content filters
355
356
    def test_content_filtering_applied_on_revert_rename(self):
357
        # Create a source branch with content filtering
358
        source, txt_fileid, bin_fileid = self.create_cf_tree(
359
            txt_reader=_uppercase, txt_writer=_lowercase, dir='source')
360
        if not source.supports_content_filtering():
361
            return
362
        self.assertFileEqual("Foo Txt", 'source/file1.txt')
363
        self.assert_basis_content("FOO TXT", source, txt_fileid)
364
365
        # Now modify & rename a file, revert it and check the content
366
        self.build_tree_contents([
367
            ('source/file1.txt', 'Foo Txt with new content')])
368
        source.rename_one('file1.txt', 'file1.bin')
369
        self.assertTrue(os.path.exists('source/file1.bin'))
370
        self.assertFalse(os.path.exists('source/file1.txt'))
371
        self.assertFileEqual("Foo Txt with new content", 'source/file1.bin')
372
        source.revert(['file1.bin'])
373
        self.assertFalse(os.path.exists('source/file1.bin'))
374
        self.assertTrue(os.path.exists('source/file1.txt'))
375
        # Note: we don't get back exactly what was in the tree
376
        # previously because lower(upper(text)) is a lossy transformation
377
        self.assertFileEqual("foo txt", 'source/file1.txt')