~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2007-08-14 03:59:22 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070814035922-siavg542cwvkf4r5
Fix pretty doc generation so works for all html docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 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
 
 
19
 
import sys
20
 
from cStringIO import StringIO
21
 
 
22
 
from bzrlib import (
23
 
    branch,
24
 
    bzrdir,
25
 
    merge_directive,
26
 
    tests,
27
 
    )
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
import os
 
20
from StringIO import StringIO
 
21
 
 
22
from bzrlib import merge_directive
28
23
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')
 
24
from bzrlib.bzrdir import BzrDir
 
25
from bzrlib import tests
 
26
 
 
27
 
 
28
def read_bundle(fileobj):
 
29
    md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
 
30
    return serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
31
 
 
32
 
 
33
class TestSend(tests.TestCaseWithTransport):
 
34
 
 
35
    def make_trees(self):
 
36
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
85
37
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
86
38
        grandparent_tree.add('file1')
87
 
        grandparent_tree.commit('initial commit', rev_id='rev1')
88
 
 
 
39
        grandparent_tree.commit('initial commit', rev_id='revision1')
89
40
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
90
41
        parent_tree = parent_bzrdir.open_workingtree()
91
 
        parent_tree.commit('next commit', rev_id='rev2')
92
 
 
 
42
        parent_tree.commit('next commit', rev_id='revision2')
93
43
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
94
44
        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])
 
45
        branch_tree.commit('last commit', rev_id='revision3')
99
46
 
100
47
    def test_uses_parent(self):
101
48
        """Parent location is used as a basis by default"""
102
 
        errmsg = self.run_send([], rc=3, wd='grandparent')[1]
 
49
        self.make_trees()
 
50
        os.chdir('grandparent')
 
51
        errmsg = self.run_bzr('send -o-', retcode=3)[1]
103
52
        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'], [])
 
53
        os.chdir('../branch')
 
54
        stdout, stderr = self.run_bzr('send -o-')
 
55
        self.assertEqual(stderr.count('Using saved location'), 1)
 
56
        br = read_bundle(StringIO(stdout))
 
57
        self.assertRevisions(br, ['revision3'])
107
58
 
108
59
    def test_bundle(self):
109
60
        """Bundle works like send, except -o is not required"""
110
 
        errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
 
61
        self.make_trees()
 
62
        os.chdir('grandparent')
 
63
        errmsg = self.run_bzr('bundle', retcode=3)[1]
111
64
        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'])
 
65
        os.chdir('../branch')
 
66
        stdout, stderr = self.run_bzr('bundle')
 
67
        self.assertEqual(stderr.count('Using saved location'), 1)
 
68
        br = read_bundle(StringIO(stdout))
 
69
        self.assertRevisions(br, ['revision3'])
 
70
 
 
71
    def assertRevisions(self, bi, expected):
 
72
        self.assertEqual(set(r.revision_id for r in bi.revisions),
 
73
            set(expected))
115
74
 
116
75
    def test_uses_submit(self):
117
76
        """Submit location can be used and set"""
118
 
        self.assertBundleContains(['rev3'], [])
119
 
        self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
 
77
        self.make_trees()
 
78
        os.chdir('branch')
 
79
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
80
        self.assertRevisions(br, ['revision3'])
 
81
        br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
82
        self.assertRevisions(br, ['revision3', 'revision2'])
120
83
        # 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,
 
84
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
85
        self.assertRevisions(br, ['revision3', 'revision2'])
 
86
        self.run_bzr('send ../parent -o-')
 
87
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
88
        self.assertRevisions(br, ['revision3', 'revision2'])
 
89
        self.run_bzr('send ../parent --remember -o-')
 
90
        br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
 
91
        self.assertRevisions(br, ['revision3'])
 
92
        err = self.run_bzr('send --remember -o-', retcode=3)[1]
 
93
        self.assertContainsRe(err, 
133
94
                              '--remember requires a branch to be specified.')
