~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2009-11-18 15:47:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4810.
  • Revision ID: john@arbash-meinel.com-20091118154716-meiszr5ej7ohas3v
Move all the stat comparison and platform checkning code to assertEqualStat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
# Authors: Aaron Bentley
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
 
 
19
import sys
19
20
from cStringIO import StringIO
20
21
 
21
22
from bzrlib import (
22
23
    branch,
 
24
    bzrdir,
23
25
    merge_directive,
24
26
    tests,
25
27
    )
26
 
from bzrlib.controldir import ControlDir
27
28
from bzrlib.bundle import serializer
28
 
from bzrlib.transport import memory
29
 
from bzrlib.tests import (
30
 
    scenarios,
31
 
    )
32
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
33
 
 
34
 
 
35
 
load_tests = scenarios.load_tests_apply_scenarios
 
29
 
 
30
 
 
31
def load_tests(standard_tests, module, loader):
 
32
    """Multiply tests for the send command."""
 
33
    result = loader.suiteClass()
 
34
 
 
35
    # one for each king of change
 
36
    changes_tests, remaining_tests = tests.split_suite_by_condition(
 
37
        standard_tests, tests.condition_isinstance((
 
38
                TestSendStrictWithChanges,
 
39
                )))
 
40
    changes_scenarios = [
 
41
        ('uncommitted',
 
42
         dict(_changes_type='_uncommitted_changes')),
 
43
        ('pending_merges',
 
44
         dict(_changes_type='_pending_merges')),
 
45
        ('out-of-sync-trees',
 
46
         dict(_changes_type='_out_of_sync_trees')),
 
47
        ]
 
48
    tests.multiply_tests(changes_tests, changes_scenarios, result)
 
49
    # No parametrization for the remaining tests
 
50
    result.addTests(remaining_tests)
 
51
 
 
52
    return result
36
53
 
37
54
 
38
55
class TestSendMixin(object):
50
67
 
51
68
    def get_MD(self, args, cmd=None, wd='branch'):
52
69
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
53
 
        return merge_directive.MergeDirective.from_lines(out)
 
70
        return merge_directive.MergeDirective.from_lines(out.readlines())
54
71
 
55
72
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
56
73
        md = self.get_MD(args, cmd=cmd, wd=wd)
62
79
 
63
80
    def setUp(self):
64
81
        super(TestSend, self).setUp()
65
 
        grandparent_tree = ControlDir.create_standalone_workingtree(
 
82
        grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
66
83
            'grandparent')
67
84
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
68
85
        grandparent_tree.add('file1')
188
205
 
189
206
    def test_note_revisions(self):
190
207
        stderr = self.run_send([])[1]
191
 
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
 
208
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
192
209
 
193
210
    def test_mailto_option(self):
194
211
        b = branch.Branch.open('branch')
195
 
        b.get_config_stack().set('mail_client', 'editor')
 
212
        b.get_config().set_user_option('mail_client', 'editor')
196
213
        self.run_bzr_error(
197
214
            ('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
198
215
            ), 'send -f branch')
199
 
        b.get_config_stack().set('mail_client', 'bogus')
 
216
        b.get_config().set_user_option('mail_client', 'bogus')
200
217
        self.run_send([])
201
 
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
 
218
        self.run_bzr_error(('Unknown mail client: bogus',),
202
219
                           'send -f branch --mail-to jrandom@example.org')
203
 
        b.get_config_stack().set('submit_to', 'jrandom@example.org')
204
 
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
 
220
        b.get_config().set_user_option('submit_to', 'jrandom@example.org')
 
221
        self.run_bzr_error(('Unknown mail client: bogus',),
205
222
                           'send -f branch')
206
223
 
207
224
    def test_mailto_child_option(self):
208
225
        """Make sure that child_submit_to is used."""
209
226
        b = branch.Branch.open('branch')
210
 
        b.get_config_stack().set('mail_client', 'bogus')
 
227
        b.get_config().set_user_option('mail_client', 'bogus')
