/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

(igc) Improve paths are not versioned reporting (Benoît PIERRE)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
 
 
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):
 
29
 
 
30
 
 
31
def read_bundle(fileobj):
 
32
    md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
 
33
    return serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
34
 
 
35
 
 
36
class TestSend(tests.TestCaseWithTransport):
80
37
 
81
38
    def setUp(self):
82
39
        super(TestSend, self).setUp()
94
51
        self.build_tree_contents([('branch/file1', 'branch')])
95
52
        branch_tree.commit('last commit', rev_id='rev3')
96
53
 
 
54
    def run_send(self, args, cmd=None, rc=0, wd='branch'):
 
55
        if cmd is None:
 
56
            cmd = ['send', '-o-']
 
57
        return self.run_bzr(cmd + args, retcode=rc, working_dir=wd)
 
58
 
 
59
    def get_MD(self, args, cmd=None, wd='branch'):
 
60
        out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
 
61
        return merge_directive.MergeDirective.from_lines(out.readlines())
 
62
 
 
63
    def get_bundle(self, args, cmd=None, wd='branch'):
 
64
        md = self.get_MD(args, cmd=cmd, wd=wd)
 
65
        return serializer.read_bundle(StringIO(md.get_raw_bundle()))
 
66
 
 
67
    def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
 
68
        out = self.run_send(args, cmd=cmd, wd=wd)[0]
 
69
        br = read_bundle(StringIO(out))
 
70
        self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
 
71
 
97
72
    def assertFormatIs(self, fmt_string, md):
98
73
        self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
99
74
 
281
256
        self.assertEqual('rev3', md.revision_id)
282
257
 
283
258
    def test_nonexistant_branch(self):
284
 
        self.vfs_transport_factory = memory.MemoryServer
285
 
        location = self.get_url('absentdir/')
 
259
        if sys.platform == "win32":
 
260
            location = "C:/i/do/not/exist/"
 
261
        else:
 
262
            location = "/i/do/not/exist/"
286
263
        out, err = self.run_bzr(["send", "--from", location], retcode=3)
287
264
        self.assertEqual(out, '')
288
265
        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']