~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Robert Collins
  • Date: 2008-04-04 00:06:58 UTC
  • mto: This revision was merged to the branch mainline in revision 3350.
  • Revision ID: robertc@robertcollins.net-20080404000658-uw2nmrw8t5kcqbly
Remove manual notification of transaction finishing on versioned files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    progress,
31
31
    )
32
32
from bzrlib.errors import (
33
 
                           RevisionNotPresent, 
 
33
                           RevisionNotPresent,
34
34
                           RevisionAlreadyPresent,
35
35
                           WeaveParentMismatch
36
36
                           )
37
37
from bzrlib.knit import (
38
 
    KnitVersionedFile,
 
38
    make_file_knit,
39
39
    KnitAnnotateFactory,
40
40
    KnitPlainFactory,
41
41
    )
59
59
    they are strictly controlled by their owning repositories.
60
60
    """
61
61
 
 
62
    def get_transaction(self):
 
63
        if not hasattr(self, '_transaction'):
 
64
            self._transaction = None
 
65
        return self._transaction
 
66
 
62
67
    def test_add(self):
63
68
        f = self.get_file()
64
69
        f.add_lines('r0', [], ['a\n', 'b\n'])
348
353
            set(f.get_ancestry('rM', topo_sorted=False)))
349
354
 
350
355
    def test_mutate_after_finish(self):
 
356
        self._transaction = 'before'
351
357
        f = self.get_file()
352
 
        f.transaction_finished()
 
358
        self._transaction = 'after'
353
359
        self.assertRaises(errors.OutSideTransaction, f.add_lines, '', [], [])
354
360
        self.assertRaises(errors.OutSideTransaction, f.add_lines_with_ghosts, '', [], [])
355
361
        self.assertRaises(errors.OutSideTransaction, f.join, '')
384
390
        f.add_lines('0', [], ['a\n'])
385
391
        t = MemoryTransport()
386
392
        f.copy_to('foo', t)
387
 
        for suffix in f.__class__.get_suffixes():
 
393
        for suffix in self.get_factory().get_suffixes():
388
394
            self.assertTrue(t.has('foo' + suffix))
389
395
 
390
396
    def test_get_suffixes(self):
391
397
        f = self.get_file()
392
 
        # should be the same
393
 
        self.assertEqual(f.__class__.get_suffixes(), f.__class__.get_suffixes())
394
398
        # and should be a list
395
 
        self.assertTrue(isinstance(f.__class__.get_suffixes(), list))
 
399
        self.assertTrue(isinstance(self.get_factory().get_suffixes(), list))
396
400
 
397
401
    def build_graph(self, file, graph):
398
402
        for node in topo_sort(graph.items()):
720
724
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
721
725
 
722
726
    def get_file(self, name='foo'):
723
 
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
 
727
        return WeaveFile(name, get_transport(self.get_url('.')), create=True,
 
728
            get_scope=self.get_transaction)
724
729
 
725
730
    def get_file_corrupted_text(self):
726
 
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True)
 
731
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
 
732
            get_scope=self.get_transaction)
727
733
        w.add_lines('v1', [], ['hello\n'])
728
734
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
729
735
        
757
763
        return w
758
764
 
759
765
    def reopen_file(self, name='foo', create=False):
760
 
        return WeaveFile(name, get_transport(self.get_url('.')), create=create)
 
766
        return WeaveFile(name, get_transport(self.get_url('.')), create=create,
 
767
            get_scope=self.get_transaction)
761
768
 
762
769
    def test_no_implicit_create(self):
763
770
        self.assertRaises(errors.NoSuchFile,
764
771
                          WeaveFile,
765
772
                          'foo',
766
 
                          get_transport(self.get_url('.')))
 
773
                          get_transport(self.get_url('.')),
 
774
                          get_scope=self.get_transaction)
767
775
 
768
776
    def get_factory(self):
769
777
        return WeaveFile
773
781
 
774
782
    def get_file(self, name='foo'):
775
783
        return self.get_factory()(name, get_transport(self.get_url('.')),
776
 
                                  delta=True, create=True)
 
784
            delta=True, create=True, get_scope=self.get_transaction)
777
785
 
778
786
    def get_factory(self):
779
 
        return KnitVersionedFile
 
787
        return make_file_knit
780
788
 
781
789
    def get_file_corrupted_text(self):
782
790
        knit = self.get_file()
794
802
        knit.check()
795
803
 
796
804
    def test_no_implicit_create(self):
797
 
        self.assertRaises(errors.NoSuchFile,
798
 
                          KnitVersionedFile,
799
 
                          'foo',
800
 
                          get_transport(self.get_url('.')))
 
805
        self.assertRaises(errors.NoSuchFile, self.get_factory(), 'foo',
 
806
            get_transport(self.get_url('.')))
801
807
 
802
808
 
803
809
class TestPlaintextKnit(TestKnit):
804
810
    """Test a knit with no cached annotations"""
805
811
 
806
 
    def _factory(self, name, transport, file_mode=None, access_mode=None,
807
 
                 delta=True, create=False):
808
 
        return KnitVersionedFile(name, transport, file_mode, access_mode,
809
 
                                 KnitPlainFactory(), delta=delta,
810
 
                                 create=create)
811
 
 
812
812
    def get_factory(self):
813
 
        return self._factory
 
813
        return make_file_knit
814
814
 
815
815
 
816
816
class TestPlanMergeVersionedFile(TestCaseWithMemoryTransport):
817
817
 
818
818
    def setUp(self):
819
819
        TestCaseWithMemoryTransport.setUp(self)
820
 
        self.vf1 = KnitVersionedFile('root', self.get_transport(), create=True)
821
 
        self.vf2 = KnitVersionedFile('root', self.get_transport(), create=True)
 
820
        self.vf1 = make_file_knit('root', self.get_transport(), create=True)
 
821
        self.vf2 = make_file_knit('root', self.get_transport(), create=True)
822
822
        self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root',
823
823
            [self.vf1, self.vf2])
824
824
 
946
946
 
947
947
class TestReadonlyHttpMixin(object):
948
948
 
 
949
    def get_transaction(self):
 
950
        return 1
 
951
 
949
952
    def test_readonly_http_works(self):
950
953
        # we should be able to read from http with a versioned file.
951
954
        vf = self.get_file()
964
967
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
965
968
 
966
969
    def get_file(self):
967
 
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True)
 
970
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True,
 
971
            get_scope=self.get_transaction)
968
972
 
969
973
    def get_factory(self):
970
974
        return WeaveFile
973
977
class TestKnitHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
974
978
 
975
979
    def get_file(self):
976
 
        return KnitVersionedFile('foo', get_transport(self.get_url('.')),
977
 
                                 delta=True, create=True)
 
980
        return make_file_knit('foo', get_transport(self.get_url('.')),
 
981
            delta=True, create=True, get_scope=self.get_transaction)
978
982
 
979
983
    def get_factory(self):
980
 
        return KnitVersionedFile
 
984
        return make_file_knit
981
985
 
982
986
 
983
987
class MergeCasesMixin(object):
1220
1224
class TestKnitMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1221
1225
 
1222
1226
    def get_file(self, name='foo'):
1223
 
        return KnitVersionedFile(name, get_transport(self.get_url('.')),
 
1227
        return make_file_knit(name, get_transport(self.get_url('.')),
1224
1228
                                 delta=True, create=True)
1225
1229
 
1226
1230
    def log_contents(self, w):
1240
1244
 
1241
1245
    overlappedInsertExpected = ['aaa', '<<<<<<< ', 'xxx', 'yyy', '=======', 
1242
1246
                                'xxx', '>>>>>>> ', 'bbb']
1243
 
 
1244
 
 
1245
 
class TestFormatSignatures(TestCaseWithMemoryTransport):
1246
 
 
1247
 
    def get_knit_file(self, name, annotated):
1248
 
        if annotated:
1249
 
            factory = KnitAnnotateFactory()
1250
 
        else:
1251
 
            factory = KnitPlainFactory()
1252
 
        return KnitVersionedFile(
1253
 
            name, get_transport(self.get_url('.')), create=True,
1254
 
            factory=factory)
1255
 
 
1256
 
    def test_knit_format_signatures(self):
1257
 
        """Different formats of knit have different signature strings."""
1258
 
        knit = self.get_knit_file('a', True)
1259
 
        self.assertEqual('knit-annotated', knit.get_format_signature())
1260
 
        knit = self.get_knit_file('p', False)
1261
 
        self.assertEqual('knit-plain', knit.get_format_signature())
1262