/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: Andrew Bennetts
  • Date: 2008-08-12 14:53:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3624.
  • Revision ID: andrew.bennetts@canonical.com-20080812145326-yx693x2jc4rcovb7
Move the notes on writing tests out of HACKING into a new file, and improve
them.

Many of the testing notes in the HACKING file were in duplicated in two places
in that file!  This change removes that duplication.  It also adds new sections
on “Where should I put a new test?” and “TestCase and its subclasses”, and
others like “Test feature dependencies” have been expanded.  The whole document
has generally been edited to be a bit more coherent. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
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
 
 
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
import os
19
20
import sys
20
 
from cStringIO import StringIO
 
21
from StringIO import StringIO
21
22
 
22
23
from bzrlib import (
23
 
    branch,
24
 
    bzrdir,
 
24
    branch as _mod_branch,
25
25
    merge_directive,
26
 
    tests,
27
26
    )
28
27
from bzrlib.bundle import serializer
29
 
from bzrlib.transport import memory
30
 
 
31
 
 
32
 
def load_tests(standard_tests, module, loader):
33
 
    """Multiply tests for the send command."""
34
 
    result = loader.suiteClass()
35
 
 
36
 
    # one for each king of change
37
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
38
 
        standard_tests, tests.condition_isinstance((
39
 
                TestSendStrictWithChanges,
40
 
                )))
41
 
    changes_scenarios = [
42
 
        ('uncommitted',
43
 
         dict(_changes_type='_uncommitted_changes')),
44
 
        ('pending_merges',
45
 
         dict(_changes_type='_pending_merges')),
46
 
        ('out-of-sync-trees',
47
 
         dict(_changes_type='_out_of_sync_trees')),
48
 
        ]
49
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
50
 
    # No parametrization for the remaining tests
51
 
    result.addTests(remaining_tests)
52
 
 
53
 
    return result
54
 
 
55
 
 
56
 
class TestSendMixin(object):
57
 
 
58
 
    _default_command = ['send', '-o-']
59
 
    _default_wd = 'branch'
60
 
 
61
 
    def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
62
 
        if cmd is None: cmd = self._default_command
63
 
        if wd is None: wd = self._default_wd
64
 
        if err_re is None: err_re = []
65
 
        return self.run_bzr(cmd + args, retcode=rc,
66
 
                            working_dir=wd,
67
 
                            error_regexes=err_re)
68
 
 
69
 
    def get_MD(self, args, cmd=None, wd='branch'):
70
 
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
71
 
        return merge_directive.MergeDirective.from_lines(out)
72
 
 
73
 
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
74
 
        md = self.get_MD(args, cmd=cmd, wd=wd)
75
 
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
76
 
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
77
 
 
78
 
 
79
 
class TestSend(tests.TestCaseWithTransport, TestSendMixin):
80
 
 
81
 
    def setUp(self):
82
 
        super(TestSend, self).setUp()
83
 
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
84
 
            'grandparent')
 
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')
85
41
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
86
42
        grandparent_tree.add('file1')
87
 
        grandparent_tree.commit('initial commit', rev_id='rev1')
88
 
 
 
43
        grandparent_tree.commit('initial commit', rev_id='revision1')
89
44
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
90
45
        parent_tree = parent_bzrdir.open_workingtree()
91
 
        parent_tree.commit('next commit', rev_id='rev2')
92
 
 
 
46
        parent_tree.commit('next commit', rev_id='revision2')
93
47
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
94
48
        self.build_tree_contents([('branch/file1', 'branch')])
95
 
        branch_tree.commit('last commit', rev_id='rev3')
96
 
 
97
 
    def assertFormatIs(self, fmt_string, md):
98
 
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
 
49
        branch_tree.commit('last commit', rev_id='revision3')
99
50
 
100
51
    def test_uses_parent(self):
101
52
        """Parent location is used as a basis by default"""
102
 
        errmsg = self.run_send([], rc=3, wd='grandparent')[1]
 
53
        self.make_trees()
 
54
        os.chdir('grandparent')
 
55
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
103
56
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
104
 
        stdout, stderr = self.run_send([])
105
 
        self.assertEqual(stderr.count('Using saved parent location'), 1)
106
 
        self.assertBundleContains(['rev3'], [])
 
57
        os.chdir('../branch')
 
58
        stdout, stderr = self.run_bzr('send -o-')
 
59
        self.assertEqual(stderr.count('Using saved location'), 1)
 
