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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
also see this file.
23
23
"""
24
24
 
25
 
from io import StringIO
 
25
from cStringIO import StringIO
26
26
 
27
 
from .. import (
28
 
    bedding,
 
27
from brzlib import (
29
28
    branch as _mod_branch,
 
29
    bzrdir,
30
30
    config,
31
31
    controldir,
32
32
    errors,
34
34
    trace,
35
35
    urlutils,
36
36
    )
37
 
from ..bzr import (
38
 
    branch as _mod_bzrbranch,
39
 
    bzrdir,
40
 
    )
41
 
from ..bzr.fullhistory import (
 
37
from brzlib.branchfmt.fullhistory import (
42
38
    BzrBranch5,
43
39
    BzrBranchFormat5,
44
40
    )
45
41
 
46
42
 
47
 
class TestErrors(tests.TestCase):
48
 
 
49
 
    def test_unstackable_branch_format(self):
50
 
        format = u'foo'
51
 
        url = "/foo"
52
 
        error = _mod_branch.UnstackableBranchFormat(format, url)
53
 
        self.assertEqualDiff(
54
 
            "The branch '/foo'(foo) is not a stackable format. "
55
 
            "You will need to upgrade the branch to permit branch stacking.",
56
 
            str(error))
57
 
 
58
 
 
59
43
class TestDefaultFormat(tests.TestCase):
60
44
 
61
45
    def test_default_format(self):
62
46
        # update this if you change the default branch format
63
47
        self.assertIsInstance(_mod_branch.format_registry.get_default(),
64
 
                              _mod_bzrbranch.BzrBranchFormat7)
 
48
                _mod_branch.BzrBranchFormat7)
65
49
 
66
50
    def test_default_format_is_same_as_bzrdir_default(self):
67
51
        # XXX: it might be nice if there was only one place the default was
74
58
    def test_get_set_default_format(self):
75
59
        # set the format and then set it back again
76
60
        old_format = _mod_branch.format_registry.get_default()
77
 
        _mod_branch.format_registry.set_default(
78
 
            SampleBranchFormat())
 
61
        _mod_branch.format_registry.set_default(SampleBranchFormat())
79
62
        try:
80
63
            # the default branch format is used by the meta dir format
81
64
            # which is not the default bzrdir format at this point
112
95
        branch = self.make_branch('.', format='knit')
113
96
        branch.set_push_location('foo')
114
97
        local_path = urlutils.local_path_from_url(branch.base[:-1])
115
 
        self.assertFileEqual(b"# comment\n"
116
 
                             b"[%s]\n"
117
 
                             b"push_location = foo\n"
118
 
                             b"push_location:policy = norecurse\n" % local_path.encode(
119
 
                                 'utf-8'),
120
 
                             bedding.locations_config_path())
 
98
        self.assertFileEqual("# comment\n"
 
99
                             "[%s]\n"
 
100
                             "push_location = foo\n"
 
101
                             "push_location:policy = norecurse\n" % local_path,
 
102
                             config.locations_config_filename())
121
103
 
122
104
    # TODO RBC 20051029 test getting a push location from a branch in a
123
105
    # recursive section - that is, it appends the branch name.
124
106
 
125
107
 
126
 
class SampleBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
 
108
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
127
109
    """A sample format
128
110
 
129
111
    this format is initializable, unsupported to aid in testing the
133
115
    @classmethod
134
116
    def get_format_string(cls):
135
117
        """See BzrBranchFormat.get_format_string()."""
136
 
        return b"Sample branch format."
 
118
        return "Sample branch format."
137
119
 
