~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2007-03-09 20:41:48 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: abentley@panoramicfeedback.com-20070309204148-vmtkocitp2er21r7
Clean up tests, add serialization text test

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    )
24
24
 
25
25
 
 
26
OUTPUT1 = """# Bazaar merge directive format experimental-1
 
27
# revision_id: example:
 
28
# target_branch: http://example.com
 
29
# testament_sha1: sha
 
30
# timestamp: 1970-01-01 00:09:33 +0002
 
31
#\x20
 
32
booga"""
 
33
 
 
34
 
 
35
OUTPUT2 = """# Bazaar merge directive format experimental-1
 
36
# revision_id: example:
 
37
# target_branch: http://example.com
 
38
# testament_sha1: sha
 
39
# timestamp: 1970-01-01 00:09:33 +0002
 
40
# source_branch: http://example.org
 
41
# message: Hi mom!
 
42
#\x20
 
43
booga"""
 
44
 
 
45
 
26
46
class TestMergeDirective(tests.TestCase):
27
47
 
28
 
    def test_init(self):
 
48
    def test_merge_source(self):
29
49
        time = 500.0
30
50
        timezone = 5
31
51
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
33
53
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
34
54
            'example:', 'sha', time, timezone, 'http://example.com',
35
55
            patch_type='diff')
36
 
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
56
        merge_directive.MergeDirective('example:', 'sha', time, timezone,
37
57
            'http://example.com', source_branch='http://example.org')
38
 
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
39
 
            'example:', 'sha', time, timezone, 'http://example.com',
40
 
            patch_type='bundle')
41
58
        md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
42
59
            'http://example.com', patch='blah', patch_type='bundle')
 
60
        self.assertIs(None, md.source_branch)
 
61
        md2 = merge_directive.MergeDirective('null:', 'sha', time, timezone,
 
62
            'http://example.com', patch='blah', patch_type='bundle',
 
63
            source_branch='bar')
 
64
        self.assertEqual('bar', md2.source_branch)
 
65
 
 
66
    def test_require_patch(self):
 
67
        time = 500.0
 
68
        timezone = 5
43
69
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
44
70
            'example:', 'sha', time, timezone, 'http://example.com',
45
 
            source_branch="http://example.org", patch_type='diff')
 
71
            patch_type='bundle')
46
72
        md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
47
73
            'http://example.com', source_branch="http://example.org",
48
74
            patch='', patch_type='diff')
 
75
        self.assertEqual(md.patch, '')
49
76
 
50
77
    def test_serialization(self):
51
78
        time = 501
52
79
        timezone = 72
53
80
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
81
            'http://example.com', patch='booga', patch_type='bundle')
 
82
        self.assertEqualDiff(OUTPUT1, ''.join(md.to_lines()))
 
83
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
84
            'http://example.com', source_branch="http://example.org",
 
85
            patch='booga', patch_type='diff', message="Hi mom!")
 
86
        self.assertEqualDiff(OUTPUT2, ''.join(md.to_lines()))
 
87
 
 
88
    def test_roundtrip(self):
 
89
        time = 501
 
90
        timezone = 72
 
91
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
54
92
            'http://example.com', source_branch="http://example.org",
55
93
            patch='booga', patch_type='diff')
56
94
        md2 = merge_directive.MergeDirective.from_lines(md.to_lines())
116
154
        tree_a.commit('Commit of rev2a', rev_id='rev2a')
117
155
        return tree_a, tree_b, branch_c
118
156
 
119
 
    def test_generate(self):
 
157
    def test_generate_patch(self):
 
158
        tree_a, tree_b, branch_c = self.make_trees()
 
159
        md2 = merge_directive.MergeDirective.from_objects(
 
160
            tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
 
161
            patch_type='diff', public_branch=tree_a.branch.base)
 
162
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
 
163
        self.assertContainsRe(md2.patch, '\\+content_c')
 
164
        self.assertNotContainsRe(md2.patch, '\\+\\+\\+ b/')
 
165
        self.assertContainsRe(md2.patch, '\\+\\+\\+ file')
 
166
 
 
167
    def test_public_branch(self):
120
168
        tree_a, tree_b, branch_c = self.make_trees()
121
169
        self.assertRaises(errors.PublicBranchOutOfDate,
122
170
            merge_directive.MergeDirective.from_objects,
126
174
        md1 = merge_directive.MergeDirective.from_objects(
127
175
            tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
128
176
            public_branch=branch_c.base)
129
 
        self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
130
 
        self.assertContainsRe(md1.patch, '\\+content_c')
131
 
        self.assertNotContainsRe(md1.patch, '\\+content_a')
132
177
        # public branch is provided with a bundle, despite possibly being out
133
178
        # of date, because it's not required if a bundle is present.
134
179
        self.assertEqual(md1.source_branch, branch_c.base)
 
180
        # Once we update the public branch, we can generate a diff.
135
181
        branch_c.pull(tree_a.branch)
136
 
        md2 = merge_directive.MergeDirective.from_objects(
 
182
        md3 = merge_directive.MergeDirective.from_objects(
137
183
            tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
138
 
            patch_type='diff', public_branch=branch_c.base)
139
 
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
140
 
        self.assertContainsRe(md1.patch, '\\+content_c')
141
 
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
184
            patch_type=None, public_branch=branch_c.base)
 
185
 
 
186
    def test_message(self):
 
187
        tree_a, tree_b, branch_c = self.make_trees()
142
188
        md3 = merge_directive.MergeDirective.from_objects(
143
189
            tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
144
190
            patch_type=None, public_branch=branch_c.base,
147
193
        self.assertIs(None, md3.patch)
148
194
        self.assertEqual('Merge message', md3.message)
149
195
 
150
 
    def test_generate_patch(self):
 
196
    def test_generate_bundle(self):
151
197
        tree_a, tree_b, branch_c = self.make_trees()
152
 
        md2 = merge_directive.MergeDirective.from_objects(
 
198
        md1 = merge_directive.MergeDirective.from_objects(
153
199
            tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
154
 
            patch_type='diff', public_branch=tree_a.branch.base)
155
 
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
156
 
        self.assertContainsRe(md2.patch, '\\+content_c')
157
 
        self.assertNotContainsRe(md2.patch, '\\+\\+\\+ b/')
158
 
        self.assertContainsRe(md2.patch, '\\+\\+\\+ file')
 
200
            public_branch=branch_c.base)
 
201
        self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
 
202
        self.assertContainsRe(md1.patch, '\\+content_c')
 
203
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
204
        self.assertContainsRe(md1.patch, '\\+content_c')
 
205
        self.assertNotContainsRe(md1.patch, '\\+content_a')
159
206
 
160
207
    def test_signing(self):
161
208
        time = 501