/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests of the parent related functions of WorkingTrees."""
18
18
 
24
24
    osutils,
25
25
    revision as _mod_revision,
26
26
    symbol_versioning,
 
27
    tests,
27
28
    )
28
29
from bzrlib.inventory import (
29
30
    Inventory,
32
33
    InventoryLink,
33
34
    )
34
35
from bzrlib.revision import Revision
35
 
from bzrlib.tests import (
36
 
    KnownFailure,
37
 
    SymlinkFeature,
38
 
    TestNotApplicable,
39
 
    UnicodeFilenameFeature,
40
 
    )
41
 
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
36
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
42
37
from bzrlib.uncommit import uncommit
43
38
 
44
39
 
234
229
 
235
230
    def test_unicode_symlink(self):
236
231
        # this tests bug #272444
237
 
        self.requireFeature(SymlinkFeature)
238
 
        self.requireFeature(UnicodeFilenameFeature)
 
232
        self.requireFeature(tests.SymlinkFeature)
 
233
        self.requireFeature(tests.UnicodeFilenameFeature)
239
234
 
240
235
        tree = self.make_branch_and_tree('tree1')
241
236
 
242
237
        # The link points to a file whose name is an omega
243
238
        # U+03A9 GREEK CAPITAL LETTER OMEGA
244
239
        # UTF-8: ce a9  UTF-16BE: 03a9  Decimal: Ω
245
 
        os.symlink(u'\u03a9','tree1/link_name')
246
 
        tree.add(['link_name'],['link-id'])
 
240
        target = u'\u03a9'
 
241
        link_name = u'\N{Euro Sign}link'
 
242
        os.symlink(target, 'tree1/' + link_name)
 
243
        tree.add([link_name],['link-id'])
247
244
 
248
 
        try:
249
 
            # the actual commit occurs without errors (strangely):
250
 
            revision1 = tree.commit('added a link to a Unicode target')
251
 
            # python 2.4 failed with UnicodeDecodeError on this commit:
252
 
            revision2 = tree.commit('this revision will be discarded')
253
 
            # python 2.5 failed with UnicodeEncodeError on set_parent_ids:
254
 
            tree.set_parent_ids([revision1])
255
 
        except (UnicodeEncodeError, UnicodeDecodeError):
256
 
            raise KnownFailure('there is no support for'
257
 
                               ' symlinks to non-ASCII targets (bug #272444)')
 
245
        revision1 = tree.commit('added a link to a Unicode target')
 
246
        revision2 = tree.commit('this revision will be discarded')
 
247
        tree.set_parent_ids([revision1])
 
248
        tree.lock_read()
 
249
        self.addCleanup(tree.unlock)
 
250
        # Check that the symlink target is safely round-tripped in the trees.
 
251
        self.assertEqual(target, tree.get_symlink_target('link-id'))
 
252
        basis = tree.basis_tree()
 
253
        self.assertEqual(target, basis.get_symlink_target('link-id'))
258
254
 
259
255
 
260
256
class TestAddParent(TestParents):
266
262
        uncommit(tree.branch, tree=tree)
267
263
        tree.add_parent_tree_id(first_revision)
268
264
        self.assertConsistentParents([first_revision], tree)
269
 
        
 
265
 
270
266
    def test_add_first_parent_id_ghost_rejects(self):
271
267
        """Test adding the first parent id - as a ghost"""
272
268
        tree = self.make_branch_and_tree('.')
273
269
        self.assertRaises(errors.GhostRevisionUnusableHere,
274
270
            tree.add_parent_tree_id, 'first-revision')
275
 
        
 
271
 
276
272
    def test_add_first_parent_id_ghost_force(self):
277
273
        """Test adding the first parent id - as a ghost"""
278
274
        tree = self.make_branch_and_tree('.')
285
281
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
286
282
        tree.add_parent_tree_id('second')
287
283
        self.assertConsistentParents(['first-revision', 'second'], tree)
288
 
        
 
284
 
289
285
    def test_add_second_parent_id(self):
290
286
        """Test adding the second parent id"""
291
287
        tree = self.make_branch_and_tree('.')
294
290
        second_revision = tree.commit('second post')
295
291
        tree.add_parent_tree_id(first_revision)
296
292
        self.assertConsistentParents([second_revision, first_revision], tree)
297
 
        
 
293
 
298
294
    def test_add_second_parent_id_ghost(self):
299
295
        """Test adding the second parent id - as a ghost"""
300
296
        tree = self.make_branch_and_tree('.')
301
297
        first_revision = tree.commit('first post')
302
298
        tree.add_parent_tree_id('second')
303
299
        self.assertConsistentParents([first_revision, 'second'], tree)
304
 
        
 
300
 
305
301
    def test_add_first_parent_tree(self):
306
302
        """Test adding the first parent id"""
307
303
        tree = self.make_branch_and_tree('.')
310
306
        tree.add_parent_tree((first_revision,
311
307
            tree.branch.repository.revision_tree(first_revision)))
312
308
        self.assertConsistentParents([first_revision], tree)
313
 
        
 
309
 
314
310
    def test_add_first_parent_tree_ghost_rejects(self):
315
311
        """Test adding the first parent id - as a ghost"""
316
312
        tree = self.make_branch_and_tree('.')
317
313
        self.assertRaises(errors.GhostRevisionUnusableHere,
318
314
            tree.add_parent_tree, ('first-revision', None))
319
 
        
 
315
 
320
316
    def test_add_first_parent_tree_ghost_force(self):
321
317
        """Test adding the first parent id - as a ghost"""
322
318
        tree = self.make_branch_and_tree('.')
323
319
        tree.add_parent_tree(('first-revision', None),
324
320
            allow_leftmost_as_ghost=True)
325
321
        self.assertConsistentParents(['first-revision'], tree)
326
 
        
 
322
 
327
323
    def test_add_second_parent_tree(self):
328
324
        """Test adding the second parent id"""
329
325
        tree = self.make_branch_and_tree('.')
333
329
        tree.add_parent_tree((first_revision,
334
330
            tree.branch.repository.revision_tree(first_revision)))
335
331
        self.assertConsistentParents([second_revision, first_revision], tree)
336
 
        
 
332
 
337
333
    def test_add_second_parent_tree_ghost(self):
338
334
        """Test adding the second parent id - as a ghost"""
339
335
        tree = self.make_branch_and_tree('.')
344
340
 
345
341
class UpdateToOneParentViaDeltaTests(TestCaseWithWorkingTree):
346
342
    """Tests for the update_basis_by_delta call.
