/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 breezy/tests/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    def test_default_format(self):
62
62
        # update this if you change the default branch format
63
63
        self.assertIsInstance(_mod_branch.format_registry.get_default(),
64
 
                _mod_bzrbranch.BzrBranchFormat7)
 
64
                              _mod_bzrbranch.BzrBranchFormat7)
65
65
 
66
66
    def test_default_format_is_same_as_bzrdir_default(self):
67
67
        # XXX: it might be nice if there was only one place the default was
115
115
        self.assertFileEqual(b"# comment\n"
116
116
                             b"[%s]\n"
117
117
                             b"push_location = foo\n"
118
 
                             b"push_location:policy = norecurse\n" % local_path.encode('utf-8'),
 
118
                             b"push_location:policy = norecurse\n" % local_path.encode(
 
119
                                 'utf-8'),
119
120
                             config.locations_config_filename())
120
121
 
121
122
    # TODO RBC 20051029 test getting a push location from a branch in a
154
155
SampleSupportedBranchFormatString = b"Sample supported branch format."
155
156
 
156
157
# And the format class can then reference the constant to avoid skew.
 
158
 
 
159
 
157
160
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
158
161
    """A sample supported format."""
159
162
 
199
202
        # create a branch with a few known format objects.
200
203
        # this is not quite the same as
201
204
        self.build_tree(["foo/", "bar/"])
 
205
 
202
206
        def check_format(format, url):
203
207
            dir = format._matchingcontroldir.initialize(url)
204
208
            dir.create_repository()
212
216
            SampleBranchFormat.from_string(b"Sample branch format."),
213
217
            SampleBranchFormat)
214
218
        self.assertRaises(AssertionError,
215
 
            SampleBranchFormat.from_string, b"Different branch format.")
 
219
                          SampleBranchFormat.from_string, b"Different branch format.")
216
220
 
217
221
    def test_find_format_not_branch(self):
218
222
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
230
234
    def test_find_format_with_features(self):
231
235
        tree = self.make_branch_and_tree('.', format='2a')
232
236
        tree.branch.update_feature_flags({b"name": b"optional"})
233
 
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(tree.controldir)
 
237
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(
 
238
            tree.controldir)
234
239
        self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
235
240
        self.assertEqual(found_format.features.get(b"name"), b"optional")
236
241
        tree.branch.update_feature_flags({b"name": None})
254
259
        format = SampleBranchFormat()
255
260
        self.registry.register(format)
256
261
        self.assertEqual(format,
257
 
            self.registry.get(b"Sample branch format."))
 
262
                         self.registry.get(b"Sample branch format."))
258
263
        self.registry.remove(format)
259
264
        self.assertRaises(KeyError, self.registry.get,
260
 
            b"Sample branch format.")
 
265
                          b"Sample branch format.")
261
266
 
262
267
    def test_get_all(self):
263
268
        format = SampleBranchFormat()
274
279
    def test_register_extra_lazy(self):
275
280
        self.assertEqual([], self.registry._get_all())
276
281
        self.registry.register_extra_lazy("breezy.tests.test_branch",
277
 
            "SampleExtraBranchFormat")
 
282
                                          "SampleExtraBranchFormat")
278
283
        formats = self.registry._get_all()
279
284
        self.assertEqual(1, len(formats))
280
285
        self.assertIsInstance(formats[0], SampleExtraBranchFormat)
323
328
 
324
329
    def do_checkout_test(self, lightweight=False):
325
330
        tree = self.make_branch_and_tree('source',
326
 
            format=self.get_format_name_subtree())
 
331
                                         format=self.get_format_name_subtree())
327
332
        subtree = self.make_branch_and_tree('source/subtree',
328
 
            format=self.get_format_name_subtree())
 
333
                                            format=self.get_format_name_subtree())
329
334
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
330
 
            format=self.get_format_name_subtree())
 
335
                                               format=self.get_format_name_subtree())
331
336
        self.build_tree(['source/subtree/file',
332
337
                         'source/subtree/subsubtree/file'])
333
338
        subsubtree.add('file')