60
        br = read_bundle(StringIO(stdout))
 
61
        self.assertRevisions(br, ['revision3'])
107
62
 
108
63
    def test_bundle(self):
109
64
        """Bundle works like send, except -o is not required"""
110
 
        errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
 
65
        self.make_trees()
 
66
        os.chdir('grandparent')
 
67
        errmsg = self.run_bzr('bundle', retcode=3)[1]
111
68
        self.assertContainsRe(errmsg, 'No submit branch known or specified')
112
 
        stdout, stderr = self.run_send([], cmd=['bundle'])
113
 
        self.assertEqual(stderr.count('Using saved parent location'), 1)
114
 
        self.assertBundleContains(['rev3'], [], cmd=['bundle'])
 
69
        os.chdir('../branch')
 
70
        stdout, stderr = self.run_bzr('bundle')
 
71
        self.assertEqual(stderr.count('Using saved 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))
115
78
 
116
79
    def test_uses_submit(self):
117
80
        """Submit location can be used and set"""
118
 
        self.assertBundleContains(['rev3'], [])
119
 
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
 
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'])
120
87
        # submit location should be auto-remembered
121
 
        self.assertBundleContains(['rev3', 'rev2'], [])
122
 
 
123
 
        self.run_send(['../parent'])
124
 
        # We still point to ../grandparent
125
 
        self.assertBundleContains(['rev3', 'rev2'], [])
126
 
        # Remember parent now
127
 
        self.run_send(['../parent', '--remember'])
128
 
        # Now we point to parent
129
 
        self.assertBundleContains(['rev3'], [])
130
 
 
131
 
        err = self.run_send(['--remember'], rc=3)[1]
132
 
        self.assertContainsRe(err,
 
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, 
133
98
                              '--remember requires a branch to be specified.')
134
99
 
135
100
    def test_revision_branch_interaction(self):
136
 
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
137
 
        self.assertBundleContains(['rev2'], ['../grandparent', '-r-2'])
138
 
        self.assertBundleContains(['rev3', 'rev2'],
139
 
                                  ['../grandparent', '-r-2..-1'])
140
 
        md = self.get_MD(['-r-2..-1'])
141
 
        self.assertEqual('rev2', md.base_revision_id)
142
 
        self.assertEqual('rev3', md.revision_id)
 
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-')
143
116
 
144
117
    def test_output(self):
145
118
        # check output for consistency
146
119
        # win32 stdout converts LF to CRLF,
147
120
        # which would break patch-based bundles
148
 
        self.assertBundleContains(['rev3'], [])
 
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'])
149
126
 
150
127
    def test_no_common_ancestor(self):
151
128
        foo = self.make_branch_and_tree('foo')
152
129
        foo.commit('rev a')
153
130
        bar = self.make_branch_and_tree('bar')
154
131
        bar.commit('rev b')
155
 
        self.run_send(['--from', 'foo', '../bar'], wd='foo')
 
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())
156
138
 
157
139
    def test_content_options(self):
158
140
        """--no-patch and --no-bundle should work and be independant"""
159
 
        md = self.get_MD([])
160
 
        self.assertIsNot(None, md.bundle)
161
 
        self.assertIsNot(None, md.patch)
162
 
 
163
 
        md = self.get_MD(['--format=0.9'])
164
 
        self.assertIsNot(None, md.bundle)
165
 
        self.assertIsNot(None, md.patch)
166
 
 
167
 
        md = self.get_MD(['--no-patch'])
 
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'])
168
152
        self.assertIsNot(None, md.bundle)
169
153
        self.assertIs(None, md.patch)
170
154
        self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
171
 
                           ['send', '--no-patch', '--format=0.9', '-o-'],
172
 
                           working_dir='branch')
173
 
        md = self.get_MD(['--no-bundle', '.', '.'])
 
155
                      'send --no-patch --format=0.9 -o-')
 
156
 
 
157
        md = self.send_directive(['--no-bundle', '.', '.'])
174
158
        self.assertIs(None, md.bundle)
175
159
        self.assertIsNot(None, md.patch)
176
160
 
177
 
        md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
 
161
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
178
162
                                  '.'])
179
163
        self.assertIs(None, md.bundle)
180
164
        self.assertIsNot(None, md.patch)
181
165
 
182
 
        md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
 
166
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
183
167
        self.assertIs(None, md.bundle)
184
168
        self.assertIs(None, md.patch)
185
169
 
186
 
        md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
187
 
                          '../parent', '.'])
 
