/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_send.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-18 18:18:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4461.
  • Revision ID: john@arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
Which is completely valid, but 'broke' one of the tests.
So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
has to check the root keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
# Authors: Aaron Bentley
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
 
 
19
import os
 
20
import sys
 
21
from StringIO import StringIO
 
22
 
 
23
from bzrlib import (
 
24
    branch as _mod_branch,
 
25
    merge_directive,
 
26
    )
 
27
from bzrlib.bundle import serializer
 
28
from bzrlib.bzrdir import BzrDir
 
29
from bzrlib import tests
 
30
 
 
31
 
 
32
def read_bundle(fileobj):
 
33
    md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
 
34
    return serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
35
 
 
36
 
 
37
class TestSend(tests.TestCaseWithTransport):
 
38
 
 
39
    def make_trees(self):
 
40
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
 
41
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
 
42
        grandparent_tree.add('file1')
 
43
        grandparent_tree.commit('initial commit', rev_id='revision1')
 
44
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
 
45
        parent_tree = parent_bzrdir.open_workingtree()
 
46
        parent_tree.commit('next commit', rev_id='revision2')
 
47
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
 
48
        self.build_tree_contents([('branch/file1', 'branch')])
 
49
        branch_tree.commit('last commit', rev_id='revision3')
 
50
 
 
51
    def test_uses_parent(self):
 
52
        """Parent location is used as a basis by default"""
 
53
        self.make_trees()
 
54
        os.chdir('grandparent')
 
55
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
 
56
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
 
57
        os.chdir('../branch')
 
58
        stdout, stderr = self.run_bzr('send -o-')
 
59
        self.assertEqual(stderr.count('Using saved parent location'), 1)
 
60
        br = read_bundle(StringIO(stdout))
 
61
        self.assertRevisions(br, ['revision3'])
 
62
 
 
63
    def test_bundle(self):
 
64
        """Bundle works like send, except -o is not required"""
 
65
        self.make_trees()
 
66
        os.chdir('grandparent')
 
67
        errmsg = self.run_bzr('bundle', retcode=3)[1]
 
68
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
 
69
        os.chdir('../branch')
 
70
        stdout, stderr = self.run_bzr('bundle')
 
71
        self.assertEqual(stderr.count('Using saved parent location'), 1)
 
72
        br = read_bundle(StringIO(stdout))
 
73
        self.assertRevisions(br, ['revision3'])
 
74
 
 
75
    def assertRevisions(self, bi, expected):
 
76
        self.assertEqual(set(r.revision_id for r in bi.revisions),
 
77
            set(expected))
 
78
 
 
79
    def test_uses_submit(self):
 
80
        """Submit location can be used and set"""
 
81
        self.make_trees()
 
82
        os.chdir('branch')
 
83
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
84
        self.assertRevisions(br, ['revision3'])
 
85
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
86
        self.assertRevisions(br, ['revision3', 'revision2'])
 
87
        # submit location should be auto-remembered
 
88
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
89
        self.assertRevisions(br, ['revision3', 'revision2'])
 
90
        self.run_bzr('send ../parent -o-')
 
91
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
92
        self.assertRevisions(br, ['revision3', 'revision2'])
 
93
        self.run_bzr('send ../parent --remember -o-')
 
94
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
95
        self.assertRevisions(br, ['revision3'])
 
96
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
 
97
        self.assertContainsRe(err,
 
98
                              '--remember requires a branch to be specified.')
 
99
 
 
100
    def test_revision_branch_interaction(self):
 
101
        self.make_trees()
 
102
        os.chdir('branch')
 
103
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
104
        self.assertRevisions(bi, ['revision3', 'revision2'])
 
105
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
 
106
        bi = read_bundle(out)
 
107
        self.assertRevisions(bi, ['revision2'])
 
108
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
 
109
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
 
110
        self.assertEqual('revision2', md.base_revision_id)
 
111
        self.assertEqual('revision3', md.revision_id)
 