138
 
    def initialize(self, a_controldir, name=None, repository=None,
 
120
    def initialize(self, a_bzrdir, name=None, repository=None,
139
121
                   append_revisions_only=None):
140
122
        """Format 4 branches cannot be created."""
141
 
        t = a_controldir.get_branch_transport(self, name=name)
 
123
        t = a_bzrdir.get_branch_transport(self, name=name)
142
124
        t.put_bytes('format', self.get_format_string())
143
125
        return 'A branch'
144
126
 
152
134
 
153
135
# Demonstrating how lazy loading is often implemented:
154
136
# A constant string is created.
155
 
SampleSupportedBranchFormatString = b"Sample supported branch format."
 
137
SampleSupportedBranchFormatString = "Sample supported branch format."
156
138
 
157
139
# And the format class can then reference the constant to avoid skew.
158
 
 
159
 
 
160
 
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
 
140
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
161
141
    """A sample supported format."""
162
142
 
163
143
    @classmethod
165
145
        """See BzrBranchFormat.get_format_string()."""
166
146
        return SampleSupportedBranchFormatString
167
147
 
168
 
    def initialize(self, a_controldir, name=None, append_revisions_only=None):
169
 
        t = a_controldir.get_branch_transport(self, name=name)
 
148
    def initialize(self, a_bzrdir, name=None, append_revisions_only=None):
 
149
        t = a_bzrdir.get_branch_transport(self, name=name)
170
150
        t.put_bytes('format', self.get_format_string())
171
151
        return 'A branch'
172
152
 
186
166
        # Network name always has to be provided.
187
167
        return "extra"
188
168
 
189
 
    def initialize(self, a_controldir, name=None):
 
169
    def initialize(self, a_bzrdir, name=None):
190
170
        raise NotImplementedError(self.initialize)
191
171
 
192
172
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
202
182
        # create a branch with a few known format objects.
203
183
        # this is not quite the same as
204
184
        self.build_tree(["foo/", "bar/"])
205
 
 
206
185
        def check_format(format, url):
207
 
            dir = format._matchingcontroldir.initialize(url)
 
186
            dir = format._matchingbzrdir.initialize(url)
208
187
            dir.create_repository()
209
188
            format.initialize(dir)
210
 
            found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(dir)
 
189
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
211
190
            self.assertIsInstance(found_format, format.__class__)
212
191
        check_format(BzrBranchFormat5(), "bar")
213
192
 
 
193
    def test_find_format_factory(self):
 
194
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
195
        SampleSupportedBranchFormat().initialize(dir)
 
196
        factory = _mod_branch.MetaDirBranchFormatFactory(
 
197
            SampleSupportedBranchFormatString,
 
198
            "brzlib.tests.test_branch", "SampleSupportedBranchFormat")
 
199
        _mod_branch.format_registry.register(factory)
 
200
        self.addCleanup(_mod_branch.format_registry.remove, factory)
 
201
        b = _mod_branch.Branch.open(self.get_url())
 
202
        self.assertEqual(b, "opened supported branch.")
 
203
 
214
204
    def test_from_string(self):
215
205
        self.assertIsInstance(
216
 
            SampleBranchFormat.from_string(b"Sample branch format."),
 
206
            SampleBranchFormat.from_string("Sample branch format."),
217
207
            SampleBranchFormat)
218
208
        self.assertRaises(AssertionError,
219
 
                          SampleBranchFormat.from_string, b"Different branch format.")
 
209
            SampleBranchFormat.from_string, "Different branch format.")
220
210
 
221
211
    def test_find_format_not_branch(self):
222
212
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
223
213
        self.assertRaises(errors.NotBranchError,
224
 
                          _mod_bzrbranch.BranchFormatMetadir.find_format,
 
214
                          _mod_branch.BranchFormatMetadir.find_format,
225
215
                          dir)
226
216
 
227
217
    def test_find_format_unknown_format(self):
228
218
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
229
219
        SampleBranchFormat().initialize(dir)
230
220
        self.assertRaises(errors.UnknownFormatError,
231
 
                          _mod_bzrbranch.BranchFormatMetadir.find_format,
 
221
                          _mod_branch.BranchFormatMetadir.find_format,
232
222
                          dir)
233
223
 
234
224
    def test_find_format_with_features(self):
235
225
        tree = self.make_branch_and_tree('.', format='2a')
236
 
        tree.branch.update_feature_flags({b"name": b"optional"})
237
 
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(
238
 
            tree.controldir)
239
 
        self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
240
 
        self.assertEqual(found_format.features.get(b"name"), b"optional")
241
 
        tree.branch.update_feature_flags({b"name": None})
 
226
        tree.branch.update_feature_flags({"name": "optional"})
 
227
        found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
 
228
        self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
 