134
95
 
135
96
    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)
 
97
        self.make_trees()
 
98
        os.chdir('branch')
 
99
        bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
 
100
        self.assertRevisions(bi, ['revision3', 'revision2'])
 
101
        out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
 
102
        bi = read_bundle(out)
 
103
        self.assertRevisions(bi, ['revision2'])
 
104
        sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
 
105
        md = merge_directive.MergeDirective.from_lines(sio.readlines())
 
106
        self.assertEqual('revision2', md.base_revision_id)
 
107
        self.assertEqual('revision3', md.revision_id)
 
108
        sio.seek(0)
 
109
        bi = read_bundle(sio)
 
110
        self.assertRevisions(bi, ['revision2', 'revision3'])
 
111
        self.run_bzr('send ../grandparent -r -2..-1 -o-')
143
112
 
144
113
    def test_output(self):
145
114
        # check output for consistency
146
115
        # win32 stdout converts LF to CRLF,
147
116
        # which would break patch-based bundles
148
 
        self.assertBundleContains(['rev3'], [])
 
117
        self.make_trees()        
 
118
        os.chdir('branch')
 
119
        stdout = self.run_bzr_subprocess('send', '-o-')[0]
 
120
        br = read_bundle(StringIO(stdout))
 
121
        self.assertRevisions(br, ['revision3'])
149
122
 
150
123
    def test_no_common_ancestor(self):
151
124
        foo = self.make_branch_and_tree('foo')
152
125
        foo.commit('rev a')
153
126
        bar = self.make_branch_and_tree('bar')
154
127
        bar.commit('rev b')
155
 
        self.run_send(['--from', 'foo', '../bar'], wd='foo')
 
128
        os.chdir('foo')
 
129
        self.run_bzr('send ../bar -o-')
 
130
 
 
131
    def send_directive(self, args):
 
132
        sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
 
133
        return merge_directive.MergeDirective.from_lines(sio.readlines())
156
134
 
157
135
    def test_content_options(self):
158
136
        """--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'])
 
137
        self.make_trees()
 
138
        os.chdir('branch')
 
139
        md = self.send_directive([])
 
140
        self.assertIsNot(None, md.bundle)
 
141
        self.assertIsNot(None, md.patch)
 
142
 
 
143
        md = self.send_directive(['--format=0.9'])
 
144
        self.assertIsNot(None, md.bundle)
 
145
        self.assertIsNot(None, md.patch)
 
146
 
 
147
        md = self.send_directive(['--no-patch'])
168
148
        self.assertIsNot(None, md.bundle)
169
149
        self.assertIs(None, md.patch)
170
150
        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', '.', '.'])
 
151
                      'send --no-patch --format=0.9 -o-')
 
152
 
 
153
        md = self.send_directive(['--no-bundle', '.', '.'])
174
154
        self.assertIs(None, md.bundle)
175
155
        self.assertIsNot(None, md.patch)
176
156
 
177
 
        md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
 
157
        md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
178
158
                                  '.'])
179
159
        self.assertIs(None, md.bundle)
180
160
        self.assertIsNot(None, md.patch)
181
161
 
182
 
        md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
 
162
        md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
183
163
        self.assertIs(None, md.bundle)
184
164
        self.assertIs(None, md.patch)
185
165
 
186
 
        md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
187
 
                          '../parent', '.'])
 
166
        md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
 
167
                                  '../parent', '.'])
188
168
        self.assertIs(None, md.bundle)
189
169
        self.assertIs(None, md.patch)
190
170
 
191
171
    def test_from_option(self):
 
172
        self.make_trees()
192
173
        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)
 
174
        md = self.send_directive(['--from', 'branch'])
 
175
        self.assertEqual('revision3', md.revision_id)
 
176
        md = self.send_directive(['-f', 'branch'])
 
177
        self.assertEqual('revision3', md.revision_id)
197
178
 
198
179
    def test_output_option(self):
 
180
        self.make_trees()
199
181
        stdout = self.run_bzr('send -f branch --output file1')[0]
200
182
        self.assertEqual('', stdout)
201
183
        md_file = open('file1', 'rb')
202
184
        self.addCleanup(md_file.close)
203
 
        self.assertContainsRe(md_file.read(), 'rev3')
 
185
        self.assertContainsRe(md_file.read(), 'revision3')
204
186
        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')
210
 
 
211
 
    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([])
219
 
        self.run_bzr_error(('Unknown mail client: bogus',),
220
 
                           'send -f branch --mail-to jrandom@example.org')
221
 
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
222
 
        self.run_bzr_error(('Unknown mail client: bogus',),
223
 
                           'send -f branch')
224
 
 
225
 
    def test_mailto_child_option(self):
226
 
        """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',
