/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_groupcompress.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-17 01:48:56 UTC
  • mfrom: (4543 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4545.
  • Revision ID: andrew.bennetts@canonical.com-20090717014856-c8igd2f9abbi3v30
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    index as _mod_index,
26
26
    osutils,
27
27
    tests,
 
28
    trace,
28
29
    versionedfile,
29
30
    )
30
31
from bzrlib.osutils import sha_string
474
475
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):
475
476
 
476
477
    def make_test_vf(self, create_graph, keylength=1, do_cleanup=True,
477
 
                     dir='.'):
 
478
                     dir='.', inconsistency_fatal=True):
478
479
        t = self.get_transport(dir)
479
480
        t.ensure_base()
480
481
        vf = groupcompress.make_pack_factory(graph=create_graph,
481
 
            delta=False, keylength=keylength)(t)
 
482
            delta=False, keylength=keylength,
 
483
            inconsistency_fatal=inconsistency_fatal)(t)
482
484
        if do_cleanup:
483
485
            self.addCleanup(groupcompress.cleanup_pack_group, vf)
484
486
        return vf
658
660
            frozenset([('parent-1',), ('parent-2',)]),
659
661
            index.get_missing_parents())
660
662
 
 
663
    def make_source_with_b(self, a_parent, path):
 
664
        source = self.make_test_vf(True, dir=path)
 
665
        source.add_lines(('a',), (), ['lines\n'])
 
666
        if a_parent:
 
667
            b_parents = (('a',),)
 
668
        else:
 
669
            b_parents = ()
 
670
        source.add_lines(('b',), b_parents, ['lines\n'])
 
671
        return source
 
672
 
 
673
    def do_inconsistent_inserts(self, inconsistency_fatal):
 
674
        target = self.make_test_vf(True, dir='target',
 
675
                                   inconsistency_fatal=inconsistency_fatal)
 
676
        for x in range(2):
 
677
            source = self.make_source_with_b(x==1, 'source%s' % x)
 
678
            target.insert_record_stream(source.get_record_stream(
 
679
                [('b',)], 'unordered', False))
 
680
 
 
681
    def test_inconsistent_redundant_inserts_warn(self):
 
682
        """Should not insert a record that is already present."""
 
683
        warnings = []
 
684
        def warning(template, args):
 
685
            warnings.append(template % args)
 
686
        _trace_warning = trace.warning
 
687
        trace.warning = warning
 
688
        try:
 
689
            self.do_inconsistent_inserts(inconsistency_fatal=False)
 
690
        finally:
 
691
            trace.warning = _trace_warning
 
692
        self.assertEqual(["inconsistent details in skipped record: ('b',)"
 
693
                          " ('42 32 0 8', ((),)) ('74 32 0 8', ((('a',),),))"],
 
694
                         warnings)
 
695
 
 
696
    def test_inconsistent_redundant_inserts_raises(self):
 
697
        e = self.assertRaises(errors.KnitCorrupt, self.do_inconsistent_inserts,
 
698
                              inconsistency_fatal=True)
 
699
        self.assertContainsRe(str(e), "Knit.* corrupt: inconsistent details"
 
700
                              " in add_records:"
 
701
                              " \('b',\) \('42 32 0 8', \(\(\),\)\) \('74 32"
 
702
                              " 0 8', \(\(\('a',\),\),\)\)")
 
703
 
661
704
 
662
705
class TestLazyGroupCompress(tests.TestCaseWithTransport):
663
706