347
 
    
 
343
 
348
344
    This is intuitively defined as 'apply an inventory delta to the basis and
349
345
    discard other parents', but for trees that have an inventory that is not
350
346
    managed as a tree-by-id, the implementation requires roughly duplicated
396
392
            try:
397
393
                if shape.root.revision is None:
398
394
                    shape.root.revision = revid
 
395
                # Create the text records for this inventory.
 
396
                for path, ie in shape.iter_entries():
 
397
                    if ie.text_size:
 
398
                        lines = ['a' * ie.text_size]
 
399
                    else:
 
400
                        lines = []
 
401
                    tree.branch.repository.texts.add_lines(
 
402
                        (ie.file_id, ie.revision), [], lines)
399
403
                sha1 = tree.branch.repository.add_inventory(revid, shape, [])
400
404
                rev = Revision(timestamp=0,
401
405
                               timezone=None,
404
408
                               inventory_sha1=sha1,
405
409
                               revision_id=revid)
406
410
                tree.branch.repository.add_revision(revid, rev)
 
411
                tree.branch.repository.commit_write_group()
407
412
            except:
408
413
                tree.branch.repository.abort_write_group()
409
414
                raise
410
 
            else:
411
 
                tree.branch.repository.commit_write_group()
412
415
        finally:
413
416
            tree.unlock()
414
417