/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/test_commit.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
import os
19
19
 
20
20
import bzrlib
21
 
from bzrlib import errors, osutils, tests
22
 
from bzrlib.tests import TestCaseWithTransport
 
21
from bzrlib import (
 
22
    errors,
 
23
    lockdir,
 
24
    osutils,
 
25
    tests,
 
26
    )
23
27
from bzrlib.branch import Branch
24
28
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
25
 
from bzrlib.workingtree import WorkingTree
26
29
from bzrlib.commit import Commit, NullCommitReporter
27
30
from bzrlib.config import BranchConfig
28
31
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed, 
29
32
                           LockContention)
 
33
from bzrlib.tests import TestCaseWithTransport
 
34
from bzrlib.workingtree import WorkingTree
30
35
 
31
36
 
32
37
# TODO: Test commit with some added, and added-but-missing files
408
413
        bound = master.sprout('bound')
409
414
        wt = bound.open_workingtree()
410
415
        wt.branch.set_bound_location(os.path.realpath('master'))
 
416
 
 
417
        orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
411
418
        master_branch.lock_write()
412
419
        try:
 
420
            lockdir._DEFAULT_TIMEOUT_SECONDS = 1
413
421
            self.assertRaises(LockContention, wt.commit, 'silly')
414
422
        finally:
 
423
            lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
415
424
            master_branch.unlock()
416
425
 
417
426
    def test_commit_bound_merge(self):
595
604
        tree = self.make_branch_and_tree('.')
596
605
        self.assertRaises(errors.PathsNotVersionedError, tree.commit, 
597
606
                          'message', specific_files=['bogus'])
 
607
 
 
608
    class Callback(object):
 
609
        
 
610
        def __init__(self, message, testcase):
 
611
            self.called = False
 
612
            self.message = message
 
613
            self.testcase = testcase
 
614
 
 
615
        def __call__(self, commit_obj):
 
616
            self.called = True
 
617
            self.testcase.assertTrue(isinstance(commit_obj, Commit))
 
618
            return self.message
 
619
 
 
620
    def test_commit_callback(self):
 
621
        """Commit should invoke a callback to get the message"""
 
622
 
 
623
        tree = self.make_branch_and_tree('.')
 
624
        try:
 
625
            tree.commit()
 
626
        except Exception, e:
 
627
            self.assertTrue(isinstance(e, BzrError))
 
628
            self.assertEqual('The message or message_callback keyword'
 
629
                             ' parameter is required for commit().', str(e))
 
630
        else:
 
631
            self.fail('exception not raised')
 
632
        cb = self.Callback(u'commit 1', self)
 
633
        tree.commit(message_callback=cb)
 
634
        self.assertTrue(cb.called)
 
635
        repository = tree.branch.repository
 
636
        message = repository.get_revision(tree.last_revision()).message
 
637
        self.assertEqual('commit 1', message)
 
638
 
 
639
    def test_no_callback_pointless(self):
 
640
        """Callback should not be invoked for pointless commit"""
 
641
        tree = self.make_branch_and_tree('.')
 
642
        cb = self.Callback(u'commit 2', self)
 
643
        self.assertRaises(PointlessCommit, tree.commit, message_callback=cb, 
 
644
                          allow_pointless=False)
 
645
        self.assertFalse(cb.called)
 
646
 
 
647
    def test_no_callback_netfailure(self):
 
648
        """Callback should not be invoked if connectivity fails"""
 
649
        tree = self.make_branch_and_tree('.')
 
650
        cb = self.Callback(u'commit 2', self)
 
651
        repository = tree.branch.repository
 
652
        # simulate network failure
 
653
        def raise_(self, arg, arg2):
 
654
            raise errors.NoSuchFile('foo')
 
655
        repository.add_inventory = raise_
 
656
        self.assertRaises(errors.NoSuchFile, tree.commit, message_callback=cb)
 
657
        self.assertFalse(cb.called)