~bzr/ubuntu/lucid/bzr/beta-ppa

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_repository.py

  • Committer: Martin Pool
  • Date: 2010-08-18 04:26:39 UTC
  • mfrom: (129.1.8 packaging-karmic)
  • Revision ID: mbp@sourcefrog.net-20100818042639-mjoxtngyjwiu05fo
* PPA rebuild for lucid.
* PPA rebuild for karmic.
* PPA rebuild onto jaunty.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from cStringIO import StringIO
20
20
import re
21
21
 
22
 
import bzrlib
23
22
from bzrlib import (
 
23
    branch as _mod_branch,
24
24
    bzrdir,
 
25
    delta as _mod_delta,
25
26
    errors,
26
27
    gpg,
27
28
    graph,
28
29
    info,
 
30
    inventory,
29
31
    osutils,
30
32
    remote,
31
33
    repository,
 
34
    revision as _mod_revision,
 
35
    tests,
 
36
    transport,
 
37
    upgrade,
 
38
    versionedfile,
 
39
    workingtree,
32
40
    xml_serializer,
33
41
    )
34
 
from bzrlib.branch import BzrBranchFormat6
35
 
from bzrlib.delta import TreeDelta
36
 
from bzrlib.inventory import CommonInventory, Inventory, InventoryDirectory
37
 
from bzrlib.repofmt.pack_repo import (
38
 
    RepositoryFormatKnitPack5RichRootBroken,
39
 
    )
40
 
from bzrlib.repofmt.weaverepo import (
41
 
    RepositoryFormat5,
42
 
    RepositoryFormat6,
43
 
    RepositoryFormat7,
44
 
    )
45
 
from bzrlib.revision import NULL_REVISION, Revision
46
 
from bzrlib.smart import server
 
42
from bzrlib.repofmt import (
 
43
    pack_repo,
 
44
    weaverepo,
 
45
    )
47
46
from bzrlib.tests import (
48
 
    KnownFailure,
49
 
    TestCaseWithTransport,
50
 
    TestNotApplicable,
51
 
    TestSkipped,
 
47
    per_repository,
 
48
    test_server,
52
49
    )
53
 
from bzrlib.tests.per_repository import TestCaseWithRepository
54
 
from bzrlib.transport import get_transport
55
 
from bzrlib.transport.fakevfat import FakeVFATServer
56
 
from bzrlib.upgrade import upgrade
57
 
from bzrlib.workingtree import WorkingTree
58
 
 
59
 
 
60
 
class TestRepositoryMakeBranchAndTree(TestCaseWithRepository):
 
50
from bzrlib.tests.matchers import *
 
51
 
 
52
 
 
53
class TestRepositoryMakeBranchAndTree(per_repository.TestCaseWithRepository):
61
54
 
62
55
    def test_repository_format(self):
63
56
        # make sure the repository on tree.branch is of the desired format,
69
62
            self.repository_format.__class__)
70
63
 
71
64
 
72
 
class TestRepository(TestCaseWithRepository):
 
65
class TestRepository(per_repository.TestCaseWithRepository):
73
66
 
74
67
    def assertFormatAttribute(self, attribute, allowed_values):
75
68
        """Assert that the format has an attribute 'attribute'."""
92
85
        """Test the _fetch_reconcile attribute."""
93
86
        self.assertFormatAttribute('_fetch_reconcile', (True, False))
94
87
 
 
88
    def test_attribute_format_experimental(self):
 
89
        self.assertFormatAttribute('experimental', (True, False))
 
90
 
95
91
    def test_attribute_format_pack_compresses(self):
96
92
        self.assertFormatAttribute('pack_compresses', (True, False))
97
93
 
99
95
        """Test the existence of the inventories attribute."""
100
96
        tree = self.make_branch_and_tree('tree')
101
97
        repo = tree.branch.repository
102
 
        self.assertIsInstance(repo.inventories,
103
 
            bzrlib.versionedfile.VersionedFiles)
 
98
        self.assertIsInstance(repo.inventories, versionedfile.VersionedFiles)
104
99
 
105
100
    def test_attribute_inventories_basics(self):