170
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
 
171
                                  '../parent', '.'])
188
172
        self.assertIs(None, md.bundle)
189
173
        self.assertIs(None, md.patch)
190
174
 
191
175
    def test_from_option(self):
 
176
        self.make_trees()
192
177
        self.run_bzr('send', retcode=3)
193
 
        md = self.get_MD(['--from', 'branch'])
194
 
        self.assertEqual('rev3', md.revision_id)
195
 
        md = self.get_MD(['-f', 'branch'])
196
 
        self.assertEqual('rev3', md.revision_id)
 
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)
197
182
 
198
183
    def test_output_option(self):
 
184
        self.make_trees()
199
185
        stdout = self.run_bzr('send -f branch --output file1')[0]
200
186
        self.assertEqual('', stdout)
201
187
        md_file = open('file1', 'rb')
202
188
        self.addCleanup(md_file.close)
203
 
        self.assertContainsRe(md_file.read(), 'rev3')
 
189
        self.assertContainsRe(md_file.read(), 'revision3')
204
190
        stdout = self.run_bzr('send -f branch --output -')[0]
205
 
        self.assertContainsRe(stdout, 'rev3')
206
 
 
207
 
    def test_note_revisions(self):
208
 
        stderr = self.run_send([])[1]
209
 
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
 
191
        self.assertContainsRe(stdout, 'revision3')
210
192
 
211
193
    def test_mailto_option(self):
212
 
        b = branch.Branch.open('branch')
213
 
        b.get_config().set_user_option('mail_client', 'editor')
214
 
        self.run_bzr_error(
215
 
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
216
 
            ), 'send -f branch')
217
 
        b.get_config().set_user_option('mail_client', 'bogus')
218
 
        self.run_send([])
 
194
        self.make_trees()
 
195
        branch = _mod_branch.Branch.open('branch')
 
196
        branch.get_config().set_user_option('mail_client', 'editor')
 
197
        self.run_bzr_error(('No mail-to address specified',), 'send -f branch')
 
198
        branch.get_config().set_user_option('mail_client', 'bogus')
 
199
        self.run_bzr('send -f branch -o-')
219
200
        self.run_bzr_error(('Unknown mail client: bogus',),
220
201
                           'send -f branch --mail-to jrandom@example.org')
221
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
202
        branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
222
203
        self.run_bzr_error(('Unknown mail client: bogus',),
223
204
                           'send -f branch')
224
205
 
225
206
    def test_mailto_child_option(self):
226
207
        """Make sure that child_submit_to is used."""
227
 
        b = branch.Branch.open('branch')
228
 
        b.get_config().set_user_option('mail_client', 'bogus')
229
 
        parent = branch.Branch.open('parent')
230
 
        parent.get_config().set_user_option('child_submit_to',
 
208
        self.make_trees()
 
209
        branch = _mod_branch.Branch.open('branch')
 
210
        branch.get_config().set_user_option('mail_client', 'bogus')
 
211
        parent = _mod_branch.Branch.open('parent')
 
212
        parent.get_config().set_user_option('child_submit_to', 
231
213
                           'somebody@example.org')
232
214
        self.run_bzr_error(('Unknown mail client: bogus',),
233
215
                           'send -f branch')
234
216
 
235
217
    def test_format(self):
236
 
        md = self.get_MD(['--format=4'])
 
218
        self.make_trees()
 
219
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
 
220
        md = merge_directive.MergeDirective.from_lines(s.readlines())
237
221
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
238
 
        self.assertFormatIs('# Bazaar revision bundle v4', md)
239
 
 
240
 
        md = self.get_MD(['--format=0.9'])
241
 
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
242
 
 
243
 
        md = self.get_MD(['--format=0.9'], cmd=['bundle'])
244
 
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
 
222
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
 
223
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
224
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
225
            '# Bazaar revision bundle v0.9')
 
226
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
 
227
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
228
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
229
            '# Bazaar revision bundle v0.9')
245
230
        self.assertIs(merge_directive.MergeDirective, md.__class__)
246
 
 
247
231
        self.run_bzr_error(['Bad value .* for option .format.'],
248
232
                            'send -f branch -o- --format=0.999')[0]
249
233
 
250
 
    def test_format_child_option(self):
251
 
        parent_config = branch.Branch.open('parent').get_config()
252
 
        parent_config.set_user_option('child_submit_format', '4')
253
 
        md = self.get_MD([])
254
 
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
255
 
 
256
 
        parent_config.set_user_option('child_submit_format', '0.9')
