~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2012-07-23 17:56:45 UTC
  • mfrom: (6538.1.34 branch-store)
  • Revision ID: pqm@pqm.ubuntu.com-20120723175645-92crzj8j7bfnuglm
(abentley) switch --store stores uncommitted changes in branch (Aaron
 Bentley)

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
import contextlib
 
20
 
19
21
from bzrlib import (
20
22
    branch as _mod_branch,
21
23
    controldir,
25
27
    merge,
26
28
    osutils,
27
29
    urlutils,
 
30
    transform,
28
31
    transport,
29
32
    remote,
30
33
    repository,
31
34
    revision,
 
35
    shelf,
32
36
    symbol_versioning,
33
37
    tests,
34
38
    )
1057
1061
        # above the control dir but we might need to relax that?
1058
1062
        self.assertEqual(br.control_url.find(br.user_url), 0)
1059
1063
        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)