~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-12-04 00:42:43 UTC
  • mfrom: (3062.1.14 fast-plan-merge)
  • Revision ID: pqm@pqm.ubuntu.com-20071204004243-cgss0sl9yf0ayepc
Speed up annotate on packs

Show diffs side-by-side

added added

removed removed

Lines of Context:
797
797
        return self._factory
798
798
 
799
799
 
 
800
class TestPlanMergeVersionedFile(TestCaseWithMemoryTransport):
 
801
 
 
802
    def setUp(self):
 
803
        TestCaseWithMemoryTransport.setUp(self)
 
804
        self.vf1 = KnitVersionedFile('root', self.get_transport(), create=True)
 
805
        self.vf2 = KnitVersionedFile('root', self.get_transport(), create=True)
 
806
        self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root',
 
807
            [self.vf1, self.vf2])
 
808
 
 
809
    def test_add_lines(self):
 
810
        self.plan_merge_vf.add_lines('a:', [], [])
 
811
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a', [],
 
812
                          [])
 
813
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a:', None,
 
814
                          [])
 
815
        self.assertRaises(ValueError, self.plan_merge_vf.add_lines, 'a:', [],
 
816
                          None)
 
817
 
 
818
    def test_ancestry(self):
 
819
        self.vf1.add_lines('A', [], [])
 
820
        self.vf1.add_lines('B', ['A'], [])
 
821
        self.plan_merge_vf.add_lines('C:', ['B'], [])
 
822
        self.plan_merge_vf.add_lines('D:', ['C:'], [])
 
823
        self.assertEqual(set(['A', 'B', 'C:', 'D:']),
 
824
            self.plan_merge_vf.get_ancestry('D:', topo_sorted=False))
 
825
 
 
826
    def setup_abcde(self):
 
827
        self.vf1.add_lines('A', [], ['a'])
 
828
        self.vf1.add_lines('B', ['A'], ['b'])
 
829
        self.vf2.add_lines('C', [], ['c'])
 
830
        self.vf2.add_lines('D', ['C'], ['d'])
 
831
        self.plan_merge_vf.add_lines('E:', ['B', 'D'], ['e'])
 
832
 
 
833
    def test_ancestry_uses_all_versionedfiles(self):
 
834
        self.setup_abcde()
 
835
        self.assertEqual(set(['A', 'B', 'C', 'D', 'E:']),
 
836
            self.plan_merge_vf.get_ancestry('E:', topo_sorted=False))
 
837
 
 
838
    def test_ancestry_raises_revision_not_present(self):
 
839
        error = self.assertRaises(errors.RevisionNotPresent,
 
840
                                  self.plan_merge_vf.get_ancestry, 'E:', False)
 
841
        self.assertContainsRe(str(error), '{E:} not present in "root"')
 
842
 
 
843
    def test_get_parents(self):
 
844
        self.setup_abcde()
 
845
        self.assertEqual(['A'], self.plan_merge_vf.get_parents('B'))
 
846
        self.assertEqual(['C'], self.plan_merge_vf.get_parents('D'))
 
847
        self.assertEqual(['B', 'D'], self.plan_merge_vf.get_parents('E:'))
 
848
        error = self.assertRaises(errors.RevisionNotPresent,
 
849
                                  self.plan_merge_vf.get_parents, 'F')
 
850
        self.assertContainsRe(str(error), '{F} not present in "root"')
 
851
 
 
852
    def test_get_lines(self):
 
853
        self.setup_abcde()
 
854
        self.assertEqual(['a'], self.plan_merge_vf.get_lines('A'))
 
855
        self.assertEqual(['c'], self.plan_merge_vf.get_lines('C'))
 
856
        self.assertEqual(['e'], self.plan_merge_vf.get_lines('E:'))
 
857
        error = self.assertRaises(errors.RevisionNotPresent,
 
858
                                  self.plan_merge_vf.get_lines, 'F')
 
859
        self.assertContainsRe(str(error), '{F} not present in "root"')
 
860
 
 
861
 
800
862
class InterString(versionedfile.InterVersionedFile):
801
863
    """An inter-versionedfile optimised code path for strings.
802
864