257
 
        md = self.get_MD([])
258
 
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
259
 
 
260
 
        md = self.get_MD([], cmd=['bundle'])
261
 
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
262
 
        self.assertIs(merge_directive.MergeDirective, md.__class__)
263
 
 
264
 
        parent_config.set_user_option('child_submit_format', '0.999')
265
 
        self.run_bzr_error(["No such send format '0.999'"],
266
 
                            'send -f branch -o-')[0]
267
 
 
268
234
    def test_message_option(self):
 
235
        self.make_trees()
269
236
        self.run_bzr('send', retcode=3)
270
 
        md = self.get_MD([])
 
237
        md = self.send_directive(['--from', 'branch'])
271
238
        self.assertIs(None, md.message)
272
 
        md = self.get_MD(['-m', 'my message'])
 
239
        md = self.send_directive(['--from', 'branch', '-m', 'my message'])
273
240
        self.assertEqual('my message', md.message)
274
241
 
275
242
    def test_omitted_revision(self):
276
 
        md = self.get_MD(['-r-2..'])
277
 
        self.assertEqual('rev2', md.base_revision_id)
278
 
        self.assertEqual('rev3', md.revision_id)
279
 
        md = self.get_MD(['-r..3', '--from', 'branch', 'grandparent'], wd='.')
280
 
        self.assertEqual('rev1', md.base_revision_id)
281
 
        self.assertEqual('rev3', md.revision_id)
 
243
        self.make_trees()
 
244
        md = self.send_directive(['-r-2..', '--from', 'branch'])
 
245
        self.assertEqual('revision2', md.base_revision_id)
 
246
        self.assertEqual('revision3', md.revision_id)
 
247
        md = self.send_directive(['-r..3', '--from', 'branch',
 
248
                                 'grandparent'])
 
249
        self.assertEqual('revision1', md.base_revision_id)
 
250
        self.assertEqual('revision3', md.revision_id)
282
251
 
283
252
    def test_nonexistant_branch(self):
284
 
        self.vfs_transport_factory = memory.MemoryServer
285
 
        location = self.get_url('absentdir/')
 
253
        if sys.platform == "win32":
 
254
            location = "C:/i/do/not/exist/"
 
255
        else:
 
256
            location = "/i/do/not/exist/"
286
257
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
287
258
        self.assertEqual(out, '')
288
259
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
289
 
 
290
 
 
291
 
class TestSendStrictMixin(TestSendMixin):
292
 
 
293
 
    def make_parent_and_local_branches(self):
294
 
        # Create a 'parent' branch as the base
295
 
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
296
 
        self.build_tree_contents([('parent/file', 'parent')])
297
 
        self.parent_tree.add('file')
298
 
        self.parent_tree.commit('first commit', rev_id='parent')
299
 
        # Branch 'local' from parent and do a change
300
 
        local_bzrdir = self.parent_tree.bzrdir.sprout('local')
301
 
        self.local_tree = local_bzrdir.open_workingtree()
302
 
        self.build_tree_contents([('local/file', 'local')])
303
 
        self.local_tree.commit('second commit', rev_id='local')
304
 
 
305
 
    _default_command = ['send', '-o-', '../parent']
306
 
    _default_wd = 'local'
307
 
    _default_sent_revs = ['local']
308
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
309
 
                       'changes \(See bzr status\)\.',]
310
 
    _default_additional_error = 'Use --no-strict to force the send.\n'
311
 
    _default_additional_warning = 'Uncommitted changes will not be sent.'
312
 
 
313
 
    def set_config_send_strict(self, value):
314
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
315
 
        # should do)
316
 
        conf = self.local_tree.branch.get_config()
317
 
        conf.set_user_option('send_strict', value)
318
 
 
319
 
    def assertSendFails(self, args):
320
 
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
321
 
        self.assertContainsRe(err, self._default_additional_error)
322
 
 
323
 
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
324
 
        if with_warning:
325
 
            err_re = self._default_errors
326
 
        else:
327
 
            err_re = []
328
 
        if revs is None:
329
 
            revs = self._default_sent_revs
330
 
        out, err = self.run_send(args, err_re=err_re)
331
 
        bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
332
 
        if with_warning:
333
 
            self.assertContainsRe(err, self._default_additional_warning)
334
 
            self.assertEndsWith(err, bundling_revs)
335
 
        else:
336
 
            self.assertEquals(bundling_revs, err)