106
101
        """Test basic aspects of the inventories attribute."""
116
111
        tree = self.make_branch_and_tree('tree')
117
112
        repo = tree.branch.repository
118
113
        self.assertIsInstance(repo.revisions,
119
 
            bzrlib.versionedfile.VersionedFiles)
 
114
            versionedfile.VersionedFiles)
120
115
 
121
116
    def test_attribute_revision_store_basics(self):
122
117
        """Test the basic behaviour of the revisions attribute."""
150
145
        tree = self.make_branch_and_tree('tree')
151
146
        repo = tree.branch.repository
152
147
        self.assertIsInstance(repo.signatures,
153
 
            bzrlib.versionedfile.VersionedFiles)
 
148
            versionedfile.VersionedFiles)
154
149
 
155
150
    def test_attribute_text_store_basics(self):
156
151
        """Test the basic behaviour of the text store."""
166
161
            try:
167
162
                rev_key = (tree.commit("foo"),)
168
163
            except errors.IllegalPath:
169
 
                raise TestNotApplicable('file_id %r cannot be stored on this'
 
164
                raise tests.TestNotApplicable(
 
165
                    'file_id %r cannot be stored on this'
170
166
                    ' platform for this repo format' % (file_id,))
171
167
            if repo._format.rich_root_data:
172
168
                root_commit = (tree.get_root_id(),) + rev_key
212
208
        tree = self.make_branch_and_tree('tree')
213
209
        repo = tree.branch.repository
214
210
        self.assertIsInstance(repo.texts,
215
 
            bzrlib.versionedfile.VersionedFiles)
 
211
            versionedfile.VersionedFiles)
216
212
 
217
213
    def test_exposed_versioned_files_are_marked_dirty(self):
218
214
        repo = self.make_repository('.')
261
257
        invs = tree.branch.repository.iter_inventories(revs)
262
258
        for rev_id, inv in zip(revs, invs):
263
259
            self.assertEqual(rev_id, inv.revision_id)
264
 
            self.assertIsInstance(inv, CommonInventory)
 
260
            self.assertIsInstance(inv, inventory.CommonInventory)
265
261
 
266
262
    def test_supports_rich_root(self):
267
263
        tree = self.make_branch_and_tree('a')
286
282
            # they may not be initializable.
287
283
            return
288
284
        # supported formats must be able to init and open
289
 
        t = get_transport(self.get_url())
290
 
        readonly_t = get_transport(self.get_readonly_url())
 
285
        t = transport.get_transport(self.get_url())
 
286
        readonly_t = transport.get_transport(self.get_readonly_url())
291
287
        made_control = self.bzrdir_format.initialize(t.base)
292
288
        made_repo = self.repository_format.initialize(made_control)
293
289
        self.assertEqual(made_control, made_repo.bzrdir)
346
342
            # because the default open will not open them and
347
343
            # they may not be initializable.
348
344
            return
349
 
        t = get_transport(self.get_url())
 
345
        t = transport.get_transport(self.get_url())
350
346
        made_control = self.bzrdir_format.initialize(t.base)
351
347
        made_repo = made_control.create_repository()
352
348
        # Check that we have a repository object.
360
356
            # because the default open will not open them and
361
357
            # they may not be initializable.
362
358
            return
363
 
        t = get_transport(self.get_url())
 
359
        t = transport.get_transport(self.get_url())
364
360
        made_control = self.bzrdir_format.initialize(t.base)
365
361
        try:
366
362
            made_repo = made_control.create_repository(shared=True)
381
377
        tree.lock_read()
382
378
        try:
383
379
            self.assertEqual('revision-1', tree.inventory.root.revision)
384
 
            expected = InventoryDirectory('fixed-root', '', None)
 
380
            expected = inventory.InventoryDirectory('fixed-root', '', None)
385
381
            expected.revision = 'revision-1'
386
382
            self.assertEqual([('', 'V', 'directory', 'fixed-root', expected)],
387
383
                             list(tree.list_files(include_root=True)))
395
391
            self.assertEqual([], list(tree.list_files(include_root=True)))
396
392
        finally:
397
393
            tree.unlock()
