~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2009-08-14 18:17:15 UTC
  • mto: (4603.1.22 shelve-editor)
  • mto: This revision was merged to the branch mainline in revision 4795.
  • Revision ID: aaron@aaronbentley.com-20090814181715-59qnhbov2stgzqt2
Allow configuring change editor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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
26
26
    tests,
27
27
    )
28
28
from bzrlib.bundle import serializer
29
 
from bzrlib.transport import memory
30
 
from bzrlib.tests import (
31
 
    scenarios,
32
 
    script,
33
 
    )
34
 
 
35
 
 
36
 
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
37
53
 
38
54
 
39
55
class TestSendMixin(object):
51
67
 
52
68
    def get_MD(self, args, cmd=None, wd='branch'):
53
69
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
54
 
        return merge_directive.MergeDirective.from_lines(out)
 
70
        return merge_directive.MergeDirective.from_lines(out.readlines())
55
71
 
56
72
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
57
73
        md = self.get_MD(args, cmd=cmd, wd=wd)
189
205
 
190
206
    def test_note_revisions(self):
191
207
        stderr = self.run_send([])[1]
192
 
        self.assertEndsWith(stderr, '\nBundling 1 revision.\n')
 
208
        self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
193
209
 
194
210
    def test_mailto_option(self):
195
211
        b = branch.Branch.open('branch')
264
280
        self.assertEqual('rev3', md.revision_id)
265
281
 
266
282
    def test_nonexistant_branch(self):
267
 
        self.vfs_transport_factory = memory.MemoryServer
268
 
        location = self.get_url('absentdir/')
 
283
        if sys.platform == "win32":
 
284
            location = "C:/i/do/not/exist/"
 
285
        else:
 
286
            location = "/i/do/not/exist/"
269
287
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
270
288
        self.assertEqual(out, '')
271
289
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
290
308
    _default_sent_revs = ['local']
291
309
    _default_errors = ['Working tree ".*/local/" has uncommitted '
292
310
                       'changes \(See bzr status\)\.',]
293
 
    _default_additional_error = 'Use --no-strict to force the send.\n'
294
 
    _default_additional_warning = 'Uncommitted changes will not be sent.'
295
311
 
296
312
    def set_config_send_strict(self, value):
297
313
        # set config var (any of bazaar.conf, locations.conf, branch.conf
298
314
        # should do)
299
 
        conf = self.local_tree.branch.get_config_stack()
300
 
        conf.set('send_strict', value)
 
315
        conf = self.local_tree.branch.get_config()
 
316
        conf.set_user_option('send_strict', value)
301
317
 
302
318
    def assertSendFails(self, args):
303
 
        out, err = self.run_send(args, rc=3, err_re=self._default_errors)
304
 
        self.assertContainsRe(err, self._default_additional_error)
 
319
        self.run_send(args, rc=3, err_re=self._default_errors)
305
320
 
306
 
    def assertSendSucceeds(self, args, revs=None, with_warning=False):
307
 
        if with_warning:
308
 
            err_re = self._default_errors
309
 
        else:
310
 
            err_re = []
 
321
    def assertSendSucceeds(self, args, revs=None):
311
322
        if revs is None:
312
323
            revs = self._default_sent_revs
313
 
        out, err = self.run_send(args, err_re=err_re)
314
 
        if len(revs) == 1:
315
 
            bundling_revs = 'Bundling %d revision.\n'% len(revs)
316
 
        else:
317
 
            bundling_revs = 'Bundling %d revisions.\n' % len(revs)
318
 
        if with_warning:
319
 
            self.assertContainsRe(err, self._default_additional_warning)
320
 
            self.assertEndsWith(err, bundling_revs)
321
 
        else:
322
 
            self.assertEquals(bundling_revs, err)
323
 
        md = merge_directive.MergeDirective.from_lines(StringIO(out))
 
324
        out, err = self.run_send(args)
 
325
        self.assertEquals(
 
326
            'Bundling %d revision(s).\n' % len(revs), err)
 
327
        md = merge_directive.MergeDirective.from_lines(
 
328
                StringIO(out).readlines())
324
329
        self.assertEqual('parent', md.base_revision_id)
325
330
        br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
326
331
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
352
357
 
353
358
 
354
359
class TestSendStrictWithChanges(tests.TestCaseWithTransport,
355
 
                                TestSendStrictMixin):
356
 
 
357
 
    # These are textually the same as test_push.strict_push_change_scenarios,
358
 
    # but since the functions are reimplemented here, the definitions are left
359
 
    # here too.
360
 
    scenarios = [
361
 
        ('uncommitted',
362
 
         dict(_changes_type='_uncommitted_changes')),
363
 
        ('pending_merges',
364
 
         dict(_changes_type='_pending_merges')),
365
 
        ('out-of-sync-trees',
366
 
         dict(_changes_type='_out_of_sync_trees')),
367
 
        ]
 
360
                                   TestSendStrictMixin):
368
361
 
369
362
    _changes_type = None # Set by load_tests
370
363
 
405
398
        self._default_sent_revs = ['modified-in-local', 'local']
406
399
 
407
400
    def test_send_default(self):
408
 
        self.assertSendSucceeds([], with_warning=True)
 
401
        self.assertSendFails([])
409
402
 
410
403
    def test_send_with_revision(self):
411
404
        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
421
414
        self.assertSendFails([])
422
415
        self.assertSendSucceeds(['--no-strict'])
423
416
 
 
417
 
424
418
    def test_send_bogus_config_var_ignored(self):
425
419
        self.set_config_send_strict("I'm unsure")
426
 
        self.assertSendSucceeds([], with_warning=True)
 
420
        self.assertSendFails([])
 
421
 
427
422
 
428
423
    def test_send_no_strict_command_line_override_config(self):
429
424
        self.set_config_send_strict('true')
430
425
        self.assertSendFails([])
431
426
        self.assertSendSucceeds(['--no-strict'])
432
427
 
433
 
    def test_send_strict_command_line_override_config(self):
 
428
    def test_push_strict_command_line_override_config(self):
434
429
        self.set_config_send_strict('false')
435
430
        self.assertSendSucceeds([])
436
431
        self.assertSendFails(['--strict'])