112
        sio.seek(0)
 
113
        bi = read_bundle(sio)
 
114
        self.assertRevisions(bi, ['revision2', 'revision3'])
 
115
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
 
116
 
 
117
    def test_output(self):
 
118
        # check output for consistency
 
119
        # win32 stdout converts LF to CRLF,
 
120
        # which would break patch-based bundles
 
121
        self.make_trees()
 
122
        os.chdir('branch')
 
123
        stdout = self.run_bzr_subprocess('send -o-')[0]
 
124
        br = read_bundle(StringIO(stdout))
 
125
        self.assertRevisions(br, ['revision3'])
 
126
 
 
127
    def test_no_common_ancestor(self):
 
128
        foo = self.make_branch_and_tree('foo')
 
129
        foo.commit('rev a')
 
130
        bar = self.make_branch_and_tree('bar')
 
131
        bar.commit('rev b')
 
132
        os.chdir('foo')
 
133
        self.run_bzr('send ../bar -o-')
 
134
 
 
135
    def send_directive(self, args):
 
136
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
 
137
        return merge_directive.MergeDirective.from_lines(sio.readlines())
 
138
 
 
139
    def test_content_options(self):
 
140
        """--no-patch and --no-bundle should work and be independant"""
 
141
        self.make_trees()
 
142
        os.chdir('branch')
 
143
        md = self.send_directive([])
 
144
        self.assertIsNot(None, md.bundle)
 
145
        self.assertIsNot(None, md.patch)
 
146
 
 
147
        md = self.send_directive(['--format=0.9'])
 
148
        self.assertIsNot(None, md.bundle)
 
149
        self.assertIsNot(None, md.patch)
 
150
 
 
151
        md = self.send_directive(['--no-patch'])
 
152
        self.assertIsNot(None, md.bundle)
 
153
        self.assertIs(None, md.patch)
 
154
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
 
155
                      'send --no-patch --format=0.9 -o-')
 
156
 
 
157
        md = self.send_directive(['--no-bundle', '.', '.'])
 
158
        self.assertIs(None, md.bundle)
 
159
        self.assertIsNot(None, md.patch)
 
160
 
 
161
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
 
162
                                  '.'])
 
163
        self.assertIs(None, md.bundle)
 
164
        self.assertIsNot(None, md.patch)
 
165
 
 
166
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
 
167
        self.assertIs(None, md.bundle)
 
168
        self.assertIs(None, md.patch)
 
169
 
 
170
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
 
171
                                  '../parent', '.'])
 
172
        self.assertIs(None, md.bundle)
 
173
        self.assertIs(None, md.patch)
 
174
 
 
175
    def test_from_option(self):
 
176
        self.make_trees()
 
177
        self.run_bzr('send', retcode=3)
 
178
        md = self.send_directive(['--from', 'branch'])
 
179
        self.assertEqual('revision3', md.revision_id)
 
180
        md = self.send_directive(['-f', 'branch'])
 
181
        self.assertEqual('revision3', md.revision_id)
 
182
 
 
183
    def test_output_option(self):
 
184
        self.make_trees()
 
185
        stdout = self.run_bzr('send -f branch --output file1')[0]
 
186
        self.assertEqual('', stdout)
 
187
        md_file = open('file1', 'rb')
 
188
        self.addCleanup(md_file.close)
 
189
        self.assertContainsRe(md_file.read(), 'revision3')
 
190
        stdout = self.run_bzr('send -f branch --output -')[0]
 
191
        self.assertContainsRe(stdout, 'revision3')
 
192
 
 
193
    def test_note_revisions(self):
 
194
        self.make_trees()
 
195
        stderr = self.run_bzr('send -f branch --output file1')[1]
 
196
        self.assertContainsRe(stderr, r'Bundling 1 revision\(s\).\n')
 
197
 
 
198
    def test_mailto_option(self):
 
199
        self.make_trees()
 
200
        branch = _mod_branch.Branch.open('branch')
 
