/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2007, 2009-2012, 2016 Canonical Ltd
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
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
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
16
17
"""Test that we can use smart_add on all Tree implementations."""
18
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
19
import os
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
20
import sys
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
23
    errors,
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
24
    ignores,
25
    osutils,
2568.2.10 by Robert Collins
And a missing import.
26
    tests,
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
27
    trace,
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
28
    workingtree,
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
31
    BytesIO,
32
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
34
    features,
35
    per_workingtree,
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
36
    test_smart_add,
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
37
    )
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
38
39
40
class TestSmartAddTree(per_workingtree.TestCaseWithWorkingTree):
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
41
42
    def test_single_file(self):
43
        tree = self.make_branch_and_tree('tree')
44
        self.build_tree(['tree/a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
45
        tree.smart_add(['tree'])
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
46
47
        tree.lock_read()
48
        try:
49
            files = [(path, status, kind)
50
                     for path, status, kind, file_id, parent_id
51
                      in tree.list_files(include_root=True)]
52
        finally:
53
            tree.unlock()
54
        self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
55
                         files)
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
56
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
57
    def assertFilenameSkipped(self, filename):
58
        tree = self.make_branch_and_tree('tree')
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
59
        try:
60
            self.build_tree(['tree/'+filename])
61
        except errors.NoSuchFile:
62
            if sys.platform == 'win32':
63
                raise tests.TestNotApplicable('Cannot create files named %r on'
64
                    ' win32' % (filename,))
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
65
        tree.smart_add(['tree'])
66
        self.assertEqual(None, tree.path2id(filename))
67
68
    def test_path_containing_newline_skips(self):
69
        self.assertFilenameSkipped('a\nb')
70
71
    def test_path_containing_carriagereturn_skips(self):
72
        self.assertFilenameSkipped('a\rb')
73
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
74
    def test_save_false(self):
75
        """Dry-run add doesn't permanently affect the tree."""
76
        wt = self.make_branch_and_tree('.')
2585.1.1 by Aaron Bentley
Unify MutableTree.smart_add behavior by disabling quirky memory-only Inventory
77
        wt.lock_write()
78
        try:
79
            self.build_tree(['file'])
80
            wt.smart_add(['file'], save=False)
81
            # the file should not be added - no id.
82
            self.assertEqual(wt.path2id('file'), None)
83
        finally:
84
            wt.unlock()
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
85
        # and the disk state should be the same - reopen to check.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
86
        wt = wt.controldir.open_workingtree()
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
87
        self.assertFalse(wt.is_versioned('file'))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
88
89
    def test_add_dot_from_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
90
        """Test adding . from the root of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
91
        paths = ("original/", "original/file1", "original/file2")
92
        self.build_tree(paths)
93
        wt = self.make_branch_and_tree('.')
94
        wt.smart_add((u".",))
95
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
96
            self.assertTrue(wt.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
97
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
98
    def test_skip_nested_trees(self):
99
        """Test smart-adding a nested tree ignors it and warns."""
100
        wt = self.make_branch_and_tree('.')
101
        nested_wt = self.make_branch_and_tree('nested')
102
        warnings = []
103
        def warning(*args):
104
            warnings.append(args[0] % args[1:])
105
        self.overrideAttr(trace, 'warning', warning)
106
        wt.smart_add((u".",))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
107
        self.assertFalse(wt.is_versioned("nested"))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
108
        self.assertEqual(
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
109
            ['skipping nested tree %r' % nested_wt.basedir], warnings)
110
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
111
    def test_add_dot_from_subdir(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
112
        """Test adding . from a subdir of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
113
        paths = ("original/", "original/file1", "original/file2")
114
        self.build_tree(paths)
115
        wt = self.make_branch_and_tree('.')
116
        wt.smart_add((u".",))
117
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
118
            self.assertTrue(wt.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
119
120
    def test_add_tree_from_above_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
121
        """Test adding a tree from above the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
122
        paths = ("original/", "original/file1", "original/file2")
123
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
124
                        "branch/original/file2")
125
        self.build_tree(branch_paths)
126
        wt = self.make_branch_and_tree('branch')
127
        wt.smart_add(("branch",))
128
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
129
            self.assertTrue(wt.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
130
131
    def test_add_above_tree_preserves_tree(self):
132
        """Test nested trees are not affect by an add above them."""
133
        paths = ("original/", "original/file1", "original/file2")
134
        child_paths = ("path",)
135
        full_child_paths = ("original/child", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
136
        build_paths = ("original/", "original/file1", "original/file2",
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
137
                       "original/child/", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
138
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
139
        self.build_tree(build_paths)
140
        wt = self.make_branch_and_tree('.')
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
141
        if wt.controldir.user_url != wt.branch.controldir.user_url:
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
142
            # Lightweight checkout, make sure we have a repo location.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
143
            wt.branch.controldir.root_transport.mkdir('original')
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
144
        child_tree = self.make_branch_and_tree('original/child')
145
        wt.smart_add((".",))
146
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
147
            self.assertNotEqual((path, wt.is_versioned(path)),
148
                                (path, False))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
149
        for path in full_child_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
150
            self.assertEqual((path, wt.is_versioned(path)),
151
                             (path, False))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
152
        for path in child_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
153
            self.assertFalse(child_tree.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
154
155
    def test_add_paths(self):
156
        """Test smart-adding a list of paths."""
157
        paths = ("file1", "file2")
158
        self.build_tree(paths)
159
        wt = self.make_branch_and_tree('.')
160
        wt.smart_add(paths)
161
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
162
            self.assertTrue(wt.is_versioned(path))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
163
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
164
    def test_add_ignored_nested_paths(self):
165
        """Test smart-adding a list of paths which includes ignored ones."""
166
        wt = self.make_branch_and_tree('.')
167
        tree_shape = ("adir/", "adir/CVS/", "adir/CVS/afile", "adir/CVS/afile2")
168
        add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
169
        expected_paths = ("adir", "adir/CVS", "adir/CVS/afile", "adir/CVS/afile2")
170
        self.build_tree(tree_shape)
171
        wt.smart_add(add_paths)
172
        for path in expected_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
173
            self.assertTrue(wt.is_versioned(path), "No id added for %s" % path)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
174
175
    def test_add_non_existant(self):
176
        """Test smart-adding a file that does not exist."""
177
        wt = self.make_branch_and_tree('.')
178
        self.assertRaises(errors.NoSuchFile, wt.smart_add, ['non-existant-file'])
179
180
    def test_returns_and_ignores(self):
181
        """Correctly returns added/ignored files"""
182
        wt = self.make_branch_and_tree('.')
183
        # The default ignore list includes '*.py[co]', but not CVS
184
        ignores._set_user_ignores(['*.py[co]'])
185
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
186
                        'inertiatic/foo.pyc'])
187
        added, ignored = wt.smart_add(u'.')
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
188
        if wt.has_versioned_directories():
189
            self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
190
                              added)
191
        else:
192
            self.assertSubset(('inertiatic/esp', 'inertiatic/CVS'),
193
                              added)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
194
        self.assertSubset(('*.py[co]',), ignored)
195
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[co]'])
196
197
    def test_add_multiple_dirs(self):
198
        """Test smart adding multiple directories at once."""
199
        added_paths = ['file1', 'file2',
200
                       'dir1/', 'dir1/file3',
201
                       'dir1/subdir2/', 'dir1/subdir2/file4',
202
                       'dir2/', 'dir2/file5',
203
                      ]
204
        not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
205
        self.build_tree(added_paths)
206
        self.build_tree(not_added)
207
208
        wt = self.make_branch_and_tree('.')
209
        wt.smart_add(['file1', 'file2', 'dir1', 'dir2'])
210
211
        for path in added_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
212
            self.assertTrue(wt.is_versioned(path.rstrip('/')),
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
213
                    'Failed to add path: %s' % (path,))
214
        for path in not_added:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
215
            self.assertFalse(wt.is_versioned(path.rstrip('/')),
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
216
                    'Accidentally added path: %s' % (path,))
217
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
218
    def test_add_file_in_unknown_dir(self):
219
        # Test that parent directory addition is implicit
220
        tree = self.make_branch_and_tree('.')
221
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
222
        tree.smart_add(['dir/subdir/foo'])
223
        tree.lock_read()
224
        self.addCleanup(tree.unlock)
225
        self.assertEqual(['', 'dir', 'dir/subdir', 'dir/subdir/foo'],
226
            [path for path, ie in tree.iter_entries_by_dir()])
227
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
228
    def test_add_dir_bug_251864(self):
5504.6.3 by Martin
Address poolie's review, mention both bugs in test and add news
229
        """Added file turning into a dir should be detected on add dir
230
231
        Similar to bug 205636 but with automatic adding of directory contents.
232
        """
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
233
        tree = self.make_branch_and_tree(".")
234
        self.build_tree(["dir"]) # whoops, make a file called dir
235
        tree.smart_add(["dir"])
236
        os.remove("dir")
237
        self.build_tree(["dir/", "dir/file"])
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
238
        tree.smart_add(["dir"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
239
        tree.commit("Add dir contents")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
240
        self.addCleanup(tree.lock_read().unlock)
241
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
242
            [(t[0], t[2]) for t in tree.list_files()])
243
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
244
245
    def test_add_subdir_file_bug_205636(self):
246
        """Added file turning into a dir should be detected on add dir/file"""
247
        tree = self.make_branch_and_tree(".")
248
        self.build_tree(["dir"]) # whoops, make a file called dir
249
        tree.smart_add(["dir"])
250
        os.remove("dir")
251
        self.build_tree(["dir/", "dir/file"])
5378.1.3 by Martin
Note that TestSmartAddTree.test_add_subdir_file_bug_205636 now passes
252
        tree.smart_add(["dir/file"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
253
        tree.commit("Add file in dir")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
254
        self.addCleanup(tree.lock_read().unlock)
255
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
256
            [(t[0], t[2]) for t in tree.list_files()])
257
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
258
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
259
    def test_custom_ids(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
260
        sio = BytesIO()
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
261
        action = test_smart_add.AddCustomIDAction(to_file=sio,
262
                                                  should_print=True)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
263
        self.build_tree(['file1', 'dir1/', 'dir1/file2'])
264
265
        wt = self.make_branch_and_tree('.')
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
266
        if not wt._format.supports_setting_file_ids:
267
            self.assertRaises(
268
                workingtree.SettingFileIdUnsupported,
269
                wt.smart_add, ['.'], action=action)
270
            return
271
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
272
        wt.smart_add(['.'], action=action)
273
        # The order of adds is not strictly fixed:
274
        sio.seek(0)
275
        lines = sorted(sio.readlines())
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
276
        self.assertEqual(['added dir1 with id directory-dir1\n',
277
                          'added dir1/file2 with id file-dir1%file2\n',
278
                          'added file1 with id file-file1\n', ]
279
                          , lines)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
280
        wt.lock_read()
281
        self.addCleanup(wt.unlock)
282
        self.assertEqual([('', wt.path2id('')),
283
                          ('dir1', 'directory-dir1'),
5807.1.8 by Jelmer Vernooij
Fix some tests.
284
                          ('file1', 'file-file1'),
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
285
                          ('dir1/file2', 'file-dir1%file2'),
286
                         ], [(path, ie.file_id) for path, ie
5807.1.8 by Jelmer Vernooij
Fix some tests.
287
                                in wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
288
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
289
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
290
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
291
292
    def make_tree_with_text_conflict(self):
293
        tb = self.make_branch_and_tree('base')
6855.4.1 by Jelmer Vernooij
Yet more bees.
294
        self.build_tree_contents([('base/file', b'content in base')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
295
        tb.add('file')
296
        tb.commit('Adding file')
297
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
298
        t1 = tb.controldir.sprout('t1').open_workingtree()
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
299
6855.4.1 by Jelmer Vernooij
Yet more bees.
300
        self.build_tree_contents([('base/file', b'content changed in base')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
301
        tb.commit('Changing file in base')
302
6855.4.1 by Jelmer Vernooij
Yet more bees.
303
        self.build_tree_contents([('t1/file', b'content in t1')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
304
        t1.commit('Changing file in t1')
305
        t1.merge_from_branch(tb.branch)
306
        return t1
307
308
    def test_cant_add_generated_files_implicitly(self):
309
        t = self.make_tree_with_text_conflict()
310
        added, ignored = t.smart_add([t.basedir])
311
        self.assertEqual(([], {}), (added, ignored))
312
313
    def test_can_add_generated_files_explicitly(self):
314
        fnames = ['file.%s' % s  for s in ('BASE', 'THIS', 'OTHER')]
315
        t = self.make_tree_with_text_conflict()
316
        added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
317
        self.assertEqual((fnames, {}), (added, ignored))
318
319
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
320
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
321
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
322
    _test_needs_features = [features.UnicodeFilenameFeature]
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
323
324
    def setUp(self):
325
        super(TestSmartAddTreeUnicode, self).setUp()
326
        self.build_tree([u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
327
        self.wt = self.make_branch_and_tree('.')
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
328
        self.overrideAttr(osutils, 'normalized_filename')
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
329
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
330
    def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
331
        """Adding unnormalized unicode filenames fail if and only if the
332
        workingtree format has the requires_normalized_unicode_filenames flag
5929.1.1 by Vincent Ladeuil
Fix spurious test failure on OSX for WorkingTreeFormat2
333
        set and the underlying filesystem doesn't normalize.
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
334
        """
335
        osutils.normalized_filename = osutils._accessible_normalized_filename
5929.1.1 by Vincent Ladeuil
Fix spurious test failure on OSX for WorkingTreeFormat2
336
        if (self.workingtree_format.requires_normalized_unicode_filenames
337
            and sys.platform != 'darwin'):
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
338
            self.assertRaises(
339
                errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
340
        else:
341
            self.wt.smart_add([u'a\u030a'])
342
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
343
    def test_accessible_explicit(self):
344
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
345
        if self.workingtree_format.requires_normalized_unicode_filenames:
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
346
            raise tests.TestNotApplicable(
347
                'Working tree format smart_add requires normalized unicode '
348
                'filenames')
5868.1.1 by Martin
Turn two long-standing unexpected successes into skips
349
        self.wt.smart_add([u'a\u030a'])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
350
        self.wt.lock_read()
351
        self.addCleanup(self.wt.unlock)
352
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
353
                         [(path, ie.kind) for path, ie in
5807.1.8 by Jelmer Vernooij
Fix some tests.
354
                          self.wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
355
356
    def test_accessible_implicit(self):
357
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
358
        if self.workingtree_format.requires_normalized_unicode_filenames:
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
359
            raise tests.TestNotApplicable(
360
                'Working tree format smart_add requires normalized unicode '
361
                'filenames')
5868.1.1 by Martin
Turn two long-standing unexpected successes into skips
362
        self.wt.smart_add([])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
363
        self.wt.lock_read()
364
        self.addCleanup(self.wt.unlock)
365
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
366
                         [(path, ie.kind) for path, ie
5807.1.8 by Jelmer Vernooij
Fix some tests.
367
                          in self.wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
368
369
    def test_inaccessible_explicit(self):
370
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
371
        self.assertRaises(errors.InvalidNormalization,
372
                          self.wt.smart_add, [u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
373
374
    def test_inaccessible_implicit(self):
375
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
376
        # TODO: jam 20060701 In the future, this should probably
377
        #       just ignore files that don't fit the normalization
378
        #       rules, rather than exploding
379
        self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])