229
        self.assertEqual(found_format.features.get("name"), "optional")
 
230
        tree.branch.update_feature_flags({"name": None})
242
231
        branch = _mod_branch.Branch.open('.')
243
232
        self.assertEqual(branch._format.features, {})
244
233
 
259
248
        format = SampleBranchFormat()
260
249
        self.registry.register(format)
261
250
        self.assertEqual(format,
262
 
                         self.registry.get(b"Sample branch format."))
 
251
            self.registry.get("Sample branch format."))
263
252
        self.registry.remove(format)
264
253
        self.assertRaises(KeyError, self.registry.get,
265
 
                          b"Sample branch format.")
 
254
            "Sample branch format.")
266
255
 
267
256
    def test_get_all(self):
268
257
        format = SampleBranchFormat()
278
267
 
279
268
    def test_register_extra_lazy(self):
280
269
        self.assertEqual([], self.registry._get_all())
281
 
        self.registry.register_extra_lazy("breezy.tests.test_branch",
282
 
                                          "SampleExtraBranchFormat")
 
270
        self.registry.register_extra_lazy("brzlib.tests.test_branch",
 
271
            "SampleExtraBranchFormat")
283
272
        formats = self.registry._get_all()
284
273
        self.assertEqual(1, len(formats))
285
274
        self.assertIsInstance(formats[0], SampleExtraBranchFormat)
286
275
 
287
276
 
 
277
#Used by TestMetaDirBranchFormatFactory 
 
278
FakeLazyFormat = None
 
279
 
 
280
 
 
281
class TestMetaDirBranchFormatFactory(tests.TestCase):
 
282
 
 
283
    def test_get_format_string_does_not_load(self):
 
284
        """Formats have a static format string."""
 
285
        factory = _mod_branch.MetaDirBranchFormatFactory("yo", None, None)
 
286
        self.assertEqual("yo", factory.get_format_string())
 
287
 
 
288
    def test_call_loads(self):
 
289
        # __call__ is used by the network_format_registry interface to get a
 
290
        # Format.
 
291
        global FakeLazyFormat
 
292
        del FakeLazyFormat
 
293
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
 
294
            "brzlib.tests.test_branch", "FakeLazyFormat")
 
295
        self.assertRaises(AttributeError, factory)
 
296
 
 
297
    def test_call_returns_call_of_referenced_object(self):
 
298
        global FakeLazyFormat
 
299
        FakeLazyFormat = lambda:'called'
 
300
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
 
301
            "brzlib.tests.test_branch", "FakeLazyFormat")
 
302
        self.assertEqual('called', factory())
 
303
 
 
304
 
288
305
class TestBranch67(object):
289
306
    """Common tests for both branch 6 and 7 which are mostly the same."""
290
307
 
299
316
 
300
317
    def test_creation(self):
301
318
        format = bzrdir.BzrDirMetaFormat1()
302
 
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat6())
 
319
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
303
320
        branch = self.make_branch('a', format=format)
304
321
        self.assertIsInstance(branch, self.get_class())
305
322
        branch = self.make_branch('b', format=self.get_format_name())
326
343
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
327
344
        self.assertEqual('ftp://example.com', branch.get_bound_location())
328
345
 
329
 
    def do_checkout_test(self, lightweight):
 
346
    def do_checkout_test(self, lightweight=False):
330
347
        tree = self.make_branch_and_tree('source',
331
 
                                         format=self.get_format_name_subtree())
 
348
            format=self.get_format_name_subtree())
332
349
        subtree = self.make_branch_and_tree('source/subtree',
333
 
                                            format=self.get_format_name_subtree())
 
350
            format=self.get_format_name_subtree())
334
351
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
335
 
                                               format=self.get_format_name_subtree())
 
352
            format=self.get_format_name_subtree())
336
353
        self.build_tree(['source/subtree/file',
337
354
                         'source/subtree/subsubtree/file'])
338
355
        subsubtree.add('file')
339
356
        subtree.add('file')
340
357
        subtree.add_reference(subsubtree)
341
 
        subtree.set_reference_info('subsubtree', subsubtree.branch.user_url)
342
358
        tree.add_reference(subtree)
