~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_smart_add.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    tests,
28
28
    workingtree,
29
29
    )
30
 
from bzrlib.add import (
31
 
    AddAction,
32
 
    AddFromBaseAction,
 
30
from bzrlib.tests import (
 
31
    features,
 
32
    test_smart_add,
 
33
    per_workingtree,
33
34
    )
34
 
from bzrlib.tests.test_smart_add import AddCustomIDAction
35
 
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
36
 
 
37
 
 
38
 
class TestSmartAddTree(TestCaseWithWorkingTree):
 
35
 
 
36
 
 
37
class TestSmartAddTree(per_workingtree.TestCaseWithWorkingTree):
39
38
 
40
39
    def test_single_file(self):
41
40
        tree = self.make_branch_and_tree('tree')
205
204
 
206
205
    def test_custom_ids(self):
207
206
        sio = StringIO()
208
 
        action = AddCustomIDAction(to_file=sio, should_print=True)
 
207
        action = test_smart_add.AddCustomIDAction(to_file=sio,
 
208
                                                  should_print=True)
209
209
        self.build_tree(['file1', 'dir1/', 'dir1/file2'])
210
210
 
211
211
        wt = self.make_branch_and_tree('.')
226
226
                         ], [(path, ie.file_id) for path, ie
227
227
                                in wt.inventory.iter_entries()])
228
228
 
229
 
    def make_unicode_containing_tree(self):
230
 
        try:
231
 
            self.build_tree([u'a\u030a'])
232
 
        except UnicodeError:
233
 
            raise tests.TestSkipped('Filesystem cannot create unicode filenames')
 
229
 
 
230
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
 
231
 
 
232
    def make_tree_with_text_conflict(self):
 
233
        tb = self.make_branch_and_tree('base')
 
234
        self.build_tree_contents([('base/file', 'content in base')])
 
235
        tb.add('file')
 
236
        tb.commit('Adding file')
 
237
 
 
238
        t1 = tb.bzrdir.sprout('t1').open_workingtree()
 
239
 
 
240
        self.build_tree_contents([('base/file', 'content changed in base')])
 
241
        tb.commit('Changing file in base')
 
242
 
 
243
        self.build_tree_contents([('t1/file', 'content in t1')])
 
244
        t1.commit('Changing file in t1')
 
245
        t1.merge_from_branch(tb.branch)
 
246
        return t1
 
247
 
 
248
    def test_cant_add_generated_files_implicitly(self):
 
249
        t = self.make_tree_with_text_conflict()
 
250
        added, ignored = t.smart_add([t.basedir])
 
251
        self.assertEqual(([], {}), (added, ignored))
 
252
 
 
253
    def test_can_add_generated_files_explicitly(self):
 
254
        fnames = ['file.%s' % s  for s in ('BASE', 'THIS', 'OTHER')]
 
255
        t = self.make_tree_with_text_conflict()
 
256
        added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
 
257
        self.assertEqual((fnames, {}), (added, ignored))
 
258
 
 
259
 
 
260
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
 
261
 
 
262
    _test_needs_features = [tests.UnicodeFilenameFeature]
 
263
 
 
264
    def setUp(self):
 
265
        super(TestSmartAddTreeUnicode, self).setUp()
 
266
        self.build_tree([u'a\u030a'])
234
267
        self.wt = self.make_branch_and_tree('.')
 
268
        self.overrideAttr(osutils, 'normalized_filename')
235
269
 
236
270
    def test_accessible_explicit(self):
237
 
        self.make_unicode_containing_tree()
238
 
        orig = osutils.normalized_filename
239
271
        osutils.normalized_filename = osutils._accessible_normalized_filename
240
 
        try:
 
272
        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
 
273
            self.expectFailure(
 
274
                'With WorkingTreeFormat2, smart_add requires'
 
275
                ' normalized unicode filenames',
 
276
                self.assertRaises, errors.NoSuchFile,
 
277
                self.wt.smart_add, [u'a\u030a'])
 
278
        else:
241
279
            self.wt.smart_add([u'a\u030a'])
242
 
            self.wt.lock_read()
243
 
            self.addCleanup(self.wt.unlock)
244
 
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
245
 
                    [(path, ie.kind) for path,ie in
246
 
                        self.wt.inventory.iter_entries()])
247
 
        finally:
248
 
            osutils.normalized_filename = orig
 
280
        self.wt.lock_read()
 
281
        self.addCleanup(self.wt.unlock)
 
282
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
 
283
                         [(path, ie.kind) for path,ie in
 
284
                          self.wt.inventory.iter_entries()])
249
285
 
250
286
    def test_accessible_implicit(self):
251
 
        self.make_unicode_containing_tree()
252
 
        orig = osutils.normalized_filename
253
287
        osutils.normalized_filename = osutils._accessible_normalized_filename
254
 
        try:
 
288
        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
 
289
            self.expectFailure(
 
290
                'With WorkingTreeFormat2, smart_add requires'
 
291
                ' normalized unicode filenames',
 
292
                self.assertRaises, errors.NoSuchFile,
 
293
                self.wt.smart_add, [])
 
294
        else:
255
295
            self.wt.smart_add([])
256
 
            self.wt.lock_read()
257
 
            self.addCleanup(self.wt.unlock)
258
 
            self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
259
 
                    [(path, ie.kind) for path,ie in
260
 
                        self.wt.inventory.iter_entries()])
261
 
        finally:
262
 
            osutils.normalized_filename = orig
 
296
        self.wt.lock_read()
 
297
        self.addCleanup(self.wt.unlock)
 
298
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
 
299
                         [(path, ie.kind) for path,ie
 
300
                          in self.wt.inventory.iter_entries()])
263
301
 
264
302
    def test_inaccessible_explicit(self):
265
 
        self.make_unicode_containing_tree()
266
 
        orig = osutils.normalized_filename
267
303
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
268
 
        try:
269
 
            self.assertRaises(errors.InvalidNormalization,
270
 
                    self.wt.smart_add, [u'a\u030a'])
271
 
        finally:
272
 
            osutils.normalized_filename = orig
 
304
        self.assertRaises(errors.InvalidNormalization,
 
305
                          self.wt.smart_add, [u'a\u030a'])
273
306
 
274
307
    def test_inaccessible_implicit(self):
275
 
        self.make_unicode_containing_tree()
276
 
        orig = osutils.normalized_filename
277
308
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
278
 
        try:
279
 
            # TODO: jam 20060701 In the future, this should probably
280
 
            #       just ignore files that don't fit the normalization
281
 
            #       rules, rather than exploding
282
 
            self.assertRaises(errors.InvalidNormalization,
283
 
                    self.wt.smart_add, [])
284
 
        finally:
285
 
            osutils.normalized_filename = orig
 
309
        # TODO: jam 20060701 In the future, this should probably
 
310
        #       just ignore files that don't fit the normalization
 
311
        #       rules, rather than exploding
 
312
        self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])