~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2012-07-19 19:27:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6540.
  • Revision ID: aaron@aaronbentley.com-20120719192722-5sadhjwr3kaby7b7
Support foreign branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for branch implementations - tests a branch format."""
18
18
 
19
 
from cStringIO import StringIO
 
19
import contextlib
20
20
 
21
21
from bzrlib import (
22
22
    branch as _mod_branch,
1075
1075
                shelf_file, tt, revision.NULL_REVISION)
1076
1076
 
1077
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
 
1078
1086
class TestUncommittedChanges(per_branch.TestCaseWithBranch):
1079
1087
 
1080
1088
    def bind(self, branch, master):
1083
1091
        except errors.UpgradeRequired:
1084
1092
            raise tests.TestNotApplicable('Branch cannot be bound.')
1085
1093
 
1086
 
    def make_bound(self):
1087
 
        tree = self.make_branch_and_tree('b')
1088
 
        branch = tree.branch
1089
 
        master = self.make_branch('master')
1090
 
        self.bind(branch, master)
1091
 
        return tree, master
1092
 
 
1093
1094
    def test_store_uncommitted(self):
1094
1095
        tree = self.make_branch_and_tree('b')
1095
1096
        branch = tree.branch
1096
1097
        creator = FakeShelfCreator(branch)
1097
 
        self.assertIs(None, branch.get_unshelver(tree))
 
1098
        with skip_if_storing_uncommitted_unsupported():
 
1099
            self.assertIs(None, branch.get_unshelver(tree))
1098
1100
        branch.store_uncommitted(creator)
1099
1101
        self.assertIsNot(None, branch.get_unshelver(tree))
1100
1102
 
1101
1103
    def test_store_uncommitted_bound(self):
1102
 
        tree, master = self.make_bound()
 
1104
        tree = self.make_branch_and_tree('b')
 
1105
        branch = tree.branch
 
1106
        master = self.make_branch('master')
 
1107
        self.bind(branch, master)
1103
1108
        creator = FakeShelfCreator(tree.branch)
1104
1109
        self.assertIs(None, tree.branch.get_unshelver(tree))
1105
1110
        self.assertIs(None, master.get_unshelver(tree))
1108
1113
 
1109
1114
    def test_store_uncommitted_already_stored(self):
1110
1115
        branch = self.make_branch('b')
1111
 
        branch.store_uncommitted(FakeShelfCreator(branch))
 
1116
        with skip_if_storing_uncommitted_unsupported():
 
1117
            branch.store_uncommitted(FakeShelfCreator(branch))
1112
1118
        self.assertRaises(errors.ChangesAlreadyStored,
1113
1119
                          branch.store_uncommitted, FakeShelfCreator(branch))
1114
1120
 
1115
1121
    def test_store_uncommitted_none(self):
1116
1122
        branch = self.make_branch('b')
1117
 
        branch.store_uncommitted(FakeShelfCreator(branch))
 
1123
        with skip_if_storing_uncommitted_unsupported():
 
1124
            branch.store_uncommitted(FakeShelfCreator(branch))
1118
1125
        branch.store_uncommitted(None)
1119
1126
        self.assertIs(None, branch.get_unshelver(None))
1120
1127
 
1123
1130
        tree.commit('')
1124
1131
        self.build_tree_contents([('tree/file', 'contents1')])
1125
1132
        tree.add('file')
1126
 
        tree.store_uncommitted()
 
1133
        with skip_if_storing_uncommitted_unsupported():
 
1134
            tree.store_uncommitted()
1127
1135
        unshelver = tree.branch.get_unshelver(tree)
1128
1136
        self.assertIsNot(None, unshelver)
1129
1137
 
1132
1140
        tree.commit('')
1133
1141
        self.build_tree_contents([('tree/file', 'contents1')])
1134
1142
        tree.add('file')
1135
 
        tree.store_uncommitted()
 
1143
        with skip_if_storing_uncommitted_unsupported():
 
1144
            tree.store_uncommitted()
1136
1145
        branch = self.make_branch('branch')
1137
1146
        self.bind(branch, tree.branch)
1138
1147
        unshelver = branch.get_unshelver(tree)