343
 
        tree.set_reference_info('subtree', subtree.branch.user_url)
344
359
        tree.commit('a revision')
345
360
        subtree.commit('a subtree file')
346
361
        subsubtree.commit('a subsubtree file')
356
371
            self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
357
372
 
358
373
    def test_checkout_with_references(self):
359
 
        self.do_checkout_test(lightweight=False)
 
374
        self.do_checkout_test()
360
375
 
361
376
    def test_light_checkout_with_references(self):
362
377
        self.do_checkout_test(lightweight=True)
365
380
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
366
381
 
367
382
    def get_class(self):
368
 
        return _mod_bzrbranch.BzrBranch6
 
383
        return _mod_branch.BzrBranch6
369
384
 
370
385
    def get_format_name(self):
371
386
        return "dirstate-tags"
375
390
 
376
391
    def test_set_stacked_on_url_errors(self):
377
392
        branch = self.make_branch('a', format=self.get_format_name())
378
 
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
379
 
                          branch.set_stacked_on_url, None)
 
393
        self.assertRaises(errors.UnstackableBranchFormat,
 
394
            branch.set_stacked_on_url, None)
380
395
 
381
396
    def test_default_stacked_location(self):
382
397
        branch = self.make_branch('a', format=self.get_format_name())
383
 
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
384
 
                          branch.get_stacked_on_url)
 
398
        self.assertRaises(errors.UnstackableBranchFormat, branch.get_stacked_on_url)
385
399
 
386
400
 
387
401
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
388
402
 
389
403
    def get_class(self):
390
 
        return _mod_bzrbranch.BzrBranch7
 
404
        return _mod_branch.BzrBranch7
391
405
 
392
406
    def get_format_name(self):
393
407
        return "1.9"
397
411
 
398
412
    def test_set_stacked_on_url_unstackable_repo(self):
399
413
        repo = self.make_repository('a', format='dirstate-tags')
400
 
        control = repo.controldir
401
 
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
 
414
        control = repo.bzrdir
 
415
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
402
416
        target = self.make_branch('b')
403
417
        self.assertRaises(errors.UnstackableRepositoryFormat,
404
 
                          branch.set_stacked_on_url, target.base)
 
418
            branch.set_stacked_on_url, target.base)
405
419
 
406
420
    def test_clone_stacked_on_unstackable_repo(self):
407
421
        repo = self.make_repository('a', format='dirstate-tags')
408
 
        control = repo.controldir
409
 
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
 
422
        control = repo.bzrdir
 
423
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
410
424
        # Calling clone should not raise UnstackableRepositoryFormat.
411
425
        cloned_bzrdir = control.clone('cloned')
412
426
 
429
443
        branch = self.make_branch('a', format=self.get_format_name())
430
444
        target = self.make_branch_and_tree('b', format=self.get_format_name())
431
445
        branch.set_stacked_on_url(target.branch.base)
432
 
        branch = branch.controldir.open_branch()
 
446
        branch = branch.bzrdir.open_branch()
433
447
        revid = target.commit('foo')
434
448
        self.assertTrue(branch.repository.has_revision(revid))
435
449
 
438
452
 
439
453
    def make_branch(self, location, format=None):
440
454
        if format is None:
441
 
            format = controldir.format_registry.make_controldir('1.9')
442
 
            format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
 
455
            format = controldir.format_registry.make_bzrdir('1.9')
 
456
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
443
457
        return tests.TestCaseWithTransport.make_branch(
444
458
            self, location, format=format)
445
459
 
446
460
    def create_branch_with_reference(self):
447
461
        branch = self.make_branch('branch')
448
 
        branch._set_all_reference_info({'path': ('location', b'file-id')})
 
462
        branch._set_all_reference_info({'file-id': ('path', 'location')})
449
463
        return branch
450
464
 
451
465
    @staticmethod
452
466
    def instrument_branch(branch, gets):
453
467
        old_get = branch._transport.get
454
 
 
455
468
        def get(*args, **kwargs):
456
469
            gets.append((args, kwargs))
457
470
            return old_get(*args, **kwargs)
463
476
        branch.lock_read()
464
477
        self.addCleanup(branch.unlock)
