~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-23 20:55:58 UTC
  • mfrom: (4034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4053.
  • Revision ID: jelmer@samba.org-20090223205558-1cx2k4w1zgs8r5qa
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    repository,
33
33
    osutils,
34
34
    symbol_versioning,
 
35
    remote,
35
36
    urlutils,
36
37
    win32utils,
37
38
    workingtree,
84
85
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
86
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
86
87
            ' repositories', deprecated=True)
87
 
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir', 
 
88
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
89
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
90
        my_format_registry.register_metadir('knit',
90
91
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
117
118
        my_bzrdir = my_format_registry.make_bzrdir('weave')
118
119
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
119
120
        my_bzrdir = my_format_registry.make_bzrdir('default')
120
 
        self.assertIsInstance(my_bzrdir.repository_format, 
 
121
        self.assertIsInstance(my_bzrdir.repository_format,
121
122
            knitrepo.RepositoryFormatKnit1)
122
123
        my_bzrdir = my_format_registry.make_bzrdir('knit')
123
 
        self.assertIsInstance(my_bzrdir.repository_format, 
 
124
        self.assertIsInstance(my_bzrdir.repository_format,
124
125
            knitrepo.RepositoryFormatKnit1)
125
126
        my_bzrdir = my_format_registry.make_bzrdir('branch6')
126
127
        self.assertIsInstance(my_bzrdir.get_branch_format(),
130
131
        my_format_registry = self.make_format_registry()
131
132
        self.assertEqual('Format registered lazily',
132
133
                         my_format_registry.get_help('lazy'))
133
 
        self.assertEqual('Format using knits', 
 
134
        self.assertEqual('Format using knits',
134
135
                         my_format_registry.get_help('knit'))
135
 
        self.assertEqual('Format using knits', 
 
136
        self.assertEqual('Format using knits',
136
137
                         my_format_registry.get_help('default'))
137
138
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
138
 
                         ' checkouts or shared repositories', 
 
139
                         ' checkouts or shared repositories',
139
140
                         my_format_registry.get_help('weave'))
140
 
        
 
141
 
141
142
    def test_help_topic(self):
142
143
        topics = help_topics.HelpTopicRegistry()
143
144
        registry = self.make_format_registry()
144
 
        topics.register('current-formats', registry.help_topic, 
 
145
        topics.register('current-formats', registry.help_topic,
145
146
                        'Current formats')
146
 
        topics.register('other-formats', registry.help_topic, 
 
147
        topics.register('other-formats', registry.help_topic,
147
148
                        'Other formats')
148
149
        new = topics.get_detail('current-formats')
149
150
        rest = topics.get_detail('other-formats')
150
151
        experimental, deprecated = rest.split('Deprecated formats')
151
152
        self.assertContainsRe(new, 'bzr help formats')
152
 
        self.assertContainsRe(new, 
 
153
        self.assertContainsRe(new,
153
154
                ':knit:\n    \(native\) \(default\) Format using knits\n')
154
 
        self.assertContainsRe(experimental, 
 
155
        self.assertContainsRe(experimental,
155
156
                ':branch6:\n    \(native\) Experimental successor to knit')
156
 
        self.assertContainsRe(deprecated, 
 
157
        self.assertContainsRe(deprecated,
157
158
                ':lazy:\n    \(native\) Format registered lazily\n')
158
159
        self.assertNotContainsRe(new, 'hidden')
159
160
 
219
220
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
220
221
    """A sample format
221
222
 
222
 
    this format is initializable, unsupported to aid in testing the 
 
223
    this format is initializable, unsupported to aid in testing the
223
224
    open and open_downlevel routines.
224
225
    """
225
226
 
246
247
    def test_find_format(self):
247
248
        # is the right format object found for a branch?
248
249
        # create a branch with a few known format objects.
249
 
        # this is not quite the same as 
 
250
        # this is not quite the same as
250
251
        t = get_transport(self.get_url())
251
252
        self.build_tree(["foo/", "bar/"], transport=t)
252
253
        def check_format(format, url):
256
257
            self.failUnless(isinstance(found_format, format.__class__))
257
258
        check_format(bzrdir.BzrDirFormat5(), "foo")
258
259
        check_format(bzrdir.BzrDirFormat6(), "bar")
259
 
        
 
260
 
260
261
    def test_find_format_nothing_there(self):
261
262
        self.assertRaises(NotBranchError,
262
263
                          bzrdir.BzrDirFormat.find_format,
306
307
                          branch.bzrdir.open_repository)
307
308
 
308
309
    def test_create_branch_and_repo_under_shared_force_new(self):
309
 
        # creating a branch and repo in a shared repo can be forced to 
 
310
        # creating a branch and repo in a shared repo can be forced to
310
311
        # make a new repo
311
312
        format = bzrdir.format_registry.make_bzrdir('knit')
312
313
        self.make_repository('.', shared=True, format=format)
317
318
 
318
319
    def test_create_standalone_working_tree(self):
319
320
        format = SampleBzrDirFormat()
320
 
        # note this is deliberately readonly, as this failure should 
 
321
        # note this is deliberately readonly, as this failure should
321
322
        # occur before any writes.
322
323
        self.assertRaises(errors.NotLocalUrl,
323
324
                          bzrdir.BzrDir.create_standalone_workingtree,
324
325
                          self.get_readonly_url(), format=format)
325
 
        tree = bzrdir.BzrDir.create_standalone_workingtree('.', 
 
326
        tree = bzrdir.BzrDir.create_standalone_workingtree('.',
326
327
                                                           format=format)
327
328
        self.assertEqual('A tree', tree)
328
329
 
330
331
        # create standalone working tree always makes a repo.
331
332
        format = bzrdir.format_registry.make_bzrdir('knit')
332
333
        self.make_repository('.', shared=True, format=format)
333
 
        # note this is deliberately readonly, as this failure should 
 
334
        # note this is deliberately readonly, as this failure should
334
335
        # occur before any writes.
335
336
        self.assertRaises(errors.NotLocalUrl,
336
337
                          bzrdir.BzrDir.create_standalone_workingtree,
337
338
                          self.get_readonly_url('child'), format=format)
338
 
        tree = bzrdir.BzrDir.create_standalone_workingtree('child', 
 
339
        tree = bzrdir.BzrDir.create_standalone_workingtree('child',
339
340
            format=format)
340
341
        tree.bzrdir.open_repository()
341
342
 
360
361
        self.vfs_transport_factory = MemoryServer
361
362
        # outside a repo the default convenience output is a repo+branch_tree
362
363
        format = bzrdir.format_registry.make_bzrdir('knit')
363
 
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(), 
 
364
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
364
365
                                                         format=format)
365
366
        self.assertRaises(errors.NoWorkingTree,
366
367
                          branch.bzrdir.open_workingtree)
376
377
        branch.bzrdir.open_workingtree()
377
378
        self.assertRaises(errors.NoRepositoryPresent,
378
379
                          branch.bzrdir.open_repository)
379
 
            
 
380
 
380
381
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
381
382
        # inside a repo the default convenience output is a branch+ follow the
382
383
        # repo tree policy but we can override that
388
389
                          branch.bzrdir.open_workingtree)
389
390
        self.assertRaises(errors.NoRepositoryPresent,
390
391
                          branch.bzrdir.open_repository)
391
 
            
 
392
 
392
393
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
393
394
        # inside a repo the default convenience output is a branch+ follow the
394
395
        # repo tree policy
395
396
        format = bzrdir.format_registry.make_bzrdir('knit')
396
397
        repo = self.make_repository('.', shared=True, format=format)
397
398
        repo.set_make_working_trees(False)
398
 
        branch = bzrdir.BzrDir.create_branch_convenience('child', 
 
399
        branch = bzrdir.BzrDir.create_branch_convenience('child',
399
400
                                                         format=format)
400
401
        self.assertRaises(errors.NoWorkingTree,
401
402
                          branch.bzrdir.open_workingtree)
725
726
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
726
727
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
727
728
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
728
 
        
 
729
 
729
730
    def test_open_from_transport_no_bzrdir(self):
730
731
        transport = get_transport(self.get_url())
731
732
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
885
886
        self.assertTrue(tree.bzrdir.needs_format_conversion(
886
887
            new_format))
887
888
 
 
889
    def test_initialize_on_format_uses_smart_transport(self):
 
890
        self.setup_smart_server_with_call_log()
 
891
        new_format = bzrdir.format_registry.make_bzrdir('dirstate')
 
892
        transport = self.get_transport('target')
 
893
        transport.ensure_base()
 
894
        self.reset_smart_call_log()
 
895
        instance = new_format.initialize_on_transport(transport)
 
896
        self.assertIsInstance(instance, remote.RemoteBzrDir)
 
897
        rpc_count = len(self.hpss_calls)
 
898
        # This figure represent the amount of work to perform this use case. It
 
899
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
900
        # being too low. If rpc_count increases, more network roundtrips have
 
901
        # become necessary for this use case. Please do not adjust this number
 
902
        # upwards without agreement from bzr's network support maintainers.
 
903
        self.assertEqual(2, rpc_count)
 
904
 
888
905
 
889
906
class TestFormat5(TestCaseWithTransport):
890
907
    """Tests specific to the version 5 bzrdir format."""
891
908
 
892
909
    def test_same_lockfiles_between_tree_repo_branch(self):
893
 
        # this checks that only a single lockfiles instance is created 
 
910
        # this checks that only a single lockfiles instance is created
894
911
        # for format 5 objects
895
912
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
896
913
        def check_dir_components_use_same_lock(dir):
903
920
        # and if we open it normally.
904
921
        dir = bzrdir.BzrDir.open(self.get_url())
905
922
        check_dir_components_use_same_lock(dir)
906
 
    
 
923
 
907
924
    def test_can_convert(self):
908
925
        # format 5 dirs are convertable
909
926
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
910
927
        self.assertTrue(dir.can_convert_format())
911
 
    
 
928
 
912
929
    def test_needs_conversion(self):
913
930
        # format 5 dirs need a conversion if they are not the default,
914
931
        # and they aren't
924
941
    """Tests specific to the version 6 bzrdir format."""
925
942
 
926
943
    def test_same_lockfiles_between_tree_repo_branch(self):
927
 
        # this checks that only a single lockfiles instance is created 
 
944
        # this checks that only a single lockfiles instance is created
928
945
        # for format 6 objects
929
946
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
930
947
        def check_dir_components_use_same_lock(dir):
937
954
        # and if we open it normally.
938
955
        dir = bzrdir.BzrDir.open(self.get_url())
939
956
        check_dir_components_use_same_lock(dir)
940
 
    
 
957
 
941
958
    def test_can_convert(self):
942
959
        # format 6 dirs are convertable
943
960
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
944
961
        self.assertTrue(dir.can_convert_format())
945
 
    
 
962
 
946
963
    def test_needs_conversion(self):
947
964
        # format 6 dirs need an conversion if they are not the default.
948
965
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
984
1001
 
985
1002
class TestNotBzrDir(TestCaseWithTransport):
986
1003
    """Tests for using the bzrdir api with a non .bzr based disk format.
987
 
    
 
1004
 
988
1005
    If/when one of these is in the core, we can let the implementation tests
989
1006
    verify this works.
990
1007
    """
991
1008
 
992
1009
    def test_create_and_find_format(self):
993
 
        # create a .notbzr dir 
 
1010
        # create a .notbzr dir
994
1011
        format = NotBzrDirFormat()
995
1012
        dir = format.initialize(self.get_url())
996
1013
        self.assertIsInstance(dir, NotBzrDir)
1021
1038
    def setUp(self):
1022
1039
        super(NonLocalTests, self).setUp()
1023
1040
        self.vfs_transport_factory = MemoryServer
1024
 
    
 
1041
 
1025
1042
    def test_create_branch_convenience(self):
1026
1043
        # outside a repo the default convenience output is a repo+branch_tree
1027
1044
        format = bzrdir.format_registry.make_bzrdir('knit')
1072
1089
 
1073
1090
    We can't inherit directly from TestCaseWithTwoWebservers or the
1074
1091
    test framework will try to create an instance which cannot
1075
 
    run, its implementation being incomplete. 
 
1092
    run, its implementation being incomplete.
1076
1093
    """
1077
1094
 
1078
1095
    def create_transport_readonly_server(self):
1194
1211
 
1195
1212
class _TestBzrDir(bzrdir.BzrDirMeta1):
1196
1213
    """Test BzrDir implementation for TestBzrDirSprout.
1197
 
    
 
1214
 
1198
1215
    When created a _TestBzrDir already has repository and a branch.  The branch
1199
1216
    is a test double as well.
1200
1217
    """
1241
1258
        Usually, BzrDir.sprout should delegate to the branch's sprout method
1242
1259
        for part of the work.  This allows the source branch to control the
1243
1260
        choice of format for the new branch.
1244
 
        
 
1261
 
1245
1262
        There are exceptions, but this tests avoids them:
1246
1263
          - if there's no branch in the source bzrdir,
1247
1264
          - or if the stacking has been requested and the format needs to be