~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-29 05:53:21 UTC
  • mfrom: (4311 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4312.
  • Revision ID: tanner@real-time.com-20090429055321-v2s5l1mgki9f6cgn
[merge] 1.14 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
 
25
    diff,
25
26
    errors,
26
27
    inventory,
 
28
    merge,
27
29
    osutils,
28
30
    repository,
29
31
    revision as _mod_revision,
 
32
    tests,
30
33
    treebuilder,
31
34
    )
32
35
from bzrlib.bundle import read_mergeable_from_url
39
42
from bzrlib.bundle.serializer.v09 import BundleSerializerV09
40
43
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
41
44
from bzrlib.branch import Branch
42
 
from bzrlib.diff import internal_diff
43
 
from bzrlib.merge import Merge3Merger
44
45
from bzrlib.repofmt import knitrepo
45
 
from bzrlib.osutils import sha_file, sha_string
46
46
from bzrlib.tests import (
47
 
    SymlinkFeature,
48
 
    TestCase,
49
 
    TestCaseInTempDir,
50
 
    TestCaseWithTransport,
51
 
    TestSkipped,
52
47
    test_read_bundle,
53
48
    test_commit,
54
49
    )
137
132
    def contents_stats(self, file_id):
138
133
        if file_id not in self.contents:
139
134
            return None, None
140
 
        text_sha1 = sha_file(self.get_file(file_id))
 
135
        text_sha1 = osutils.sha_file(self.get_file(file_id))
141
136
        return text_sha1, len(self.contents[file_id])
142
137
 
143
138
 
144
 
class BTreeTester(TestCase):
 
139
class BTreeTester(tests.TestCase):
145
140
    """A simple unittest tester for the BundleTree class."""
146
141
 
147
142
    def make_tree_1(self):
225
220
 
226
221
    def unified_diff(self, old, new):
227
222
        out = StringIO()
228
 
        internal_diff("old", old, "new", new, out)
 
223
        diff.internal_diff("old", old, "new", new, out)
229
224
        out.seek(0,0)
230
225
        return out.read()
231
226
 
319
314
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
320
315
 
321
316
 
322
 
class BundleTester1(TestCaseWithTransport):
 
317
class BundleTester1(tests.TestCaseWithTransport):
323
318
 
324
319
    def test_mismatched_bundle(self):
325
320
        format = bzrdir.BzrDirMetaFormat1()
366
361
    def make_branch_and_tree(self, path, format=None):
367
362
        if format is None:
368
363
            format = self.bzrdir_format()
369
 
        return TestCaseWithTransport.make_branch_and_tree(self, path, format)
 
364
        return tests.TestCaseWithTransport.make_branch_and_tree(
 
365
            self, path, format)
370
366
 
371
367
    def make_branch(self, path, format=None):
372
368
        if format is None:
373
369
            format = self.bzrdir_format()
374
 
        return TestCaseWithTransport.make_branch(self, path, format)
 
370
        return tests.TestCaseWithTransport.make_branch(self, path, format)
375
371
 
376
372
    def create_bundle_text(self, base_rev_id, rev_id):
377
373
        bundle_txt = StringIO()
521
517
            self.assert_(not repository.has_revision(rev.revision_id),
522
518
                'Revision {%s} present before applying bundle'
523
519
                % rev.revision_id)
524
 
        merge_bundle(info, to_tree, True, Merge3Merger, False, False)
 
520
        merge_bundle(info, to_tree, True, merge.Merge3Merger, False, False)
525
521
 
526
522
        for rev in info.real_revisions:
527
523
            self.assert_(repository.has_revision(rev.revision_id),
662
658
        bundle = self.get_valid_bundle('a@cset-0-6', 'a@cset-0-7')
663
659
 
664
660
    def test_symlink_bundle(self):
665
 
        self.requireFeature(SymlinkFeature)
 
661
        self.requireFeature(tests.SymlinkFeature)
666
662
        self.tree1 = self.make_branch_and_tree('b1')
667
663
        self.b1 = self.tree1.branch
668
664
        tt = TreeTransform(self.tree1)
794
790
        return bundle_file.getvalue()
795
791
 
796
792
    def test_unicode_bundle(self):
 
793
        self.requireFeature(tests.UnicodeFilenameFeature)
797
794
        # Handle international characters
798
795
        os.mkdir('b1')
799
 
        try:
800
 
            f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
801
 
        except UnicodeEncodeError:
802
 
            raise TestSkipped("Filesystem doesn't support unicode")
 
796
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
803
797
 
804
798
        self.tree1 = self.make_branch_and_tree('b1')
805
799
        self.b1 = self.tree1.branch
843
837
 
844
838
    def test_whitespace_bundle(self):
845
839
        if sys.platform in ('win32', 'cygwin'):
846
 
            raise TestSkipped('Windows doesn\'t support filenames'
847
 
                              ' with tabs or trailing spaces')
 
840
            raise tests.TestSkipped('Windows doesn\'t support filenames'
 
841
                                    ' with tabs or trailing spaces')
848
842
        self.tree1 = self.make_branch_and_tree('b1')
849
843
        self.b1 = self.tree1.branch
850
844
 
1030
1024
        repo = self.make_repo_with_installed_revisions()
1031
1025
        recorded_inv_sha1 = repo.get_inventory_sha1('rev2')
1032
1026
        xml = repo.get_inventory_xml('rev2')
1033
 
        self.assertEqual(sha_string(xml), recorded_inv_sha1)
 
1027
        self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
1034
1028
 
1035
1029
    def test_across_models_incompatible(self):
1036
1030
        tree = self.make_simple_tree('dirstate-with-subtree')
1039
1033
        try:
1040
1034
            bundle = read_bundle(self.create_bundle_text('null:', 'rev1')[0])
1041
1035
        except errors.IncompatibleBundleFormat:
1042
 
            raise TestSkipped("Format 0.8 doesn't work with knit3")
 
1036
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
1043
1037
        repo = self.make_repository('repo', format='knit')
1044
1038
        bundle.install_revisions(repo)
1045
1039
 
1066
1060
        try:
1067
1061
            bundle = read_bundle(self.create_bundle_text('null:', 'rev1')[0])
1068
1062
        except errors.IncompatibleBundleFormat:
1069
 
            raise TestSkipped("Format 0.8 doesn't work with knit3")
 
1063
            raise tests.TestSkipped("Format 0.8 doesn't work with knit3")
1070
1064
        if isinstance(bundle, v09.BundleInfo09):
1071
 
            raise TestSkipped("Format 0.9 doesn't work with subtrees")
 
1065
            raise tests.TestSkipped("Format 0.9 doesn't work with subtrees")
1072
1066
        repo = self.make_repository('repo', format='knit')
1073
1067
        self.assertRaises(errors.IncompatibleRevision,
1074
1068
                          bundle.install_revisions, repo)
1081
1075
        try:
1082
1076
            self.tree1.commit('Revision/id/with/slashes', rev_id='rev/id')
1083
1077
        except ValueError:
1084
 
            raise TestSkipped("Repository doesn't support revision ids with"
1085
 
                              " slashes")
 
1078
            raise tests.TestSkipped(
 
1079
                "Repository doesn't support revision ids with slashes")
1086
1080
        bundle = self.get_valid_bundle('null:', 'rev/id')
1087
1081
 
1088
1082
    def test_skip_file(self):
1104
1098
        self.tree1.commit('rev3', rev_id='rev3')
1105
1099
        bundle = self.get_valid_bundle('reva', 'rev3')
1106
1100
        if getattr(bundle, 'get_bundle_reader', None) is None:
1107
 
            raise TestSkipped('Bundle format cannot provide reader')
 
1101
            raise tests.TestSkipped('Bundle format cannot provide reader')
1108
1102
        # be sure that file1 comes before file2
1109
1103
        for b, m, k, r, f in bundle.get_bundle_reader().iter_records():
1110
1104
            if f == 'file3-id':
1113
1107
        bundle.install_revisions(target.branch.repository)
1114
1108
 
1115
1109
 
1116
 
class V08BundleTester(BundleTester, TestCaseWithTransport):
 
1110
class V08BundleTester(BundleTester, tests.TestCaseWithTransport):
1117
1111
 
1118
1112
    format = '0.8'
1119
1113
 
1252
1246
        return format
1253
1247
 
1254
1248
 
1255
 
class V4BundleTester(BundleTester, TestCaseWithTransport):
 
1249
class V4BundleTester(BundleTester, tests.TestCaseWithTransport):
1256
1250
 
1257
1251
    format = '4'
1258
1252
 
1463
1457
        self.check_valid(bundle)
1464
1458
 
1465
1459
 
1466
 
class MungedBundleTesterV09(TestCaseWithTransport, MungedBundleTester):
 
1460
class MungedBundleTesterV09(tests.TestCaseWithTransport, MungedBundleTester):
1467
1461
 
1468
1462
    format = '0.9'
1469
1463
 
1501
1495
        self.check_valid(bundle)
1502
1496
 
1503
1497
 
1504
 
class MungedBundleTesterV4(TestCaseWithTransport, MungedBundleTester):
 
1498
class MungedBundleTesterV4(tests.TestCaseWithTransport, MungedBundleTester):
1505
1499
 
1506
1500
    format = '4'
1507
1501
 
1508
1502
 
1509
 
class TestBundleWriterReader(TestCase):
 
1503
class TestBundleWriterReader(tests.TestCase):
1510
1504
 
1511
1505
    def test_roundtrip_record(self):
1512
1506
        fileobj = StringIO()
1577
1571
        self.assertRaises(errors.BadBundle, record_iter.next)
1578
1572
 
1579
1573
 
1580
 
class TestReadMergeableFromUrl(TestCaseWithTransport):
 
1574
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
1581
1575
 
1582
1576
    def test_read_mergeable_skips_local(self):
1583
1577
        """A local bundle named like the URL should not be read.