211
228
        parent = branch.Branch.open('parent')
212
 
        parent.get_config_stack().set('child_submit_to', 'somebody@example.org')
213
 
        self.run_bzr_error(('Bad value "bogus" for option "mail_client"',),
214
 
                'send -f branch')
 
229
        parent.get_config().set_user_option('child_submit_to',
 
230
                           'somebody@example.org')
 
231
        self.run_bzr_error(('Unknown mail client: bogus',),
 
232
                           'send -f branch')
215
233
 
216
234
    def test_format(self):
217
235
        md = self.get_MD(['--format=4'])
229
247
                            'send -f branch -o- --format=0.999')[0]
230
248
 
231
249
    def test_format_child_option(self):
232
 
        br = branch.Branch.open('parent')
233
 
        conf = br.get_config_stack()
234
 
        conf.set('child_submit_format', '4')
 
250
        parent_config = branch.Branch.open('parent').get_config()
 
251
        parent_config.set_user_option('child_submit_format', '4')
235
252
        md = self.get_MD([])
236
253
        self.assertIs(merge_directive.MergeDirective2, md.__class__)
237
254
 
238
 
        conf.set('child_submit_format', '0.9')
 
255
        parent_config.set_user_option('child_submit_format', '0.9')
239
256
        md = self.get_MD([])
240
257
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
241
258
 
243
260
        self.assertFormatIs('# Bazaar revision bundle v0.9', md)
244
261
        self.assertIs(merge_directive.MergeDirective, md.__class__)
245
262
 
246
 
        conf.set('child_submit_format', '0.999')
 
263
        parent_config.set_user_option('child_submit_format', '0.999')
247
264
        self.run_bzr_error(["No such send format '0.999'"],
248
265
                            'send -f branch -o-')[0]
249
266
 
263
280
        self.assertEqual('rev3', md.revision_id)
264
281
 
265
282
    def test_nonexistant_branch(self):
266
 
        self.vfs_transport_factory = memory.MemoryServer
 
283
        self.vfs_transport_factory = tests.MemoryServer
267
284
        location = self.get_url('absentdir/')
268
285
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
269
286
        self.assertEqual(out, '')
274
291
 
275
292
    def make_parent_and_local_branches(self):
276
293
        # Create a 'parent' branch as the base
277
 
        self.parent_tree = ControlDir.create_standalone_workingtree('parent')
 
294
        self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
278
295
        self.build_tree_contents([('parent/file', 'parent')])
279
296
        self.parent_tree.add('file')
280
297
        self.parent_tree.commit('first commit', rev_id='parent')
289
306
    _default_sent_revs = ['local']
290
307
    _default_errors = ['Working tree ".*/local/" has uncommitted '
291
308
                       'changes \(See bzr status\)\.',]
292
 
    _default_additional_error = 'Use --no-strict to force the send.\n'
293
 
    _default_additional_warning = 'Uncommitted changes will not be sent.'
294
309
 
295
310
    def set_config_send_strict(self, value):
296
 
        br = branch.Branch.open('local')
297
 
        br.get_config_stack().set('send_strict', value)
 
311
        # set config var (any of bazaar.conf, locations.conf, branch.conf
 
312
        # should do)
 
313
        conf = self.local_tree.branch.get_config()
 
314
        conf.set_user_option('send_strict', value)
298
315
 
299
316
    def assertSendFails(self, args):
300
 
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
301
 
        self.assertContainsRe(err, self._default_additional_error)
 
317
        self.run_send(args, rc=3, err_re=self._default_errors)
302
318
 
303
 
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
304
 
        if with_warning:
305
 
            err_re = self._default_errors
306
 
        else:
307
 
            err_re = []
 
319
    def assertSendSucceeds(self, args, revs=None):
308
320
        if revs is None:
309
321
            revs = self._default_sent_revs
310
 
        out, err = self.run_send(args, err_re=err_re)
311
 
        if len(revs) == 1:
312
 
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
313
 
        else:
314
 
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
315
 
        if with_warning:
316
 
            self.assertContainsRe(err, self._default_additional_warning)
317
 
            self.assertEndsWith(err, bundling_revs)
318
 
        else:
319
 
            self.assertEqual(bundling_revs, err)
320
 
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
 
322
        out, err = self.run_send(args)
 
323
        self.assertEquals(
 
324
            'Bundling %d revision(s).\n' % len(revs), err)
 
325
        md = merge_directive.MergeDirective.from_lines(
 
326
                StringIO(out).readlines())
321
327
        self.assertEqual('parent', md.base_revision_id)
322
328
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
323
329
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
330
336
        super(TestSendStrictWithoutChanges, self).setUp()
331
337
        self.make_parent_and_local_branches()
332
338
 
333
 
    def test_send_without_workingtree(self):
334
 
        ControlDir.open("local").destroy_workingtree()
335
 
        self.assertSendSucceeds([])
336
 
 
337
339
    def test_send_default(self):
338
340
        self.assertSendSucceeds([])
339
341
 
353
355
 
354
356
 
355
357
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
356
 
                                TestSendStrictMixin):
357
 
 
358
 
    # These are textually the same as test_push.strict_push_change_scenarios,
359
 
    # but since the functions are reimplemented here, the definitions are left
360
 
    # here too.
361
 
    scenarios = [
362
 
        ('uncommitted',
363
 
         dict(_changes_type='_uncommitted_changes')),
364
 
        ('pending_merges',
365
 
         dict(_changes_type='_pending_merges')),
366
 
        ('out-of-sync-trees',
367
 
         dict(_changes_type='_out_of_sync_trees')),
368
 
        ]
 
358
                                   TestSendStrictMixin):
369
359
 
370
360
    _changes_type = None # Set by load_tests
371
361
 
406
396
        self._default_sent_revs = ['modified-in-local', 'local']
407
397
 
408
398
    def test_send_default(self):
409
 
        self.assertSendSucceeds([], with_warning=True)
 
399
        self.assertSendFails([])
410
400
 
411
401
    def test_send_with_revision(self):
412
402
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
422
412
        self.assertSendFails([])
423
413
        self.assertSendSucceeds(['--no-strict'])
424
414
 
 
415
 
425
416
    def test_send_bogus_config_var_ignored(self):
426
417
        self.set_config_send_strict("I'm unsure")
427
 
        self.assertSendSucceeds([], with_warning=True)
 
418
        self.assertSendFails([])
 
419
 
428
420
 
429
421
    def test_send_no_strict_command_line_override_config(self):
430
422
        self.set_config_send_strict('true')
440
432
class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
441
433
 
442
434
    _default_command = ['bundle-revisions', '../parent']
443
 
 
444
 
 
445
 
class TestSmartServerSend(tests.TestCaseWithTransport):
446
 
 
447
 
    def test_send(self):
448
 
        self.setup_smart_server_with_call_log()
449
 
        t = self.make_branch_and_tree('branch')
450
 
        self.build_tree_contents([('branch/foo', 'thecontents')])
451
 
        t.add("foo")
452
 
        t.commit("message")
453
 
        local = t.bzrdir.sprout('local-branch').open_workingtree()
454
 
        self.build_tree_contents([('branch/foo', 'thenewcontents')])
455
 
        local.commit("anothermessage")
456
 
        self.reset_smart_call_log()
457
 
        out, err = self.run_bzr(
458
 
            ['send', '-o', 'x.diff', self.get_url('branch')], working_dir='local-branch')
459
 
        # This figure represent the amount of work to perform this use case. It
460
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
461
 
        # being too low. If rpc_count increases, more network roundtrips have
462
 
        # become necessary for this use case. Please do not adjust this number
463
 
        # upwards without agreement from bzr's network support maintainers.
464
 
        self.assertLength(7, self.hpss_calls)
465
 
        self.assertLength(1, self.hpss_connections)
466
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)