231
 
                           'somebody@example.org')
232
 
        self.run_bzr_error(('Unknown mail client: bogus',),
 
187
        self.assertContainsRe(stdout, 'revision3')
 
188
 
 
189
    def test_output_option_required(self):
 
190
        self.make_trees()
 
191
        self.run_bzr_error(('File must be specified with --output',),
233
192
                           'send -f branch')
234
193
 
235
194
    def test_format(self):
236
 
        md = self.get_MD(['--format=4'])
 
195
        self.make_trees()
 
196
        s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
 
197
        md = merge_directive.MergeDirective.from_lines(s.readlines())
237
198
        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)
 
199
        s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
 
200
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
201
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
202
            '# Bazaar revision bundle v0.9')
 
203
        s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
 
204
        md = merge_directive.MergeDirective.from_lines(s.readlines())
 
205
        self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
 
206
            '# Bazaar revision bundle v0.9')
245
207
        self.assertIs(merge_directive.MergeDirective, md.__class__)
246
 
 
247
208
        self.run_bzr_error(['Bad value .* for option .format.'],
248
209
                            'send -f branch -o- --format=0.999')[0]
249
 
 
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
 
    def test_message_option(self):
269
 
        self.run_bzr('send', retcode=3)
270
 
        md = self.get_MD([])
271
 
        self.assertIs(None, md.message)
272
 
        md = self.get_MD(['-m', 'my message'])
273
 
        self.assertEqual('my message', md.message)
274
 
 
275
 
    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)
282
 
 
283
 
    def test_nonexistant_branch(self):
284
 
        self.vfs_transport_factory = memory.MemoryServer
285
 
        location = self.get_url('absentdir/')
286
 
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
287
 
        self.assertEqual(out, '')
288
 
        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
 
 
311
 
    def set_config_send_strict(self, value):
312
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
313
 
        # should do)
314
 
        conf = self.local_tree.branch.get_config()
315
 
        conf.set_user_option('send_strict', value)
316
 
 
317
 
    def assertSendFails(self, args):
318
 
        self.run_send(args, rc=3, err_re=self._default_errors)
319
 
 
320
 
    def assertSendSucceeds(self, args, revs=None):
321
 
        if revs is None:
322
 
            revs = self._default_sent_revs
323
 
        out, err = self.run_send(args)
324
 
        self.assertEquals(
325
 
            'Bundling %d revision(s).\n' % len(revs), err)
326
 
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
327
 
        self.assertEqual('parent', md.base_revision_id)
328
 
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
329
 
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
330
 
 
331
 
 
332
 
class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
333
 
                                   TestSendStrictMixin):
334
 
 
335
 
    def setUp(self):
336
 
        super(TestSendStrictWithoutChanges, self).setUp()
337
 
        self.make_parent_and_local_branches()
338
 
 
339
 
    def test_send_default(self):
340
 
        self.assertSendSucceeds([])
341
 
 
342
 
    def test_send_strict(self):
343
 
        self.assertSendSucceeds(['--strict'])
