~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-23 17:00:36 UTC
  • mfrom: (4032.1.4 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090223170036-3q1v68ewdt8i0to5
(Marius Kruger) Remove all trailing whitespace and add tests to
        enforce this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
    def add_dir(self, file_id, path):
115
115
        self.paths[file_id] = path
116
116
        self.ids[path] = file_id
117
 
    
 
117
 
118
118
    def add_file(self, file_id, path, contents):
119
119
        self.add_dir(file_id, path)
120
120
        self.contents[file_id] = contents
151
151
        mtree.add_file("c", "grandparent/parent/file", "Hello\n")
152
152
        mtree.add_dir("d", "grandparent/alt_parent")
153
153
        return BundleTree(mtree, ''), mtree
154
 
        
 
154
 
155
155
    def test_renames(self):
156
156
        """Ensure that file renames have the proper effect on children"""
157
157
        btree = self.make_tree_1()[0]
158
158
        self.assertEqual(btree.old_path("grandparent"), "grandparent")
159
 
        self.assertEqual(btree.old_path("grandparent/parent"), 
 
159
        self.assertEqual(btree.old_path("grandparent/parent"),
160
160
                         "grandparent/parent")
161
161
        self.assertEqual(btree.old_path("grandparent/parent/file"),
162
162
                         "grandparent/parent/file")
202
202
        self.assertTrue(btree.path2id("grandparent2/parent") is None)
203
203
        self.assertTrue(btree.path2id("grandparent2/parent/file") is None)
204
204
 
205
 
        btree.note_rename("grandparent/parent/file", 
 
205
        btree.note_rename("grandparent/parent/file",
206
206
                          "grandparent2/parent2/file2")
207
207
        self.assertEqual(btree.id2path("a"), "grandparent2")
208
208
        self.assertEqual(btree.id2path("b"), "grandparent2/parent2")
217
217
    def test_moves(self):
218
218
        """Ensure that file moves have the proper effect on children"""
219
219
        btree = self.make_tree_1()[0]
220
 
        btree.note_rename("grandparent/parent/file", 
 
220
        btree.note_rename("grandparent/parent/file",
221
221
                          "grandparent/alt_parent/file")
222
222
        self.assertEqual(btree.id2path("c"), "grandparent/alt_parent/file")
223
223
        self.assertEqual(btree.path2id("grandparent/alt_parent/file"), "c")
231
231
 
232
232
    def make_tree_2(self):
233
233
        btree = self.make_tree_1()[0]
234
 
        btree.note_rename("grandparent/parent/file", 
 
234
        btree.note_rename("grandparent/parent/file",
235
235
                          "grandparent/alt_parent/file")
236
236
        self.assertTrue(btree.id2path("e") is None)
237
237
        self.assertTrue(btree.path2id("grandparent/parent/file") is None)
266
266
    def make_tree_3(self):
267
267
        btree, mtree = self.make_tree_1()
268
268
        mtree.add_file("e", "grandparent/parent/topping", "Anchovies\n")
269
 
        btree.note_rename("grandparent/parent/file", 
 
269
        btree.note_rename("grandparent/parent/file",
270
270
                          "grandparent/alt_parent/file")
271
 
        btree.note_rename("grandparent/parent/topping", 
 
271
        btree.note_rename("grandparent/parent/topping",
272
272
                          "grandparent/alt_parent/stopping")
273
273
        return btree
274
274
 
313
313
            [inventory.ROOT_ID, 'a', 'b', 'c', 'd'])
314
314
        btree.note_deletion("grandparent/parent/file")
315
315
        btree.note_id("e", "grandparent/alt_parent/fool", kind="directory")
316
 
        btree.note_last_changed("grandparent/alt_parent/fool", 
 
316
        btree.note_last_changed("grandparent/alt_parent/fool",
317
317
                                "revisionidiguess")
318
318
        self.assertEqual(self.sorted_ids(btree),
319
319
            [inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
326
326
        format.repository_format = knitrepo.RepositoryFormatKnit3()
327
327
        serializer = BundleSerializerV08('0.8')
328
328
        b = self.make_branch('.', format=format)
329
 
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write, 
 
329
        self.assertRaises(errors.IncompatibleBundleFormat, serializer.write,
330
330
                          b.repository, [], {}, StringIO())
331
331
 
332
332
    def test_matched_bundle(self):
352
352
        format = bzrdir.BzrDirMetaFormat1()
353
353
        format.repository_format = knitrepo.RepositoryFormatKnit1()
354
354
        target = self.make_branch('target', format=format)
355
 
        self.assertRaises(errors.IncompatibleRevision, install_bundle, 
 
355
        self.assertRaises(errors.IncompatibleRevision, install_bundle,
356
356
                          target.repository, read_bundle(text))
357
357
 
358
358
 
375
375
 
376
376
    def create_bundle_text(self, base_rev_id, rev_id):
377
377
        bundle_txt = StringIO()
378
 
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
 
378
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
379
379
                               bundle_txt, format=self.format)
380
380
        bundle_txt.seek(0)
381
 
        self.assertEqual(bundle_txt.readline(), 
 
381
        self.assertEqual(bundle_txt.readline(),
382
382
                         '# Bazaar revision bundle v%s\n' % self.format)
383
383
        self.assertEqual(bundle_txt.readline(), '#\n')
384
384
 
392
392
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
393
393
        Make sure that the text generated is valid, and that it
394
394
        can be applied against the base, and generate the same information.
395
 
        
396
 
        :return: The in-memory bundle 
 
395
 
 
396
        :return: The in-memory bundle
397
397
        """
398
398
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
399
399
 
400
 
        # This should also validate the generated bundle 
 
400
        # This should also validate the generated bundle
401
401
        bundle = read_bundle(bundle_txt)
402
402
        repository = self.b1.repository
403
403
        for bundle_rev in bundle.real_revisions:
407
407
            # it
408
408
            branch_rev = repository.get_revision(bundle_rev.revision_id)
409
409
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
410
 
                      'timestamp', 'timezone', 'message', 'committer', 
 
410
                      'timestamp', 'timezone', 'message', 'committer',
411
411
                      'parent_ids', 'properties'):
412
 
                self.assertEqual(getattr(branch_rev, a), 
 
412
                self.assertEqual(getattr(branch_rev, a),
413
413
                                 getattr(bundle_rev, a))
414
 
            self.assertEqual(len(branch_rev.parent_ids), 
 
414
            self.assertEqual(len(branch_rev.parent_ids),
415
415
                             len(bundle_rev.parent_ids))
416
 
        self.assertEqual(rev_ids, 
 
416
        self.assertEqual(rev_ids,
417
417
                         [r.revision_id for r in bundle.real_revisions])
418
418
        self.valid_apply_bundle(base_rev_id, bundle,
419
419
                                   checkout_dir=checkout_dir)
423
423
    def get_invalid_bundle(self, base_rev_id, rev_id):
424
424
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
425
425
        Munge the text so that it's invalid.
426
 
        
 
426
 
427
427
        :return: The in-memory bundle
428
428
        """
429
429
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
430
 
        new_text = bundle_txt.getvalue().replace('executable:no', 
 
430
        new_text = bundle_txt.getvalue().replace('executable:no',
431
431
                                               'executable:yes')
432
432
        bundle_txt = StringIO(new_text)
433
433
        bundle = read_bundle(bundle_txt)
434
434
        self.valid_apply_bundle(base_rev_id, bundle)
435
 
        return bundle 
 
435
        return bundle
436
436
 
437
437
    def test_non_bundle(self):
438
438
        self.assertRaises(errors.NotABundle,
519
519
        self.assertIs(repository.has_revision(base_rev_id), True)
520
520
        for rev in info.real_revisions:
521
521
            self.assert_(not repository.has_revision(rev.revision_id),
522
 
                'Revision {%s} present before applying bundle' 
 
522
                'Revision {%s} present before applying bundle'
523
523
                % rev.revision_id)
524
524
        merge_bundle(info, to_tree, True, Merge3Merger, False, False)
525
525
 
526
526
        for rev in info.real_revisions:
527
527
            self.assert_(repository.has_revision(rev.revision_id),
528
 
                'Missing revision {%s} after applying bundle' 
 
528
                'Missing revision {%s} after applying bundle'
529
529
                % rev.revision_id)
530
530
 
531
531
        self.assert_(to_tree.branch.repository.has_revision(info.target))
537
537
        rev = info.real_revisions[-1]
538
538
        base_tree = self.b1.repository.revision_tree(rev.revision_id)
539
539
        to_tree = to_tree.branch.repository.revision_tree(rev.revision_id)
540
 
        
 
540
 
541
541
        # TODO: make sure the target tree is identical to base tree
542
542
        #       we might also check the working tree.
543
543
 
603
603
 
604
604
        bundle = self.get_valid_bundle('a@cset-0-1', 'a@cset-0-2')
605
605
 
606
 
        # Check a rollup bundle 
 
606
        # Check a rollup bundle
607
607
        bundle = self.get_valid_bundle('null:', 'a@cset-0-2')
608
608
 
609
609
        # Now delete entries
617
617
        tt.set_executability(False, trans_id)
618
618
        tt.apply()
619
619
        self.tree1.commit('removed', rev_id='a@cset-0-3')
620
 
        
 
620
 
621
621
        bundle = self.get_valid_bundle('a@cset-0-2', 'a@cset-0-3')
622
622
        self.assertRaises((errors.TestamentMismatch,
623
623
            errors.VersionedFileInvalidChecksum), self.get_invalid_bundle,
624
624
            'a@cset-0-2', 'a@cset-0-3')
625
 
        # Check a rollup bundle 
 
625
        # Check a rollup bundle
626
626
        bundle = self.get_valid_bundle('null:', 'a@cset-0-3')
627
627
 
628
628
        # Now move the directory
630
630
        self.tree1.commit('rename dir', rev_id='a@cset-0-4')
631
631
 
632
632
        bundle = self.get_valid_bundle('a@cset-0-3', 'a@cset-0-4')
633
 
        # Check a rollup bundle 
 
633
        # Check a rollup bundle
634
634
        bundle = self.get_valid_bundle('null:', 'a@cset-0-4')
635
635
 
636
636
        # Modified files
638
638
        open('b1/sub/dir/ pre space', 'ab').write(
639
639
             '\r\nAdding some\r\nDOS format lines\r\n')
640
640
        open('b1/sub/dir/nolastnewline.txt', 'ab').write('\n')
641
 
        self.tree1.rename_one('sub/dir/ pre space', 
 
641
        self.tree1.rename_one('sub/dir/ pre space',
642
642
                              'sub/ start space')
643
643
        self.tree1.commit('Modified files', rev_id='a@cset-0-5')
644
644
        bundle = self.get_valid_bundle('a@cset-0-4', 'a@cset-0-5')
696
696
        self.tree1 = self.make_branch_and_tree('b1')
697
697
        self.b1 = self.tree1.branch
698
698
        tt = TreeTransform(self.tree1)
699
 
        
 
699
 
700
700
        # Add
701
701
        tt.new_file('file', tt.root, '\x00\n\x00\r\x01\n\x02\r\xff', 'binary-1')
702
702
        tt.new_file('file2', tt.root, '\x01\n\x02\r\x03\n\x04\r\xff',
875
875
        self.tree1.commit('removed', rev_id='white-4')
876
876
 
877
877
        bundle = self.get_valid_bundle('white-3', 'white-4')
878
 
        
 
878
 
879
879
        # Now test a complet roll-up
880
880
        bundle = self.get_valid_bundle('null:', 'white-4')
881
881
 
894
894
                          timezone=19800, timestamp=1152544886.0)
895
895
 
896
896
        bundle = self.get_valid_bundle('null:', 'tz-1')
897
 
        
 
897
 
898
898
        rev = bundle.revisions[0]
899
899
        self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
900
900
        self.assertEqual(19800, rev.timezone)
1260
1260
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
1261
1261
        Make sure that the text generated is valid, and that it
1262
1262
        can be applied against the base, and generate the same information.
1263
 
        
1264
 
        :return: The in-memory bundle 
 
1263
 
 
1264
        :return: The in-memory bundle
1265
1265
        """
1266
1266
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
1267
1267
 
1268
 
        # This should also validate the generated bundle 
 
1268
        # This should also validate the generated bundle
1269
1269
        bundle = read_bundle(bundle_txt)
1270
1270
        repository = self.b1.repository
1271
1271
        for bundle_rev in bundle.real_revisions:
1275
1275
            # it
1276
1276
            branch_rev = repository.get_revision(bundle_rev.revision_id)
1277
1277
            for a in ('inventory_sha1', 'revision_id', 'parent_ids',
1278
 
                      'timestamp', 'timezone', 'message', 'committer', 
 
1278
                      'timestamp', 'timezone', 'message', 'committer',
1279
1279
                      'parent_ids', 'properties'):
1280
 
                self.assertEqual(getattr(branch_rev, a), 
 
1280
                self.assertEqual(getattr(branch_rev, a),
1281
1281
                                 getattr(bundle_rev, a))
1282
 
            self.assertEqual(len(branch_rev.parent_ids), 
 
1282
            self.assertEqual(len(branch_rev.parent_ids),
1283
1283
                             len(bundle_rev.parent_ids))
1284
1284
        self.assertEqual(set(rev_ids),
1285
1285
                         set([r.revision_id for r in bundle.real_revisions]))
1311
1311
 
1312
1312
    def create_bundle_text(self, base_rev_id, rev_id):
1313
1313
        bundle_txt = StringIO()
1314
 
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
 
1314
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id,
1315
1315
                               bundle_txt, format=self.format)
1316
1316
        bundle_txt.seek(0)
1317
 
        self.assertEqual(bundle_txt.readline(), 
 
1317
        self.assertEqual(bundle_txt.readline(),
1318
1318
                         '# Bazaar revision bundle v%s\n' % self.format)
1319
1319
        self.assertEqual(bundle_txt.readline(), '#\n')
1320
1320
        rev = self.b1.repository.get_revision(rev_id)