~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-22 18:24:25 UTC
  • mfrom: (1803 +trunk)
  • mto: (1793.3.6 bundle-fixes)
  • mto: This revision was merged to the branch mainline in revision 1806.
  • Revision ID: john@arbash-meinel.com-20060622182425-6f45cb7acd587216
[merge] bzr.dev 1804 and fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib.builtins import merge
20
20
from bzrlib.bzrdir import BzrDir
21
21
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
22
 
from bzrlib.bundle.read_bundle import BundleTree, BundleReader
23
 
from bzrlib.bundle.serializer import write_bundle
 
22
from bzrlib.bundle.bundle_data import BundleTree
 
23
from bzrlib.bundle.serializer import write_bundle, read_bundle
24
24
from bzrlib.diff import internal_diff
25
25
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle
26
26
from bzrlib.merge import Merge3Merger
324
324
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
325
325
 
326
326
        # This should also validate the generated bundle 
327
 
        bundle = BundleReader(bundle_txt)
 
327
        bundle = read_bundle(bundle_txt)
328
328
        repository = self.b1.repository
329
 
        for bundle_rev in bundle.info.real_revisions:
 
329
        for bundle_rev in bundle.real_revisions:
330
330
            # These really should have already been checked when we read the
331
331
            # bundle, since it computes the sha1 hash for the revision, which
332
332
            # only will match if everything is okay, but lets be explicit about
340
340
            self.assertEqual(len(branch_rev.parent_ids), 
341
341
                             len(bundle_rev.parent_ids))
342
342
        self.assertEqual(rev_ids, 
343
 
                         [r.revision_id for r in bundle.info.real_revisions])
 
343
                         [r.revision_id for r in bundle.real_revisions])
344
344
        self.valid_apply_bundle(base_rev_id, bundle,
345
345
                                   checkout_dir=checkout_dir)
346
346
 
356
356
        new_text = bundle_txt.getvalue().replace('executable:no', 
357
357
                                               'executable:yes')
358
358
        bundle_txt = StringIO(new_text)
359
 
        bundle = BundleReader(bundle_txt)
 
359
        bundle = read_bundle(bundle_txt)
360
360
        self.valid_apply_bundle(base_rev_id, bundle)
361
361
        return bundle 
362
362
 
363
363
    def test_non_bundle(self):
364
 
        self.assertRaises(NotABundle, BundleReader, StringIO('#!/bin/sh\n'))
 
364
        self.assertRaises(NotABundle, read_bundle, StringIO('#!/bin/sh\n'))
365
365
 
366
366
    def get_checkout(self, rev_id, checkout_dir=None):
367
367
        """Get a new tree, with the specified revision in it.
381
381
        s.seek(0)
382
382
        assert isinstance(s.getvalue(), str), (
383
383
            "Bundle isn't a bytestring:\n %s..." % repr(s.getvalue())[:40])
384
 
        install_bundle(tree.branch.repository, BundleReader(s))
 
384
        install_bundle(tree.branch.repository, read_bundle(s))
385
385
        for ancestor in ancestors:
386
386
            old = self.b1.repository.revision_tree(ancestor)
387
387
            new = tree.branch.repository.revision_tree(ancestor)
400
400
            tree.update()
401
401
        return tree
402
402
 
403
 
    def valid_apply_bundle(self, base_rev_id, reader, checkout_dir=None):
 
403
    def valid_apply_bundle(self, base_rev_id, info, checkout_dir=None):
404
404
        """Get the base revision, apply the changes, and make
405
405
        sure everything matches the builtin branch.
406
406
        """
407
407
        to_tree = self.get_checkout(base_rev_id, checkout_dir=checkout_dir)
408
408
        repository = to_tree.branch.repository
409
409
        self.assertIs(repository.has_revision(base_rev_id), True)
410
 
        info = reader.info
411
410
        for rev in info.real_revisions:
412
411
            self.assert_(not repository.has_revision(rev.revision_id),
413
412
                'Revision {%s} present before applying bundle' 
414
413
                % rev.revision_id)
415
 
        merge_bundle(reader, to_tree, True, Merge3Merger, False, False)
 
414
        merge_bundle(info, to_tree, True, Merge3Merger, False, False)
416
415
 
417
416
        for rev in info.real_revisions:
418
417
            self.assert_(repository.has_revision(rev.revision_id),
700
699
    def check_valid(self, bundle):
701
700
        """Check that after whatever munging, the final object is valid."""
702
701
        self.assertEqual(['a@cset-0-2'], 
703
 
            [r.revision_id for r in bundle.info.real_revisions])
 
702
            [r.revision_id for r in bundle.real_revisions])
704
703
 
705
704
    def test_extra_whitespace(self):
706
705
        bundle_txt = self.build_test_bundle()
712
711
        bundle_txt.write('\n')
713
712
        bundle_txt.seek(0)
714
713
 
715
 
        bundle = BundleReader(bundle_txt)
 
714
        bundle = read_bundle(bundle_txt)
716
715
        self.check_valid(bundle)
717
716
 
718
717
    def test_extra_whitespace_2(self):
725
724
        bundle_txt.write('\n\n')
726
725
        bundle_txt.seek(0)
727
726
 
728
 
        bundle = BundleReader(bundle_txt)
 
727
        bundle = read_bundle(bundle_txt)
729
728
        self.check_valid(bundle)
730
729
 
731
730
    def test_missing_trailing_whitespace(self):
740
739
        self.assertEqual('\n\n', raw[-2:])
741
740
        bundle_text = StringIO(raw[:-1])
742
741
 
743
 
        bundle = BundleReader(bundle_txt)
 
742
        bundle = read_bundle(bundle_txt)
744
743
        self.check_valid(bundle)