344
 
 
345
 
    def test_send_no_strict(self):
346
 
        self.assertSendSucceeds(['--no-strict'])
347
 
 
348
 
    def test_send_config_var_strict(self):
349
 
        self.set_config_send_strict('true')
350
 
        self.assertSendSucceeds([])
351
 
 
352
 
    def test_send_config_var_no_strict(self):
353
 
        self.set_config_send_strict('false')
354
 
        self.assertSendSucceeds([])
355
 
 
356
 
 
357
 
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
358
 
                                   TestSendStrictMixin):
359
 
 
360
 
    _changes_type = None # Set by load_tests
361
 
 
362
 
    def setUp(self):
363
 
        super(TestSendStrictWithChanges, self).setUp()
364
 
        # load tests set _changes_types to the name of the method we want to
365
 
        # call now
366
 
        do_changes_func = getattr(self, self._changes_type)
367
 
        do_changes_func()
368
 
 
369
 
    def _uncommitted_changes(self):
370
 
        self.make_parent_and_local_branches()
371
 
        # Make a change without committing it
372
 
        self.build_tree_contents([('local/file', 'modified')])
373
 
 
374
 
    def _pending_merges(self):
375
 
        self.make_parent_and_local_branches()
376
 
        # Create 'other' branch containing a new file
377
 
        other_bzrdir = self.parent_tree.bzrdir.sprout('other')
378
 
        other_tree = other_bzrdir.open_workingtree()
379
 
        self.build_tree_contents([('other/other-file', 'other')])
380
 
        other_tree.add('other-file')
381
 
        other_tree.commit('other commit', rev_id='other')
382
 
        # Merge and revert, leaving a pending merge
383
 
        self.local_tree.merge_from_branch(other_tree.branch)
384
 
        self.local_tree.revert(filenames=['other-file'], backups=False)
385
 
 
386
 
    def _out_of_sync_trees(self):
387
 
        self.make_parent_and_local_branches()
388
 
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
389
 
        # Make a change and commit it
390
 
        self.build_tree_contents([('local/file', 'modified in local')])
391
 
        self.local_tree.commit('modify file', rev_id='modified-in-local')
392
 
        # Exercise commands from the checkout directory
393
 
        self._default_wd = 'checkout'
394
 
        self._default_errors = ["Working tree is out of date, please run"
395
 
                                " 'bzr update'\.",]
396
 
        self._default_sent_revs = ['modified-in-local', 'local']
397
 
 
398
 
    def test_send_default(self):
399
 
        self.assertSendFails([])
400
 
 
401
 
    def test_send_with_revision(self):
402
 
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
403
 
 
404
 
    def test_send_no_strict(self):
405
 
        self.assertSendSucceeds(['--no-strict'])
406
 
 
407
 
    def test_send_strict_with_changes(self):
408
 
        self.assertSendFails(['--strict'])
409
 
 
410
 
    def test_send_respect_config_var_strict(self):
411
 
        self.set_config_send_strict('true')
412
 
        self.assertSendFails([])
413
 
        self.assertSendSucceeds(['--no-strict'])
414
 
 
415
 
 
416
 
    def test_send_bogus_config_var_ignored(self):
417
 
        self.set_config_send_strict("I'm unsure")
418
 
        self.assertSendFails([])
419
 
 
420
 
 
421
 
    def test_send_no_strict_command_line_override_config(self):
422
 
        self.set_config_send_strict('true')
423
 
        self.assertSendFails([])
424
 
        self.assertSendSucceeds(['--no-strict'])
425
 
 
426
 
    def test_send_strict_command_line_override_config(self):
427
 
        self.set_config_send_strict('false')
428
 
        self.assertSendSucceeds([])
429
 
        self.assertSendFails(['--strict'])
430
 
 
431
 
 
432
 
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
433
 
 
434
 
    _default_command = ['bundle-revisions', '../parent']