201
        branch.get_config().set_user_option('mail_client', 'editor')
 
202
        self.run_bzr_error(
 
203
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
 
204
            ), 'send -f branch')
 
205
        branch.get_config().set_user_option('mail_client', 'bogus')
 
206
        self.run_bzr('send -f branch -o-')
 
207
        self.run_bzr_error(('Unknown mail client: bogus',),
 
208
                           'send -f branch --mail-to jrandom@example.org')
 
209
        branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
210
        self.run_bzr_error(('Unknown mail client: bogus',),
 
211
                           'send -f branch')
 
212
 
 
213
    def test_mailto_child_option(self):
 
214
        """Make sure that child_submit_to is used."""
 
215
        self.make_trees()
 
216
        branch = _mod_branch.Branch.open('branch')
 
217
        branch.get_config().set_user_option('mail_client', 'bogus')
 
218
        parent = _mod_branch.Branch.open('parent')
 
219
        parent.get_config().set_user_option('child_submit_to',
 
220
                           'somebody@example.org')
 
221
        self.run_bzr_error(('Unknown mail client: bogus',),
 
222
                           'send -f branch')
 
223
 
 
224
    def test_format(self):
 
225
        self.make_trees()
 
226
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
 
227
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
228
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
 
229
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
 
230
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
231
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
232
            '# Bazaar revision bundle v0.9')
 
233
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
 
234
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
235
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
236
            '# Bazaar revision bundle v0.9')
 
237
        self.assertIs(merge_directive.MergeDirective, md.__class__)
 
238
        self.run_bzr_error(['Bad value .* for option .format.'],
 
239
                            'send -f branch -o- --format=0.999')[0]
 
240
 
 
241
    def test_format_child_option(self):
 
242
        self.make_trees()
 
243
        parent = _mod_branch.Branch.open('parent')
 
244
        parent.get_config().set_user_option('child_submit_format', '4')
 
245
        s = StringIO(self.run_bzr('send -f branch -o-')[0])
 
246
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
247
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
 
248
        parent.get_config().set_user_option('child_submit_format', '0.9')
 
249
        s = StringIO(self.run_bzr('send -f branch -o-')[0])
 
250
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
251
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
252
            '# Bazaar revision bundle v0.9')
 
253
        s = StringIO(self.run_bzr('bundle -f branch -o-')[0])
 
254
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
255
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
256
            '# Bazaar revision bundle v0.9')
 
257
        self.assertIs(merge_directive.MergeDirective, md.__class__)
 
258
        parent.get_config().set_user_option('child_submit_format', '0.999')
 
259
        self.run_bzr_error(["No such send format '0.999'"],
 
260
                            'send -f branch -o-')[0]
 
261
 
 
262
    def test_message_option(self):
 
263
        self.make_trees()
 
264
        self.run_bzr('send', retcode=3)
 
265
        md = self.send_directive(['--from', 'branch'])
 
266
        self.assertIs(None, md.message)
 
267
        md = self.send_directive(['--from', 'branch', '-m', 'my message'])
 
268
        self.assertEqual('my message', md.message)
 
269
 
 
270
    def test_omitted_revision(self):
 
271
        self.make_trees()
 
272
        md = self.send_directive(['-r-2..', '--from', 'branch'])
 
273
        self.assertEqual('revision2', md.base_revision_id)
 
274
        self.assertEqual('revision3', md.revision_id)
 
275
        md = self.send_directive(['-r..3', '--from', 'branch',
 
276
                                 'grandparent'])
 
277
        self.assertEqual('revision1', md.base_revision_id)
 
278
        self.assertEqual('revision3', md.revision_id)
 
279
 
 
280
    def test_nonexistant_branch(self):
 
281
        if sys.platform == "win32":
 
282
            location = "C:/i/do/not/exist/"
 
283
        else:
 
284
            location = "/i/do/not/exist/"
 
285
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
 
286
        self.assertEqual(out, '')
 
287
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)