369
374
    def test_set_stacked_on_url_errors(self):
370
375
        branch = self.make_branch('a', format=self.get_format_name())
371
376
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
372
 
            branch.set_stacked_on_url, None)
 
377
                          branch.set_stacked_on_url, None)
373
378
 
374
379
    def test_default_stacked_location(self):
375
380
        branch = self.make_branch('a', format=self.get_format_name())
376
 
        self.assertRaises(_mod_branch.UnstackableBranchFormat, branch.get_stacked_on_url)
 
381
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
 
382
                          branch.get_stacked_on_url)
377
383
 
378
384
 
379
385
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
393
399
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
394
400
        target = self.make_branch('b')
395
401
        self.assertRaises(errors.UnstackableRepositoryFormat,
396
 
            branch.set_stacked_on_url, target.base)
 
402
                          branch.set_stacked_on_url, target.base)
397
403
 
398
404
    def test_clone_stacked_on_unstackable_repo(self):
399
405
        repo = self.make_repository('a', format='dirstate-tags')
443
449
    @staticmethod
444
450
    def instrument_branch(branch, gets):
445
451
        old_get = branch._transport.get
 
452
 
446
453
        def get(*args, **kwargs):
447
454
            gets.append((args, kwargs))
448
455
            return old_get(*args, **kwargs)
490
497
    def _recordParentMapCalls(self, repo):
491
498
        self._parent_map_calls = []
492
499
        orig_get_parent_map = repo.revisions.get_parent_map
 
500
 
493
501
        def get_parent_map(q):
494
502
            q = list(q)
495
503
            self._parent_map_calls.extend([e[0] for e in q])
525
533
        self.assertFileEqual(reference_url.encode('utf-8'),
526
534
                             'checkout/.bzr/branch/location')
527
535
        self.assertEqual(reference_url,
528
 
            _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
 
536
                         _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
529
537
 
530
538
 
531
539
class TestHooks(tests.TestCaseWithTransport):
534
542
        """Check that creating a BranchHooks instance has the right defaults."""
535
543
        hooks = _mod_branch.BranchHooks()
536
544
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
537
 
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
 
545
        self.assertTrue("post_commit" in hooks,
 
546
                        "post_commit not in %s" % hooks)
538
547
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
539
548
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
540
549
        self.assertTrue("post_uncommit" in hooks,
555
564
    def test_post_branch_init_hook(self):
556
565
        calls = []
557
566
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
558
 
            calls.append, None)
 
567
                                                    calls.append, None)
559
568
        self.assertLength(0, calls)
560
569
        branch = self.make_branch('a')
561
570
        self.assertLength(1, calls)
567
576
    def test_post_branch_init_hook_repr(self):
568
577
        param_reprs = []
569
578
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
570
 
            lambda params: param_reprs.append(repr(params)), None)
 
579
                                                    lambda params: param_reprs.append(repr(params)), None)
571
580
        branch = self.make_branch('a')
572
581
        self.assertLength(1, param_reprs)
573
582
        param_repr = param_reprs[0]
577
586
        from .. import switch
578
587
        calls = []
579
588
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
580
 
            calls.append, None)
 
589
                                                    calls.append, None)
581
590
        tree = self.make_branch_and_tree('branch-1')
582
591
        self.build_tree(['branch-1/file-1'])
583
592
        tree.add('file-1')
613
622
 
614
623
    def test_valid_append_revisions_only(self):
615
624
        self.assertEqual(None,
616
 
                          self.config_stack.get('append_revisions_only'))
 
625
                         self.config_stack.get('append_revisions_only'))
617
626
        self.check_append_revisions_only(None)
618
627
        self.check_append_revisions_only(False, 'False')
619
628
        self.check_append_revisions_only(True, 'True')
625
634
    def test_invalid_append_revisions_only(self):
626
635
        """Ensure warning is noted on invalid settings"""
627
636
        self.warnings = []
 
637
 
628
638
        def warning(*args):
629
639
            self.warnings.append(args[0] % args[1:])
630
640
        self.overrideAttr(trace, 'warning', warning)