~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-06 20:45:48 UTC
  • mfrom: (4728.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091006204548-bjnc3z4k256ppimz
MutableTree.has_changes() does not require a tree parameter anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the Branch facility that are not interface  tests.
18
18
 
19
 
For interface tests see tests/branch_implementations/*.py.
 
19
For interface tests see tests/per_branch/*.py.
20
20
 
21
21
For concrete class tests see this file, and for meta-branch tests
22
22
also see this file.
40
40
    BzrBranch5,
41
41
    BzrBranchFormat5,
42
42
    BzrBranchFormat6,
 
43
    BzrBranchFormat7,
43
44
    PullResult,
44
45
    _run_with_write_locked_target,
45
46
    )
60
61
    def test_default_format(self):
61
62
        # update this if you change the default branch format
62
63
        self.assertIsInstance(BranchFormat.get_default_format(),
63
 
                BzrBranchFormat6)
 
64
                BzrBranchFormat7)
64
65
 
65
66
    def test_default_format_is_same_as_bzrdir_default(self):
66
67
        # XXX: it might be nice if there was only one place the default was
228
229
        branch = self.make_branch('a', format=self.get_format_name())
229
230
        self.failUnlessExists('a/.bzr/branch/last-revision')
230
231
        self.failIfExists('a/.bzr/branch/revision-history')
 
232
        self.failIfExists('a/.bzr/branch/references')
231
233
 
232
234
    def test_config(self):
233
235
        """Ensure that all configuration data is stored in the branch"""
334
336
        return _mod_branch.BzrBranch7
335
337
 
336
338
    def get_format_name(self):
337
 
        return "development"
 
339
        return "1.9"
338
340
 
339
341
    def get_format_name_subtree(self):
340
342
        return "development-subtree"
378
380
        self.assertTrue(branch.repository.has_revision(revid))
379
381
 
380
382
 
 
383
class BzrBranch8(TestCaseWithTransport):
 
384
 
 
385
    def make_branch(self, location, format=None):
 
386
        if format is None:
 
387
            format = bzrdir.format_registry.make_bzrdir('1.9')
 
388
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
 
389
        return TestCaseWithTransport.make_branch(self, location, format=format)
 
390
 
 
391
    def create_branch_with_reference(self):
 
392
        branch = self.make_branch('branch')
 
393
        branch._set_all_reference_info({'file-id': ('path', 'location')})
 
394
        return branch
 
395
 
 
396
    @staticmethod
 
397
    def instrument_branch(branch, gets):
 
398
        old_get = branch._transport.get
 
399
        def get(*args, **kwargs):
 
400
            gets.append((args, kwargs))
 
401
            return old_get(*args, **kwargs)
 
402
        branch._transport.get = get
 
403
 
 
404
    def test_reference_info_caching_read_locked(self):
 
405
        gets = []
 
406
        branch = self.create_branch_with_reference()
 
407
        branch.lock_read()
 
408
        self.addCleanup(branch.unlock)
 
409
        self.instrument_branch(branch, gets)
 
410
        branch.get_reference_info('file-id')
 
411
        branch.get_reference_info('file-id')
 
412
        self.assertEqual(1, len(gets))
 
413
 
 
414
    def test_reference_info_caching_read_unlocked(self):
 
415
        gets = []
 
416
        branch = self.create_branch_with_reference()
 
417
        self.instrument_branch(branch, gets)
 
418
        branch.get_reference_info('file-id')
 
419
        branch.get_reference_info('file-id')
 
420
        self.assertEqual(2, len(gets))
 
421
 
 
422
    def test_reference_info_caching_write_locked(self):
 
423
        gets = []
 
424
        branch = self.make_branch('branch')
 
425
        branch.lock_write()
 
426
        self.instrument_branch(branch, gets)
 
427
        self.addCleanup(branch.unlock)
 
428
        branch._set_all_reference_info({'file-id': ('path2', 'location2')})
 
429
        path, location = branch.get_reference_info('file-id')
 
430
        self.assertEqual(0, len(gets))
 
431
        self.assertEqual('path2', path)
 
432
        self.assertEqual('location2', location)
 
433
 
 
434
    def test_reference_info_caches_cleared(self):
 
435
        branch = self.make_branch('branch')
 
436
        branch.lock_write()
 
437
        branch.set_reference_info('file-id', 'path2', 'location2')
 
438
        branch.unlock()
 
439
        doppelganger = Branch.open('branch')
 
440
        doppelganger.set_reference_info('file-id', 'path3', 'location3')
 
441
        self.assertEqual(('path3', 'location3'),
 
442
                         branch.get_reference_info('file-id'))
 
443
 
381
444
class TestBranchReference(TestCaseWithTransport):
382
445
    """Tests for the branch reference facility."""
383
446
 
441
504
        a = "%d revisions pulled" % r
442
505
        self.assertEqual(a, "10 revisions pulled")
443
506
 
 
507
    def test_report_changed(self):
 
508
        r = PullResult()
 
509
        r.old_revid = "old-revid"
 
510
        r.old_revno = 10
 
511
        r.new_revid = "new-revid"
 
512
        r.new_revno = 20
 
513
        f = StringIO()
 
514
        r.report(f)
 
515
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
516
 
 
517
    def test_report_unchanged(self):
 
518
        r = PullResult()
 
519
        r.old_revid = "same-revid"
 
520
        r.new_revid = "same-revid"
 
521
        f = StringIO()
 
522
        r.report(f)
 
523
        self.assertEqual("No revisions to pull.\n", f.getvalue())
444
524
 
445
525
 
446
526
class _StubLockable(object):