~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests of the parent related functions of WorkingTrees."""
18
18
 
19
 
from errno import EEXIST
 
19
from cStringIO import StringIO
20
20
import os
21
21
 
22
22
from bzrlib import (
23
23
    errors,
24
24
    osutils,
25
25
    revision as _mod_revision,
26
 
    symbol_versioning,
27
26
    tests,
28
27
    )
29
28
from bzrlib.inventory import (
32
31
    InventoryDirectory,
33
32
    InventoryLink,
34
33
    )
35
 
from bzrlib.revision import Revision
 
34
from bzrlib.revisiontree import InventoryRevisionTree
36
35
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
37
36
from bzrlib.uncommit import uncommit
38
37
 
386
385
        return delta
387
386
 
388
387
    def fake_up_revision(self, tree, revid, shape):
 
388
 
 
389
        class ShapeTree(InventoryRevisionTree):
 
390
 
 
391
            def __init__(self, shape):
 
392
                self._repository = tree.branch.repository
 
393
                self._inventory = shape
 
394
 
 
395
            def get_file_text(self, file_id, path=None):
 
396
                ie = self.inventory[file_id]
 
397
                if ie.kind != "file":
 
398
                    return ""
 
399
                return 'a' * ie.text_size
 
400
 
 
401
            def get_file(self, file_id, path=None):
 
402
                return StringIO(self.get_file_text(file_id))
 
403
 
389
404
        tree.lock_write()
390
405
        try:
391
 
            tree.branch.repository.start_write_group()
392
 
            try:
393
 
                if shape.root.revision is None:
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)
403
 
                sha1 = tree.branch.repository.add_inventory(revid, shape, [])
404
 
                rev = Revision(timestamp=0,
405
 
                               timezone=None,
406
 
                               committer="Foo Bar <foo@example.com>",
407
 
                               message="Message",
408
 
                               inventory_sha1=sha1,
409
 
                               revision_id=revid)
410
 
                tree.branch.repository.add_revision(revid, rev)
411
 
                tree.branch.repository.commit_write_group()
412
 
            except:
413
 
                tree.branch.repository.abort_write_group()
414
 
                raise
 
406
            if shape.root.revision is None:
 
407
                shape.root.revision = revid
 
408
            builder = tree.branch.get_commit_builder(
 
409
                    parents=[],
 
410
                    timestamp=0,
 
411
                    timezone=None,
 
412
                    committer="Foo Bar <foo@example.com>",
 
413
                    revision_id=revid)
 
414
            shape_tree = ShapeTree(shape)
 
415
            base_tree = tree.branch.repository.revision_tree(
 
416
                    _mod_revision.NULL_REVISION)
 
417
            changes = shape_tree.iter_changes(
 
418
                base_tree)
 
419
            list(builder.record_iter_changes(shape_tree,
 
420
                base_tree.get_revision_id(), changes))
 
421
            builder.finish_inventory()
 
422
            builder.commit("Message")
415
423
        finally:
416
424
            tree.unlock()
417
425