398
 
        tree = wt.branch.repository.revision_tree(NULL_REVISION)
 
394
        tree = wt.branch.repository.revision_tree(_mod_revision.NULL_REVISION)
399
395
        tree.lock_read()
400
396
        try:
401
397
            self.assertEqual([], list(tree.list_files(include_root=True)))
412
408
        tree_a.commit('rev2', rev_id='rev2')
413
409
 
414
410
        delta = tree_a.branch.repository.get_revision_delta('rev1')
415
 
        self.assertIsInstance(delta, TreeDelta)
 
411
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
416
412
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
417
413
        delta = tree_a.branch.repository.get_revision_delta('rev2')
418
 
        self.assertIsInstance(delta, TreeDelta)
 
414
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
419
415
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
420
416
 
421
417
    def test_get_revision_delta_filtered(self):
431
427
        # Test multiple files
432
428
        delta = tree_a.branch.repository.get_revision_delta('rev1',
433
429
            specific_fileids=['foo-id', 'baz-id'])
434
 
        self.assertIsInstance(delta, TreeDelta)
 
430
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
435
431
        self.assertEqual([
436
432
            ('baz', 'baz-id', 'file'),
437
433
            ('foo', 'foo-id', 'file'),
439
435
        # Test a directory
440
436
        delta = tree_a.branch.repository.get_revision_delta('rev1',
441
437
            specific_fileids=['bar-id'])
442
 
        self.assertIsInstance(delta, TreeDelta)
 
438
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
443
439
        self.assertEqual([
444
440
            ('bar', 'bar-id', 'directory'),
445
441
            ('bar/b1', 'b1-id', 'file'),
448
444
        # Test a file in a directory
449
445
        delta = tree_a.branch.repository.get_revision_delta('rev1',
450
446
            specific_fileids=['b2-id'])
451
 
        self.assertIsInstance(delta, TreeDelta)
 
447
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
452
448
        self.assertEqual([
453
449
            ('bar', 'bar-id', 'directory'),
454
450
            ('bar/b2', 'b2-id', 'file'),
456
452
        # Try another revision
457
453
        delta = tree_a.branch.repository.get_revision_delta('rev2',
458
454
                specific_fileids=['b3-id'])
459
 
        self.assertIsInstance(delta, TreeDelta)
 
455
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
460
456
        self.assertEqual([
461
457
            ('bar', 'bar-id', 'directory'),
462
458
            ('bar/b3', 'b3-id', 'file'),
463
459
            ], delta.added)
464
460
        delta = tree_a.branch.repository.get_revision_delta('rev2',
465
461
                specific_fileids=['foo-id'])
466
 
        self.assertIsInstance(delta, TreeDelta)
 
462
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
467
463
        self.assertEqual([], delta.added)
468
464
 
469
465
    def test_clone_bzrdir_repository_revision(self):
470
466
        # make a repository with some revisions,
471
467
        # and clone it, this should not have unreferenced revisions.
472
468
        # also: test cloning with a revision id of NULL_REVISION -> empty repo.
473
 
        raise TestSkipped('revision limiting is not implemented yet.')
 
469
        raise tests.TestSkipped('revision limiting is not implemented yet.')
474
470
 
475
471
    def test_clone_repository_basis_revision(self):
476
 
        raise TestSkipped('the use of a basis should not add noise data to the result.')
 
472
        raise tests.TestSkipped(
 
473
            'the use of a basis should not add noise data to the result.')
477
474
 
478
475
    def test_clone_shared_no_tree(self):
479
476
        # cloning a shared repository keeps it shared
514
511
            # This gives metadir branches something they can convert to.
515
512
            # it would be nice to have a 'latest' vs 'default' concept.
516
513
            format = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
517
 
            upgrade(repo.bzrdir.root_transport.base, format=format)
 
514
            upgrade.upgrade(repo.bzrdir.root_transport.base, format=format)
518
515
        except errors.UpToDateFormat:
519
516
            # this is in the most current format already.
520
517
            return
521
518
        except errors.BadConversionTarget, e:
522
 
            raise TestSkipped(str(e))
523
 
        wt = WorkingTree.open(wt.basedir)
 
519
            raise tests.TestSkipped(str(e))
 
520
        wt = workingtree.WorkingTree.open(wt.basedir)
524
521
        new_signature = wt.branch.repository.get_signature_text('A')
525
522
        self.assertEqual(old_signature, new_signature)
526
523
 
608
605
            return # local conversion to/from RemoteObjects is irrelevant.
609
606
        if self.repository_format.get_format_description() \
610
607
            == "Repository format 4":
611
 
            raise TestSkipped('Cannot convert format-4 to itself')
 
608
            raise tests.TestSkipped('Cannot convert format-4 to itself')
612
609
        self.build_tree_contents(_upgrade_dir_template)
613
 
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
 
610
        old_repodir = bzrdir.BzrDir.open_unsupported('.')
614
611
        old_repo_format = old_repodir.open_repository()._format
615
612
        format = self.repository_format._matchingbzrdir
616
613
        try:
617
614
            format.repository_format = self.repository_format
618
615
        except AttributeError:
619
616
            pass
620
 
        upgrade('.', format)
 
617
        upgrade.upgrade('.', format)
621
618
 
622
619
    def test_pointless_commit(self):
623
620
        tree = self.make_branch_and_tree('.')
728
725
        self.assertTrue('ghost' not in parents)
729
726
        self.assertEqual(parents['rev2'], ('rev1', 'ghost'))
730
727
 
 
728
    def test_get_known_graph_ancestry(self):
 
729
        tree = self.make_branch_and_tree('here')
 
730
        tree.lock_write()
 
731
        self.addCleanup(tree.unlock)
 
732
        # A
 
733
        # |\
 
734
        # | B
 
735
        # |/
 
736
        # C
 
737
        tree.commit('initial commit', rev_id='A')
 
738
        tree_other = tree.bzrdir.sprout('there').open_workingtree()
 
739
        tree_other.commit('another', rev_id='B')
 
740
        tree.merge_from_branch(tree_other.branch)
 
741
        tree.commit('another', rev_id='C')
 
742
        kg = tree.branch.repository.get_known_graph_ancestry(
 
743
            ['C'])
 
744
        self.assertEqual(['C'], list(kg.heads(['A', 'B', 'C'])))
 
745
        self.assertEqual(['A', 'B', 'C'], list(kg.topo_sort()))
 
746
 
731
747
    def test_parent_map_type(self):
732
748
        tree = self.make_branch_and_tree('here')
733
749
        tree.lock_write()
735
751
        tree.commit('initial commit', rev_id='rev1')
736
752
        tree.commit('next commit', rev_id='rev2')
737
753
        graph = tree.branch.repository.get_graph()
738
 
        parents = graph.get_parent_map([NULL_REVISION, 'rev1', 'rev2'])
 
754
        parents = graph.get_parent_map(
 
755
            [_mod_revision.NULL_REVISION, 'rev1', 'rev2'])
739
756
        for value in parents.values():
740
757
            self.assertIsInstance(value, tuple)
741
758
 
763
780
        self.addCleanup(repo.unlock)
764
781
        repo.start_write_group()
765
782
        self.addCleanup(repo.abort_write_group)
766
 
        inv = Inventory(revision_id='A')
 
783
        inv = inventory.Inventory(revision_id='A')
767
784
        inv.root.revision = 'A'
768
785
        repo.add_inventory('A', inv, [])
769
 
        repo.add_revision('A', Revision('A', committer='A', timestamp=0,
770
 
                          inventory_sha1='', timezone=0, message='A'))
 
786
        repo.add_revision('A', _mod_revision.Revision(
 
787
                'A', committer='A', timestamp=0,
 
788
                inventory_sha1='', timezone=0, message='A'))
771
789
        repo.add_signature_text('A', 'This might be a signature')
772
790
        self.assertEqual('This might be a signature',
773
791
                         repo.get_signature_text('A'))
774
792
 
775
793
    def test_add_revision_inventory_sha1(self):
776
 
        inv = Inventory(revision_id='A')
 
794
        inv = inventory.Inventory(revision_id='A')
777
795
        inv.root.revision = 'A'
778
796
        inv.root.file_id = 'fixed-root'
779
797
        # Insert the inventory on its own to an identical repository, to get
791
809
        repo.start_write_group()
792
810
        root_id = inv.root.file_id
793
811
        repo.texts.add_lines(('fixed-root', 'A'), [], [])
794
 
        repo.add_revision('A', Revision('A', committer='B', timestamp=0,
795
 
                          timezone=0, message='C'), inv=inv)
 
812
        repo.add_revision('A', _mod_revision.Revision(
 
813
                'A', committer='B', timestamp=0,
 
814
                timezone=0, message='C'), inv=inv)
796
815
        repo.commit_write_group()
797
816
        repo.unlock()
798
817
        repo.lock_read()
825
844
        """Make a RemoteRepository object backed by a real repository that will
826
845
        be created at the given path."""
827
846
        repo = self.make_repository(path, shared=shared)
828
 
        smart_server = server.SmartTCPServer_for_testing()
 
847
        smart_server = test_server.SmartTCPServer_for_testing()
829
848
        self.start_server(smart_server, self.get_server())
830
 
        remote_transport = get_transport(smart_server.get_url()).clone(path)
 
849
        remote_transport = transport.get_transport(
 
850
            smart_server.get_url()).clone(path)
831
851
        remote_bzrdir = bzrdir.BzrDir.open_from_transport(remote_transport)
832
852
        remote_repo = remote_bzrdir.open_repository()
833
853
        return remote_repo
834
854
 
835
855
    def test_sprout_from_hpss_preserves_format(self):
836
856
        """repo.sprout from a smart server preserves the repository format."""
837
 
        if self.repository_format == RepositoryFormat7():
838
 
            raise TestNotApplicable(
 
857
        if self.repository_format == weaverepo.RepositoryFormat7():
 
858
            raise tests.TestNotApplicable(
839
859
                "Cannot fetch weaves over smart protocol.")
840
860
        remote_repo = self.make_remote_repository('remote')
841
861
        local_bzrdir = self.make_bzrdir('local')
842
862
        try:
843
863
            local_repo = remote_repo.sprout(local_bzrdir)
844
864
        except errors.TransportNotPossible:
845
 
            raise TestNotApplicable(
 
865
            raise tests.TestNotApplicable(
846
866
                "Cannot lock_read old formats like AllInOne over HPSS.")
847
867
        remote_backing_repo = bzrdir.BzrDir.open(
848
868
            self.get_vfs_only_url('remote')).open_repository()
851
871
    def test_sprout_branch_from_hpss_preserves_repo_format(self):
852
872
        """branch.sprout from a smart server preserves the repository format.
853
873
        """
854
 
        weave_formats = [RepositoryFormat5(), RepositoryFormat6(),
855
 
                         RepositoryFormat7()]
 
874
        weave_formats = [weaverepo.RepositoryFormat5(),
 
875
                         weaverepo.RepositoryFormat6(),
 
876
                         weaverepo.RepositoryFormat7()]
856
877
        if self.repository_format in weave_formats:
857
 
            raise TestNotApplicable(
 
878
            raise tests.TestNotApplicable(
858
879
                "Cannot fetch weaves over smart protocol.")
859
880
        remote_repo = self.make_remote_repository('remote')
860
881
        remote_branch = remote_repo.bzrdir.create_branch()
861
882
        try:
862
883
            local_bzrdir = remote_branch.bzrdir.sprout('local')
863
884
        except errors.TransportNotPossible:
864
 
            raise TestNotApplicable(
 
885
            raise tests.TestNotApplicable(
865
886
                "Cannot lock_read old formats like AllInOne over HPSS.")
866
887
        local_repo = local_bzrdir.open_repository()
867
888
        remote_backing_repo = bzrdir.BzrDir.open(
872
893
        """branch.sprout from a smart server preserves the repository format of
873
894
        a branch from a shared repository.
874
895
        """
875
 
        weave_formats = [RepositoryFormat5(), RepositoryFormat6(),
876
 
                         RepositoryFormat7()]
 
896
        weave_formats = [weaverepo.RepositoryFormat5(),
 
897
                         weaverepo.RepositoryFormat6(),
 
898
                         weaverepo.RepositoryFormat7()]
877
899
        if self.repository_format in weave_formats:
878
 
            raise TestNotApplicable(
 
900
            raise tests.TestNotApplicable(
879
901
                "Cannot fetch weaves over smart protocol.")
880
902
        # Make a shared repo
881
903
        remote_repo = self.make_remote_repository('remote', shared=True)
894
916
        try:
895
917
            local_bzrdir = remote_branch.bzrdir.sprout('local')
896
918
        except errors.TransportNotPossible:
897
 
            raise TestNotApplicable(
 
919
            raise tests.TestNotApplicable(
898
920
                "Cannot lock_read old formats like AllInOne over HPSS.")
899
921
        local_repo = local_bzrdir.open_repository()
900
922
        self.assertEqual(remote_backing_repo._format, local_repo._format)
901
923
 
902
924
    def test_clone_to_hpss(self):
903
 
        pre_metadir_formats = [RepositoryFormat5(), RepositoryFormat6()]
 
925
        pre_metadir_formats = [weaverepo.RepositoryFormat5(),
 
926
                               weaverepo.RepositoryFormat6()]
904
927
        if self.repository_format in pre_metadir_formats:
905
 
            raise TestNotApplicable(
 
928
            raise tests.TestNotApplicable(
906
929
                "Cannot lock pre_metadir_formats remotely.")
907
930
        remote_transport = self.make_smart_server('remote')
908
931
        local_branch = self.make_branch('local')
919
942
        try:
920
943
            repo = self.make_repository('repo', shared=True)
921
944
        except errors.IncompatibleFormat:
922
 
            raise TestNotApplicable('Cannot make a shared repository')
 
945
            raise tests.TestNotApplicable('Cannot make a shared repository')
923
946
        if isinstance(repo.bzrdir, bzrdir.BzrDirPreSplitOut):
924
 
            raise KnownFailure("pre metadir branches do not upgrade on push "
 
947
            raise tests.KnownFailure(
 
948
                "pre metadir branches do not upgrade on push "
925
949
                "with stacking policy")
926
 
        if isinstance(repo._format, RepositoryFormatKnitPack5RichRootBroken):
927
 
            raise TestNotApplicable("unsupported format")
 
950
        if isinstance(repo._format,
 
951
                      pack_repo.RepositoryFormatKnitPack5RichRootBroken):
 
952
            raise tests.TestNotApplicable("unsupported format")
928
953
        # Make a source branch in 'repo' in an unstackable branch format
929
954
        bzrdir_format = self.repository_format._matchingbzrdir
930
955
        transport = self.get_transport('repo/branch')
931
956
        transport.mkdir('.')
932
957
        target_bzrdir = bzrdir_format.initialize_on_transport(transport)
933
 
        branch = BzrBranchFormat6().initialize(target_bzrdir)
 
958
        branch = _mod_branch.BzrBranchFormat6().initialize(target_bzrdir)
934
959
        # Ensure that stack_on will be stackable and match the serializer of
935
960
        # repo.
936
961
        if isinstance(repo, remote.RemoteRepository):
1011
1036
        try:
1012
1037
            repo = self.make_repository_and_foo_bar(shared=True)
1013
1038
        except errors.IncompatibleFormat:
1014
 
            raise TestNotApplicable
 
1039
            raise tests.TestNotApplicable
1015
1040
        branches = repo.find_branches(using=True)
1016
1041
        self.assertContainsRe(branches[-1].base, 'repository/foo/$')
1017
1042
        # in some formats, creating a repo creates a branch
1045
1070
        try:
1046
1071
            repo.set_make_working_trees(True)
1047
1072
        except errors.RepositoryUpgradeRequired, e:
1048
 
            raise TestNotApplicable('Format does not support this flag.')
 
1073
            raise tests.TestNotApplicable('Format does not support this flag.')
1049
1074
        self.assertTrue(repo.make_working_trees())
1050
1075
 
1051
1076
    def test_set_get_make_working_trees_false(self):
1053
1078
        try:
1054
1079
            repo.set_make_working_trees(False)
1055
1080
        except errors.RepositoryUpgradeRequired, e:
1056
 
            raise TestNotApplicable('Format does not support this flag.')
 
1081
            raise tests.TestNotApplicable('Format does not support this flag.')
1057
1082
        self.assertFalse(repo.make_working_trees())
1058
1083
 
1059
1084
 
1060
 
class TestRepositoryLocking(TestCaseWithRepository):
 
1085
class TestRepositoryLocking(per_repository.TestCaseWithRepository):
1061
1086
 
1062
1087
    def test_leave_lock_in_place(self):
1063
1088
        repo = self.make_repository('r')
1064
1089
        # Lock the repository, then use leave_lock_in_place so that when we
1065
1090
        # unlock the repository the lock is still held on disk.
1066
 
        token = repo.lock_write()
 
1091
        token = repo.lock_write().repository_token
1067
1092
        try:
1068
1093
            if token is None:
1069
1094
                # This test does not apply, because this repository refuses lock
1083
1108
    def test_dont_leave_lock_in_place(self):
1084
1109
        repo = self.make_repository('r')
1085
1110
        # Create a lock on disk.
1086
 
        token = repo.lock_write()
 
1111
        token = repo.lock_write().repository_token
1087
1112
        try:
1088
1113
            if token is None:
1089
1114
                # This test does not apply, because this repository refuses lock
1117
1142
        repo.lock_read()
1118
1143
        repo.unlock()
1119
1144
 
1120
 
 
1121
 
class TestCaseWithComplexRepository(TestCaseWithRepository):
 
1145
    def test_lock_read_returns_unlockable(self):
 
1146
        repo = self.make_repository('r')
 
1147
        self.assertThat(repo.lock_read, ReturnsUnlockable(repo))
 
1148
 
 
1149
    def test_lock_write_returns_unlockable(self):
 
1150
        repo = self.make_repository('r')
 
1151
        self.assertThat(repo.lock_write, ReturnsUnlockable(repo))
 
1152
 
 
1153
 
 
1154
class TestCaseWithComplexRepository(per_repository.TestCaseWithRepository):
1122
1155
 
1123
1156
    def setUp(self):
1124
1157
        super(TestCaseWithComplexRepository, self).setUp()
1148
1181
        try:
1149
1182
            tree_a.commit('rev3', rev_id='rev3', allow_pointless=True)
1150
1183
        except errors.RevisionNotPresent:
1151
 
            raise TestNotApplicable("Cannot test with ghosts for this format.")
 
1184
            raise tests.TestNotApplicable(
 
1185
                "Cannot test with ghosts for this format.")
1152
1186
        # add another reference to a ghost, and a second ghost.
1153
1187
        tree_a.add_parent_tree_id('ghost1')
1154
1188
        tree_a.add_parent_tree_id('ghost2')
1208
1242
            repo.unlock()
1209
1243
 
1210
1244
 
1211
 
class TestCaseWithCorruptRepository(TestCaseWithRepository):
 
1245
class TestCaseWithCorruptRepository(per_repository.TestCaseWithRepository):
1212
1246
 
1213
1247
    def setUp(self):
1214
1248
        super(TestCaseWithCorruptRepository, self).setUp()
1217
1251
        repo = self.make_repository('inventory_with_unnecessary_ghost')
1218
1252
        repo.lock_write()
1219
1253
        repo.start_write_group()
1220
 
        inv = Inventory(revision_id = 'ghost')
 
1254
        inv = inventory.Inventory(revision_id = 'ghost')
1221
1255
        inv.root.revision = 'ghost'
1222
1256
        if repo.supports_rich_root():
1223
1257
            root_id = inv.root.file_id
1224
1258
            repo.texts.add_lines((root_id, 'ghost'), [], [])
1225
1259
        sha1 = repo.add_inventory('ghost', inv, [])
1226
 
        rev = bzrlib.revision.Revision(timestamp=0,
1227
 
                                       timezone=None,
1228
 
                                       committer="Foo Bar <foo@example.com>",
1229
 
                                       message="Message",
1230
 
                                       inventory_sha1=sha1,
1231
 
                                       revision_id='ghost')
 
1260
        rev = _mod_revision.Revision(
 
1261
            timestamp=0, timezone=None, committer="Foo Bar <foo@example.com>",
 
1262
            message="Message", inventory_sha1=sha1, revision_id='ghost')
1232
1263
        rev.parent_ids = ['the_ghost']
1233
1264
        try:
1234
1265
            repo.add_revision('ghost', rev)
1235
1266
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
1236
 
            raise TestNotApplicable("Cannot test with ghosts for this format.")
 
1267
            raise tests.TestNotApplicable(
 
1268
                "Cannot test with ghosts for this format.")
1237
1269
 
1238
 
        inv = Inventory(revision_id = 'the_ghost')
 
1270
        inv = inventory.Inventory(revision_id = 'the_ghost')
1239
1271
        inv.root.revision = 'the_ghost'
1240
1272
        if repo.supports_rich_root():
1241
1273
            root_id = inv.root.file_id
1242
1274
            repo.texts.add_lines((root_id, 'the_ghost'), [], [])
1243
1275
        sha1 = repo.add_inventory('the_ghost', inv, [])
1244
 
        rev = bzrlib.revision.Revision(timestamp=0,
1245
 
                                       timezone=None,
1246
 
                                       committer="Foo Bar <foo@example.com>",
1247
 
                                       message="Message",
1248
 
                                       inventory_sha1=sha1,
1249
 
                                       revision_id='the_ghost')
 
1276
        rev = _mod_revision.Revision(
 
1277
            timestamp=0, timezone=None, committer="Foo Bar <foo@example.com>",
 
1278
            message="Message", inventory_sha1=sha1, revision_id='the_ghost')
1250
1279
        rev.parent_ids = []
1251
1280
        repo.add_revision('the_ghost', rev)
1252
1281
        # check its setup usefully
1279
1308
 
1280
1309
# FIXME: document why this is a TestCaseWithTransport rather than a
1281
1310
#        TestCaseWithRepository
1282
 
class TestEscaping(TestCaseWithTransport):
 
1311
class TestEscaping(tests.TestCaseWithTransport):
1283
1312
    """Test that repositories can be stored correctly on VFAT transports.
1284
1313
 
1285
1314
    Makes sure we have proper escaping of invalid characters, etc.
1293
1322
    def test_on_vfat(self):
1294
1323
        # dont bother with remote repository testing, because this test is
1295
1324
        # about local disk layout/support.
1296
 
        from bzrlib.remote import RemoteRepositoryFormat
1297
 
        if isinstance(self.repository_format, RemoteRepositoryFormat):
 
1325
        if isinstance(self.repository_format, remote.RemoteRepositoryFormat):
1298
1326
            return
1299
 
        self.transport_server = FakeVFATServer
 
1327
        self.transport_server = test_server.FakeVFATServer
1300
1328
        FOO_ID = 'foo<:>ID'
1301
1329
        REV_ID = 'revid-1'
1302
1330
        # this makes a default format repository always, which is wrong:
1321
1349
        wt.add('file1')
1322
1350
        wt.commit('file1', rev_id='rev1')
1323
1351
        fileobj = StringIO()
1324
 
        wt.branch.repository.create_bundle('rev1', NULL_REVISION, fileobj)
 
1352
        wt.branch.repository.create_bundle(
 
1353
            'rev1', _mod_revision.NULL_REVISION, fileobj)
 
1354
 
 
1355
 
 
1356
 
 
1357
 
 
1358
class TestRepositoryControlComponent(per_repository.TestCaseWithRepository):
 
1359
    """Repository implementations adequately implement ControlComponent."""
 
1360
    
 
1361
    def test_urls(self):
 
1362
        repo = self.make_repository('repo')
 
1363
        self.assertIsInstance(repo.user_url, str)
 
1364
        self.assertEqual(repo.user_url, repo.user_transport.base)
 
1365
        # for all current bzrdir implementations the user dir must be 
 
1366
        # above the control dir but we might need to relax that?
 
1367
        self.assertEqual(repo.control_url.find(repo.user_url), 0)
 
1368
        self.assertEqual(repo.control_url, repo.control_transport.base)