~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Aaron Bentley
  • Date: 2006-08-24 03:35:48 UTC
  • mto: (1910.2.43 format-bumps)
  • mto: This revision was merged to the branch mainline in revision 1997.
  • Revision ID: aaron.bentley@utoronto.ca-20060824033548-104450f485b42c75
Fix bugs in basis inventory handling, change filename

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2004-2006 by Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
import sys
20
20
import tempfile
21
21
 
 
22
from bzrlib import inventory
22
23
from bzrlib.builtins import merge
23
24
from bzrlib.bzrdir import BzrDir
24
25
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
26
27
from bzrlib.bundle.serializer import write_bundle, read_bundle
27
28
from bzrlib.branch import Branch
28
29
from bzrlib.diff import internal_diff
29
 
from bzrlib.delta import compare_trees
30
 
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle, BadBundle
 
30
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle, 
 
31
                           NoSuchFile,)
31
32
from bzrlib.merge import Merge3Merger
32
33
from bzrlib.osutils import has_symlinks, sha_file
33
34
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
38
39
 
39
40
class MockTree(object):
40
41
    def __init__(self):
41
 
        from bzrlib.inventory import RootEntry, ROOT_ID
 
42
        from bzrlib.inventory import InventoryDirectory, ROOT_ID
42
43
        object.__init__(self)
43
44
        self.paths = {ROOT_ID: ""}
44
45
        self.ids = {"": ROOT_ID}
45
46
        self.contents = {}
46
 
        self.root = RootEntry(ROOT_ID)
 
47
        self.root = InventoryDirectory(ROOT_ID, '', None)
47
48
 
48
49
    inventory = property(lambda x:x)
49
50
 
290
291
    def test_iteration(self):
291
292
        """Ensure that iteration through ids works properly"""
292
293
        btree = self.make_tree_1()[0]
293
 
        self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'c', 'd'])
 
294
        self.assertEqual(self.sorted_ids(btree),
 
295
            [inventory.ROOT_ID, 'a', 'b', 'c', 'd'])
294
296
        btree.note_deletion("grandparent/parent/file")
295
297
        btree.note_id("e", "grandparent/alt_parent/fool", kind="directory")
296
298
        btree.note_last_changed("grandparent/alt_parent/fool", 
297
299
                                "revisionidiguess")
298
 
        self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'd', 'e'])
 
300
        self.assertEqual(self.sorted_ids(btree),
 
301
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
299
302
 
300
303
 
301
304
class BundleTester(TestCaseWithTransport):
372
375
 
373
376
    def test_crlf_bundle(self):
374
377
        try:
375
 
            read_bundle(StringIO('# Bazaar revision bundle v0.7\r\n'))
 
378
            read_bundle(StringIO('# Bazaar revision bundle v0.8\r\n'))
376
379
        except BadBundle:
377
380
            # It is currently permitted for bundles with crlf line endings to
378
381
            # make read_bundle raise a BadBundle, but this should be fixed.
400
403
            new = tree.branch.repository.revision_tree(ancestor)
401
404
 
402
405
            # Check that there aren't any inventory level changes
403
 
            delta = compare_trees(old, new)
 
406
            delta = new.changes_from(old)
404
407
            self.assertFalse(delta.has_changed(),
405
408
                             'Revision %s not copied correctly.'
406
409
                             % (ancestor,))
409
412
            for inventory_id in old:
410
413
                try:
411
414
                    old_file = old.get_file(inventory_id)
412
 
                except:
 
415
                except NoSuchFile:
413
416
                    continue
414
417
                if old_file is None:
415
418
                    continue
419
422
            rh = self.b1.revision_history()
420
423
            tree.branch.set_revision_history(rh[:rh.index(rev_id)+1])
421
424
            tree.update()
422
 
            delta = compare_trees(self.b1.repository.revision_tree(rev_id),
423
 
                                  tree)
 
425
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
424
426
            self.assertFalse(delta.has_changed(),
425
427
                             'Working tree has modifications')
426
428
        return tree
798
800
        self.assertEqual(19800, rev.timezone)
799
801
        self.assertEqual(1152544886.0, rev.timestamp)
800
802
 
 
803
    def test_bundle_root_id(self):
 
804
        self.tree1 = self.make_branch_and_tree('b1')
 
805
        self.b1 = self.tree1.branch
 
806
        self.tree1.commit('message', rev_id='revid1')
 
807
        bundle = self.get_valid_bundle(None, 'revid1')
 
808
        tree = bundle.revision_tree(self.b1.repository, 'revid1')
 
809
        self.assertEqual('revid1', tree.inventory.root.revision)
 
810
 
801
811
 
802
812
class MungedBundleTester(TestCaseWithTransport):
803
813
 
809
819
        wt.commit('add one', rev_id='a@cset-0-1')
810
820
        self.build_tree(['b1/two'])
811
821
        wt.add('two')
812
 
        wt.commit('add two', rev_id='a@cset-0-2')
 
822
        wt.commit('add two', rev_id='a@cset-0-2',
 
823
                  revprops={'branch-nick':'test'})
813
824
 
814
825
        bundle_txt = StringIO()
815
826
        rev_ids = write_bundle(wt.branch.repository, 'a@cset-0-2',
820
831
 
821
832
    def check_valid(self, bundle):
822
833
        """Check that after whatever munging, the final object is valid."""
823
 
        self.assertEqual(['a@cset-0-2'], 
 
834
        self.assertEqual(['a@cset-0-2'],
824
835
            [r.revision_id for r in bundle.real_revisions])
825
836
 
826
837
    def test_extra_whitespace(self):
859
870
        # creates a blank line at the end, and fails if that
860
871
        # line is stripped
861
872
        self.assertEqual('\n\n', raw[-2:])
862
 
        bundle_text = StringIO(raw[:-1])
863
 
 
864
 
        bundle = read_bundle(bundle_txt)
865
 
        self.check_valid(bundle)
 
873
        bundle_txt = StringIO(raw[:-1])
 
874
 
 
875
        bundle = read_bundle(bundle_txt)
 
876
        self.check_valid(bundle)
 
877
 
 
878
    def test_opening_text(self):
 
879
        bundle_txt = self.build_test_bundle()
 
880
 
 
881
        bundle_txt = StringIO("Some random\nemail comments\n"
 
882
                              + bundle_txt.getvalue())
 
883
 
 
884
        bundle = read_bundle(bundle_txt)
 
885
        self.check_valid(bundle)
 
886
 
 
887
    def test_trailing_text(self):
 
888
        bundle_txt = self.build_test_bundle()
 
889
 
 
890
        bundle_txt = StringIO(bundle_txt.getvalue() +
 
891
                              "Some trailing\nrandom\ntext\n")
 
892
 
 
893
        bundle = read_bundle(bundle_txt)
 
894
        self.check_valid(bundle)
 
895