337
 
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
338
 
        self.assertEqual('parent', md.base_revision_id)
339
 
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
340
 
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
341
 
 
342
 
 
343
 
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
344
 
                                   TestSendStrictMixin):
345
 
 
346
 
    def setUp(self):
347
 
        super(TestSendStrictWithoutChanges, self).setUp()
348
 
        self.make_parent_and_local_branches()
349
 
 
350
 
    def test_send_default(self):
351
 
        self.assertSendSucceeds([])
352
 
 
353
 
    def test_send_strict(self):
354
 
        self.assertSendSucceeds(['--strict'])
355
 
 
356
 
    def test_send_no_strict(self):
357
 
        self.assertSendSucceeds(['--no-strict'])
358
 
 
359
 
    def test_send_config_var_strict(self):
360
 
        self.set_config_send_strict('true')
361
 
        self.assertSendSucceeds([])
362
 
 
363
 
    def test_send_config_var_no_strict(self):
364
 
        self.set_config_send_strict('false')
365
 
        self.assertSendSucceeds([])
366
 
 
367
 
 
368
 
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
369
 
                                   TestSendStrictMixin):
370
 
 
371
 
    _changes_type = None # Set by load_tests
372
 
 
373
 
    def setUp(self):
374
 
        super(TestSendStrictWithChanges, self).setUp()
375
 
        # load tests set _changes_types to the name of the method we want to
376
 
        # call now
377
 
        do_changes_func = getattr(self, self._changes_type)
378
 
        do_changes_func()
379
 
 
380
 
    def _uncommitted_changes(self):
381
 
        self.make_parent_and_local_branches()
382
 
        # Make a change without committing it
383
 
        self.build_tree_contents([('local/file', 'modified')])
384
 
 
385
 
    def _pending_merges(self):
386
 
        self.make_parent_and_local_branches()
387
 
        # Create 'other' branch containing a new file
388
 
        other_bzrdir = self.parent_tree.bzrdir.sprout('other')
389
 
        other_tree = other_bzrdir.open_workingtree()
390
 
        self.build_tree_contents([('other/other-file', 'other')])
391
 
        other_tree.add('other-file')
392
 
        other_tree.commit('other commit', rev_id='other')
393
 
        # Merge and revert, leaving a pending merge
394
 
        self.local_tree.merge_from_branch(other_tree.branch)
395
 
        self.local_tree.revert(filenames=['other-file'], backups=False)
396
 
 
397
 
    def _out_of_sync_trees(self):
398
 
        self.make_parent_and_local_branches()
399
 
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
400
 
        # Make a change and commit it
401
 
        self.build_tree_contents([('local/file', 'modified in local')])
402
 
        self.local_tree.commit('modify file', rev_id='modified-in-local')
403
 
        # Exercise commands from the checkout directory
404
 
        self._default_wd = 'checkout'
405
 
        self._default_errors = ["Working tree is out of date, please run"
406
 
                                " 'bzr update'\.",]
407
 
        self._default_sent_revs = ['modified-in-local', 'local']
408
 
 
409
 
    def test_send_default(self):
410
 
        self.assertSendSucceeds([], with_warning=True)
411
 
 
412
 
    def test_send_with_revision(self):
413
 
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
414
 
 
415
 
    def test_send_no_strict(self):
416
 
        self.assertSendSucceeds(['--no-strict'])
417
 
 
418
 
    def test_send_strict_with_changes(self):
419
 
        self.assertSendFails(['--strict'])
420
 
 
421
 
    def test_send_respect_config_var_strict(self):
422
 
        self.set_config_send_strict('true')
423
 
        self.assertSendFails([])
424
 
        self.assertSendSucceeds(['--no-strict'])
425
 
 
426
 
    def test_send_bogus_config_var_ignored(self):
427
 
        self.set_config_send_strict("I'm unsure")
428
 
        self.assertSendSucceeds([], with_warning=True)
429
 
 
430
 
    def test_send_no_strict_command_line_override_config(self):
431
 
        self.set_config_send_strict('true')
432
 
        self.assertSendFails([])
433
 
        self.assertSendSucceeds(['--no-strict'])
434
 
 
435
 
    def test_send_strict_command_line_override_config(self):
436
 
        self.set_config_send_strict('false')
437
 
        self.assertSendSucceeds([])
438
 
        self.assertSendFails(['--strict'])
439
 
 
440
 
 
441
 
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
442
 
 
443
 
    _default_command = ['bundle-revisions', '../parent']