465
478
        self.instrument_branch(branch, gets)
466
 
        branch.get_reference_info('path')
467
 
        branch.get_reference_info('path')
 
479
        branch.get_reference_info('file-id')
 
480
        branch.get_reference_info('file-id')
468
481
        self.assertEqual(1, len(gets))
469
482
 
470
483
    def test_reference_info_caching_read_unlocked(self):
471
484
        gets = []
472
485
        branch = self.create_branch_with_reference()
473
486
        self.instrument_branch(branch, gets)
474
 
        branch.get_reference_info('path')
475
 
        branch.get_reference_info('path')
 
487
        branch.get_reference_info('file-id')
 
488
        branch.get_reference_info('file-id')
476
489
        self.assertEqual(2, len(gets))
477
490
 
478
491
    def test_reference_info_caching_write_locked(self):
481
494
        branch.lock_write()
482
495
        self.instrument_branch(branch, gets)
483
496
        self.addCleanup(branch.unlock)
484
 
        branch._set_all_reference_info({'path2': ('location2', b'file-id')})
485
 
        location, file_id = branch.get_reference_info('path2')
 
497
        branch._set_all_reference_info({'file-id': ('path2', 'location2')})
 
498
        path, location = branch.get_reference_info('file-id')
486
499
        self.assertEqual(0, len(gets))
487
 
        self.assertEqual(b'file-id', file_id)
 
500
        self.assertEqual('path2', path)
488
501
        self.assertEqual('location2', location)
489
502
 
490
503
    def test_reference_info_caches_cleared(self):
491
504
        branch = self.make_branch('branch')
492
 
        with branch.lock_write():
493
 
            branch.set_reference_info(b'file-id', 'location2', 'path2')
 
505
        branch.lock_write()
 
506
        branch.set_reference_info('file-id', 'path2', 'location2')
 
507
        branch.unlock()
494
508
        doppelganger = _mod_branch.Branch.open('branch')
495
 
        doppelganger.set_reference_info(b'file-id', 'location3', 'path3')
496
 
        self.assertEqual(('location3', 'path3'),
497
 
                         branch.get_reference_info(b'file-id'))
 
509
        doppelganger.set_reference_info('file-id', 'path3', 'location3')
 
510
        self.assertEqual(('path3', 'location3'),
 
511
                         branch.get_reference_info('file-id'))
498
512
 
499
513
    def _recordParentMapCalls(self, repo):
500
514
        self._parent_map_calls = []
501
515
        orig_get_parent_map = repo.revisions.get_parent_map
502
 
 
503
516
        def get_parent_map(q):
504
517
            q = list(q)
505
518
            self._parent_map_calls.extend([e[0] for e in q])
519
532
        target_branch = dir.create_branch()
520
533
        t.mkdir('branch')
521
534
        branch_dir = bzrdirformat.initialize(self.get_url('branch'))
522
 
        made_branch = _mod_bzrbranch.BranchReferenceFormat().initialize(
 
535
        made_branch = _mod_branch.BranchReferenceFormat().initialize(
523
536
            branch_dir, target_branch=target_branch)
524
537
        self.assertEqual(made_branch.base, target_branch.base)
525
538
        opened_branch = branch_dir.open_branch()
529
542
        """For a BranchReference, get_reference should return the location."""
530
543
        branch = self.make_branch('target')
531
544
        checkout = branch.create_checkout('checkout', lightweight=True)
532
 
        reference_url = branch.controldir.root_transport.abspath('') + '/'
 
545
        reference_url = branch.bzrdir.root_transport.abspath('') + '/'
533
546
        # if the api for create_checkout changes to return different checkout types
534
547
        # then this file read will fail.
535
 
        self.assertFileEqual(reference_url.encode('utf-8'),
536
 
                             'checkout/.bzr/branch/location')
 
548
        self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
537
549
        self.assertEqual(reference_url,
538
 
                         _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
 
550
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
539
551
 
540
552
 
541
553
class TestHooks(tests.TestCaseWithTransport):
544
556
        """Check that creating a BranchHooks instance has the right defaults."""
545
557
        hooks = _mod_branch.BranchHooks()
546
558
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
547
 
        self.assertTrue("post_commit" in hooks,
548
 
                        "post_commit not in %s" % hooks)
 
559
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
549
560
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
550
561
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
551
562
        self.assertTrue("post_uncommit" in hooks,
566
577
    def test_post_branch_init_hook(self):
567
578
        calls = []
568
579
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
569
 
                                                    calls.append, None)
 
580
            calls.append, None)
570
581
        self.assertLength(0, calls)
571
582
        branch = self.make_branch('a')
572
583
        self.assertLength(1, calls)
573
584
        params = calls[0]
574
585
        self.assertIsInstance(params, _mod_branch.BranchInitHookParams)
575
 
        self.assertTrue(hasattr(params, 'controldir'))
 
586
        self.assertTrue(hasattr(params, 'bzrdir'))
576
587
        self.assertTrue(hasattr(params, 'branch'))
577
588
 
578
589
    def test_post_branch_init_hook_repr(self):
579
590
        param_reprs = []
580
591
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
581
 
                                                    lambda params: param_reprs.append(repr(params)), None)
 
