~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_branch.py

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for branch implementations - tests a branch format."""
18
18
 
19
 
import contextlib
20
 
 
21
19
from bzrlib import (
22
20
    branch as _mod_branch,
23
 
    controldir,
 
21
    bzrdir,
24
22
    config,
25
23
    delta as _mod_delta,
26
24
    errors,
 
25
    gpg,
27
26
    merge,
28
27
    osutils,
29
28
    urlutils,
30
 
    transform,
31
29
    transport,
32
30
    remote,
33
31
    repository,
34
32
    revision,
35
 
    shelf,
36
33
    symbol_versioning,
37
34
    tests,
38
35
    )
324
321
        if repo.bzrdir._format.colocated_branches:
325
322
            raise tests.TestNotApplicable(
326
323
                "control dir does not support colocated branches")
327
 
        self.assertEqual(0, len(repo.bzrdir.list_branches()))
 
324
        self.assertEquals(0, len(repo.bzrdir.list_branches()))
328
325
        if not self.bzrdir_format.colocated_branches:
329
326
            raise tests.TestNotApplicable("control dir format does not support "
330
327
                "colocated branches")
335
332
            # branch references are not default init'able and
336
333
            # not all bzrdirs support colocated branches.
337
334
            return
338
 
        self.assertEqual(1, len(repo.bzrdir.list_branches()))
 
335
        self.assertEquals(1, len(repo.bzrdir.list_branches()))
339
336
        self.branch_format.initialize(repo.bzrdir, name='branch2')
340
 
        self.assertEqual(2, len(repo.bzrdir.list_branches()))
 
337
        self.assertEquals(2, len(repo.bzrdir.list_branches()))
341
338
 
342
339
    def test_create_append_revisions_only(self):
343
340
        try:
352
349
                # branch references are not default init'able and
353
350
                # not all branches support append_revisions_only
354
351
                return
355
 
            self.assertEqual(True, branch.get_append_revisions_only())
 
352
            self.assertEquals(True, branch.get_append_revisions_only())
356
353
            repo.bzrdir.destroy_branch()
357
354
 
358
355
    def test_get_set_append_revisions_only(self):
479
476
        checkout = source_branch.create_checkout('c')
480
477
        self.assertEqual(rev_id, checkout.last_revision())
481
478
 
 
479
    def test_set_revision_history(self):
 
480
        tree = self.make_branch_and_tree('a')
 
481
        tree.commit('a commit', rev_id='rev1')
 
482
        br = tree.branch
 
483
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
484
            br.set_revision_history, ["rev1"])
 
485
        self.assertEquals(br.last_revision(), "rev1")
 
486
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
487
            br.set_revision_history, [])
 
488
        self.assertEquals(br.last_revision(), 'null:')
 
489
 
482
490
    def test_heads_to_fetch(self):
483
491
        # heads_to_fetch is a method that returns a collection of revids that
484
492
        # need to be fetched to copy this branch into another repo.  At a
521
529
            looked_up_format = registry.get(network_name)
522
530
            self.assertEqual(format.__class__, looked_up_format.__class__)
523
531
 
524
 
    def test_get_config_calls(self):
 
532
    def get_get_config_calls(self):
525
533
        # Smoke test that all branch succeed getting a config
526
534
        br = self.make_branch('.')
527
535
        br.get_config()
701
709
        self.assertIsInstance(made_branch, _mod_branch.Branch)
702
710
 
703
711
        # find it via bzrdir opening:
704
 
        opened_control = controldir.ControlDir.open(readonly_t.base)
 
712
        opened_control = bzrdir.BzrDir.open(readonly_t.base)
705
713
        direct_opened_branch = opened_control.open_branch()
706
714
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
707
715
        self.assertEqual(opened_control, direct_opened_branch.bzrdir)
772
780
        branch.unbind()
773
781
        self.assertEqual(None, branch.get_master_branch())
774
782
 
 
783
    def test_unlocked_does_not_cache_master_branch(self):
 
784
        """Unlocked branches do not cache the result of get_master_branch."""
 
785
        master = self.make_branch('master')
 
786
        branch1 = self.make_branch('branch')
 
787
        try:
 
788
            branch1.bind(master)
 
789
        except errors.UpgradeRequired:
 
790
            raise tests.TestNotApplicable('Format does not support binding')
 
791
        # Open branch1 again
 
792
        branch2 = branch1.bzrdir.open_branch()
 
793
        self.assertNotEqual(None, branch1.get_master_branch())
 
794
        # Unbind the branch via branch2.  branch1 isn't locked so will
 
795
        # immediately return the new value for get_master_branch.
 
796
        branch2.unbind()
 
797
        self.assertEqual(None, branch1.get_master_branch())
 
798
 
775
799
    def test_bind_clears_cached_master_branch(self):
776
800
        """b.bind clears any cached value of b.get_master_branch."""
777
801
        master1 = self.make_branch('master1')
842
866
    def test_fallbacks_not_opened(self):
843
867
        stacked = self.make_branch_with_fallback()
844
868
        self.get_transport('').rename('fallback', 'moved')
845
 
        reopened_dir = controldir.ControlDir.open(stacked.base)
 
869
        reopened_dir = bzrdir.BzrDir.open(stacked.base)
846
870
        reopened = reopened_dir.open_branch(ignore_fallbacks=True)
847
871
        self.assertEqual([], reopened.repository._fallback_repositories)
848
872
 
849
873
    def test_fallbacks_are_opened(self):
850
874
        stacked = self.make_branch_with_fallback()
851
 
        reopened_dir = controldir.ControlDir.open(stacked.base)
 
875
        reopened_dir = bzrdir.BzrDir.open(stacked.base)
852
876
        reopened = reopened_dir.open_branch(ignore_fallbacks=False)
853
877
        self.assertLength(1, reopened.repository._fallback_repositories)
854
878
 
1061
1085
        # above the control dir but we might need to relax that?
1062
1086
        self.assertEqual(br.control_url.find(br.user_url), 0)
1063
1087
        self.assertEqual(br.control_url, br.control_transport.base)
1064
 
 
1065
 
 
1066
 
class FakeShelfCreator(object):
1067
 
 
1068
 
    def __init__(self, branch):
1069
 
        self.branch = branch
1070
 
 
1071
 
    def write_shelf(self, shelf_file, message=None):
1072
 
        tree = self.branch.repository.revision_tree(revision.NULL_REVISION)
1073
 
        with transform.TransformPreview(tree) as tt:
1074
 
            shelf.ShelfCreator._write_shelf(
1075
 
                shelf_file, tt, revision.NULL_REVISION)
1076
 
 
1077
 
 
1078
 
@contextlib.contextmanager
1079
 
def skip_if_storing_uncommitted_unsupported():
1080
 
    try:
1081
 
        yield
1082
 
    except errors.StoringUncommittedNotSupported:
1083
 
        raise tests.TestNotApplicable('Cannot store uncommitted changes.')
1084
 
 
1085
 
 
1086
 
class TestUncommittedChanges(per_branch.TestCaseWithBranch):
1087
 
 
1088
 
    def bind(self, branch, master):
1089
 
        try:
1090
 
            branch.bind(master)
1091
 
        except errors.UpgradeRequired:
1092
 
            raise tests.TestNotApplicable('Branch cannot be bound.')
1093
 
 
1094
 
    def test_store_uncommitted(self):
1095
 
        tree = self.make_branch_and_tree('b')
1096
 
        branch = tree.branch
1097
 
        creator = FakeShelfCreator(branch)
1098
 
        with skip_if_storing_uncommitted_unsupported():
1099
 
            self.assertIs(None, branch.get_unshelver(tree))
1100
 
        branch.store_uncommitted(creator)
1101
 
        self.assertIsNot(None, branch.get_unshelver(tree))
1102
 
 
1103
 
    def test_store_uncommitted_bound(self):
1104
 
        tree = self.make_branch_and_tree('b')
1105
 
        branch = tree.branch
1106
 
        master = self.make_branch('master')
1107
 
        self.bind(branch, master)
1108
 
        creator = FakeShelfCreator(tree.branch)
1109
 
        self.assertIs(None, tree.branch.get_unshelver(tree))
1110
 
        self.assertIs(None, master.get_unshelver(tree))
1111
 
        tree.branch.store_uncommitted(creator)
1112
 
        self.assertIsNot(None, master.get_unshelver(tree))
1113
 
 
1114
 
    def test_store_uncommitted_already_stored(self):
1115
 
        branch = self.make_branch('b')
1116
 
        with skip_if_storing_uncommitted_unsupported():
1117
 
            branch.store_uncommitted(FakeShelfCreator(branch))
1118
 
        self.assertRaises(errors.ChangesAlreadyStored,
1119
 
                          branch.store_uncommitted, FakeShelfCreator(branch))
1120
 
 
1121
 
    def test_store_uncommitted_none(self):
1122
 
        branch = self.make_branch('b')
1123
 
        with skip_if_storing_uncommitted_unsupported():
1124
 
            branch.store_uncommitted(FakeShelfCreator(branch))
1125
 
        branch.store_uncommitted(None)
1126
 
        self.assertIs(None, branch.get_unshelver(None))
1127
 
 
1128
 
    def test_get_unshelver(self):
1129
 
        tree = self.make_branch_and_tree('tree')
1130
 
        tree.commit('')
1131
 
        self.build_tree_contents([('tree/file', 'contents1')])
1132
 
        tree.add('file')
1133
 
        with skip_if_storing_uncommitted_unsupported():
1134
 
            tree.store_uncommitted()
1135
 
        unshelver = tree.branch.get_unshelver(tree)
1136
 
        self.assertIsNot(None, unshelver)
1137
 
 
1138
 
    def test_get_unshelver_bound(self):
1139
 
        tree = self.make_branch_and_tree('tree')
1140
 
        tree.commit('')
1141
 
        self.build_tree_contents([('tree/file', 'contents1')])
1142
 
        tree.add('file')
1143
 
        with skip_if_storing_uncommitted_unsupported():
1144
 
            tree.store_uncommitted()
1145
 
        branch = self.make_branch('branch')
1146
 
        self.bind(branch, tree.branch)
1147
 
        unshelver = branch.get_unshelver(tree)
1148
 
        self.assertIsNot(None, unshelver)