592
            lambda params: param_reprs.append(repr(params)), None)
582
593
        branch = self.make_branch('a')
583
594
        self.assertLength(1, param_reprs)
584
595
        param_repr = param_reprs[0]
585
596
        self.assertStartsWith(param_repr, '<BranchInitHookParams of ')
586
597
 
587
598
    def test_post_switch_hook(self):
588
 
        from .. import switch
 
599
        from brzlib import switch
589
600
        calls = []
590
601
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
591
 
                                                    calls.append, None)
 
602
            calls.append, None)
592
603
        tree = self.make_branch_and_tree('branch-1')
593
604
        self.build_tree(['branch-1/file-1'])
594
605
        tree.add('file-1')
595
606
        tree.commit('rev1')
596
 
        to_branch = tree.controldir.sprout('branch-2').open_branch()
 
607
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
597
608
        self.build_tree(['branch-1/file-2'])
598
609
        tree.add('file-2')
599
610
        tree.remove('file-1')
600
611
        tree.commit('rev2')
601
612
        checkout = tree.branch.create_checkout('checkout')
602
613
        self.assertLength(0, calls)
603
 
        switch.switch(checkout.controldir, to_branch)
 
614
        switch.switch(checkout.bzrdir, to_branch)
604
615
        self.assertLength(1, calls)
605
616
        params = calls[0]
606
617
        self.assertIsInstance(params, _mod_branch.SwitchHookParams)
624
635
 
625
636
    def test_valid_append_revisions_only(self):
626
637
        self.assertEqual(None,
627
 
                         self.config_stack.get('append_revisions_only'))
 
638
                          self.config_stack.get('append_revisions_only'))
628
639
        self.check_append_revisions_only(None)
629
640
        self.check_append_revisions_only(False, 'False')
630
641
        self.check_append_revisions_only(True, 'True')
636
647
    def test_invalid_append_revisions_only(self):
637
648
        """Ensure warning is noted on invalid settings"""
638
649
        self.warnings = []
639
 
 
640
650
        def warning(*args):
641
651
            self.warnings.append(args[0] % args[1:])
642
652
        self.overrideAttr(trace, 'warning', warning)
696
706
 
697
707
    def test_report_changed(self):
698
708
        r = _mod_branch.PullResult()
699
 
        r.old_revid = b"old-revid"
 
709
        r.old_revid = "old-revid"
700
710
        r.old_revno = 10
701
 
        r.new_revid = b"new-revid"
 
711
        r.new_revid = "new-revid"
702
712
        r.new_revno = 20
703
713
        f = StringIO()
704
714
        r.report(f)
705
715
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
716
        self.assertEqual("Now on revision 20.\n", f.getvalue())
706
717
 
707
718
    def test_report_unchanged(self):
708
719
        r = _mod_branch.PullResult()
709
 
        r.old_revid = b"same-revid"
710
 
        r.new_revid = b"same-revid"
 
720
        r.old_revid = "same-revid"
 
721
        r.new_revid = "same-revid"
711
722
        f = StringIO()
712
723
        r.report(f)
713
724
        self.assertEqual("No revisions or tags to pull.\n", f.getvalue())